Coldfusion到PayPal Express REST API错误:没有价值通过付款

时间:2017-09-15 17:41:36

标签: javascript php json paypal coldfusion

使用ColdFusion设置与PayPal Express结账的连接,我在使用PayPal Express Checkout和PayPal checkout.js时出现此错误 - "Uncaught Error: No value passed to payment"。 这是我的代码,我创建了PayPal付款并返回存储在我网站paypal.cfm文件中的JSON中的paymentID:

 <cfset aresponse = deserializeJSON(cfhttp.FileContent)>

 <cfheader statusCode = "200"  statusText = "OK">
 <cfheader  name="Content-Type"  value="application/json">
 <cfheader name="Accept-Language" value="en_US">

  <cfset res = StructNew()>
  <cfset res = {"paymentID" = aresponse.id}>
  <cfset res = serializeJSON(res)>
  <cfoutput>#serializeJSON(res)#</cfoutput>

这是带有PayPal按钮的js代码,我的paypal.cfm文件被调用来创建付款并从中获取paymentID以传递给PayPal:

<script>
    paypal.Button.render({

        env: 'sandbox', // sandbox | production

        commit: true,

        payment: function() {


            var CREATE_URL = 'https://example.com/paypal.cfm';

            // Make a call to your server to set up the payment
            return paypal.request.post(CREATE_URL)
                .then(function(res) {
                      return res.paymentID;
                });
        },

        // onAuthorize() is called when the buyer approves the payment
        onAuthorize: function(data, actions) {

            var EXECUTE_URL = 'https://example.com/paypalex.cfm';

            var data = {
                paymentID: data.paymentID,
                payerID: data.payerID
            };

            return paypal.request.post(EXECUTE_URL, data)
                .then(function (res) {
                    window.alert('Payment Complete!');
                });
        }

    }, '#paypal-button-container');
</script>

所以,我成功创建了付款,当我直接调用pp-json.cfm时,我创建了包含以下格式的paymentID的JSON响应:{"paymentID":"PAY-XXXXXXXXXXXXXXX"}但是当我尝试将其与PayPal按钮一起使用时,我得到了错误说Error: No value passed to payment (checkout.js line 2857)
谁知道它会是什么?任何JSON响应都不正确吗?如果是这样,应该是什么?任何帮助是极大的赞赏。

0 个答案:

没有答案