Stripe Customer ID Generation (from Token ID)

Registers a customer in Stripe by using the ID which tokenized credit card information. Customer ID used for billing, last 4 digits of the credit card, status of registration processing, and communication log are stored in Data Item.

    A. Set SecretKey for Stripe Access (sk_xxx: 32 letters)Single-line inputRequired
    B. Select STRING DATA for Token IdData selectString(single line)Required
    C. Select STRING DATA for Customer EmailData selectString(single line)Required
    D. Select STRING/SELECT DATA for Description (e.g. Corp Name)Data selectString(single line)orSelect(radio/select/search)
    E. Select STRING DATA for Customer ID on Stripe (update)Data selectString(single line)Required
    F. Select STRING DATA for Last4 of CardNumber (update)Data selectString(single line)
    W. Select STRING DATA for Http Status (update)Data selectString(single line)Required
    X. Select STRING DATA for Access Log (update)Data selectString(multiple line)
    -variable namevariable label
    Aconf_SecretKeySet SecretKey for Stripe Access (sk_xxx: 32 letters)
    Bconf_DataIdBSelect STRING DATA for Token Id
    Cconf_DataIdCSelect STRING DATA for Customer Email
    Dconf_DataIdDSelect STRING/SELECT DATA for Description (e.g. Corp Name)
    Econf_DataIdESelect STRING DATA for Customer ID on Stripe (update)
    Fconf_DataIdFSelect STRING DATA for Last4 of CardNumber (update)
    Wconf_DataIdWSelect STRING DATA for Http Status (update)
    Xconf_DataIdXSelect STRING DATA for Access Log (update)
    // Stripe Elements Token to Stripe Customer ID (ver. 20170901)
    // (c) 2016, Questetra, Inc. (the MIT License)
    
    //// == Config Retrieving / 工程コンフィグの参照 ==
    var secretKey = configs.get( "conf_SecretKey" ) + "";
    var dataIdB = configs.get( "conf_DataIdB" ) + "";
    var dataIdC = configs.get( "conf_DataIdC" ) + "";
    var dataIdD = configs.get( "conf_DataIdD" ) + "";
    var dataIdE = configs.get( "conf_DataIdE" ) + "";
    var dataIdF = configs.get( "conf_DataIdF" ) + "";
    var dataIdW = configs.get( "conf_DataIdW" ) + "";
    var dataIdX = configs.get( "conf_DataIdX" ) + "";
    // convet 'java.lang.String' to 'javascript string'
    
    //// == Data Retrieving / ワークフローデータの参照 ==
    var stripeTokenId = engine.findDataByNumber( dataIdB ) + "";
    var customerEmail = engine.findDataByNumber( dataIdC ) + "";
    var customerDescr = "";
    if( engine.findDataDefinitionByNumber( dataIdD ).matchDataType( "SELECT_SINGLE" ) ){
      customerDescr = engine.findDataByNumber( dataIdD ).get(0).getValue() + "";
    }else if( engine.findDataDefinitionByNumber( dataIdD ).matchDataType( "STRING_TEXTFIELD" ) ){
      customerDescr = engine.findDataByNumber( dataIdD ) + "";
    }
    // convet 'java.lang.String' to 'javascript string'
    
    //// == Calculating / 演算 ==
    
    // preparing for API Request
    var apiRequest = httpClient.begin(); // HttpRequestWrapper
    
    // preparing for API Request (OAuth2 Token, HTTP Basic Auth, etc)
    apiRequest = apiRequest.basic( secretKey, "" );
    
    // preparing for API Request (Path parameters)
    var apiUri = "https://api.stripe.com/v1/customers";
    
    // preparing for API Request (Query parameters)
    // (no set)
    
    // preparing for API Request (JSON Body, Form Parameters)
    apiRequest = apiRequest.formParam( "source",      stripeTokenId );
    apiRequest = apiRequest.formParam( "email",       customerEmail );
    apiRequest = apiRequest.formParam( "description", customerDescr );
    
    // Request to the API (POST, GET, PUT, etc)
    var response = apiRequest.post( apiUri ); // HttpResponseWrapper
    var httpStatus = response.getStatusCode() + "";
    var accessLog = "---POST request--- " + httpStatus + "\n";
    accessLog += response.getResponseAsString() + "\n";
    var responseObj = JSON.parse( response.getResponseAsString() );
    
    // Retrieve Properties from Response-JSON
    var stripeCustomerId = "";
    var stripeLast4 = "";
    if( httpStatus === "200" ){
      stripeCustomerId  = responseObj.id;
      stripeLast4 = responseObj.sources.data[0].last4;
    }
    
    // Error Handling - https://stripe.com/docs/api#errors
    // (no action)
    
    
    //// == Data Updating / ワークフローデータへの代入 ==
    if ( dataIdE !== "" ){
      engine.setDataByNumber( dataIdE, stripeCustomerId );
    }
    if ( dataIdF !== "" ){
      engine.setDataByNumber( dataIdF, stripeLast4 );
    }
    if ( dataIdW !== "" ){
      engine.setDataByNumber( dataIdW, httpStatus );
    }
    if ( dataIdX !== "" ){
      engine.setDataByNumber( dataIdX, accessLog );
    }
    

    • B’: Token ID stored in the Data Item selected at config B
    • C’: C’: Email information stored in the Data Item selected at config C
    • D’: customer information stored in the Data Item selected at config D
    • A customer of tokenized card information B’ who is with C’ D’ will be registered in Stripe
    • Customer ID to charge will be stored in the Data Item selected at config E
    • The last four digits of a registered credit card number will be stored in the Data Item selected at config F
    • The status of the registration processing will be stored in the Data Item selected in config W
    • The communication log will be stored in the Data Item selected in config X
    • It requires acquiring Secret Key at Stripe Dashboard in advance
    • Supported cards or currency varies from country to country