PayPal Create

Generates Paypal invoice automatically from the setting item information, and stores Paypal Invoice ID in a String type data item

    A. Set CLIENT-ID and SECRET for PayPal-REST-API (2-lines)Multi-line inputRequired
    B. Set BUSINESS NAME for MerchantSingle-line inputRequired
    C. Set COUNTRY-CODE/POSTAL-CODE/Pref/City for Merchant (4-lns)Multi-line inputRequired
    D. Set ADDRESS for Merchant (2-lines)Multi-line inputRequired
    E. Set PHONE-COUNTRY-CODE/NUMBER/EMAIL/URL for Merchant (4-lns)Multi-line inputRequired
    F. Select STRING DATA for Billing Business NameData selectString(single line)Required
    G. Select STRING DATA for Billing Name1Data selectString(single line)Required
    H. Select STRING DATA for Billing Name2Data selectString(single line)Required
    I. Select STRING DATA for Billing EmailData selectString(single line)Required
    J. Select STRING DATA for Item NameData selectString(single line)Required
    K. Select STRING DATA for Item DescriptionData selectString(single line)Required
    L. Select NUMERIC DATA for Item QuantityData selectNumericRequired
    M. Select NUMERIC DATA for Unit PriceData selectNumericRequired
    N. Set ItemTax Percent (e.g. "8" "10")Single-line inputRequired
    O. Select STRING DATA for Invoice IDData selectString(single line)Required
    P. Select DATE DATA for Payment Due DateData selectDateRequired
    Q. Select STRING DATA for Invoice NoteData selectStringRequired
    R. Select STRING DATA for Invoice TermsData selectStringRequired
    S. Set Logo Url (e.g. "https://example.com/a.png")Single-line inputRequired
    T. Select STRING DATA for Paypal Invoice ID (update)Data selectString(single line)Required
    -variable namevariable label
    Aconf_ClientId_SecretSet CLIENT-ID and SECRET for PayPal-REST-API (2-lines)
    Bconf_MerchantBusinessNameSet BUSINESS NAME for Merchant
    Cconf_MerchantPostalCodeSet COUNTRY-CODE/POSTAL-CODE/Pref/City for Merchant (4-lns)
    Dconf_MerchantAddressSet ADDRESS for Merchant (2-lines)
    Econf_MerchantPhoneEmailSet PHONE-COUNTRY-CODE/NUMBER/EMAIL/URL for Merchant (4-lns)
    Fconf_DataIdFSelect STRING DATA for Billing Business Name
    Gconf_DataIdGSelect STRING DATA for Billing Name1
    Hconf_DataIdHSelect STRING DATA for Billing Name2
    Iconf_DataIdISelect STRING DATA for Billing Email
    Jconf_DataIdJSelect STRING DATA for Item Name
    Kconf_DataIdKSelect STRING DATA for Item Description
    Lconf_DataIdLSelect NUMERIC DATA for Item Quantity
    Mconf_DataIdMSelect NUMERIC DATA for Unit Price
    Nconf_ItemTaxSet ItemTax Percent (e.g. "8" "10")
    Oconf_DataIdOSelect STRING DATA for Invoice ID
    Pconf_DataIdPSelect DATE DATA for Payment Due Date
    Qconf_DataIdQSelect STRING DATA for Invoice Note
    Rconf_DataIdRSelect STRING DATA for Invoice Terms
    Sconf_logoUrlSet Logo Url (e.g. "https://example.com/a.png")
    Tconf_DataIdTSelect STRING DATA for Paypal Invoice ID (update)
    // PayPal Invoicing Create (JPY/ja_JP) (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 merchantBusinessName = configs.get( "conf_MerchantBusinessName" ) + "";
    
    var merchantPostalCode   = configs.get( "conf_MerchantPostalCode" ) + "";
    var array_merchantPostalCode = merchantPostalCode.split("\n");
    var merchantAddressCC    = array_merchantPostalCode[0];
    var merchantAddressPC    = array_merchantPostalCode[1];
    var merchantAddressState = array_merchantPostalCode[2];
    var merchantAddressCity  = array_merchantPostalCode[3];
    
    var merchantAddress      = configs.get( "conf_MerchantAddress" ) + "";
    var array_merchantAddress = merchantAddress.split("\n");
    var merchantAddress1     = array_merchantAddress[0];
    var merchantAddress2     = array_merchantAddress[1];
    
    var merchantPhoneEmail   = configs.get( "conf_MerchantPhoneEmail" ) + "";
    var array_merchantPhoneEmail  = merchantPhoneEmail.split("\n");
    var merchantPhoneCC      = array_merchantPhoneEmail[0];
    var merchantPhoneNum     = array_merchantPhoneEmail[1];
    var merchantEmail        = array_merchantPhoneEmail[2];
    var merchantWebsite      = array_merchantPhoneEmail[3];
    
    var billingLanguage      = "ja_JP"; /// HARD-CODED
    var itemUnitPriceCurrency = "JPY"; /// HARD-CODED
    var itemTaxName          = "TAX"; /// HARD-CODED
    var itemTaxPercent       = configs.get( "conf_ItemTax" ) - 0;
    var logoUrl              = configs.get( "conf_logoUrl" ) + "";
    
    var dataIdF = configs.get( "conf_DataIdF" );
    var dataIdG = configs.get( "conf_DataIdG" );
    var dataIdH = configs.get( "conf_DataIdH" );
    var dataIdI = configs.get( "conf_DataIdI" );
    var dataIdJ = configs.get( "conf_DataIdJ" );
    var dataIdK = configs.get( "conf_DataIdK" );
    var dataIdL = configs.get( "conf_DataIdL" );
    var dataIdM = configs.get( "conf_DataIdM" );
    
    var dataIdO = configs.get( "conf_DataIdO" );
    var dataIdP = configs.get( "conf_DataIdP" );
    var dataIdQ = configs.get( "conf_DataIdQ" );
    var dataIdR = configs.get( "conf_DataIdR" );
    var dataIdT = configs.get( "conf_DataIdT" );
    
    
    //// == ワークフローデータの参照 / Data Retrieving ==
    var billingBusinessName  = data.get( dataIdF ) + ""; // Max 100
    var billingName1         = data.get( dataIdG ) + ""; // Max 30
    var billingName2         = data.get( dataIdH ) + ""; // Max 30
    var billingEmail         = data.get( dataIdI ) + ""; // Max 260
    var itemName             = data.get( dataIdJ ) + ""; // Max 200
    var itemDescription      = data.get( dataIdK ) + ""; // Max 1000
    var itemQuantity         = data.get( dataIdL ) - 0;
    var itemUnitPrice        = data.get( dataIdM ) + ""; // STRING!!
    
    var invoiceNumber        = data.get( dataIdO ) + ""; // Max 25
    var paymentTermDueDate   = data.get( dataIdP ) + " PST";
    var invoiceNote          = data.get( dataIdQ ) + ""; // Max 4000
    var invoiceTerms         = data.get( dataIdR ) + ""; // Max 4000
    
    var merchantMemo = "BPMS Process ID: " + processInstance.getProcessInstanceId();
    
    
    //// == 演算 / 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;
    
    // Create invoice
    var invoiceObj = {};
      invoiceObj.number = invoiceNumber;
      invoiceObj.payment_term = {};
      invoiceObj.payment_term.due_date = paymentTermDueDate;
      invoiceObj.note = invoiceNote;
      invoiceObj.terms = invoiceTerms;
      invoiceObj.logo_url = logoUrl;
      invoiceObj.merchant_memo = merchantMemo;
      invoiceObj.merchant_info = {};
        invoiceObj.merchant_info.email = merchantEmail;
        invoiceObj.merchant_info.business_name = merchantBusinessName;
        invoiceObj.merchant_info.address = {};
          invoiceObj.merchant_info.address.line1 = merchantAddress1;
          invoiceObj.merchant_info.address.line2 = merchantAddress2;
          invoiceObj.merchant_info.address.city = merchantAddressCity;
          invoiceObj.merchant_info.address.state = merchantAddressState;
          invoiceObj.merchant_info.address.postal_code = merchantAddressPC;
          invoiceObj.merchant_info.address.country_code = merchantAddressCC;
          invoiceObj.merchant_info.address.phone = {};
            invoiceObj.merchant_info.address.phone.country_code = merchantPhoneCC;
            invoiceObj.merchant_info.address.phone.national_number = merchantPhoneNum;
        invoiceObj.merchant_info.website = merchantWebsite;
      invoiceObj.billing_info = [];
        invoiceObj.billing_info[0] = {};
          invoiceObj.billing_info[0].email = billingEmail;
          invoiceObj.billing_info[0].first_name = billingName1;
          invoiceObj.billing_info[0].last_name = billingName2;
          invoiceObj.billing_info[0].business_name = billingBusinessName;
          invoiceObj.billing_info[0].language = billingLanguage;
      invoiceObj.items = [];
        invoiceObj.items[0] = {};
          invoiceObj.items[0].name = itemName;
          invoiceObj.items[0].description =itemDescription;
          invoiceObj.items[0].quantity = itemQuantity;
          invoiceObj.items[0].unit_price = {};
            invoiceObj.items[0].unit_price.currency = itemUnitPriceCurrency;
            invoiceObj.items[0].unit_price.value = itemUnitPrice;
          if( itemTaxPercent !== 0 ){
          invoiceObj.items[0].tax = {};
            invoiceObj.items[0].tax.name = itemTaxName;
            invoiceObj.items[0].tax.percent = itemTaxPercent;
          }
    var uriCreate = "https://api.paypal.com/v1/invoicing/invoices/";
    var responseCreate = httpClient.begin()
      .bearer( oauthToken )
      .body( JSON.stringify( invoiceObj ), "application/json" )
      .post( uriCreate );
    
    var paypalIdObj = JSON.parse( responseCreate.getResponseAsString() );
    var paypalId    = paypalIdObj.id;
    
    
    //// == ワークフローデータへの代入 / Data Updating ==
    retVal.put( dataIdT, paypalId );
    //retVal.put( "q_accessLog", responseCreate.getResponseAsString() ); // for debug
    

    • B’: Trade name of the seller entered in B
    • C’: Country code / Postal code / Prefecture / City of the seller entered in C
    • D’: Address of the seller entered in D
    • E’: Country calling code/ Telephone number/ Email address/ URL of the seller entered in E
    • F’: Billing Company name stored in the Data Item that is selected at config F
    • G’: Billing Department name stored in the Data Item that is selected at config G
    • H’: Billing Representative name stored in the Data Item that is selected at config H
    • I’: Billing Email address stored in the Data Item that is selected at config I
    • J’: Item name stored in the Data Item selected at config J
    • K’: Detailed description of delivery stored in the Data Item selected at config K
    • L’: Quantity of delivery stored in the Data Item selected at config L
    • M’: Unit price of delivery stored in the Data Item selected at config M
    • N’: Tax rate entered in N
    • O’: Invoice ID stored in the Data Item selected at config O
    • P’: Payment due date stored in the Data Item selected at config P
    • Q’: Remarks on Invoice stored in the Data Item selected at config Q
    • R’: Terms of contract and conditions stored in the Data Item selected at config R
    • S’: URL of logo image entered at config S
    • A Paypal invoice is automatically generated with the information of properties of B’ to S’
    • Paypal Invoice ID is stored in the Data Item selected at config T
    • You need to create App at Paypal Dashboard beforehand and obtain Client ID/Secret in advance