PayPal Send

Sends an invoice with the Paypal Invoice ID specified by String type data item via email, and stores the status in a String type data item

    A. Set CLIENT-ID and SECRET for PayPal-REST-API (2-lines)Multi-line inputRequired
    B. Select STRING DATA for Paypal Invoice IDData selectString(single line)Required
    C. Select STRING DATA for Paypal Invoice Status (update)Data selectString(single line)Required
    -variable namevariable label
    Aconf_ClientId_SecretSet CLIENT-ID and SECRET for PayPal-REST-API (2-lines)
    Bconf_DataIdBSelect STRING DATA for Paypal Invoice ID
    Cconf_DataIdCSelect STRING DATA for Paypal Invoice Status (update)
    // PayPal Invoicing Send (ver. 20170602)
    // (c) 2017, Questetra, Inc. (the MIT License)
    
    //// == 工程コンフィグの参照 / 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
    

    • B’: Paypal Invoice ID stored in the Data Item that is selected at config B
    • Invoice of property B’ is emailed
    • Paypal Invoice Status is stored in the Data Item selected at C
    • You need to create App at Paypal Dashboard beforehand and obtain Client ID/Secret