触发PayPal结帐按钮点击 [英] Trigger PayPal checkout button click

查看:504
本文介绍了触发PayPal结帐按钮点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何触发PayPal Checkout按钮单击? 我们在信用卡旁边有一个网站,我们还将接受PayPal付款,我已决定放置单选按钮供客户选择付款方式以及PayPal Checkout按钮:

How can I trigger PayPal Checkout button click? We have a website were beside the Credit Cards we are going to accept also PayPal payments and I have decided to put radio buttons for the customers to choose which way the customer is going to pay and also PayPal Checkout button:

PayPal Checkout按钮本身会打开PayPal安全窗口,其余的工作正常.当客户单击第一个单选按钮时,我要再次打开PayPal安全窗口,即触发单击PayPal结帐按钮. 如果按钮本身出现在iframe中,但我无法触发该按钮跨域的点击事件,该怎么办?有什么方法可以触发结帐按钮的点击?

PayPal Checkout button click itself opens the PayPal secure window and the rest works fine. When customer click the 1st radio button I want again open PayPal secure window i.e. trigger click on PayPal checkout button. How can I do that if the button itself appearing in iframe and I am not able to trigger click event of that button cross domain? Is there any way to trigger checkout button click?

这是HTML代码:

<html>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script src="https://www.paypalobjects.com/api/checkout.js"></script>
    <script type="text/javascript" src="paypal.js">

    </script>
    <body>
        <div>
        <span style="vertical-align: 50%"><input id="rd" name="aaa" type="radio"/></span>
        <div id="paypal-button-container" style="display: inline-block"></div><hr/>
        <input id="rd1" name="aaa" type="radio"/>
        </div>
    </body>
</html>

和Javascript代码:

And Javascript code:

// paypal.js
// Render the PayPal button
$(function(){
    paypal.Button.render({

        // Set your environment

        //TODO: Dynamically provide sandbox or production
        env: 'sandbox', // sandbox | production

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

        //TODO: Dynamically provide clientID
        client: {
            sandbox:    'ZZZZZZ',
            production: '//TODO: Provide this later'
        },

        // Wait for the PayPal button to be clicked

        payment: function() {

            // 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: '13.10', currency: 'USD' }
                    }
                ]
            });
        },

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

        onAuthorize: function(data, actions) {

            return actions.payment.get().then(function(paymentData) {

                $('#paypal-button-container').style.display = 'none'; //hide button

                //TODO: Show user payment details
                //TODO: Create input hidden fields and set payerID, paymentID, etc..for later authoriza/capture
            });
        },

        onClick: function(){
            $('#rd').trigger('click');
        },

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

作为一个工作示例,我建议您使用此网站,但这与我需要的内容略有不同. https://developer.paypal.com/demo/checkout/#/pattern/mark

As a working example I would suggest this site, but this is little bit different what I need https://developer.paypal.com/demo/checkout/#/pattern/mark

推荐答案

贝宝(PayPal)按钮目前不支持此功能.官方政策是,仅单击按钮本身即可打开一个结帐窗口.

This isn't something that's supported by the PayPal button right now. The official policy is, only a click on the button itself should open a checkout window.

这篇关于触发PayPal结帐按钮点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