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

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

问题描述

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

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

这是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"><身体><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"/>

和 Javascript 代码:

//paypal.js//渲染 PayPal 按钮$(函数(){paypal.Button.render({//设置环境//TODO: 动态提供沙箱或生产env: '沙箱',//沙箱 |生产//PayPal 客户 ID - 替换为您自己的//创建一个 PayPal 应用:https://developer.paypal.com/developer/applications/create//TODO: 动态提供clientID客户: {沙箱:'ZZZZZZ',生产:'//TODO:稍后提供'},//等待 PayPal 按钮被点击付款:函数(){//对 REST api 进行客户端调用以创建付款return paypal.rest.payment.create(this.props.env, this.props.client, {交易:[{金额:{总计:'13.10',货币:'美元'}}]});},//等待客户授权付款onAuthorize:函数(数据,动作){返回 actions.payment.get().then(function(paymentData) {$('#paypal-button-container').style.display = 'none';//隐藏按钮//TODO: 显示用户支付详情//TODO: 创建输入隐藏字段并设置payerID、paymentID等..为以后的授权/捕获});},点击:函数(){$('#rd').trigger('click');},}, '#paypal-button-container');});

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

解决方案

PayPal 按钮目前不支持此功能.官方政策是,只需单击按钮本身即可打开结帐窗口.

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 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?

Here is the HTML code:

<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>

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');
});

EDIT: 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

解决方案

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天全站免登陆