Stripe: Customer Object, Create
Stripe: Customer Object, Create

Creates the Customer object on the payment platform Stripe. Once the object is created, subsequent card billing is possible. Token ID and the customer email etc are required. Realizes a billing environment that does not touch sensitive info.

2020-06-02 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/stripe-customer-object-create/

Configs
  • A: Set SecretKey of Stripe (sk_xxx: 32 letters) * #{EL}
  • B: Set Token ID * #{EL}
  • C1: Set Customer Email * #{EL}
  • C2: Set Customer Description (Registration Num, Corp Name, etc) * #{EL}
  • C3: Set Customer Name (Contact Name, Trade Name, etc) #{EL}
  • D1: Select STRING DATA for Stripe Customer ID (update) *
  • D2: Select STRING DATA for Card Brand (update)
  • D3: Select STRING DATA for Card Last4 (update)
  • D4: Select STRING/YMDATE for Card Exp (update)
Script
// Nashorn Script (engine type: 1)
// 
// Notes:
// Token is generated by JavaScript on the browser.
// - "Checkout" (forms hosted on Stripe) https://stripe.com/docs/payments/checkout
// - "Elements" (custom payment forms) https://stripe.com/docs/stripe-js
// - If M213-decoration "jQuery.getScript('https://js.stripe.com/v3/', function(){..."
// -- https://questetra.zendesk.com/hc/en-us/articles/360002245252-M213
// The card number etc is deposited at Stripe, and only the token flows in the workflow.
// Token is converted to Customer object and continuous billing becomes possible.
// There is no way to incorporate sensitive information into workflow data.
// - PAN: Primary Account Number
// - PIN: Personal Identification Number
// - CVC: Card Verification Code/Value (3 digit number, to be exact CVC2, CID)
// * also on the Stripe Dashboard (Non-retention of card information)
// Refer to the following for the error codes (ResponseCode other than 200).
// - https://stripe.com/docs/api/errors

// Notes(ja):
// Tokenはブラウザ上のJavaScriptによって生成されます。
// - "Checkout" (forms hosted on Stripe) https://stripe.com/docs/payments/checkout
// - "Elements" (custom payment forms) https://stripe.com/docs/stripe-js
// - M213デコの場合 "jQuery.getScript('https://js.stripe.com/v3/', function(){..."
// -- https://questetra.zendesk.com/hc/ja/articles/360002245252-M213
// カード番号等はStripe社に預けられ、フローには「預かり番号」としてのTokenを流します。
// TokenはCustomerオブジェクト(Customer ID)に変換され、継続課金が可能な状態となります。
// センシティブ情報をワークフローデータに取り込む方法はありません。(カード情報の非保持)
// - PAN:Primary Account Number (カード番号)
// - PIN:Personal Identification Number (暗証番号)
// - CVC: Card Verification Code/Value (3桁数字/正確にはCVC2/CIDとも)
// ※Stripe管理画面からも取得できません。(カード情報の非保持)
// エラーコード(200以外のResponseCode)の内容については以下を参照してください。
// - https://stripe.com/docs/api/errors

/*
 Questetra BPMS V12.0 (released 2020-05-11)
 - configs.getObject()
 - engine.findData()
 - engine.setData()
*/

//////// START "main()" /////////////////////////////////////////////////////////////////

main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const strSecretKey     = configs.get( "strSetConfA"  ); // required
const strTokenId       = configs.get( "strSetConfB"  ); // required
const strCustomerEmail = configs.get( "strSetConfC1" ); // required
const strCustomerDescr = configs.get( "strSetConfC2" ); // required
const strCustomerName  = configs.get( "strSetConfC3" ); // not
const pocketCustomerId = configs.getObject( "SelectConfD1" ); // required
const pocketCardBrand  = configs.getObject( "SelectConfD2" ); // not
const pocketCardLast4  = configs.getObject( "SelectConfD3" ); // not
const pocketCardExp    = configs.getObject( "SelectConfD4" ); // not *STRING/YMDATE

if( strSecretKey === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {SecretKey A} is empty \n" );
}
if( strTokenId === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {Token ID B} is empty \n" );
}
if( strCustomerEmail === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {CustomerEmail C1} is empty \n" );
}
if( strCustomerDescr === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {CustomerDescription C2} is empty \n" );
}


