cancel
Showing results for 
Search instead for 
Did you mean: 

ERROR WITH IONIC INTEGRATION

New Community Member

ERROR WITH IONIC INTEGRATION

Hello, I am trying to integrate payment with paypal in my ionic app. Then I have this code

import { Component, OnInit } from '@angular/core';
import { IoncabServicesService } from '../ioncab-services.service';
import { PayPal, PayPalPayment, PayPalConfiguration} from '@ionic-native/paypal/ngx';

import { ToastController } from '@ionic/angular';
import { Router } from '@angular/router';

@Component({
selector: 'app-paypalpago',
templateUrl: './paypalpago.page.html',
styleUrls: ['./paypalpago.page.scss'],
})
export class PaypalpagoPage implements OnInit {
totalFare: number;
 

 

 
paymentAmount= 'totalFare' ;
currency: string = 'EUR';
/*currencyIcon: string = '$';*/
 
constructor(public serviceProvider: IoncabServicesService,
private payPal:PayPal,public toastController: ToastController,public route:Router, ) { }

ngOnInit() {
 
this.totalFare = Math.round(this.serviceProvider.tripDistance * this.serviceProvider.farePerKm + this.serviceProvider.tarifaBase);
 
}
 
payWithPaypal(){
 
this.payPal.init({
PayPalEnvironmentProduction: '',
PayPalEnvironmentSandbox: 'ASdoJu_T3ORqC2AI-Hx2UYTa8afcSOmyVZMr_KDdaXvufeX6-S7CuTjgyhEYy1_uaSSsjkgtD4qbQS3o'
}).then(() => {
// Environments: PayPalEnvironmentNoNetwork, PayPalEnvironmentSandbox, PayPalEnvironmentProduction
this.payPal.prepareToRender('PayPalEnvironmentSandbox', new PayPalConfiguration({
acceptCreditCards:true,
 
 
})).then(() => {
console.log(this.totalFare);
let payment = new PayPalPayment( this.paymentAmount, 'EUR', 'Descripción', 'sale');
this.payPal.renderSinglePaymentUI(payment).then(()=>{
this.route.navigate(['/bookingconfirmation']);
})

})
})
}
}
totalfare calculates an operation that is the distance * km this would have to give a number that is the price that the user would have to pay.
I have put paymentAmount = 'totalfare'.The problem is that I do not open paypal when the button is clicked