bvstone

How BVSTools Uses GreenTools for PayPal (G4PP)

Posted:

How BVSTools Uses GreenTools for PayPal (G4PP)

For many years we've accepted credit cards as payment using PayPal for customers that required use of a credit card, or that were out of the country and couldn't pay using check or EFT.

Before creating GreenTools for PayPal (G4PP) and the Invoicing Addon (G4PPINV) we would manually log on to PayPal and create and send the invoice.  Not a huge task, but it did take time that is rare these days.

The first thing we did was add a "Send PayPal Invoice" button to our Customer Web Application.  I wrote this MANY years ago to keep track of customers, license keys, support and maintenance, etc using eRPG of course!

The code for this was pretty simple:

<button id="sendPayPalInvoiceButton" type="button">Send PayPal Invoice</button>

Now, when this button is clicked we want to display a popup with the customer information, and allow entering of the invoice number and invoice total.

This is done using a hidden HTML Div element and some JavaScript:

<div id="sendPayPalInvoiceDialog" title="Send PayPal Invoice" style="display: none">
  <form id="sendPayPalInvoiceForm" action="/cgi-bin/sndppinv">
    <table border=0>
      <tr>
        <td>Email Address:</td><td><input name="email" value="/%email%/"><br></td>
      </tr>
      <tr>
        <td>First Name:</td><td><input name="fname" value="/%firstname%/"><br></td>
      </tr>
      <tr>
        <td>Last Name:</td><td><input name="lname" value="/%lastname%/"><br></td>
      </tr>
      <tr>
        <td>Business Name</td><td> <input name="bname" value="/%customer%/"><br></td>
      </tr>
      <tr>
        <td>Address 1:</td><td><input name="add1" value="/%address1%/"><br></td>
      </tr>
      <tr>
        <td>Address 2:</td><td><input name="add2" value="/%address2%/"><br></td>
      </tr>
      <tr>
        <td>City:</td><td><input name="city" value="/%city%/"><br></td>
      </tr>
      <tr>
        <td>State:</td><td><input name="state" value="/%state%/"><br></td>
      </tr>
      <tr>
        <td>Zip:</td><td><input name="zip" value="/%zip%/"><br></td>
      </tr>
      <tr>
        <td>Invoice Number:</td><td><input name="invnbr"></td>
      </tr>
      <tr>
        <td>Invoice Total:</td><td><input name="invtot" type="number"></td>
      </tr>
    </table>
    <button id="sendThePayPalInvoice" type="button">Send PayPal Invoice</button>
    <div id="sendPayPalInvoiceDialogError" style="color: red"></div>
  </form>
</div>
  $('#sendPayPalInvoiceButton').click(function() {
    $('#sendPayPalInvoiceDialogError').html('');
    $("#sendPayPalInvoiceDialog").dialog();
  });

Next, after the invoice number and invoice total have been entered we click the "Send PayPal Invoice" which calls an eRPG program to do the real work.

  $('#sendThePayPalInvoice').click(function(e) {
    $('#sendPayPalInvoiceDialogError').html('');
    showMessage('Sending PayPal Invoice...');
    var formData = $('#sendPayPalInvoiceForm').serialize();
    var postURL = $('#sendPayPalInvoiceForm').attr('action');
            
    $.post(postURL, formData)
    .done(function(data) {
       $('#sendPayPalInvoiceDialogError').html(data);
     })
    .fail(function(xhr, status, error) {
      $('#sendPayPalInvoiceDialogError').html('There was an error!  See the console.');
      console.log('status' + status);
      console.log('error:' + error);
     })
    .always(function(data) {
      $.unblockUI();
    })
  });       

