javascript - 如何使用 $http POST 和 Angular-Payments 传递电子邮件地址以及 strip token ?

标签 javascript angularjs stripe-payments

当我处理订阅信用卡付款时,我想在继续下一步(设置实际帐户)之前包含用户的电子邮件地址。

我可以成功设置订阅/为卡充值,但似乎无法包含电子邮件地址。我正在使用 Angular 支付模块。

如何将电子邮件地址传递给 stripe?

形式:

<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>

Controller :

// 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!'});
        }
    });
}

最佳答案

创建 token 时, strip 不需要电子邮件地址。 但是当您将表单发布到节点时。您可以使用 req.body.email 捕获电子邮件,并在创建客户时将其传递到节点端的 stripe 调用中

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

关于javascript - 如何使用 $http POST 和 Angular-Payments 传递电子邮件地址以及 strip token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26936946/

相关文章:

forms - AngularJS : How to mock a FormController injected in scope?

stripe-payments - 在 Stripe 中更新计划成本

google-apps-script - 谷歌应用程序脚本 : Deploy as web app and get url without 302 redirects

javascript - 无法在 iOS phonegap adobe build 上使用 navigator.camera.getPicture

javascript - 调用组件时定义变量

javascript - 输入 tab 键在 Bootstrap Modal 中不起作用

javascript - 如果 Angular-ui-layout 处于 Angular View 中,如何使其保留在其容器内?

php - 使用 Laravel Stripe 支付错误(您必须提供卡或客户 ID)

javascript - 嵌套在 for 循环外部的 return 语句出现问题

javascript - 在关联数组javascript中添加键值