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:

Calculating the Size of a File Before Base64 Encoding Calculating the Size of a File Before Base64 Encoding
Posted by August 13, 2022
Programming >> RPG Programming
GreenTools for Microsoft Apps (G4MS) v9.12 Now Includes Function to Send Emails using MIME File GreenTools for Microsoft Apps (G4MS) v9.12 Now Includes Function to Send Emails using MIME File
Posted by August 11, 2022
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
GreenTools for Google Apps (G4G) v15.20 Now Supports Shortcuts GreenTools for Google Apps (G4G) v15.20 Now Supports Shortcuts
Posted by August 6, 2022
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
GreenTools for Microsoft Apps (G4MS) Groups Admin Authority Instructions GreenTools for Microsoft Apps (G4MS) Groups Admin Authority Instructions
Posted by July 26, 2022
BVSTools >> BVSTools Software Discussion >> GreenTools for Microsoft Apps (G4MS) Specific Discussion
GreenTools for Microsoft Apps (G4MS) v9.10 Now Includes OneDrive Functions that Work With Groups/Shared Drives GreenTools for Microsoft Apps (G4MS) v9.10 Now Includes OneDrive Functions that Work With Groups/Shared Drives
Posted by July 19, 2022
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
GreenTools for Google Apps (G4G) v15.10 Now Includes Drive Functions that Work With Shared Drives GreenTools for Google Apps (G4G) v15.10 Now Includes Drive Functions that Work With Shared Drives
Posted by July 15, 2022
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
GreenTools for Microsoft Apps (G4MS) v9.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page GreenTools for Microsoft Apps (G4MS) v9.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page
Posted by July 4, 2022
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
What Objects Should I Omit from Replication to Ensure My License Keys Work on my HA/DR System? What Objects Should I Omit from Replication to Ensure My License Keys Work on my HA/DR System?
Posted by June 27, 2022
BVSTools >> BVSTools Software Discussion
GreenTools for Google Apps (G4G) v15.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page GreenTools for Google Apps (G4G) v15.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page
Posted by May 3, 2022
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
How Do I Switch From MAILTOOL Plus to GreenTools for Google or Microsoft Office 365? How Do I Switch From MAILTOOL Plus to GreenTools for Google or Microsoft Office 365?
Posted by April 18, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
PTFs Issued for SSL/TLS Issues PTFs Issued for SSL/TLS Issues
Posted by March 12, 2022
IBM Power Systems >> PTF Watch
Google Dropping Support for Google Dropping Support for "Less Secure Apps" May 30th, 2022. What Does This Mean for Your IBM i Email?
Posted by March 4, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Have You Installed a New Version of MAILTOOL and Now Things Are Acting Different?  Check the Command Defaults! Have You Installed a New Version of MAILTOOL and Now Things Are Acting Different? Check the Command Defaults!
Posted by February 28, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Using MAILTOOL Plus on V7R1, or Any OS Using TLS 1.1 or Older Using MAILTOOL Plus on V7R1, or Any OS Using TLS 1.1 or Older
Posted by January 27, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
BVSTools ILE Functions Being Updated to Remove Hashtag (#) from Function Names BVSTools ILE Functions Being Updated to Remove Hashtag (#) from Function Names
Posted by December 30, 2021
BVSTools >> BVSTools Announcements

Reply




Copyright 1983-2020 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).