添加PayPal付款方式Ionic

时间:2017-06-06 15:22:08

标签: angular typescript ionic-framework paypal

我正在尝试使用Ionic 2/3制作的APP实施PayPal付款方式,我已经安装了

$ ionic cordova plugin add com.paypal.cordova.mobilesdk
$ npm install --save @ionic-native/paypal

但是现在我怎么能创建事件按钮,我的意思是当我按下按钮时它需要调用PayPal API给他们产品和价格我猜,然后付款。

我已阅读Paypal Ionic documentation但是当它显示用法时,我不知道在哪里放置此代码。

任何人都可以指导我如何实施它?或者至少是一个指导?

1 个答案:

答案 0 :(得分:2)

我没有机会自己测试,但你可以有一个调用initiatePaypal()的按钮,如下所示:

import { Injectable } from '@angular/core';
//import { Paypal, PaypalPayments } from 'ionic-native';

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


@Injectable()
export class Payments {

paymentdata : any;
paymentdetails: any;

constructor() {

}

initiatePaypal(){
PayPal.init({
        "PayPalEnvironmentProduction": "YOUR_PRODUCTION_CLIENT_ID",
        "PayPalEnvironmentSandbox": "AFcWxV21C7fd0v3bYYYRCpSSRl31ACxTIGBF1mQyNN7DjU1eCzpAZer8"
        })
    .then(onSuccess => {
        console.log("init success")
    })
    .catch(onError => {
        console.log("init failed", Error)
    });
}


initiatePayment(){

    this.paymentdata = new PayPalPayment("10.00","SGD", "MMS tickets", "MMS sale");

    PayPal.renderSinglePaymentUI(this.paymentdata)
    .then(onSuccess => {
         console.log('OnSuccess Render: ' + JSON.stringify(onSuccess));
         alert('OnSuccess Render: ' + JSON.stringify(onSuccess));
       })
    .catch(onError=> {
       console.log('onError Render: ' + JSON.stringify(onError));
       alert('onError Render: ' + JSON.stringify(onError));
         });
}



}

如果其他所有方法都失败了,请尝试按照此香草js example usage of the plugin进行操作。取自MyCordovaShop