Bez popisu

checkout.page.ts 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { Component, OnInit } from '@angular/core';
  2. import { ModalController, Platform } from '@ionic/angular';
  3. import { PayPal, PayPalPayment, PayPalConfiguration } from '@ionic-native/paypal/ngx';
  4. @Component({
  5. selector: 'app-checkout',
  6. templateUrl: './checkout.page.html',
  7. styleUrls: ['./checkout.page.scss'],
  8. })
  9. export class CheckoutPage implements OnInit {
  10. constructor(public modalController: ModalController, private payPal: PayPal) { }
  11. ngOnInit() {
  12. }
  13. dismiss() {
  14. // using the injected ModalController this page
  15. // can "dismiss" itself and optionally pass back data
  16. this.modalController.dismiss({
  17. 'dismissed': true
  18. });
  19. }
  20. paymentAmount: string = '640';
  21. currency: string = 'USD';
  22. currencyIcon: string = 'USD';
  23. payWithPaypal() {
  24. this.payPal.init({
  25. PayPalEnvironmentProduction: 'YOUR_PRODUCTION_CLIENT_ID',
  26. PayPalEnvironmentSandbox: 'AVszPxWCuK3FGXKlgOCFu3gVXr8lFkKj9z1wUo9BYdestZbGRg5vDqWm_pqlLkhEu8KHsjP8NmfPhc_o'
  27. }).then(() => {
  28. // Environments: PayPalEnvironmentNoNetwork, PayPalEnvironmentSandbox, PayPalEnvironmentProduction
  29. this.payPal.prepareToRender('PayPalEnvironmentSandbox', new PayPalConfiguration({
  30. // Only needed if you get an "Internal Service Error" after PayPal login!
  31. //payPalShippingAddressOption: 2 // PayPalShippingAddressOptionPayPal
  32. })).then(() => {
  33. let payment = new PayPalPayment(this.paymentAmount, this.currency, 'Description', 'sale');
  34. this.payPal.renderSinglePaymentUI(payment).then((res) => {
  35. console.log(res);
  36. // Successfully paid
  37. }, (error) => {
  38. console.log(error);
  39. // Error or render dialog closed without being successful
  40. });
  41. }, (error) => {
  42. console.log(error);
  43. // Error in configuration
  44. });
  45. }, (error) => {
  46. console.log(error);
  47. // Error in initialization, maybe PayPal isn't supported or something else
  48. });
  49. }
  50. }