javascript - Paypal Javascript SDK订阅按钮和购买按钮在同一页面上
问题描述
谁能帮我把订阅按钮和购买按钮放在同一页面上。
我需要两次引用 JS SDK,一次是购买按钮的默认意图,另一次是订阅选项的 intent=subscription。
但是,第二次调用它会破坏第一次。代码如下。这只会生成购买按钮。同样,如果您切换排序,它只会创建订阅按钮。
<html>
<body>
<div id="paypal-button-subscribe"></div></br>
<div id="paypal-button-purchase"></div>
<!-- ***********************SUBSCRIPTION BUTTON CODE********************** -->
<script src="https://www.paypal.com/sdk/js?client-id=HIDDENFORTHISPURPOSE&vault=true&intent=subscription" data-sdk-integration-source="button-factory"></script>
<script>
paypal.Buttons({
style: {
shape: 'rect',
color: 'silver',
layout: 'vertical',
label: 'subscribe'
},
createSubscription: function(data, actions) {
return actions.subscription.create({
plan_id: 'P-9JP33954G5530770FMBXXXXX',
custom_id: "123",
application_context: {
shipping_preference: 'NO_SHIPPING',
brand_name: 'MyBrand'
}
});
},
onApprove: function(data, actions) {
window.location.assign("https://example.co/purchase/success.php?sub=" + data.subscriptionID + "&authdata=" + authdata + "&type=1");
}
}).render('#paypal-button-subscribe'); // Renders the PayPal button
</script>
<!-- ***************************************************************************** -->
<!-- *******************PURCHASE BUTTON CODE********************** -->
<script src="https://www.paypal.com/sdk/js?client-id=HIDDENFORTHISPURPOSEt¤cy=GBP"></script>
<script>
function initPayPalButton() {
paypal.Buttons({
style: {
shape: 'rect',
color: 'gold',
layout: 'vertical',
label: 'paypal',
},
createOrder: function(data, actions) {
return actions.order.create(
{
purchase_units: [{"description":"lifetime licence key-","amount":{"currency_code":"GBP","value":0.1}}],
application_context: {
shipping_preference: 'NO_SHIPPING',
brand_name: 'MyBrand'
}
}
);
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
window.location.assign("https://example.co/purchase/success2.php?sub=" + details.payer.name.given_name);
});
},
}).render('#paypal-button-purchase');
}
initPayPalButton();
</script>
<!-- **************************************************************************** -->
</body>
</html>
解决方案
推荐阅读
- excel - 如何使用 Excel VBA 为每个项目的不同范围创建 For 循环?
- java - 如何使用 Java 将我们的 CSV 文件索引到 Elastic Search 中?
- mysql - 如何为表中的两列返回相同的值
- radio - 2FSK 使用 Yardstick One 嗅探 RFCat
- selenium - @BeforeClass 注解不在子类上运行
- python - 如何创建新的 pandas 列,其中列表值 ==df 索引但列表的长度与原始数据帧的长度不同
- c# - 如何在 .net 中使用 ODBCConnection 进行多行插入?
- javascript - 我想在导航栏的右侧显示一些项目
- tomcat - chown -R vs chmod 777 -Rf,tomcat catalina.sh 权限被拒绝
- javascript - gltf-js-utils 在 Node.js 中设置纹理