触发PayPal结账按钮点击

Ars*_*yan 18 paypal paypal-sandbox

如何触发PayPal Checkout按钮点击?我们有一个网站旁边的信用卡,我们将接受PayPal付款,我已决定为客户提供单选按钮,以选择客户将支付的方式以及PayPal Checkout按钮: 在此输入图像描述

PayPal Checkout按钮单击本身打开PayPal安全窗口,其余工作正常.当客户点击第一个单选按钮我想再次打开PayPal安全窗口,即触发点击PayPal结账按钮.如果按钮本身出现在iframe中并且我无法触发该按钮跨域的点击事件,我该怎么办呢?有没有办法触发结账按钮点击?

这是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>
Run Code Online (Sandbox Code Playgroud)

和Javascript代码:

// 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');
});
Run Code Online (Sandbox Code Playgroud)

编辑:作为一个工作的例子我会建议这个网站,但这有点不同我需要https://developer.paypal.com/demo/checkout/#/pattern/mark

blu*_*ume 10

这不是现在PayPal按钮支持的.官方政策是,只需点击按钮本身即可打开结帐窗口.

  • 它实际上不受支持.您不能以编程方式将消息发送到iframe(在这种情况下,支付宝按钮)并让它打开一个弹出窗口 - 因为这使得`window.open`异步(不是立即点击按钮)并导致浏览器'弹出窗口拦截器以防止它.为什么甚至有iframe?好吧,除了允许我们呈现一个像素完美按钮之外,它还解决了IE中一个令人讨厌的问题,你实际上无法在不同域上的弹出窗口和父窗口之间发送消息.因此,它最终成为确保一切无缝运行的最简单方法. (2认同)

小智 6

我想我有点晚了,但我希望这会帮助遇到这个问题的人,就像我一样。

您可以将贝宝的按钮不透明度设置为 0 并将其放在您自己的结帐按钮上。然后您可以根据单选按钮值将其显示设置为“无”或“阻止”。