diff --git a/src/app/accounts/addcredit/addcredit.page.html b/src/app/accounts/addcredit/addcredit.page.html index 961e5a9..a92e181 100644 --- a/src/app/accounts/addcredit/addcredit.page.html +++ b/src/app/accounts/addcredit/addcredit.page.html @@ -33,7 +33,7 @@ Amount({{currency_code}}) : Amount({{currency_code}}) : @@ -180,6 +181,7 @@ - + + {{item}} + + + + + + {{item[1]}} + - - - + placeholder="CVV"> - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/app/accounts/addcredit/addcredit.page.ts b/src/app/accounts/addcredit/addcredit.page.ts index 5108d3d..52feddf 100644 --- a/src/app/accounts/addcredit/addcredit.page.ts +++ b/src/app/accounts/addcredit/addcredit.page.ts @@ -1,125 +1,154 @@ -import { Component, OnInit } from '@angular/core'; -import {AlertController, LoadingController, NavController} from "@ionic/angular"; -import {Router} from "@angular/router"; -import {SessionDataProviderService} from "../../store/session-data-provider.service"; -import {WrenchService} from "../../services/wrench.service"; -import {BlogDataService} from "../../store/blog-data.service"; -import {UserWalletService} from "../../store/user-wallet.service"; -import {Unary} from "@angular/compiler"; -import {Flutterwave, AsyncPaymentOptions, PaymentSuccessResponse} from "flutterwave-angular-v3" +import { Component, OnInit } from "@angular/core"; +import { + AlertController, + LoadingController, + NavController, +} from "@ionic/angular"; +import { Router } from "@angular/router"; +import { SessionDataProviderService } from "../../store/session-data-provider.service"; +import { WrenchService } from "../../services/wrench.service"; +import { BlogDataService } from "../../store/blog-data.service"; +import { UserWalletService } from "../../store/user-wallet.service"; +import { Unary } from "@angular/compiler"; +import { + Flutterwave, + AsyncPaymentOptions, + PaymentSuccessResponse, +} from "flutterwave-angular-v3"; @Component({ - selector: 'app-addcredit', - templateUrl: './addcredit.page.html', - styleUrls: ['./addcredit.page.scss'], + selector: "app-addcredit", + templateUrl: "./addcredit.page.html", + styleUrls: ["./addcredit.page.scss"], }) export class AddcreditPage implements OnInit { - walletData:any; - tabs = 'bank_redeem'; - curr_balance:number =0; - currency_description : string=''; - currency_code:string=''; - wallet_uid:string=''; - isDisabled:boolean=true; - isProcessDisabled:boolean=false; - curr_page:string= 'redeem_start'; - processor:number=0; - isModalOpen:boolean = false; - isModalOpenBackdrop:boolean = false; - card_level:number=200; - flutterwave_key:string=''; + walletData: any; + tabs = "bank_redeem"; + curr_balance: number = 0; + currency_description: string = ""; + currency_code: string = ""; + wallet_uid: string = ""; + isDisabled: boolean = true; + isProcessDisabled: boolean = false; + curr_page: string = "redeem_start"; + processor: number = 0; + isModalOpen: boolean = false; + isModalOpenBackdrop: boolean = false; + card_level: number = 200; + flutterwave_key: string = ""; - card_count:number = 0; + card_count: number = 0; - publicKey = "FLWPUBK_TEST-XXXXXXXXX"; + publicKey = "FLWPUBK_TEST-XXXXXXXXX"; - customerDetails = { name: 'Demo Customer Name', email: 'customer@mail.com', phone_number: '08100000000'} + customerDetails = { + name: "Demo Customer Name", + email: "customer@mail.com", + phone_number: "08100000000", + }; - customizations = {title: 'Customization Title', description: 'Customization Description', - logo: 'https://www.wrenchboard.com/assets/ext/images/wrench-icon.png'} + customizations = { + title: "Customization Title", + description: "Customization Description", + logo: "https://www.wrenchboard.com/assets/ext/images/wrench-icon.png", + }; - meta: {counsumer_id: string, consumer_mac:string}; + meta: { counsumer_id: string; consumer_mac: string }; - paymentData : AsyncPaymentOptions = { - public_key: this.publicKey, - tx_ref: this.generateReference(), - amount: 10, - currency: 'NGN', - payment_options: 'card,ussd', - meta: '', - customer: this.customerDetails, - customizations: this.customizations, + paymentData: AsyncPaymentOptions = { + public_key: this.publicKey, + tx_ref: this.generateReference(), + amount: 10, + currency: "NGN", + payment_options: "card,ussd", + meta: "", + customer: this.customerDetails, + customizations: this.customizations, + }; + + monthsData:any; + cardExpirationYears:any; + + constructor( + private navctr: NavController, + private router: Router, + public sessionDataProviderService: SessionDataProviderService, + private wrenchService: WrenchService, + public blogDataService: BlogDataService, + private loadingCtrl: LoadingController, + public alertController: AlertController, + private flutterwave: Flutterwave, + public userWalletService: UserWalletService + ) { + this.walletData = this.router.getCurrentNavigation().extras.state; + + this.monthsData = this.sessionDataProviderService.getMonths(); + this.cardExpirationYears = this.sessionDataProviderService.getCardExpirationYears(); + + if (this.walletData != undefined) { + this.curr_balance = this.walletData.amount * 0.01; + this.currency_code = this.walletData.code; + this.currency_description = this.walletData.description; + this.wallet_uid = this.walletData.wallet_uid; + this.processor = this.walletData.processor; + } else { + this.onBack(); } - - - constructor(private navctr: NavController, - private router: Router, - public sessionDataProviderService: SessionDataProviderService, - private wrenchService: WrenchService, - public blogDataService: BlogDataService, - private loadingCtrl: LoadingController, - public alertController: AlertController, - private flutterwave: Flutterwave, - public userWalletService: UserWalletService) { - this.walletData = this.router.getCurrentNavigation().extras.state; - if ( this.walletData != undefined ){ - this.curr_balance = this.walletData.amount*0.01; - this.currency_code = this.walletData.code; - this.currency_description = this.walletData.description; - this.wallet_uid= this.walletData.wallet_uid; - this.processor = this.walletData.processor; - } - else{ - this.onBack(); - } - } ngOnInit() { - this.getUsersCardsList(); + this.getUsersCardsList(); } onBack() { - // this.setCloseModal(); + // this.setCloseModal(); this.navctr.back(); - } - setCcType(cc_type){ - this.card_level = cc_type; - } + setCcType(cc_type) { + this.card_level = cc_type; + } usrData: { - action:number, member_id: number, uid: string, sessionid: string, limit:20, page:1,offset: 0 + action: number; + member_id: number; + uid: string; + sessionid: string; + limit: 20; + page: 1; + offset: 0; }; - usersCardsTotalData:any; + usersCardsTotalData: any; usersCardsData: any; - getUsersCardsList(){ - this.usrData = - { - action:11055, - member_id: this.sessionDataProviderService.member_id, - uid: this.sessionDataProviderService.member_uid, - sessionid: this.sessionDataProviderService.session , - limit:20, page:1,offset: 0 - }; + getUsersCardsList() { + this.usrData = { + action: 11055, + member_id: this.sessionDataProviderService.member_id, + uid: this.sessionDataProviderService.member_uid, + sessionid: this.sessionDataProviderService.session, + limit: 20, + page: 1, + offset: 0, + }; - this.wrenchService.getusersCardList(this.usrData).subscribe( - usersCardsTotalData => { - this.usersCardsTotalData = usersCardsTotalData; - console.log("usersCardsTotalData TOTAL RETURN->", this.usersCardsTotalData); - this.usersCardsData = this.usersCardsTotalData.result_list; - // debugger; - console.log("usersCardsData RETURN DATA->", this.usersCardsData); - this.card_count = this.usersCardsData.length; - if (this.card_count == 0 ){ - this.setCcType(400); - } - //this.total_family = this.familyData.length; + this.wrenchService + .getusersCardList(this.usrData) + .subscribe((usersCardsTotalData) => { + this.usersCardsTotalData = usersCardsTotalData; + console.log( + "usersCardsTotalData TOTAL RETURN->", + this.usersCardsTotalData + ); + this.usersCardsData = this.usersCardsTotalData.result_list; + // debugger; + console.log("usersCardsData RETURN DATA->", this.usersCardsData); + this.card_count = this.usersCardsData.length; + if (this.card_count == 0) { + this.setCcType(400); } - ); - + //this.total_family = this.familyData.length; + }); } -/* + /* paymentData : AsyncPaymentOptions = { public_key: this.publicKey, tx_ref: this.generateReference(), @@ -139,252 +168,272 @@ export class AddcreditPage implements OnInit { card_uid: this.startCreditResult.card_uid, action:11056 */ - payViaPromise() { + payViaPromise() { + this.customerDetails = { + name: + this.sessionDataProviderService.firstname + + " " + + this.sessionDataProviderService.firstname, + email: this.sessionDataProviderService.email, + phone_number: "08100000000", + }; + this.meta = { + counsumer_id: this.sessionDataProviderService.member_id.toString(), + consumer_mac: this.sessionDataProviderService.member_uid, + }; - this.customerDetails = { name: this.sessionDataProviderService.firstname+' '+this.sessionDataProviderService.firstname, - email: this.sessionDataProviderService.email, phone_number: '08100000000'}; - this.meta = { counsumer_id: this.sessionDataProviderService.member_id.toString(), - consumer_mac: this.sessionDataProviderService.member_uid,}; + this.isProcessDisabled = true; + this.paymentData.public_key = this.flutterwave_key; + this.paymentData.tx_ref = this.startCreditResult.credit_reference; + this.paymentData.amount = this.startCreditResult.amount * 0.01; // no kobo + this.paymentData.meta = this.meta; + this.paymentData.customer = this.customerDetails; - this.isProcessDisabled = true; - this.paymentData.public_key = this.flutterwave_key; - this.paymentData.tx_ref = this.startCreditResult.credit_reference; - this.paymentData.amount = this.startCreditResult.amount*0.01; // no kobo - this.paymentData.meta = this.meta; - this.paymentData.customer = this.customerDetails; + this.flutterwave.asyncInlinePay(this.paymentData).then((response) => { + if (response == "closed") { + console.log("Promise Res FAILED", response); + } else { + console.log("Promise Res GOOD", response); + //debugger; + if (response?.status != undefined && response.status == "successful") { + this.credit_confirmation = "Successful"; + this.showCrediAlert("Payment Processing", "Completed"); + //--------------------------------------------------- + var completeCredit = { + action: 11061, + member_id: this.sessionDataProviderService.member_id, + uid: this.sessionDataProviderService.member_uid, + sessionid: this.sessionDataProviderService.session, + tx_ref: this.startCreditResult.credit_reference, + }; + console.log("completeCredit **************** ->", completeCredit); + this.wrenchService + .topupResultFLTW(completeCredit) + .subscribe((competeCreditResult) => { + console.log( + "startCreditResult TOTAL RETURN->", + this.startCreditResult + ); + const event = new Event("app-wallet-refresh"); + dispatchEvent(event); + // debugger; + if ( + competeCreditResult != undefined && + competeCreditResult.tx_ref != "" && + competeCreditResult.confirmation != "" + ) { + this.credit_confirmation = competeCreditResult.confirmation; + } + }); + // ------------------------------------------------------ + } + } + this.flutterwave.closePaymentModal(5); + }); + } - this.flutterwave.asyncInlinePay(this.paymentData).then( - (response) =>{ - if (response == 'closed'){ - console.log("Promise Res FAILED" , response); - } - else { - console.log("Promise Res GOOD" , response); - //debugger; - if (response?.status != undefined && response.status=='successful'){ - this.credit_confirmation = 'Successful'; - this.showCrediAlert("Payment Processing","Completed"); - //--------------------------------------------------- - var completeCredit = { - action:11061, - member_id: this.sessionDataProviderService.member_id, - uid: this.sessionDataProviderService.member_uid, - sessionid: this.sessionDataProviderService.session , - tx_ref: this.startCreditResult.credit_reference - }; - console.log("completeCredit **************** ->", completeCredit); - this.wrenchService.topupResultFLTW(completeCredit).subscribe( - competeCreditResult => { - console.log("startCreditResult TOTAL RETURN->", this.startCreditResult); - const event = new Event("app-wallet-refresh"); - dispatchEvent(event); - // debugger; - if ( competeCreditResult!=undefined && competeCreditResult.tx_ref!='' && competeCreditResult.confirmation!='' ){ - this.credit_confirmation = competeCreditResult.confirmation; - } - } - ); - // ------------------------------------------------------ - } - } - this.flutterwave.closePaymentModal(5) - } - ) - - } - - /* + /* topupResultFLTW(reqData){ return this.getPostData("topupresult", reqData); } */ - generateReference(): string { - let date = new Date(); - return date.getTime().toString(); - } + generateReference(): string { + let date = new Date(); + return date.getTime().toString(); + } + startCreditData: { + member_id: number; + sessionid: string; + uid: string; + currency: string; + amount: number; + card_uid: string; + action: number; + }; - startCreditData:{ - member_id:number, - sessionid:string, - uid:string, - currency: string, - amount:number, - card_uid: string, - action:number -}; - - startCreditResult:any; - async contineAddCredit(processor){ - const loading = await this.loadingCtrl.create({ - message: 'Starting...', - duration: 2500, - }); - this.startCreditData = { - member_id:this.sessionDataProviderService.member_id, - sessionid:this.sessionDataProviderService.session, - uid:this.sessionDataProviderService.member_uid, - currency: this.currency_code, - amount:this.amount*100, - card_uid: this.payment_card, - action:11053 - }; - this.isDisabled=true; - loading.present(); - this.wrenchService.startCredit(this.startCreditData).subscribe( - startCreditResult => { - loading.dismiss(); - console.log("startCreditResult TOTAL RETURN->", this.startCreditResult); - if ( startCreditResult!=undefined && startCreditResult.credit_reference!='' ){ - this.startCreditResult = startCreditResult; - this.flutterwave_key = this.startCreditResult.flutterwave_key; - - this.isModalOpen = true; - this.isModalOpenBackdrop= true; - } - } - ); - } - setCloseModal(){ - //debugger; - this.isModalOpen = false; - setTimeout(()=>{ - this.isModalOpenBackdrop= false; - this.myWallet(); - },1000); - } - - amount:number =0; - fee:number = 0; - fee_display: string; - total:number = 0; - total_display: string; - recipient:string =''; - recipient_name:string =''; - payment_card:string = ''; - selPaymentCard:any; - - feeReturn: any; - refreshFee(){ - this.isDisabled = true; - this.total = this.fee = 0; - console.log("Refresh Fee******************"); - // this.usrData = {action:33025, - // member_id: this.sessionDataProviderService.member_id, - // uid: this.sessionDataProviderService.member_uid, - // sessionid: this.sessionDataProviderService.session , - // limit:20, page:1,offset: 0, amount: this.amount*100} - // if (this.amount <= 0 ) return; - - - // this.wrenchService.sendMoneyFee(this.usrData).subscribe( - // feeReturn => { - // this.feeReturn = feeReturn; - // if ( this.feeReturn != null && this.feeReturn.processing_fee >= 0 ){ - this.fee = 0; // this.feeReturn.processing_fee*0.01; - var num = new Number(this.fee); - this.fee_display = num.toFixed(2); - // parseFloat("123.456").toFixed(2); - this.total = this.fee+this.amount; // this.feeReturn.total_amount*0.01; - var numt = new Number(this.total); - this.total_display= numt.toFixed(2); - if (this.total > 100 && this.processor==3030 ){ - this.isDisabled=false; - } - if (this.total > 5 && this.processor==5000 && this.payment_card !="" ){ - this.selPaymentCard = this.usersCardsData.filter((item) => item.card_uid == this.payment_card)[0]; - this.isDisabled=false; - } - // } - // } - // ); - - - // this.total = this.fee + this.amount; - } - - credit_confirmation :string=''; - - creditResult:any; - async processPayment(processor){ - this.credit_confirmation=''; - const loading = await this.loadingCtrl.create({ - message: 'Processing...', - duration: 3500, - }); - - if(this.processor == 3030){ - // debugger; - loading.present(); - this.payViaPromise(); - return 0; - } - if (this.processor == 5000){ - this.isProcessDisabled = true; - this.payPevCreditData={ - member_id:this.sessionDataProviderService.member_id, - sessionid:this.sessionDataProviderService.session, - uid:this.sessionDataProviderService.member_uid, - currency: this.currency_code, - amount:this.startCreditResult.amount, - credit_reference:this.startCreditResult.credit_reference, - card_uid: this.startCreditResult.card_uid, - action:11056 - }; - - - loading.present(); - this.wrenchService.payPrevCard(this.payPevCreditData).subscribe( - creditResult => { - loading.dismiss(); - console.log("creditResult TOTAL RETURN->", this.creditResult); - if ( creditResult!=undefined && creditResult.internal_return > 0 && creditResult.confirmation !=''){ - this.userWalletService.getWalletData(); // refresh the wallet - this.credit_confirmation = creditResult.confirmation; - this.showCrediAlert("Credit Processing","Completed"); - - setTimeout(()=>{ - // this.setCloseModal(); - }, 5000); - } - } - ); - - } - - - } - - myWallet(){ - this.router.navigate(['tabs/tab4']); - } - - payPevCreditData:{ - member_id:number, - sessionid:string, - uid:string, - currency: string, - amount:number, - credit_reference:string, - card_uid: string, - action:number + startCreditResult: any; + async contineAddCredit(processor) { + const loading = await this.loadingCtrl.create({ + message: "Starting...", + duration: 2500, + }); + this.startCreditData = { + member_id: this.sessionDataProviderService.member_id, + sessionid: this.sessionDataProviderService.session, + uid: this.sessionDataProviderService.member_uid, + currency: this.currency_code, + amount: this.amount * 100, + card_uid: this.payment_card, + action: 11053, }; + this.isDisabled = true; + loading.present(); + this.wrenchService + .startCredit(this.startCreditData) + .subscribe((startCreditResult) => { + loading.dismiss(); + console.log( + "startCreditResult TOTAL RETURN->", + this.startCreditResult + ); + if ( + startCreditResult != undefined && + startCreditResult.credit_reference != "" + ) { + this.startCreditResult = startCreditResult; + this.flutterwave_key = this.startCreditResult.flutterwave_key; - async showCrediAlert(mtitle: string, amessage: string) { + this.isModalOpen = true; + this.isModalOpenBackdrop = true; + } + }); + } + setCloseModal() { + //debugger; + this.isModalOpen = false; + setTimeout(() => { + this.isModalOpenBackdrop = false; + this.myWallet(); + }, 1000); + } - const alert = await this.alertController.create({ - header: 'WrenchBoard', - subHeader: mtitle, - message: amessage, - buttons: [{ - text: 'OK', - role: 'confirm', - handler: () => { - this.setCloseModal(); - this.onBack(); - }, - }], - }); - await alert.present(); + amount: number = 0; + fee: number = 0; + fee_display: string; + total: number = 0; + total_display: string; + recipient: string = ""; + recipient_name: string = ""; + payment_card: string = ""; + selPaymentCard: any; + + feeReturn: any; + + veriyEntry(){ + this.refreshFee(); + } + refreshFee() { + this.isDisabled = true; + this.total = this.fee = 0; + console.log("Refresh Fee******************"); + // this.usrData = {action:33025, + // member_id: this.sessionDataProviderService.member_id, + // uid: this.sessionDataProviderService.member_uid, + // sessionid: this.sessionDataProviderService.session , + // limit:20, page:1,offset: 0, amount: this.amount*100} + // if (this.amount <= 0 ) return; + + // this.wrenchService.sendMoneyFee(this.usrData).subscribe( + // feeReturn => { + // this.feeReturn = feeReturn; + // if ( this.feeReturn != null && this.feeReturn.processing_fee >= 0 ){ + this.fee = 0; // this.feeReturn.processing_fee*0.01; + var num = new Number(this.fee); + this.fee_display = num.toFixed(2); + // parseFloat("123.456").toFixed(2); + this.total = this.fee + this.amount; // this.feeReturn.total_amount*0.01; + var numt = new Number(this.total); + this.total_display = numt.toFixed(2); + if (this.total > 100 && this.processor == 3030) { + this.isDisabled = false; } + if (this.total > 5 && this.processor == 5000 && this.payment_card != "") { + this.selPaymentCard = this.usersCardsData.filter( + (item) => item.card_uid == this.payment_card + )[0]; + this.isDisabled = false; + } + // } + // } + // ); + + // this.total = this.fee + this.amount; + } + + credit_confirmation: string = ""; + + creditResult: any; + async processPayment(processor) { + this.credit_confirmation = ""; + const loading = await this.loadingCtrl.create({ + message: "Processing...", + duration: 3500, + }); + + if (this.processor == 3030) { + // debugger; + loading.present(); + this.payViaPromise(); + return 0; + } + if (this.processor == 5000) { + this.isProcessDisabled = true; + this.payPevCreditData = { + member_id: this.sessionDataProviderService.member_id, + sessionid: this.sessionDataProviderService.session, + uid: this.sessionDataProviderService.member_uid, + currency: this.currency_code, + amount: this.startCreditResult.amount, + credit_reference: this.startCreditResult.credit_reference, + card_uid: this.startCreditResult.card_uid, + action: 11056, + }; + + loading.present(); + this.wrenchService + .payPrevCard(this.payPevCreditData) + .subscribe((creditResult) => { + loading.dismiss(); + console.log("creditResult TOTAL RETURN->", this.creditResult); + if ( + creditResult != undefined && + creditResult.internal_return > 0 && + creditResult.confirmation != "" + ) { + this.userWalletService.getWalletData(); // refresh the wallet + this.credit_confirmation = creditResult.confirmation; + this.showCrediAlert("Credit Processing", "Completed"); + + setTimeout(() => { + // this.setCloseModal(); + }, 5000); + } + }); + } + } + + myWallet() { + this.router.navigate(["tabs/tab4"]); + } + + payPevCreditData: { + member_id: number; + sessionid: string; + uid: string; + currency: string; + amount: number; + credit_reference: string; + card_uid: string; + action: number; + }; + + async showCrediAlert(mtitle: string, amessage: string) { + const alert = await this.alertController.create({ + header: "WrenchBoard", + subHeader: mtitle, + message: amessage, + buttons: [ + { + text: "OK", + role: "confirm", + handler: () => { + this.setCloseModal(); + this.onBack(); + }, + }, + ], + }); + await alert.present(); + } } diff --git a/src/app/store/session-data-provider.service.ts b/src/app/store/session-data-provider.service.ts index 3ea44ee..3ac39e1 100644 --- a/src/app/store/session-data-provider.service.ts +++ b/src/app/store/session-data-provider.service.ts @@ -88,6 +88,7 @@ export class SessionDataProviderService { session_contructed:boolean = false; + getMonths(){ // return ["January","February","March","April","May","June","July", // "August","September","October","November","December"]; @@ -107,6 +108,15 @@ export class SessionDataProviderService { ]; } + getCardExpirationYears(){ + var currY = new Date().getFullYear(); + var arrY = []; + + for(var i=1; i<=10; i++) { + arrY.push(currY+i); + } + return arrY; + } durationArray = [ { duration: 1, name: "1 day" }, { duration: 2, name: "2 days" },