//// == Data Retrieving / ワークフローデータの参照 ==
// (nothing, except Expression Language config)


//// == Calculating / 演算 ==
/// POST /v1/customers
// https://stripe.com/docs/api/customers/create
// curl https://api.stripe.com/v1/customers \
//   -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
//   -d description="My First Test Customer (created for API docs)"

// preparing for API Request
let apiUri = "https://api.stripe.com/v1/customers";
let apiRequest = httpClient.begin(); // HttpRequestWrapper
    apiRequest = apiRequest.basic( strSecretKey, "" );
    apiRequest = apiRequest.formParam( "source",      strTokenId );
    apiRequest = apiRequest.formParam( "email",       strCustomerEmail );
    apiRequest = apiRequest.formParam( "description", strCustomerDescr );
    apiRequest = apiRequest.formParam( "name",        strCustomerName );

// throwing Request to the API (POST, GET, PUT, etc)
engine.log( " AutomatedTask Trying: POST " + apiUri );
const response = apiRequest.post( apiUri );
const responseCode = response.getStatusCode() + "";
engine.log( " AutomatedTask ApiResponse: Status " + responseCode );
if( responseCode !== "200"){
  throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                    responseCode + "\n" + response.getResponseAsString() + "\n" );
} // C.F. https://stripe.com/docs/api/errors

// parsing Response Json
const responseStr = response.getResponseAsString() + "";
//engine.log( " DEBUG for api upgrade: \n" + responseStr );
const responseObj = JSON.parse( responseStr );
engine.log( " AutomatedTask ApiResponse:" +
            " New CustomerObject ID: " + responseObj.id );
engine.log( " AutomatedTask ApiResponse:" +
            " Card Brand: " + responseObj.sources.data[0].brand );


//// == Data Updating / ワークフローデータへの代入 ==
engine.setData( pocketCustomerId, responseObj.id );
if( pocketCardBrand !== null ){ // STRING
  engine.setData( pocketCardBrand, responseObj.sources.data[0].brand );
}
if( pocketCardLast4 !== null ){ // STRING
  engine.setData( pocketCardLast4, responseObj.sources.data[0].last4 );
}
if( pocketCardExp !== null ){ // STRING or YMDATE
  if( pocketCardExp.matchDataType( "STRING" ) ){
    engine.setData( pocketCardExp, 
         ("0" + responseObj.sources.data[0].exp_month).slice(-2) + "/" +
         responseObj.sources.data[0].exp_year );
  }else{
    engine.setData( pocketCardExp, 
         java.sql.Date.valueOf(
           responseObj.sources.data[0].exp_year + "-" +
           ("0" + responseObj.sources.data[0].exp_month).slice(-2) + "-01"
         )
    );
  }
}

} //////// END "main()" /////////////////////////////////////////////////////////////////

Download

Capture

Creates the Customer object on the payment platform Stripe. Once the object is created, subsequent card billing is possible. Token ID and the customer email etc are required. Realizes a billing environment that does not touch sensitive info.

Notes

  1. Token is generated by JavaScript on the browser.
    1. “Checkout” (forms hosted on Stripe) https://stripe.com/docs/payments/checkout
    2. “Elements” (custom payment forms) https://stripe.com/docs/stripe-js
    3. If M213-decoration “jQuery.getScript(‘https://js.stripe.com/v3/ ‘, function(){…”
      1. https://questetra.zendesk.com/hc/en-us/articles/360002245252-M213
  2. The card number etc is deposited at Stripe, and only the token flows in the workflow.
  3. Token is converted to Customer object and continuous billing becomes possible.
  4. There is no way to incorporate sensitive information into workflow data.
    1. PAN: Primary Account Number
    2. PIN: Personal Identification Number
    3. CVC: Card Verification Code/Value (3 digit number, to be exact CVC2, CID)
    4. * also on the Stripe Dashboard (Non-retention of card information)
  5. Refer to the following for the error codes (ResponseCode other than 200).
    1. https://stripe.com/docs/api/errors

See also

4 thoughts on “Stripe: Customer Object, Create”

  1. Pingback: Stripe Customer ID Create from Token – Questetra Support

  2. Pingback: Card Info to Stripe (MM/YY edition) – Questetra Support

  3. Pingback: Card Info to Stripe – Questetra Support

  4. Pingback: Stripe: Charge Object, Create – Questetra Support

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: