PAYPAL PAYMENT客户端REST SCRIPT

时间:2017-06-19 12:06:41

标签: php jquery paypal paypal-rest-sdk

我已将PayPal客户端REST集成到我的网站。我使用了以下链接提供的示例代码: https://developer.paypal.com/demo/checkout/#/pattern/client

以下代码工作了一个多月,但今天它显示以下错误 错误:请求发布https://www.sandbox.paypal.com/v1/payments/payment

 <div id="paypal-button-container" class="info"></div><script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>

    // Render the PayPal button

    paypal.Button.render({

        // Set your environment

        env: 'production', // sandbox | production

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

        client: {
            sandbox:    '<?=SANDBOXPAYPAL?>',
            production: '<?=PAYPAL_TOKEN?>'
        },

        // Set to 'Pay Now'

        commit: true,

        // Wait for the PayPal button to be clicked

        payment: function() {
$('#card').attr('checked',true);
            // Make a client-side call to the REST api to create the payment


            return paypal.rest.payment.create(this.props.env, this.props.client, {
                transactions: [
                    {
                        amount: { total: '12.99', currency: 'GBP' }
                    }
                ]
            });
        },

        // Wait for the payment to be authorized by the customer

        onAuthorize: function(data, actions) {

           jQuery.ajax({
           type: "POST",
           url: "ipn.php",
           data: data,
           success: function(data){ 
           }
         });

            return actions.payment.execute().then(function() {
                document.querySelector('#paypal-button-container').innerText = 'Payment Complete!';
            });
        }

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

</script>

我的代码如下:

<div class="div-1">
    <div class="div-2">
        <span class="wrapper">test</span>
        <div class="div-3">
        </div>  
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

您的代码与示例不完全匹配,但我也在使用我正在构建的Laravel Shoping Cart中的client-sdie API,我使用AJAX将支付数据以这种方式推送回我的系统:

onAuthorize:function(data, actions)
    {
        console.log("onAuthorize()");
        console.log("Dumping DATA");
        console.log(data);
        console.log("Dumping ACTIONS");
        console.log(actions);
        return actions.payment.execute().then(function(payment)
        {
            console.log("payment.execute called");
            document.querySelector('#paypal-button-container').innerText = 'Payment Complete!';
            console.log("Dumping payment:");
            console.log("CART: "+payment['cart']);
            console.log(payment);

            var values = encodeURIComponent(JSON.stringify(payment));
            $.ajaxSetup({headers:{'X-CSRF-TOKEN':'{{ $token }}' } } );
            ajaxRequest= $.ajax({ url: "/ajax/payment", type: "post",data:values });
            ajaxRequest.done(function(response, textStatus, jqXHR)
            {
                var result = $.parseJSON(response);
                console.log(result);
            });

        });
    },

/ ajax / payment是我目前正在开发的捕获脚本,但它确实记录了购买的所有数据..希望它有所帮助。