Stripe: 顧客, 課金
Stripe: 顧客, 課金 (Stripe: Customer, Charge)
決済プラットフォームStripe上に “課金オブジェクト” を生成します。Stripe上のCustomerID(cus_12345678901234)に対して、任意の課金額を任意の課金通貨コードで課金します。課金処理が失敗した場合は、課金オブジェクトは生成されず、expired_card などのエラーログ出力されます。
Configs
  • U: HTTP認証設定を選択してください *
  • B: Customer ID をセットしてください *#{EL}
  • C1: 課金する金額を(正の整数で)セットしてください *#{EL}
  • C2: 課金通貨コードをセットしてください (”USD” “JPY” “EUR” など) *#{EL}
  • C3: 課金説明をセットしてください (会員番号・法人名など) *#{EL}
  • D1: Stripe課金IDが格納される文字列型データを選択してください (更新)
  • D2: カードBrandが格納される文字列型データを選択してください (更新)
  • D3: カード末尾4桁が格納される文字列型データを選択してください (更新)
  • D4: カード有効期限が格納される文字列型or年月型データを選択してください (更新)
Script (click to open)
// GraalJS Script (engine type: 2)

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

main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const strAuthzSetting     = configs.get      ( "AuthzConfU" );   /// REQUIRED
  engine.log( " AutomatedTask Config: Authz Setting: " + strAuthzSetting );
const strCustomerId    = configs.get( "strSetConfB"  ); // required
let   strChargeAmount  = configs.get( "strSetConfC1" ); // required
const strCurrencyCode  = configs.get( "strSetConfC2" ); // required
const strChargeDescr   = configs.get( "strSetConfC3" ); // required
const pocketChargeId   = configs.getObject( "SelectConfD1" ); // not
const pocketCardBrand  = configs.getObject( "SelectConfD2" ); // not
const pocketCardLast4  = configs.getObject( "SelectConfD3" ); // not
const pocketCardExp    = configs.getObject( "SelectConfD4" ); // not *STRING/YMDATE

if( strCustomerId === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {Customer ID B} is empty \n" );
}
if( strChargeAmount === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {ChargeAmount C1} is empty \n" );
}
if( strCurrencyCode === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {CurrencyCode C2} is empty \n" );
}
if( strChargeDescr === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {ChargeDescription C3} is empty \n" );
}

strChargeAmount = strChargeAmount.replace(/,/g, '').replace(/\./g, '');
let numChargeAmount = parseInt( strChargeAmount, 10 );
if( numChargeAmount <= 0 ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {ChargeAmount C1} must be positive \n" );
}
strChargeAmount = numChargeAmount + "";


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


//// == Calculating / 演算 ==
/// Create Charge Object
/// POST /v1/charges
// https://stripe.com/docs/api/charges/create
// https://stripe.com/docs/api/authentication
// If you need to authenticate via bearer auth (e.g., for a cross-origin request), 
// use -H "Authorization: Bearer sk_xxx" instead of -u sk_test_xxx.

// preparing for API Request
let apiUri = "https://api.stripe.com/v1/charges";
let apiRequest = httpClient.begin(); // HttpRequestWrapper
    apiRequest = apiRequest.authSetting( strAuthzSetting ); // with "Authorization: Bearer XX"
    // https://questetra.zendesk.com/hc/en-us/articles/360024574471-R2300#HttpRequestWrapper
    apiRequest = apiRequest.formParam( "customer",    strCustomerId   );
    apiRequest = apiRequest.formParam( "amount",      strChargeAmount );
    apiRequest = apiRequest.formParam( "currency",    strCurrencyCode );
    apiRequest = apiRequest.formParam( "description", strChargeDescr  );

// 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 ChargeObject ID: " + responseObj.id );
engine.log( " AutomatedTask ApiResponse:" +
            " Card Brand: " + responseObj.source.brand );


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

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

