PayPal Invoicing Send
Sends an invoice with the Paypal Invoice ID specified by a String-type Data Item via email, and stores the status in a String-type Data Item.
2017 (C) Questetra, Inc. (MIT License)
Configs
  • A: Set CLIENT-ID and SECRET for PayPal-REST-API (2-lines) *
  • B: Select STRING DATA for Paypal Invoice ID *
  • C: Select STRING DATA for Paypal Invoice Status (update) *
Script
//// == 工程コンフィグの参照 / Config Retrieving ==
var clientId_secret = configs.get( "conf_ClientId_Secret" ) + "";
var array_clientId_secret = clientId_secret.split("\n");
var clientId = array_clientId_secret[0];
var secret   = array_clientId_secret[1];

var dataIdB = configs.get( "conf_DataIdB" );
var dataIdC = configs.get( "conf_DataIdC" );


//// == ワークフローデータの参照 / Data Retrieving ==
var paypalId         = data.get( dataIdB ) + "";


//// == 演算 / Calculating ==
// Get OAuth Token with Client Credentials
var uri = "https://api.paypal.com/v1/oauth2/token";
var response = httpClient.begin()
  .basic( clientId, secret )
  .formParam( "grant_type", "client_credentials" )
  .post( uri );
var oauthTokenObj = JSON.parse( response.getResponseAsString() );
var oauthToken = oauthTokenObj.access_token;

// Send invoice
var uriSend = "https://api.paypal.com/v1/invoicing/invoices/" + paypalId + "/send";
var responseSend = httpClient.begin()
  .bearer( oauthToken )
  .post( uriSend );
var statusByCode = responseSend.getStatusCode() + "";

//// == ワークフローデータへの代入 / Data Updating ==
retVal.put( dataIdC, statusByCode );
///retVal.put( "q_accessLog", responseSend.getResponseAsString() ); // for debug

Download

Capture

Notes

  • You need to create App at PayPal Dashboard beforehand and obtain Client ID/Secret

Workflow-Sample

%d bloggers like this: