贝宝-无需重定向即可将信息发送给父母

时间:2018-07-12 23:48:37

标签: paypal asp-classic

我有一个PayPal,现在在我的网站上购买它的客户端REST。付款程序在我端可以正常运行,但是客户付款后,看不到付款确认屏幕,而是返回到登录名。我已经读过PayPal Dev,我必须显示确认而不重定向,这是我现在正在做的事情。

  

您必须显示确认而不重定向页面。如果您重定向页面,则无法使用actions.payment.execute()和actions.payment.get()函数。

这是我正在使用的代码:

payment.asp

<script src="https://www.paypalobjects.com/api/checkout.js"></script>
</head>
<%
Dim price : price = "134.96"
%>
<body>
<div id="paypal-button-container"></div>
</body>
<input type="hidden" name="price" id="price" value="<%=price%>" />
<script src="payment.js"></script>  

payment.js

// JavaScript Document
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
        style: {
        label: 'checkout',
        size:  'medium',    // small | medium | large | responsive
        shape: 'pill',     // pill | rect
        color: 'silver'      // gold | blue | silver | black
        },

        client: {
            sandbox:    'aaaaaaaaa',
            production: '<insert production client id>'
        },

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

        // payment() is called when the button is clicked
        payment: function(data, actions) {

            // Make a call to the REST api to create the payment
            return actions.payment.create({
                payment: {
                    transactions: [
                        {
                            amount: { total: document.getElementById('price').value, currency: 'GBP' }
                        }
                    ]
                },
                experience: {
                            input_fields: {
                                no_shipping: 1
                            }
                            }
            });
        },

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

            // Make a call to the REST api to execute the payment

            return actions.payment.execute().then(function(data) {
                window.location.href='paymentresponse.asp?paymentdone=1';
            }).catch(function(err) {
                window.location.href='paymentresponse.asp?paymentdone=0';
            });
        }

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

paymentresponse.asp

<%
if request("paymentdone") = 1 then response.write "Payment Done"
if request("paymentdone") = 0 then response.write "Payment failed"
%>

我对JavaScript的了解很少,而我对删除重定向(payingresponse.asp)想要达到的目的几乎一无所知,一旦子窗口关闭,它将向父窗口发送一个变量,该变量将确定交易是否为完成失败。

在新的payment.asp页中,我想要捕获这样的变量:

<script src="https://www.paypalobjects.com/api/checkout.js"></script>
</head>
<%
Dim price : price = "134.96"
%>
<body>
<%
if "a variable sent back from child window" = 0 then
%>
<div id="paypal-button-container"></div>
<%Else%>
<a href="booked.asp" style="float: left;" class="button">Continue</a>
<%End If%>
</body>
<input type="hidden" name="price" id="price"  value="<%=price%>" />
<script src="payment.js"></script>  

是否有可能像我上面提到的那样将一个变量从payment.js发送到payment.asp。

0 个答案:

没有答案