我正在使用流星进行条纹支付测试,
我收到的付款要成功通过我的服务器进行条带化,
我在流星方法中这样做,
但我需要
我怎么能这两个?
提交活动
Template.step4.events({
'submit #insertpaymentInfo':function(e){
e.preventDefault();
Stripe.setPublishableKey('PUBLISHABLEKEY');
var $form = $('#insertpaymentInfo');
$form.find('button').prop('disabled', true);
Stripe.card.createToken($form, callbackStripe);
}
});
收到令牌后来自条带服务器的回调
function callbackStripe(status, response){
var $form = $('#insertpaymentInfo');
console.log("hi 1")
if (response.error) {
$form.find('.payment-errors').text(response.error.message);
$form.find('button').prop('disabled', false);
} else {
var token = response.id;
//TODO build an array of relevant data that needs to be sent to the server
//Token on its own only sent for testing
Meteor.call('processPayment',token);
}
}
这是我的meteor方法服务器端
Meteor.methods({
'processPayment':function(stripeToken){
console.log("stripe token = "+ stripeToken);
check(stripeToken,String);
console.log("payment and order can be processed and created");
var Stripe = StripeAPI('TESTKEY');
Stripe.charges.create({
amount: 1000, // amount in cents, again
currency: "usd",
card: stripeToken,
description: "payinguser@example.com"
}, function (err, res) {
console.log(err, res);
});
}
});
答案 0 :(得分:1)
您可以使用反应变量在同一父模板中处理所有这些模板以显示不同的子模板。
Template.step4.created = function(){
this.state = new ReactiveVar("editing");
}
<template name="step4">
{{#if state "editing"}}
{{> payment_form}}
{{/if}}
{{#if state "processing"}}
{{> processing}}
{{/if}}
{{#if state "success"}}
{{> success}}
{{/if}}
</template>
Template.step4.helpers({
state: function(param){
return Template.instance().state.get() === param;
}
});
Template.step4.events({
'submit #insertpaymentInfo':function(e, template){
e.preventDefault();
Stripe.setPublishableKey('PUBLISHABLEKEY');
var $form = $('#insertpaymentInfo');
$form.find('button').prop('disabled', true);
template.state.set("processing");
Stripe.card.createToken($form, function(err, res){
if (error){
template.state.set("editing");
// error handle as you did above
} else {
template.state.set("success");
// show info via response object
}
});
}
});