【问题标题】:Paypal and ionic 2 not working and giving JSON errorPaypal 和 ionic 2 不工作并给出 JSON 错误
【发布时间】:2016-10-07 02:55:03
【问题描述】:

我不确定为什么我无法将 Ionic2 应用程序与 Paypal 集成。

我正在为 PayPal cordova mobile sdk 使用 Ionic 原生包装器。

Paypal.init 获得成功,但renderSinglePaymentUI 获得 JSON 错误

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

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

@Injectable()
export class Payments {

paymentdata : PayPalPayment;
paymentdetails: PayPalPaymentDetails;
paypalConfig: PayPalConfiguration;
paypalConfigOptions: PayPalConfigurationOptions;

constructor() {
 this.initiatePaypal();   
}

initiatePaypal(){
   // this.paypalConfig = new PayPalConfiguration("ssn.bala@gmail.com","+65", "85256592", "MMS", "mmssingapore.org","mmssingapore.org",YES,0,YES,"en",YES,NO,YES,"ssn.bala-buyer@gmail.com", "testing123" );

PayPal.init({
        "PayPalEnvironmentProduction": "YOUR_PRODUCTION_CLIENT_ID",
        "PayPalEnvironmentSandbox": "AYghcu8pISVBO03yX58CVC7vccATg5jraW-k52jPw9V63RQkuIaS2H8moi2OnWln97FPvP-gDEMbMlHj"
        })
    .then(onSuccess => {
        console.log("init success");
        alert("init success" + JSON.stringify(onSuccess));
    })
    .catch(onError => {
        console.log("init failed", Error);
        alert("init failed" + JSON.stringify(onError));
    });
}


initiatePayment(){

    this.paymentdetails = new PayPalPaymentDetails("10.00", "0", "hello");
    this.paymentdata = new PayPalPayment("10.00","USD", "MMS tickets", "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));
         });
}



}

我正在使用 Ionic 2 RC0。

您的系统信息:

科尔多瓦 CLI:6.3.1 离子框架版本:2.0.0-rc.0 离子 CLI 版本:2.1.0 Ionic App Lib 版本:2.1.0-beta.1 操作系统: 节点版本:v6.7.0

【问题讨论】:

  • 你没有提到错误,你得到了什么错误

标签: cordova paypal ionic-framework ionic2


【解决方案1】:

今天我尝试同时使用 Ionic 2 和 PayPal。我按照http://ionicframework.com/docs/native/paypal 的说明进行操作,几乎一切正常,但有一些例外。所以这是一个运行良好的简单提供程序。希望能帮助到你! 'preload' 应该在付款之前调用,当然这只是一个示例代码。

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

@Injectable()
export class PaypalProvider {    
    private paypal: PayPal;

    constructor() { }

    public preload() {
        this.paypal = new PayPal();

        this.paypal.init({
            PayPalEnvironmentProduction: "YOUR_PRODUCTION_CLIENT_ID",
            PayPalEnvironmentSandbox: "YOUR_SANDBOX_CLIENT_ID"
        }).then(value => {
            console.log('[???] init:', value);
            this.paypal.prepareToRender('PayPalEnvironmentSandbox', new PayPalConfiguration({
                presentingInPopover: true,
            })).then(value => {
                console.log('[???] prepared:', value);
            }).catch(error => {
                console.log('[???] Error:', error);
            });
        }).catch(error => {
            console.log('[???] Error:', error);
        });
    }

    public fooPayment() {
        let payment = new PayPalPayment('10.00', 'BRL', 'Some Product', 'Assinatura');
        this.paypal.renderSinglePaymentUI(payment).then(value => {
            console.log('[???] Payment:', value);
        }).catch(error => {
            console.log('[???] Payment Error', error);
        });
    }    
} // - - - 

我的系统:

Cordova CLI: 6.5.0
Ionic Framework Version: 2.3.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.1.4
OS: Windows 8.1
Node Version: v6.9.1

【讨论】:

  • 这对我不起作用。我仍然收到JSON error
猜你喜欢
  • 2020-02-25
  • 2021-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多