如何使用Meteor js重定向到Stripe成功后的成功页面
How to redirect to a success page After Stripe success with Meteor js
我正在用流星、进行条纹支付测试
我正在从我的服务器成功地获得付款
我用流星法,
但我需要
- 向用户显示付款处理的可视化信息,然后在付款成功时显示
- 返回一个成功的支付对象)到客户端(我可以这样做,然后用各种信息呈现一个成功模板
我怎么能同时做到这两件事呢?
提交事件
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.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);
});
}
});
您可以使用一个反应变量来显示不同的子模板,在同一个父模板中处理所有这些模板。
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
}
});
}
});
相关文章:
- 尽管链接成功并已成功下载,但未找到NPM模块
- 在另一个函数成功结束后调用该函数
- 在ajax成功后,cluetip不适用于首次点击活动元素
- jQuery成功函数中的ajax成功函数
- 如何使用Stripe'验证优惠券;s JavaScript API
- jQuery触发器点击未从AJAX成功工作
- 如何使用jQuery可编辑插件检查ajax是否成功完成
- 执行ajax成功函数-jQUERY
- 解析云代码错误:解析.错误{代码:141,消息:“未调用成功/错误”}
- 如何从servlet获取数据到ajax成功
- 成功回调永远不会被JSONP请求调用
- 将表单张贴到MailChimp,但显示动态成功页面
- ajax请求成功,但可以'我看不到我的数据
- I'我试图在文本区域中进行特定的输入,调用特定的javascript函数,但没有成功;不起作用
- AngularJs|Don'在成功加载所有指令htmls之前,不显示页面
- Node.js Passport成功登录后显示用户名
- 通过mvc中的ajax动作链接获取关于成功的响应头
- 查询后websql成功回调无法访问变量
- 如何使用Meteor js重定向到Stripe成功后的成功页面
- Stripe在本地返回成功的测试事务,但不在活动页面上返回