The RPG program we call, SNDPPINV is as follows:

     H DFTACTGRP(*NO) BNDDIR('ERPGSDK')
      ****************************************************************
      * Imports
      ****************************************************************
      /COPY QCOPYSRC,P.ERPGSDK
      /COPY QCOPYSRC,P.STRING
      /COPY QCOPYSRC,P.LIBL
      /COPY G4PPBVS/QCOPYSRC,P.G4PPINV
      ****************************************************************
      * Data read in from Web Page
     D email           S            256
     D fname           S            256
     D lname           S            256
     D bname           S            256
     D add1            S            256
     D add2            S            256
     D city            S            256
     D state           S            256
     D zip             S            256
     D country         S            256
     D invnbr          S             10
     D invtot          S              9  2
      *
     D rc              S             10i 0
     D errorMsg        S            256
     D out_file        S            256
     D out_id          S            256
      ****************************************************************
      /free

       #pushLib('G4PPBVS');
       exsr $Input;
       exsr $CreateInvoice;
       exsr $SendInvoice;

       errorMsg = 'Invoice sent to ' + %trim(email) + '.';
       EXSR $return;

       //***************************************************************
       //* Create Invoice
       //***************************************************************
       begsr $CreateInvoice;

         rc = #g4ppinv_setValue('account':'bvstone@bvstools.com');
         rc = #g4ppinv_setValue('merchant_email':
                                'bvstone@bvstools.com');
         rc = #g4ppinv_setValue('merchant_first_name':'Bradley');
         rc = #g4ppinv_setValue('merchant_last_name':'Stone');
         rc = #g4ppinv_setValue('merchant_business_name':'BVSTools');
         rc = #g4ppinv_setValue('merchant_phone':'5306437264');
         rc = #g4ppinv_setValue('merchant_website':'www.bvstools.com');
         rc = #g4ppinv_setValue('merchant_address1':'201 Mapleridge Drive');
         rc = #g4ppinv_setValue('merchant_country_code':'US');
         rc = #g4ppinv_setValue('merchant_postal_code':'56001');
         rc = #g4ppinv_setValue('merchant_state':'MN');
         rc = #g4ppinv_setValue('payment_term_type':'DUE_ON_RECEIPT');
         rc = #g4ppinv_setValue('logo_url':
                                'https://www.bvstools.com' +
                                '/images/bvstoolslogo.gif');

         rc = #g4ppinv_createBilling();
         rc = #g4ppinv_setBillingValue('email':email);
         rc = #g4ppinv_setBillingValue('first_name':fname);
         rc = #g4ppinv_setBillingValue('last_name':lname);
         rc = #g4ppinv_setBillingValue('business_name':bname);
         rc = #g4ppinv_setBillingValue('address1':add1);
         rc = #g4ppinv_setBillingValue('address2':add2);
         rc = #g4ppinv_setBillingValue('city':city);
         rc = #g4ppinv_setBillingValue('state':state);
         rc = #g4ppinv_setBillingValue('postal_code':zip);
         rc = #g4ppinv_setBillingValue('notification_channel':'EMAIL');

         rc = #g4ppinv_createItem();
         rc = #g4ppinv_setItemValue('name':'INV-' + %trim(invnbr));
         rc = #g4ppinv_setItemValue('description':'Invoice ' + %trim(invnbr));
         rc = #g4ppinv_setItemValue('quantity':'1');
         rc = #g4ppinv_setItemValue('uom':'AMOUNT');
         rc = #g4ppinv_setItemValue('price_value':%char(invtot));
         rc = #g4ppinv_setValue('save_invoice_draft':'true');

         // Create the invoice.  If you leave out_file blank, the file name will be auto-generated.
         //  Or, you can enter your own fully qualified path to the file you want to use.  Be aware
         //  that if it already exists it will be overwritten.

         out_file = '/paypal invoices/inv' + %trim(invnbr) + '.json';
         // rc = #g4ppinv_setValue('debug':'*YES');

         rc = #g4ppinv_createInvoice(out_id:out_file:errorMsg);

         if (rc < 0);
           EXSR $return;
         endif;

       endsr;
       //***************************************************************
       //* Send Invoice
       //***************************************************************
       begsr $SendInvoice;

         rc = #g4ppinv_setValue('account':'bvstone@bvstools.com');
         rc = #g4ppinv_setValue('number':out_id);
         // rc = #g4ppinv_setValue('debug':'*YES');
         rc = #g4ppinv_sendInvoice(errorMsg);

         if (rc < 0);
           EXSR $return;
         endif;

       endsr;
       //***************************************************************
       //* Read Input
       //***************************************************************
       begsr $Input;

         email = #getData('email');
         fname = #getData('fname');
         lname = #getData('lname');
         bname = #getData('bname');
         add1 = #getData('add1');
         add2 = #getData('add2');
         city = #getData('city');
         state = #getData('state');
         zip = #getData('zip');
         invnbr = #getData('invnbr');
         invtot = #CtoN(#getData('invtot'));

         if (email = ' ');
           errorMsg = 'Email Address is blank.';
           exsr $return;
         endif;

         if (fname = ' ');
           errorMsg = 'First Name is blank.';
           exsr $return;
         endif;

         if (lname = ' ');
           errorMsg = 'Last Name is blank.';
           exsr $return;
         endif;

         if (bname = ' ');
           errorMsg = 'Business Name is blank.';
           exsr $return;
         endif;

         if (invnbr = ' ');
           errorMsg = 'Invoice Number is blank.';
           exsr $return;
         endif;

         if (invtot <= 0);
           errorMsg = 'Invoice Total is invalid.';
           exsr $return;
         endif;

       endsr;
       //***************************************************************
       //* Return
       //***************************************************************
       begsr $return;

         #startup();
         #writeTemplate('stdhtmlheader.erpg');
         #loadTemplate('sndppinv.erpg');
         #replaceData('/%msg%/':errorMsg);
         #writeSection();
         #cleanup();

         #popLib('G4PPBVS');

         *INLR = *ON;
         return;

       endsr;
      /end-free

