贝宝。 Bootstrap 5 手风琴中的按钮
我有一个手风琴,里面有一些东西。现在我想在每个手风琴项目中显示一个 paypal 付款按钮。我正在使用 paypal JS SDK。因此,它仅适用于第一个打开的手风琴项目。显示贝宝按钮,我可以单击它,贝宝模式将打开以登录和付款。
我创建了一个文件,其中添加了“paypal-button-container”,并包含了一个带有 paypal JS 脚本的 PHP 文件:
<?php
include_once ('method/paypal_accordion.php');
?>
<div id="paypal-button-container"></div>
在包含的文件“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) {
...
});
},
如何在每个打开的手风琴项目上显示 paypal 按钮? 目前我只在那里看到 paypal div,但没有按钮:
<div id="paypal-button-container"></div>
我应该重新加载 DOM 还是手风琴中有一个事件可以做到这一点? 或者我应该使用带有表单或某些 AJAX 的按钮?
I have an accordion with some items. Now I want to show a paypal pay button in each accordion item. I am using the paypal JS SDK. So for it is working just for the first open accordion item. There the paypal button is shown, I can click on it and paypal modal is opening to login and pay.
I have created a file where I have added the "paypal-button-container" and included a PHP file with the paypal JS script:
<?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:
<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?
Currently I just see the paypal div there, but no button:
<div id="paypal-button-container"></div>
Should I reload the DOM or is there an event in the accordion to do that?
Or should I use a button with a form or some AJAX?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要呈现 PayPal 按钮的每个 div 都必须有一个唯一的
id
每次调用
paypal.Buttons({...})
并调用.render('#some-id-goes-here')
,要渲染的选择器应该是这些 id 之一。Each div where you want to render a PayPal button must have a unique
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.