Stripe: Charge Create
Creates a new Stripe Charge. Automatic billing will be done to registered Customer. When an error occurs, an error code is stored in „Status Code“. https://stripe.com/docs/api/errors
https://support.questetra.com/addons/extractor-serialized-string/
2018-10-18 Questetra, Inc. (MIT license)
Configs
  • A: Set SecretKey for Stripe Access (sk_xxx: 32 letters) *
  • B: Select STRING DATA for Description (e.g. Corp Name)
  • C: Select STRING DATA for CustomerID *
  • D: Select NUMERIC/STRING DATA for Amount (Unit: Cent, Yen) *
  • E: Select STRING/SELECT DATA for CurrencyCode (e.g. jpy, usd) *
  • F: Select STRING DATA for Charge ID on Stripe (update)
  • G: Select STRING DATA for Last4 of CardNumber (update)
  • W: Select STRING DATA for Status Code (update) *
  • X: Select STRING DATA for Access Log (update) *
Script Source
// 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 ); }

Download

https://questetra.github.io/addon/service-task/Stripe-chargeCreate.xml

Capture

Notes

  1. It requires acquiring Secret Key at Stripe Dashboard in advance
  2. Supported cards or currency vary from country to country
  3. 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”)
  4. If “1,234.56” is entered, “. (dot)” will be removed by Addon and will be sent to Stripe API as “123456”

See also

第595話:アンケート回答期限、もうひとつの設定方法

Cloud BPM v11.6 Supports Webhook Start

(pinbacks)
 

Kommentar verfassen

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.

Scroll to Top