2017-11-01 2 views
0

ストライプカスタムに対してstripe.accounts.create({})を設定しようとしています。ここでの目標は、すべてのフォームを1つのフォームで作成して、フォームが競合した後にユーザーがストライプアカウントのすべての情報要件を満たして取引することです。 Stripeが推奨するクレジットカード番号を使用して現在のコードをテストすると、次のコードブロックの後に表示されるエラーが表示されます。ストライプ作成のアカウント文書で参照されていない行方不明のトークン化プロセスがあるかどうか疑問に思っています。私はストライプをテストすることをお勧めしますことを、クレジットカード情報を入力したとき、私は、ユーザーが作成されると予想とき、これは私の現在のpostメソッドストライプアカウントの設定とテストストライプカスタムの作成

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

は、私は次のエラー

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

を取得しています。

EDIT:この記事のknexデータベースコードの一部を削除して、現在のエラーとは関係なく長さを短くしました。現在のエラーは、具体的にはStripeの約束によるものです。

答えて

0

お客様のコードは、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); 
}); 
関連する問題