【问题标题】:Configuring and testing Stripe Accounts Create for Stripe custom配置和测试 Stripe Accounts Create for Stripe custom
【发布时间】:2017-11-01 00:51:27
【问题描述】:

我正在尝试为 Stripe 自定义配置 stripe.accounts.create({})。我的目标是在一个表单中创建所有内容,以便用户在表单完成后满足其条带帐户的所有信息要求以进行交易。使用 Stripe 推荐的信用卡号测试当前代码时,出现以下代码块后显示的错误。我想知道是否有一个我缺少的标记化过程在条带创建帐户文档中没有引用。这是我目前的发帖方式

var knex = require("../models/knex"),
    express = require('express'),
    middleware = require("../middleware/index"),
    stripe = require("stripe")("sk_test_VALUEOFMYTESTKEY"),
    router = express.Router({mergeParams:true});
    router.post("/formuser",function(req,res){
    console.log(req.user[0].user_id);
    knex("users.user").select("*").where("user_id",req.user[0].user_id)
    .then((user) => {
      var today = new Date(Date.now()).toLocaleString();
      var accountType = String(req.body.accountType).toLowerCase();
      var checkIfCard = accountType=="card";
      console.log(req.body.accountType,checkIfCard,String(req.body.cardNumber));
      var ip = req.headers['x-forwarded-for'] || 
               req.connection.remoteAddress || 
               req.socket.remoteAddress ||
               req.connection.socket.remoteAddress; 

      console.log(ip);
      if(!checkIfCard){
          stripe.accounts.create({
        email: user.email,
        country: "US",
        type: "custom",
        //Required fields for Custom via... https://stripe.com/docs/connect/required-verification-information
        metadata: {
        "external_account": {
          "object": "bank_account", 
          "exp_month": req.body.cardExpirationMonth,
          "exp_year":  req.body.cardExpirationYear,// : null,
          "number":  req.body.bankNumber,// : null,

        },                        //external account info... https://stripe.com/docs/api#account_create_bank_account
        "city": req.body.city,
        "legal_entity.adress.line1": req.body.streetAddress,
        "legal_entity.address.postal_code": req.body.zipCode,
        "legal_entity.address.state": req.body.state,
        "legal_entity.dob.day": req.body.birthDay,
        "legal_entity.dob.month": req.body.birthMonth,
        "legal_entity.dob.year": req.body.birthYear,
        "legal_entity.first_name": req.body.firstName,
        "legal_entity.last_name": req.body.lastName,
        "legal_entity.ssn_last_4": req.body.ssn_last_4,
        "tos_acceptance.date": today,
        "tos_acceptance.ip": ip,
        }

      }).then((acct) => {
        res.redirect("/");
      })
    .catch((e) => {
        console.log(e);
    });
      } else {
          stripe.accounts.create({
        email: user.email,
        country: "US",
        type: "custom",
        //Required fields for Custom via... https://stripe.com/docs/connect/required-verification-information
        metadata: {
        "external_account": {
          "object": "card", //bank account or cc or dc...
          "card": req.body.cardNumber.toString(),
          "cvc" : req.body.cvc.toString(),
          "currency" : "usd",// : null

        },                        //external account info... https://stripe.com/docs/api#account_create_bank_account
        "city": req.body.city,
        "legal_entity.adress.line1": req.body.streetAddress,
        "legal_entity.address.postal_code": req.body.zipCode,
        "legal_entity.address.state": req.body.state,
        "legal_entity.dob.day": req.body.birthDay,
        "legal_entity.dob.month": req.body.birthMonth,
        "legal_entity.dob.year": req.body.birthYear,
        "legal_entity.first_name": req.body.firstName,
        "legal_entity.last_name": req.body.lastName,
        "legal_entity.ssn_last_4": req.body.ssn_last_4,
        "tos_acceptance.date": today,
        "tos_acceptance.ip": ip,
        }

      }).then((acct) => {
        res.redirect("/");
      })
    .catch((e) => {
        console.log(e);
    });
      }});
});

当我输入 Stripe 推荐测试的信用卡信息时,我收到以下错误

   { [Error: Invalid val: {"object"=>"card", "card"=>"4242 4242 4242 4242", "cvc"=>"111", "currency"=>"usd"} must be a string under 500 characters]
  type: 'StripeInvalidRequestError',
  stack: 'Error: Invalid val: {"object"=>"card", "card"=>"4242 4242 4242 4242", "cvc"=>"111", "currency"=>"usd"} must be a string under 500 character

当我希望创建一个用户时。

编辑:我在这篇文章中删除了一些 knex 数据库代码以缩短它的长度,因为它与当前错误无关。当前的错误专门来自 Stripe 的承诺。

【问题讨论】:

    标签: node.js stripe-payments stripe-connect


    【解决方案1】:

    您的代码正在尝试传递 external_account 中的银行帐户详细信息,但同时也传递卡数据。这不太可能是您想要的。

    除此之外,您根本不应该在服务器端传递这些信息,因为它很敏感。相反,您应该创建一个令牌客户端。对于卡数据,您将使用 Elements,对于银行账户数据,您将构建自己的表单并使用 Stripe.js 进行标记。完成此操作后,您将获得卡令牌 tok_123 或银行帐户令牌 btok_123,然后可以在 external_account 参数中使用此服务器端。

    然后,您还应该将数据作为嵌套散列传递。这意味着您不会通过"legal_entity.adress.line1",而是通过legal_entity[address][line1]。您的代码应如下所示:

    stripe.accounts.create( 
    {
      type: 'custom',
      country: 'US',
      legal_entity : {
        first_name : 'john',
        last_name : 'doe',
        type : 'individual',
        address: {
          line1: 'line1',
          city: 'city',
          state: 'state',
          postal_code: '90210',
          country: 'US'
        } 
      },
      external_account: 'tok_visa_debit',
    }).then((acct) => {
      console.log('account: ', JSON.stringify(acct));
    }).catch((e) => {
      console.log(e);
    });
    

    【讨论】:

      猜你喜欢
      • 2018-11-04
      • 2021-03-26
      • 1970-01-01
      • 2021-01-01
      • 2021-10-24
      • 2021-07-03
      • 1970-01-01
      • 2021-11-29
      • 2016-11-30
      相关资源
      最近更新 更多