PayPal Check

Stored the status of the Paypal Invoice ID specified by String type data item in a String type data item, and if having been paid, stores the payment date and time and the amount in a 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
    D. Select STRING DATA for Payment Timestamp (update)Data selectString(single line)
    E. Select NUMBER DATA for Payment Amount (update)Data selectNumeric
    -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)
    Dconf_DataIdDSelect STRING DATA for Payment Timestamp (update)
    Econf_DataIdESelect NUMBER DATA for Payment Amount (update)
    // PayPal Invoicing Status (ver. 20170603)
    // (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" ) + "";
    var dataIdD = configs.get( "conf_DataIdD" ) + "";
    var dataIdE = configs.get( "conf_DataIdE" ) + "";
    
    
    //// == ワークフローデータの参照 / 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;
    
    // Show Invoice Details
    var uriDetail = "https://api.paypal.com/v1/invoicing/invoices/" + paypalId;
    var responseDetail = httpClient.begin()
      .bearer( oauthToken )
      .get( uriDetail );
    var paypalInvoiceObj = JSON.parse( responseDetail.getResponseAsString() );
    var paypalInvoiceStatus = paypalInvoiceObj.status;
    
    
    //// == ワークフローデータへの代入 / Data Updating ==
    retVal.put( dataIdC, paypalInvoiceStatus ); // DRAFT, SENT, PAID, etc
    if( dataIdD !== "" ){
      if ( paypalInvoiceStatus == "PAID" ){
        retVal.put( dataIdD, paypalInvoiceObj.payments[0].date );
      }
    }
    if( dataIdE !== "" ){
      if ( paypalInvoiceStatus == "PAID" ){
        var amountValue = parseFloat( paypalInvoiceObj.payments[0].amount.value );
        retVal.put( dataIdE, java.math.BigDecimal( amountValue ) );
      }
    }
    ///retVal.put( "q_accessLog", responseDetail.getResponseAsString() ); // for debug
    

    • B’: Paypal Invoice ID stored in the Data Item selected at config B
    • Status of Invoice of property B’ is confirmed
    • Paypal Invoice Status is stored in the Data Item selected at config C
    • If Status was PAID, the Date / Amount of the payment is stored in the Data Item selected at config D and E
    • You need to create App at Paypal Dashboard beforehand and obtain Client ID/Secret