Dan*_*elC 5 google-chrome paypal paypal-sandbox google-chrome-extension paypal-buttons
我认为这将是一个简单的 2 线集成,如下所示。但在添加正确的 CSP 以允许在线执行后,行为并不符合预期。窗口弹出并立即关闭。
这是我的 popup.html
<html>
<head>
<title>Quick Launcher</title>
<link rel="stylesheet" href="style.css" />
<script src="https://www.paypal.com/sdk/js?client-id=sb"></script>
</head>
<body>
<h1>My chrome</h1>
<script>paypal.Buttons().render('body');</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
清单.json
{
"manifest_version": 2,
"name": "Quick Launcher",
"description": "Smart links organizer. Create collection of related links or add urls of different environments(uat, prod) of various deployed apps",
"version": "1.2.10",
"icons": {
},
"browser_action": {
"default_icon": {
},
"default_popup": "popup.html"
},
"content_security_policy": "script-src 'self' https://www.paypal.com 'sha256-U2vsCzUQ797LcHkgCQJsOSAJxY/+LTdJONJ+wacPXrI='; object-src 'self' https://www.paypal.com 'sha256-U2vsCzUQ797LcHkgCQJsOSAJxY/+LTdJONJ+wacPXrI='; script-src-elem 'self' https://www.paypal.com 'sha256-U2vsCzUQ797LcHkgCQJsOSAJxY/+LTdJONJ+wacPXrI='",
"background": {
"scripts": [
"background.js"
]
},
"permissions": ["tabs", "activeTab"]
}
Run Code Online (Sandbox Code Playgroud)
小智 1
这只是初始化SDK。你必须做几件事:
client-id=sb为您自己的客户端 ID。https://developer.paypal.com/docs/api/overview/#get-credentials
创建一个空的<div>div 并在 render() 方法中通过 id 引用该 div
添加适当的回调函数来创建并完成订单。
前任。
paypal.Buttons({
createOrder: function(data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
purchase_units: [{
amount: {
value: '0.01'
}
}]
});
},
onApprove: function(data, actions) {
// This function captures the funds from the transaction.
return actions.order.capture().then(function(details) {
// This function shows a transaction success message to your buyer.
alert('Transaction completed by ' + details.payer.name.given_name);
});
}
}).render('#paypal-button-container');
//This function displays Smart Payment Buttons on your web page.
Run Code Online (Sandbox Code Playgroud)
https://developer.paypal.com/docs/checkout/integrate/#
谢谢!
| 归档时间: |
|
| 查看次数: |
667 次 |
| 最近记录: |