簡體   English   中英

如何使用$ http POST和angular-payments傳遞電子郵件地址和條紋令牌?

[英]How can I pass an email address along with stripe token using $http POST and angular-payments?

當我處理訂閱信用卡付款時,我想在繼續下一步(設置實際帳戶)之前包括用戶的電子郵件地址。

我可以成功設置訂閱/收費卡,但似乎無法包含電子郵件地址。 我正在使用角度付款模塊。

如何將電子郵件地址傳遞給條紋?

表格:

<form stripe-form="stripeCallback" name="checkoutForm">          
  <input type="email" placeholder="Email" ng-model="email" name="email">
  <input ng-model="number" placeholder="Card Number" payments-format="card" payments-validate="card" name="card" />         
  <input ng-model="expiry" placeholder="Expiration" payments-format="expiry" payments-validate="expiry" name="expiry" />        
  <input ng-model="cvc" placeholder="CVC" payments-format="cvc" payments-validate="cvc" name="cvc" />  
  <button type="submit" class="button cta payment">Subscribe</button>
</form>

控制器:

// Stripe Response Handler
        $scope.stripeCallback = function (code, result) {
          if (result.error) {
            window.alert('it failed! error: ' + result.error.message);
          } else {
          $http.post('/charge', result)
          .success(function(data, status, headers, config) {
            alert('success');
          })
          .error(function(data, status, headers, config) {
            console.log(status);
            alert('error');
          });
          }
        };

節點:

// for subscriptions:
function subscribeUser(token, res){
    // this assumes you've already created a plan (dashboard.stripe.com/plans) named 'test'
    stripe.customers.create({
        card: token,
        plan: '001'
    }, function(err, customer) {
        // you'll probably want to store a reference (customer.id) to the customer
        if (err) {
            res.send({
        ok: false, message: 'There was a problem processing your card (error: ' + JSON.stringify(err) + ')'});
        } else {
            res.send({
        ok: true, message: 'You have been subscribed to a plan!'});
        }
    });
}

創建令牌時,條帶不希望電子郵件地址。 但是當您將表單發布到節點時。 您可以使用req.body.email捕獲電子郵件,並在創建客戶時將其傳遞到節點側的條紋調用中

function subscribeUser(token, res){
    //NOTE: stripe.customers.create does not create subscription
    stripe.customers.create({
        card: token,
        plan: '001',
        email: req.body.email // THIS IS HOW EMAIL IS SENT TO STRIPE
    }, 
      function(err, customer) {
        if (err) console.log(err);
        else console.log('customer create successfully',customer)
      });
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM