通过Angularjs将自定义值传递给payPal / Cordova插件

时间:2016-12-22 17:24:08

标签: angularjs cordova paypal

我正在尝试将payPal插件添加到我的cordova / Angularjs应用程序中。当我用预定义的值测试它时,一切都很好。但是,当我尝试将自己的自定义值传递给它时失败。

请问如何将值/数据传递给Angularjs中的makePayment()或createPayment()方法。 当我在控制器中执行Wallet.makePayment($scope.MMParams);时 我得到"无法获得未定义的属性值。"

 .factory('Wallet', function ($q, $ionicPlatform, $window) {
    var service = {
        initPaymentUI: initPaymentUI,
        onSuccesfulPayment: onSuccesfulPayment,
        onFuturePaymentAuthorization: onFuturePaymentAuthorization,
        createPayment: createPayment,
        configuration: configuration,
        onPrepareRender: onPrepareRender,
        onPayPalMobileInit: onPayPalMobileInit,
        onUserCanceled: onUserCanceled,
        makePayment: makePayment
    };


    function initPaymentUI() {
        var clientIDs = {
            "PayPalEnvironmentProduction": "YOUR_PRODUCTION_CLIENT_ID",
            "PayPalEnvironmentSandbox": "YOUR_SANDBOX_CLIENT_ID"
        };
        PayPalMobile.init(clientIDs, onPayPalMobileInit());

    }

    function onSuccesfulPayment(payment) {
        console.log("payment success: " + JSON.stringify(payment, null, 4));
    }

    function onFuturePaymentAuthorization(authorization) {
        console.log("authorization: " + JSON.stringify(authorization, null, 4));
    }
    function createPayment() {
        // for simplicity use predefined amount
        var paymentDetails = new PayPalPaymentDetails("1.50", "0.40", "0.05");
        var payment = new PayPalPayment("1.95", "USD", "Awesome Sauce", "Sale", paymentDetails);
        return payment;
    }
    function configuration() {
        // for more options see `paypal-mobile-js-helper.js`
        var config = new PayPalConfiguration({merchantName: "My Test Shop", merchantPrivacyPolicyURL: "https://mytestshop.com/policy", merchantUserAgreementURL: "https://mytestshop.com/agreement"});
        return config;
    }
    function onPayPalMobileInit() {
        // must be called
        // use PayPalEnvironmentNoNetwork mode to get look and feel of the flow
        PayPalMobile.prepareToRender("PayPalEnvironmentNoNetwork", configuration(), onPrepareRender());
    }
    function onUserCanceled(result) {
        console.log(result);
    }
    function onPrepareRender() {}

    function makePayment() {
        PayPalMobile.renderSinglePaymentUI(createPayment(), onSuccesfulPayment(), onUserCanceled());
    }

    return service;
});

如果有人可以提供帮助,我将很高兴,谢谢你。

1 个答案:

答案 0 :(得分:0)

你必须将函数作为回调传递,因为renderSinglePaymentUI会自己调用它,但是你正在调用它并传递返回值。

function makePayment() {
    PayPalMobile.renderSinglePaymentUI(createPayment(), onSuccesfulPayment(), onUserCanceled());
}

应该是

function makePayment() {
    PayPalMobile.renderSinglePaymentUI(createPayment(), onSuccesfulPayment, onUserCanceled);
}

也许这已经解决了你的问题