Stripe Credit card Charge

From Customer ID, charge amount, currency code etc. stores Charge ID, last 4 digits of credit card number, status of registration process, communication log respectively into data items as billing record

Stripe Charge to Customer ID
stripe-charge-create-20170925-addonxmltxt
(md5:bae492fcd978fc17d5d3467078d7aaaa)



    A. Set SecretKey for Stripe Access (sk_xxx: 32 letters)Single-line inputRequired
    B. Select STRING DATA for Description (e.g. Corp Name)Data selectString(single line)
    C. Select STRING DATA for CustomerIDData selectString(single line)Required
    D. Select NUMERIC/STRING DATA for Amount (Unit: Cent, Yen)Data selectString(single line)orNumericRequired
    E. Select STRING/SELECT DATA for CurrencyCode (e.g. jpy, usd)Data selectString(single line)orSelect(radio/select/search)Required
    F. Select STRING DATA for Charge ID on Stripe (update)Data selectString(single line)
    G. Select STRING DATA for Last4 of CardNumber (update)Data selectString(single line)
    W. Select STRING DATA for Status Code Log (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 Description (e.g. Corp Name)
    Cconf_DataIdCSelect STRING DATA for CustomerID
    Dconf_DataIdDSelect NUMERIC/STRING DATA for Amount (Unit: Cent, Yen)
    Econf_DataIdESelect STRING/SELECT DATA for CurrencyCode (e.g. jpy, usd)
    Fconf_DataIdFSelect STRING DATA for Charge ID on Stripe (update)
    Gconf_DataIdGSelect STRING DATA for Last4 of CardNumber (update)
    Wconf_DataIdWSelect STRING DATA for Status Code Log (update)
    Xconf_DataIdXSelect STRING DATA for Access Log (update)
    // Stripe Charge to Customer ID (ver. 20170925)
    // (c) 2017, 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 dataIdG = configs.get( "conf_DataIdG" ) + "";
    var dataIdW = configs.get( "conf_DataIdW" ) + "";
    var dataIdX = configs.get( "conf_DataIdX" ) + "";
    // convet 'java.lang.String' to 'javascript string'
    
    //// == Data Retrieving / ワークフローデータの参照 ==
    var stripeDescr = engine.findDataByNumber( dataIdB ) + "";
    var stripeCusId = engine.findDataByNumber( dataIdC ) + "";
    var stripeAmount = engine.findDataByNumber( dataIdD ) + ""; // DECIMAL or STRING_TEXTFIELD
      stripeAmount = stripeAmount.replace(/,/g,"").replace(/\./g,""); // Remove dots and commas
      // NOTICE: Stripe only accepts a positive integer in the smallest currency unit
      // (e.g., 100 cents to charge $1.00 or 100 to charge 100 jpy, a zero-decimal currency) 
      // https://stripe.com/docs/currencies#minimum-and-maximum-charge-amounts
    var stripeCurrency = engine.findDataByNumber( dataIdE ) + ""; // SELECT_SINGLE or STRING_TEXTFIELD
    if( engine.findDataDefinitionByNumber( dataIdE ).matchDataType( "SELECT_SINGLE" ) ){
        stripeCurrency = engine.findDataByNumber( dataIdE ).get(0).getValue() + "";
    }else if( engine.findDataDefinitionByNumber( dataIdE ).matchDataType( "STRING_TEXTFIELD" ) ){
        stripeCurrency = engine.findDataByNumber( dataIdE ) + "";
    } // iso-code in all lowercase letters https://stripe.com/docs/currencies
    // convet 'java.lang.String' to 'javascript string'
    
    //// == Calculating / 演算 ==
    // preparing for API Request
    var apiRequest = httpClient.begin(); // HttpRequestWrapper
    // com.questetra.bpms.core.event.scripttask.HttpClientWrapper
    
    // 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/charges";
    
    // preparing for API Request (Query parameters)
    // (no set)
    
    // preparing for API Request (JSON Body, Form Parameters)
    apiRequest = apiRequest.formParam( "amount",   stripeAmount );
    apiRequest = apiRequest.formParam( "currency", stripeCurrency );
    apiRequest = apiRequest.formParam( "customer",   stripeCusId );
    apiRequest = apiRequest.formParam( "description", stripeDescr );
    
    // 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 stripeChargeId = "";
    var stripeLast4 = "";
    if( httpStatus === "200" ){
      stripeChargeId = responseObj.id;
      stripeLast4 = responseObj.source.last4;
    }
    
    // Error Handling - https://stripe.com/docs/api#errors
    // (no action)
    
    
    //// == Data Updating / ワークフローデータへの代入 ==
    if ( dataIdF !== "" ){ engine.setDataByNumber( dataIdF, stripeChargeId ); }
    if ( dataIdG !== "" ){ engine.setDataByNumber( dataIdG, stripeLast4 ); }
    engine.setDataByNumber( dataIdW, httpStatus );
    if ( dataIdX !== "" ){ engine.setDataByNumber( dataIdX, accessLog ); }
    

    • B’: Description information stored in the Data Item selected at config B
    • C’: Customer ID information stored in the Data Item selected at config C
    • D’: Charge amount information stored in the Data Item selected at config D
    • E’: Currency code information stored in the Data Item selected at config E
    • Charging to Credit card with properties of B’ C’ D’ E’ are registered to Stripe
    • Charge ID is stored in the Data Item selected at config F as a Charge record
    • The last four digits of the charged Credit card number is stored in the Data Item selected at config G
    • Status of registration processing is stored in the Data Item selected at config W (To be used for handling of processing error)
    • The communication logs are stored in the Data Item selected at config X
    • It requires acquiring Secret Key at Stripe Dashboard in advance
    • Supported cards or currency vary from country to country
    • The Stripe API billing amount (D’) is specified in the minimum currency unit (positive integer) ($ 1234.56 USD is “123456”, 1,000 JPY is “1000”)
      If “1,234.56” is entered, “. (dot)” will be removed by Addon and will be sent to Stripe API as “123456”