简体   繁体   English

动态贝宝快递结帐按钮

[英]Dynamic paypal express checkout button

Here's the deal. 这是交易。 I'm trying to make some kind of online store for a project, this snippet of code comes from my app. 我正在尝试为某个项目建立某种在线商店,此代码段来自我的应用程序。

<div class="row">
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
    {{#each this.products}}
        <div class="col-sm-6 col-md-4">
            <div class="thumbnail">
                <img style="height: 275px;" class="img-thumbnail" src="/products_images/{{this.image_products}}" alt="...">
                <div class="caption">
                    <h3>{{this.name_products}}</h3>
                    <p>{{this.description_products}}</p>
                    <p>Products quantity: {{this.quantity_products}}</p>
                    <p>Price: €{{this.price_products}}</p>  
                    <div class="center-div" id="paypal-button-container"></div>
            <script>
                    // Render the PayPal button
                    paypal.Button.render({
                    // Set your environment
                    env: 'sandbox', // sandbox | production

                    // Specify the style of the button
                    style: {
                    layout: 'vertical',  // horizontal | vertical
                    size:   'medium',    // medium | large | responsive
                    shape:  'rect',      // pill | rect
                    color:  'gold'       // gold | blue | silver | white | black
                    },

                    // Specify allowed and disallowed funding sources
                    //
                    // Options:
                    // - paypal.FUNDING.CARD
                    // - paypal.FUNDING.CREDIT
                    // - paypal.FUNDING.ELV
                    funding: {
                    allowed: [
                        paypal.FUNDING.CARD,
                        paypal.FUNDING.CREDIT
                    ],
                    disallowed: []
                    },

                    // PayPal Client IDs - replace with your own
                    // Create a PayPal app: https://developer.paypal.com/developer/applications/create
                    client: {
                    sandbox: '-----------------',
                    production: '-----------------'
                    },

                    payment: function (data, actions) {
                    return actions.payment.create({
                        payment: {
                        transactions: [
                            {
                            amount: {
                                total: '5.00',
                                currency: 'EUR'
                            }
                            }
                        ]
                        }
                    });
                    },

                    onAuthorize: function (data, actions) {
                    return actions.payment.execute()
                        .then(function () {
                        window.alert('Payment Complete!');
                        });
                    }
                    }, '#paypal-button-container');

            </script>

                </div>
            </div>
        </div>
     {{/each}}

</div>

I'm trying to create a paypal button under each object. 我正在尝试在每个对象下创建一个贝宝按钮。 However when I run the code all the buttons are stacked on the left side of the screen. 但是,当我运行代码时,所有按钮都堆叠在屏幕的左侧。

这是应用程序的外观

Could I use some kind of "product_ID" and pass it to the paypal button to make sure that the button and the object are locked together in the same div? 我可以使用某种“ product_ID”并将其传递给Paypal按钮,以确保按钮和对象在同一div中锁定在一起吗?

Also, what is the best way to pass the "price_products" variable to the "amount" field? 另外,将“ price_products”变量传递到“金额”字段的最佳方法是什么?

amount: {
            total: '5.00',
            currency: 'EUR'
        }

I want every button to have the corresponding price of the object linked to it 我希望每个按钮都具有链接到该对象的相应价格

You might try to change the id of the paypal button: 您可以尝试更改Paypal按钮的ID:

       <div class="center-div" id="paypal-button-container"></div>
        <script>

Like 喜欢

       <div class="center-div" id="paypal-button-container1"></div>
        <script>
       <div class="center-div" id="paypal-button-container2"></div>
        <script>

And so on. 等等。 Make sure to change it also at the end of the paypal script 确保在贝宝脚本的末尾也进行更改

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

and so on. 等等。

This should solve the problem for the graphical part. 这应该解决图形部分的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM