2017-11-01 11 views
0

스트라이프 사용자 정의에 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); 
    }); 
     }}); 
}); 

, 나는 다음과 같은 오류 내가 만들 수있는 사용자를 예상

{ [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의 약속에서 비롯된 것입니다.

답변

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