【发布时间】:2014-03-09 11:05:11
【问题描述】:
我正在尝试将使用 Jquery 构建的 Stripe Checkout 集成到使用 Angular 构建的 SPA 中。我想使用自定义版本,并能够根据当前范围更改金额或电子邮件等数据。
我尝试过写一个指令:
.directive('ngSparkline', function() {
return {
restrict: 'E',
scope: {
amount: '@'
},
templateUrl: 'views/stripe.html',
replace: true
};
});
根据 Stripe 的文档,其中 stripe.html 包含以下 sn-p:
<button id="customButton">Purchase</button>
<script>
var handler = StripeCheckout.configure({
key: "pk_test_sK21onMmCuKNuoY7pbml8z3Q",
image: "apple-touch-icon.png",
token: function(token, args) {
jQuery.ajax({
type:"POST",
url: "/stripetoken/", //For own custom domain, put the full https appspot url here
data: token,
timeout: 200000,
beforeSend: function(settings) {
console.log("About to send the transaction, may take a while, but this will be async")
},
success: function(result)
{
alert("Paiement Effectué");
},
error: function(result) {
console.log("Error",result);
}
});
}
});
document.getElementById("customButton").addEventListener("click", function(e) {
// Open Checkout with further options
handler.open({
name: "Vinify",
description: "Recharge Vinibar",
currency: "EUR",
panelLabel: "Payer",
amount: {{amount}}
});
e.preventDefault();
});
</script>
但结帐不会触发,即使我只是尝试使用硬写的随机数量。当我将相同的 sn-p 直接放在我的 html 中时,将 {{amount}} 替换为随机数量,它工作正常。
最好的方法是什么?我想用 checkout 是因为 UI 已经建好了,重写会有点痛苦。我尝试过 angular-payments,但代码与我使用的 ionic 框架混淆了。
谢谢!
【问题讨论】:
-
我绝对不会在
<script>标签中放置 Angular 绑定... -
是的,我知道这感觉很奇怪。但它适用于更简单的 javascript sn-p。不是 Jquery 的东西。
-
我认为这会导致浏览器在每次更改绑定值时重新编译并重新执行
<script>标签的全部内容。
标签: jquery angularjs angularjs-directive stripe-payments