paypal - 没有值(value)传递给付款

标签 paypal paypal-sandbox payment

我在尝试使用 Paypal Express Checkout 和 Paypal 的 checkout.js 进行 Paypal Checkout 时遇到此错误。

Object {error: "Error: Error: No value passed to payment↵    at Ob…://www.paypalobjects.com/api/checkout.js:2401:13)", timestamp: 1497283288966, windowID: "2832566843", pageID: "e2a3d3f3ff", referer: "http://m.coleman.renegade.local"…}country: "US"env: "sandbox"error: "Error: Error: No value passed to payment↵    at Object.onSuccess (https://www.paypalobjects.com/api/checkout.js:8035:52)↵    at https://www.paypalobjects.com/api/checkout.js:3636:82↵    at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js:3651:19)↵    at SyncPromise.resolve (https://www.paypalobjects.com/api/checkout.js:3614:18)↵    at https://www.paypalobjects.com/api/checkout.js:3597:33↵    at flush (https://www.paypalobjects.com/api/checkout.js:3520:43)↵    at Object.err [as onSuccess] (https://www.paypalobjects.com/api/checkout.js:3528:21)↵    at https://www.paypalobjects.com/api/checkout.js:3636:82↵    at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js:3651:19)↵    at SyncPromise.resolve (https://www.paypalobjects.com/api/checkout.js:3614:18)↵    at Object._RECEIVE_MESSAGE_TYPE.(anonymous function) [as postrobot_message_response] (https://www.paypalobjects.com/api/checkout.js:2477:118)↵    at receiveMessage (https://www.paypalobjects.com/api/checkout.js:2381:73)↵    at messageListener (https://www.paypalobjects.com/api/checkout.js:2401:13)"host: "www.sandbox.paypal.com"lang: "en"pageID: "e2a3d3f3ff"path: "/webapps/hermes/button"referer: "http://m.coleman.renegade.local"timestamp: 1497283288966uid: "bfd31206ee"ver: "4.0.82"windowID: "2832566843"__proto__: Object 

 Error: Error: No value passed to payment
    at Object.onSuccess (https://www.paypalobjects.com/api/checkout.js:8035:52)
    at https://www.paypalobjects.com/api/checkout.js:3636:82
    at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js:3651:19)
    at SyncPromise.resolve (https://www.paypalobjects.com/api/checkout.js:3614:18)
    at https://www.paypalobjects.com/api/checkout.js:3597:33
    at flush (https://www.paypalobjects.com/api/checkout.js:3520:43)
    at Object.err [as onSuccess] (https://www.paypalobjects.com/api/checkout.js:3528:21)
    at https://www.paypalobjects.com/api/checkout.js:3636:82
    at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js:3651:19)
    at SyncPromise.resolve (https://www.paypalobjects.com/api/checkout.js:3614:18)
    at Object._RECEIVE_MESSAGE_TYPE.(anonymous function) [as postrobot_message_response] (https://www.paypalobjects.com/api/checkout.js:2477:118)
    at receiveMessage (https://www.paypalobjects.com/api/checkout.js:2381:73)
    at messageListener (https://www.paypalobjects.com/api/checkout.js:2401:13)
__webpack_require__.i.window.console.window.console.(anonymous function) @ index.js:536

types.js:122 Uncaught Error: Error: No value passed to payment
    at Object.onSuccess (https://www.paypalobjects.com/api/checkout.js:8035:52)
    at https://www.paypalobjects.com/api/checkout.js:3636:82
    at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js:3651:19)
    at SyncPromise.resolve (https://www.paypalobjects.com/api/checkout.js:3614:18)
    at https://www.paypalobjects.com/api/checkout.js:3597:33
    at flush (https://www.paypalobjects.com/api/checkout.js:3520:43)
    at Object.err [as onSuccess] (https://www.paypalobjects.com/api/checkout.js:3528:21)
    at https://www.paypalobjects.com/api/checkout.js:3636:82
    at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js:3651:19)
    at SyncPromise.resolve (https://www.paypalobjects.com/api/checkout.js:3614:18)
    at Object.onSuccess (https://www.paypalobjects.com/api/checkout.js:8035:52)
    at https://www.paypalobjects.com/api/checkout.js:3636:82
    at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js:3651:19)
    at SyncPromise.resolve (https://www.paypalobjects.com/api/checkout.js:3614:18)
    at https://www.paypalobjects.com/api/checkout.js:3597:33
    at flush (https://www.paypalobjects.com/api/checkout.js:3520:43)
    at Object.err [as onSuccess] (https://www.paypalobjects.com/api/checkout.js:3528:21)
    at https://www.paypalobjects.com/api/checkout.js:3636:82
    at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js:3651:19)
    at SyncPromise.resolve (https://www.paypalobjects.com/api/checkout.js:3614:18)
    at Object._RECEIVE_MESSAGE_TYPE.(anonymous function) [as postrobot_message_response] (https://www.paypalobjects.com/api/checkout.js:2477:118)
    at receiveMessage (https://www.paypalobjects.com/api/checkout.js:2381:73)
    at messageListener (https://www.paypalobjects.com/api/checkout.js:2401:13)
_RECEIVE_MESSAGE_TYPE.(anonymous function) @ types.js:122
receiveMessage @ index.js:94
messageListener @ index.js:119

这是使用 actions.payment.create() 方法随请求一起发送的数据

{"intent":"authorize","transactions":[{"amount":{"total":"105.00","currency":"USD"},"payee":{"email":"rashid-facilitator@somedomain.com"},"description":"Payment","item_list":{"items":[{"name":"Oleta Dresser","description":"","quantity":1,"price":"105.00","sku":"CST-203183","currency":"USD"}]}}],"redirect_urls":{"return_url":"https://www.sandbox.paypal.com","cancel_url":"https://www.sandbox.paypal.com"},"payer":{"payment_method":"paypal"}}

我无法完成这项工作。有人知道吗?

这是完整的代码。

import React, { Component, PropTypes } from 'react';

export default class PaypalButton extends React.Component {
    constructor(props) {
        super(props);

        this.client = {
            sandbox:    'client id stripped',
            production: '<insert production client id>'
        };

        this.onCheckoutButtonClick = this.onCheckoutButtonClick.bind(this);
        this.onPaymentApproval = this.onPaymentApproval.bind(this);
    }

    render() {
        return <div id="paypal-button-container"></div>;
    }

    componentDidMount() {
        window.PAYPAL? this.renderPaypalButton(): loadScript('https://www.paypalobjects.com/api/checkout.js', true, () => {
            this.renderPaypalButton();
        });
    }

    onCheckoutButtonClick(data, actions) {
        // prepare item list from order summary
        let desc = '';
        let items = this.props.items.map(item => {
            if( item.type == 'bundle' ) {
                desc = item.products_option[0].required.items.join();
                if( item.products_option[0].optional )
                    desc += item.products_option[0].optional.items.join();
            }
            return {
                "name": item.name,
                "description": desc,
                "quantity": item.qty,
                "price": item.price,
                "sku": item.sku,
                "currency": "USD"
            }
        })
        // Make a call to the REST api to create the payment
        return actions.payment.create({
            intent: 'authorize',
            transactions: [
                {
                    amount: { 
                        total: this.props.totals.grand_total[0].value, 
                        currency: 'USD'
                    },
                    payee: { 
                        email: 'john-facilitator@example.com'
                    },
                    description: 'Payment',
                    item_list: {
                        items: items
                    }
                }
            ]
        }).then(data2 => {
            jQuery(document).trigger('onPaymentCreate.colemanReact', data2);
        });
    }

    onPaymentApproval(data, actions) {
        // Make a call to the REST api to execute the payment
        // this will get us an approved payment to be captured later
        return actions.payment.execute().then(function(data3) {
            // Show a thank-you note
            console.log('execute', data3);
            jQuery(document).trigger('onPaymentApproval.colemanReact', data3);
        });

    }

    onPaymentError(err) {
        console.log(err);
        jQuery(document).trigger('onPaymentError.colemanReact', err);
    }

    onPaymentCancellation(data, actions) {
        jQuery(document).trigger('onPaymentCancellation.colemanReact', data3);
    }

    renderPaypalButton() {
        paypal.Button.render({

            env: 'sandbox', // sandbox | production

            // PayPal Client IDs - replace with your own
            // Create a PayPal app: https://developer.paypal.com/developer/applications/create
            client: this.client,

            // Show the buyer a 'Pay Now' button in the checkout flow
            commit: false,

            // payment() is called when the button is clicked
            payment: this.onCheckoutButtonClick,

            // onAuthorize() is called when the buyer approves the payment
            onAuthorize: this.onPaymentApproval,

            // onCancel() is called when the buyer cancels the payment
            onCancel: this.onPaymentCancellation,

            // Show an error page here, when an error occurs
            onError: this.onPaymentError

        }, '#paypal-button-container');
    }
}

最佳答案

这是你的问题:

   return actions.payment.create({
        intent: 'authorize',
        transactions: [
            {
                amount: { 
                    total: this.props.totals.grand_total[0].value, 
                    currency: 'USD'
                },
                payee: { 
                    email: 'john-facilitator@example.com'
                },
                description: 'Payment',
                item_list: {
                    items: items
                }
            }
        ]
    }).then(data2 => {
        jQuery(document).trigger('onPaymentCreate.colemanReact', data2);
    });

您正在添加 .then() 但未在 promise 中返回付款 ID。您可以尝试以下操作吗:

   return actions.payment.create({
        intent: 'authorize',
        transactions: [
            {
                amount: { 
                    total: this.props.totals.grand_total[0].value, 
                    currency: 'USD'
                },
                payee: { 
                    email: 'john-facilitator@example.com'
                },
                description: 'Payment',
                item_list: {
                    items: items
                }
            }
        ]
    }).then(data2 => {
        jQuery(document).trigger('onPaymentCreate.colemanReact', paymentID);
        return paymentID
    });

关于paypal - 没有值(value)传递给付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44504104/

相关文章:

paypal - Opencart Paypal - 无需 paypal 账户即可付款

paypal - GetBasicPersonalData 返回错误 570058 : "Authentication failed. User account is not confirmed"

ios - 我如何使用 Braintree 保存客户卡信息,以便稍后他们购物时我可以从中扣款?

php - 在使用 Stripe 收费之前,我可以检查客户的卡是否会被拒绝吗?

Paypal 错误 : Merchant country unsupported

PHP MySQL IPN问题

ios - Paypal 初始化时出错

ruby-on-rails - 错误 : No route matches [GET] "/cgi-bin/webscr"

php - 无法在 paypal 快速结帐时传递负值

magento - PayPal 网站付款标准错误