【问题标题】:How to redirect to a success page After Stripe success with Meteor js使用 Meteor js 进行 Stripe 成功后如何重定向到成功页面
【发布时间】:2015-04-08 18:27:22
【问题描述】:

我正在使用流星进行条纹支付测试,

我正在获得付款以成功从我的服务器中删除,

我正在使用流星方法进行此操作,

但我需要

  1. 向用户显示支付处理的视觉效果,然后在支付成功时显示
  2. 将成功的支付对象返回给客户(我可以这样做,然后使用各种信息呈现成功模板

我怎么能做到这两点?

提交事件

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);
     });
 }
});

【问题讨论】:

标签: javascript node.js meteor stripe-payments


【解决方案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
      }
    });
  }
});

【讨论】:

  • 嘿,非常感谢,这对我帮助很大,我相信从现在开始我将使用 reactiveVars。
猜你喜欢
  • 2021-01-13
  • 1970-01-01
  • 1970-01-01
  • 2014-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-12
  • 2019-02-25
相关资源
最近更新 更多