ionic学习与开发

ionic3 调用paypal

2018-04-24  本文已影响165人  亦久亦韭

#1.安装插件

ionic cordova plugin add com.paypal.cordova.mobilesdk

npm install --save @ionic-native/paypal

2.在app.module.ts里引用

import { PayPal} from '@ionic-native/paypal';

providers: [ PayPal ]

3.home.ts

import { PayPal, PayPalPayment, PayPalConfiguration } from '@ionic-native/paypal';

currencies = ['USD', 'EUR'];//优先货币选择

  responsestr: any;//接受返回值

//去支付

  goPay() {

    this.payPal.init({

      PayPalEnvironmentProduction: '生产环境的签名',

      PayPalEnvironmentSandbox: '沙盒环境的签名'

    }).then(() => {

      // Environments: PayPalEnvironmentNoNetwork, PayPalEnvironmentSandbox, PayPalEnvironmentProduction

      this.payPal.prepareToRender('PayPalEnvironmentSandbox', new PayPalConfiguration({

        // Only needed if you get an "Internal Service Error" after PayPal login!

        //payPalShippingAddressOption: 2 // PayPalShippingAddressOptionayPal

      })).then(() => {

        let payment = new PayPalPayment('5', 'USD', '会员充值', '会员充值');

        this.payPal.renderSinglePaymentUI(payment).then((response) => {

          alert('Successfully Paid');

          this.responsestr = JSON.stringify(response, null, 2);

        }, () => {

          alert('Error or render dialog closed without being successful');

        });

      }, () => {

        alert('Error in configuration');

      });

    }, () => {

      alert('Error in initialization, maybe PayPal isn\'t supported or something else');

    });

  }

demo下载:https://download.csdn.net/download/ylellen/10371001

上一篇下一篇

猜你喜欢

热点阅读