我在使用REST API在单个页面上实现多个PayPal Express Checkout按钮时遇到问题。这是一个视频购买网站,用户只会购买单个视频,因此无需购买可跟踪多个项目的购物车。我只是想列出可用的视频,然后在每个视频旁边显示一个PayPal立即购买按钮。我有一个循环,它从我的数据库中提取视频信息内容,但我似乎无法弄清楚为什么这些按钮无法正常工作。
我在控制台中不断收到错误
错误:文档已准备就绪,元素#ws_lifh1不存在 https://www.paypalobjects.com/api/checkout.js:7798:54↵
ws_lifh1是每个视频的视频ID。我收到此错误4次,但每次都在错误中显示正确的视频ID。
以下是我生成此代码的代码
var ppbutton = paypal.Button.render( {
env: 'sandbox', // Or 'sandbox',
client: {
sandbox: 'something',
production: 'something'
},
commit: true, // Show a 'Pay Now' button
style: {
label: 'buynow',
branding: 'true',
size: 'small', // small | medium | large | responsive
shape: 'rect', // pill | rect
color: 'blue' // gold | blue | silver | black
},
payment: function ( data, actions ) {
return actions.payment.create( {
payment: {
transactions: [ {
amount: {
total: '12.95',
currency: 'USD'
},
description: 'Video purchase from Boomer Fitness with Michael G.',
item_list: {
items: [ {
name: 'Lean in Fifteen at Home #1',
videoid: 'ws_lifh1',
price: '12.95',
currency: 'USD'
} ]
}
} ]
}
} );
},
onAuthorize: function ( data, actions ) {
return actions.payment.execute().then( function ( payment ) {
window.alert( 'payment received' );
} );
},
onCancel: function ( data, actions ) {
/*
* Buyer cancelled the payment
*/
},
onError: function ( err ) {
/*
* An error occurred during the transaction
*/
}
}, '#' + videoid );
var videolisting = document.createElement( 'div' );
videolisting.setAttribute( 'class', 'row bottom-margin' );
videolisting.innerHTML = "<div class='col-md-12'><h3>" + videoname + "</h3><h3>$ " + videoprice + "</h3><div id='" + videoid + "'></div>" + ppbutton + "</div></div>";
document.getElementById( 'container' ).appendChild( videolisting );
} );
&#13;