我实际上正在处理付款SDK示例。下面是我如何做到这一点......请注意,我的initApp函数在webworksready事件被触发时被调用。
在你的index.html中,你需要为此创建一个事件监听器。在此事件触发之前,您无法访问任何本机API。
<!-- Set the webworksready event handler -->
<head>
<script type="text/javascript">
document.addEventListener("webworksready", initApp);
</script>
</head>
然后,JavaScript的部分...
/**
* called by the webworksready event when the environment is ready
*/
function initApp() {
// init payment service development mode
try {
blackberry.payment.developmentMode = true;
} catch(e) {}
}
function purchase() {
console.log('purchasing');
try {
blackberry.payment.purchase({
"digitalGoodID": "123",
"digitalGoodSKU": "someSKU",
"digitalGoodName": "SomeName",
"metaData": "metadata",
"purchaseAppName": "WebWorks APP",
"purchaseAppIcon": null,
"extraParameters": {
"key1": "value1",
"key2": "value2"
}
},
onSuccess, onFailure);
} catch (e) {
alert("Error" + e);
}
}
function onSuccess(purchasedItem) {
console.log(purchasedItem)
}
function onFailure(error) {
console.log(error);
}