/*

Notes-en:
- Can include the automated step "charging process" into the workflow. (No code)
    - When the matter reaches, a charging request is automatically sent to the Stripe API.
    - https://stripe.com/docs/api/charges
- A positive integer representing how much to charge in the smallest currency unit.
    - e.g., "100" cents to charge $1.00
    - e.g., "100" to charge \100 (a zero-decimal currency) (JPY)
    - "#{#q_numUsdWithoutCent}00" is also possible if numerical data without auxiliary info
- If present, commas "," and periods "." are removed in advance.
    - When using numeric data, be careful of the number of digits after the decimal point.

APPENDIX-en:
- Numeric parsing depends on JavaScript parseInt(x,10). (The prefix gives an error)
    - See below for more information on available currency codes (JPY, USD, EUR, ...).
    - https://stripe.com/docs/currencies
- In case of USD, the minimum amount is $0.50 or equivalent.
    - The amount value supports up to eight digits (e.g., for a USD charge of $999,999.99)
- Refer to the following for the error codes (ResponseCode other than 200).
    - https://stripe.com/docs/api/errors

Notes-ja:
- ワークフロー内に自動工程『課金処理』を組み込むことができるようになります。(ノーコード実装)
    - 案件が自動工程に到達すると、Stripe API に対して課金リクエストが自動送信されます。
    - https://stripe.com/docs/api/charges
- 課金額の設定は、最小の通貨単位で表現します。(正の整数)
    - "1.00ドル" の場合は "100" セント (USD)
    - 小数のない円通貨の場合は "100円" は "100" 円 (JPY)
    - "1(ドル)" といったデータの場合 "#{#q_numUsdWithoutCent}00" のように設定します。
- もしカンマ "," やピリオド "." が存在する場合は課金処理前に除去されます。
    - 数値型データの小数を使う場合、小数点以下の桁数設定に注意
    - "100.00円" は「1万円」の課金になります。

APPENDIX-ja:
- 数値判定は JavaScript parseInt(x,10) に依存します (接頭辞はエラーになります)
    - 利用できる通貨コードの詳細は以下を参照してください (JPY, USD, EUR, ...)
    - https://stripe.com/docs/currencies
- 最小課金金額は、日本円の場合、50円です。
    - 課金額の最大桁数は8桁です。(日本円の場合、99,999,999円)
- エラーコード(200以外のResponseCode)の内容については以下を参照してください。
    - https://stripe.com/docs/api/errors
*/

Download

2021-06-08 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/ja/addons/stripe-customer-charge-2021/
Addonファイルのインポートは Professional でのみご利用いただけます

Notes

  • ワークフロー内に自動工程『課金処理』を組み込むことができるようになります。(ノーコード実装)
  • 課金額の設定は、最小の通貨単位で表現します。(正の整数)
    • “1.00ドル” の場合は “100” セント (USD)
    • 小数のない円通貨の場合は “100円” は “100” 円 (JPY)
    • “1(ドル)” といった「最小通貨単位でないデータ」を参照したい場合 “#{#q_numUsdWithoutCent}00” のように設定します。
  • もしカンマ “,” やピリオド “.” が存在する場合は課金処理前に除去されます
    • 数値型データの小数を使う場合、小数点以下の桁数設定に注意
    • “100.00円” は「1万円」の課金になります。

Capture

決済プラットフォームStripe上に "課金オブジェクト" を生成します。Stripe上のCustomerID(cus_12345678901234)に対して、任意の課金額を任意の課金通貨コードで課金します。課金処理が失敗した場合は、課金オブジェクトは生成されず、expired_card などのエラーログ出力されます。
決済プラットフォームStripe上に "課金オブジェクト" を生成します。Stripe上のCustomerID(cus_12345678901234)に対して、任意の課金額を任意の課金通貨コードで課金します。課金処理が失敗した場合は、課金オブジェクトは生成されず、expired_card などのエラーログ出力されます。

Appendix

  • 数値判定は JavaScript parseInt(x,10) に依存します (接頭辞はエラーになります)
  • 最小課金金額は、日本円の場合、50円です。
    • 課金額の最大桁数は8桁です。(日本円の場合、99,999,999円)
  • エラーコード(200以外のResponseCode)の内容については以下を参照してください。

See also

コメントを残す

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

%d人のブロガーが「いいね」をつけました。