[英]Paypal. button in bootstrap 5 accordion
I have an accordion with some items.我有一些物品的手风琴。 Now I want to show a paypal pay button in each accordion item.
现在我想在每个手风琴项目中显示一个 paypal 支付按钮。 I am using the paypal JS SDK. So for it is working just for the first open accordion item.
我正在使用 paypal JS SDK。因此它仅适用于第一个打开的手风琴项目。 There the paypal button is shown, I can click on it and paypal modal is opening to login and pay.
那里显示了 paypal 按钮,我可以点击它,paypal 模式正在打开以登录和支付。
I have created a file where I have added the "paypal-button-container" and included a PHP file with the paypal JS script:我创建了一个文件,其中添加了“paypal-button-container”,并包含一个 PHP 文件和 paypal JS 脚本:
<?php
include_once ('method/paypal_accordion.php');
?>
<div id="paypal-button-container"></div>
In the included file 'method/paypal_accordion.php' I have the paypal script with the variables for the payment:在包含的文件“method/paypal_accordion.php”中,我有带有付款变量的 paypal 脚本:
<script>
// Loop over each funding source/payment method
var FUNDING_SOURCES = [
paypal.FUNDING.PAYPAL
];
FUNDING_SOURCES.forEach(function(fundingSource) {
// Initialize the buttons
var button = paypal.Buttons({
fundingSource: fundingSource,
createOrder: function (data, actions) {
return actions.order.create({
application_context: {
brand_name: 'my-page.com',
locale: 'en_gb',
shipping_preference: 'SET_PROVIDED_ADDRESS',
},
intent: 'CAPTURE',
payer: {
email_address: '<?php echo $email; ?>',
...
onApprove: function (data, actions) {
return actions.order.capture().then(function (orderData) {
...
});
},
How can the paypal button be shown on every opened accordion item? paypal 按钮如何显示在每个打开的手风琴项目上? Currently I just see the paypal div there, but no button:
目前我只看到 paypal div,但没有按钮:
<div id="paypal-button-container"></div>
Should I reload the DOM or is there an event in the accordion to do that?我应该重新加载 DOM 还是手风琴中有一个事件可以做到这一点? Or should I use a button with a form or some AJAX?
或者我应该使用带有表单的按钮还是一些 AJAX?
Each div where you want to render a PayPal button must have a unique id
您要呈现 PayPal 按钮的每个 div 必须具有唯一的
id
Each time you invoke paypal.Buttons({...})
and call .render('#some-id-goes-here')
, the selector to render in should be one of those ids.每次调用
paypal.Buttons({...})
并调用 .render .render('#some-id-goes-here')
时,要呈现的选择器应该是这些 ID 之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.