As we can see, even this process if very simple.  First we read the data from the form, check for errors, and if there are none we create the invoice and then send it using the G4PPINV functions.  All of the OAuth 2.0 token logic is taken care of automatically by G4PP in the background, making things very simple.

When we're done both the customer and myself will receive an email automatically from PayPal and allow simply payment using a credit card without the need for having a PayPal account on the customer side.

Every little thing to make work easier and faster pays off, and this certainly did!


Last edited 08/11/2017 at 08:49:04



Latest Posts:

GreenTools for G Suite (G4G) Now Includes Send Mail Functionality (G4GSMAIL Addon) GreenTools for G Suite (G4G) Now Includes Send Mail Functionality (G4GSMAIL Addon)
Posted by August 27, 2019
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
GreenTools For G Suite (G4G) v12.00 Released With Base OAuth 2.0 Functionality GreenTools For G Suite (G4G) v12.00 Released With Base OAuth 2.0 Functionality
Posted by July 28, 2019
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
BVSTools Small Price Increase in 2020 BVSTools Small Price Increase in 2020
Posted by July 26, 2019
BVSTools >> BVSTools Announcements
GreenTools for Vertex Cloud (VTXCLOUD) Now Available GreenTools for Vertex Cloud (VTXCLOUD) Now Available
Posted by July 22, 2019
BVSTools >> BVSTools Announcements >> GreenTools for Vertex Cloud (VTXCLOUD) Specific Announcements
GreenTools for Google Apps (G4G) - Drive Addon Successfully Verified by Google GreenTools for Google Apps (G4G) - Drive Addon Successfully Verified by Google
Posted by July 22, 2019
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
Why I Cancelled my DynDNS Service and How I Replaced It with an IBM i Application Why I Cancelled my DynDNS Service and How I Replaced It with an IBM i Application
Posted by July 17, 2019
IBM Power Systems >> (QGPL) IBM i
Green Tools for G Suite (G4G) Product Updates (Licensing, Functionality, Base Product) Green Tools for G Suite (G4G) Product Updates (Licensing, Functionality, Base Product)
Posted by July 13, 2019
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
Reading JSON Data from Standard Input With YAJL and RPG Reading JSON Data from Standard Input With YAJL and RPG
Posted by July 12, 2019
Programming >> Proof of Concept (POC)
MAILTOOL Updated to Allow Use of IBM Global Security Kit (GSKIT) for SSL/TLS Communications MAILTOOL Updated to Allow Use of IBM Global Security Kit (GSKIT) for SSL/TLS Communications
Posted by June 19, 2019
BVSTools >> BVSTools Announcements >> eMail Tool (MAILTOOL) Specific Announcements
GETURI v10.00 Released Supporting IBM Global Security Kit (GSKIT) and Server Name Indication (SNI) GETURI v10.00 Released Supporting IBM Global Security Kit (GSKIT) and Server Name Indication (SNI)
Posted by June 11, 2019
BVSTools >> BVSTools Announcements >> Get URI (GETURI) Specific Announcements
BVSTools Now Offers Vertex Cloud Interface BVSTools Now Offers Vertex Cloud Interface
Posted by April 15, 2019
BVSTools >> BVSTools Announcements
Token Has an Invalid Signature Error for Office 365 Email Token Has an Invalid Signature Error for Office 365 Email
Posted by March 22, 2019
BVSTools >> BVSTools Software Discussion >> GreenTools for Microsoft Apps (G4MS) Specific Discussion
Resending Emails that have Errored Out with Updated Router or Authentication Information Resending Emails that have Errored Out with Updated Router or Authentication Information
Posted by March 1, 2019
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
BVSTools Offers Toolset to Work With HubSpot OAuth 2.0 APIs On Your IBM i BVSTools Offers Toolset to Work With HubSpot OAuth 2.0 APIs On Your IBM i
Posted by January 27, 2019
BVSTools >> BVSTools Announcements
G4MSDRV Currently Not Supported G4MSDRV Currently Not Supported
Posted by January 17, 2019
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements

Reply




Copyright 1983-2019 BVSTools
GreenBoard(v3) Powered by the eRPG SDK, MAILTOOL Plus!, GreenTools for Google Apps, jQuery, jQuery UI, BlockUI, CKEditor and running on the IBM i (AKA AS/400, iSeries, System i).