[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: HTTPAPI examples



Sender: tomh@xxxxxxxxx

Here goes.... as you can tell, pretty much a hack from the examples 
included in the HTTPAPI package.  Using a front-end program which calls 
this thing, we've run about a dozen test transactions (live and expired), 
and received responses for each transaction.


==========Start===========

      *************************************************************
      *  CCECHO1R    Credit Card processing program               *
      *                                                           *
      *  11.28.03  SI  Tom                                        *
      *************************************************************

     H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('LIBHTTP/HTTPAPI')

     d/copy libhttp/qrpglesrc,httpapi_h

     d ENTRY           pr                  extpgm('CCECH1R')
      *  Billing phone number
     d  phone                        12

      *  Credit card number
     d  sfcrdn                       16

      *  Expiration date
     d  sfcexd                        6p 0

      *  Duplication counter
      *  If 2 or more transactions in a single 2-hour period
      *  are submitted having the same echo-id, c/c number, trans code
      *  and amount then this field must be unique for each transaction
     d  counter                       5p 0

      *  Total amount of the transaction
     d  amt                           9p 2

      *  Is the transaction accepted?
      *  retcode = Y or N
     d  retcode                       1

      *  Decline code, if declined
     d  dc                            4

      *  Decline msg, if declined
     d  dcmsg                       128

     d ENTRY           pi
      *  Billing phone number
     d  phone                        12

      *  Credit card number
     d  sfcrdn                       16

      *  Expiration date
     d  sfcexd                        6p 0

      *  Duplication counter
      *  If 2 or more transactions in a single 2-hour period
      *  are submitted having the same echo-id, c/c number, trans code
      *  and amount then this field must be unique for each transaction
     d  counter                       5p 0

      *  Total amount of the transaction
     d  amt                           9p 2

      *  Is the transaction accepted?
      *  retcode = Y or N
     d  retcode                       1

      *  Decline code, if declined
     d  dc                            4

      *  Decline msg, if declined
     d  dcmsg                       128

      ********************************************************
      *  Pull out the error message return code              *
      *  Lookup the corresponding error message, return      *
      *  in 'rmsg'                                           *
      ********************************************************
     dGetMsgText       pr
     d msg                          128

     D translate       pr                  ExtPgm('QDCXLATE')
     D   length                       5P 0 const
     D   data                     32766A   options(*varsize)
     D   table                       10A   const

     D incoming        pr            10I 0
     D   descriptor                  10I 0 value
     D   data                      8192A   options(*varsize)
     D   datalen                     10I 0 value

     D cmd             pr                  extpgm('QCMDEXC')
     D  command                     200A   const
     D  length                       15P 5 const


      *************************************************************
      *  Decline/Error Codes tables                               *
      *************************************************************
     dtabdc            s              4    dim(85) perrcd(1) ctdata
     dtabdmsg          s             80    dim(85) alt(tabdc)


      *************************************************************
      *  Misc variables                                           *
      *************************************************************
     D APP_ID          c                   CONST('SCK_HTTPAPI_EXAMPLES')
     D rc              s             10I 0
     D msg             s             52A
     D data            s           1024A
     D retdata         s          32766A
     D retlen          s             10I 0
     D nextpos         s             10I 0 inz(1)

     d                 ds                  inz
      *  get these from ECHOnline
     d our_id                        11    inz('123456789AB')
     d our_pin                        8    inz('12345678')
      *  our_ip should be our PUBLIC address
     d our_ip                        15    inz('10.0.0.1')
     d our_email                     20    inz('echo@xxxxxxxxxxxxx')
     d x                              9  0
     d x1                             9  0
     d x2                             9  0
     d xx                             2

     c/free

       *inlr = *on;

       exsr initsr;

       // *********************************************************
       // * Format the authorize/deposit request:                 *
       // *   https://wwws.echo-inc.com/ISPGuide-Interface.asp    *
       // *********************************************************
       data= 'transaction_type=ES' +
             '&order_type=S' +
             '&counter=' + %trim(%editc(counter:'Q')) +
             '&debug=F' +
             '&merchant_echo_id=' +  our_id +
             '&merchant_pin=' + our_pin +
             '&isp_echo_id=' +
             '&isp_pin=' +
             '&billing_ip_address=' + %trim(our_ip) +
             '&merchant_email=' + %trim(our_email) +
             '&billing_phone=' + %trim(phone) +
             '&cc_number=' + %trim(sfcrdn) +
             '&ccexp_month=' + %subst(%editw(sfcexd:'0      '):6:2) +
             '&ccexp_year=' + %subst(%editw(sfcexd:'0      '):4:2) +
             '&grand_total=' + %trim(%editc(amt:'Q')) +
             '&original_amount=' + %trim(%editc(amt:'Q'));


       // *********************************************************
       // * Send the request as URL:                              *
       // *   https://wwws.echo-inc.com/ISPGuide-Interface.asp    *
       // *********************************************************
       rc = 
http_url_post_raw('https://wwws.echo-inc.com/scripts/INR200.EXE':
            %addr(data): %len(%trimr(data)): 30: %paddr('INCOMING'));
       //if rc <> 1;
       //  msg = http_error;
       //  dsply '' '' msg;
       //  return;
       //endif;


       // *********************************************************
       // * Convert the data we just received to EBCDIC (from ASCII)
       // *********************************************************
       if retlen > 1;
         callp Translate(retlen: retdata: 'QTCPEBC');
       endif;


       // *********************************************************
       // * Now the returned data is in the 'retdata' string      *
       // *  Look for the APPROVED string                         *
       // *    https://wwws.echo-inc.com/ISPGuide-Response.asp    *
       // *********************************************************
       x = %scan('<ECHOTYPE1>APPROVED': retdata);
       if x > 0;
         retcode = 'Y';
         dc = 'OK  ';
       else;
         retcode = 'N';
       endif;


       // *********************************************************
       // *  Parse out all text between the <ECHOTYPE1> and the   *
       // *  </ECHOTYPE1> tags.  Return that text in dcmsg for    *
       // *  use by the calling program                           *
       // *********************************************************
       x1 = %scan('<ECHOTYPE1>': retdata);
       x2 = %scan('</ECHOTYPE1>': retdata);
       if x1 > 0 and x2 > x1;
         dcmsg = %subst(retdata:x1+11:x2-(x1+11));
       else;
         // *******************************************************
         // *  ECHOnline response is either missing or incomplete *
         // *  Mary should check ECHOnet to see if the trans      *
         // *  went thru...                                       *
         // *******************************************************
         dcmsg = 'ZZZZ 8999';
       endif;


       // **********************************************************
       // *  Pull error/decline code, get corresponding error msg  *
       // **********************************************************
       callp GetMsgText(dcmsg);
       return;
      /end-free


      *************************************************************
      *  End program mainline.  Subroutines/Subprocedures follow  *
      *************************************************************


      *************************************************************
      *   before you can use the https (http over SSL) stuff, you *
      *   must call https_init() to initialize the library.       *
      *   see also the comments in the RegisterMe subroutine)     *
      *************************************************************
     c     initsr        begsr
     c/free
       rc = https_init(APP_ID);

       if rc < 0;
         msg = http_error(rc);
         if rc = HTTP_NOTREG;
           exsr RegisterMe;
           return;
         else;
           dsply '' '' msg;
           return;
         endif;
       endif;
      /end-free

     c                   endsr


      *************************************************************
      * before we can do SSL, we must register ourself with the   *
      * AS/400's digital certificate manager.   This allows the   *
      * AS/400 admin to assign us certificates, tell us which     *
      * cert authorities to trust, etc.   This should only be     *
      * done the first time...                                    *
      *************************************************************
     CSR   RegisterMe    begsr

     c/free
       rc=https_dcm_reg(APP_ID: *ON);
       if rc < 0;
         msg = http_error;
         dsply msg;
         leavesr;
       endif;

       msg = 'This program has not yet been registered with the';
       dsply msg;

       msg = 'Digital Certificate Manager.  I have registered it';
       dsply msg;

       msg = 'as '+ APP_ID + ' please restart the D.C.M.';
       dsply msg;

       msg = 'and assign it a certificate, then call this again.';
       dsply msg;

       msg = 'press <ENTER> to continue';
       dsply '' '' msg;
      /end-free

     csr                 endsr

     P*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P*  this procedure will receive the raw data received from EchOnline
     P*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P incoming        B
     D incoming        PI            10I 0
     D   descriptor                  10I 0 value
     D   data                      8192A   options(*varsize)
     D   datalen                     10I 0 value

     c/free
       // Make sure we don't overflow the string:
       retlen = (nextpos + datalen) - 1;
       if retlen > %size(retdata);
         datalen=datalen-(%size(retdata)-retlen);
       endif;

       // If there is nothing to write, return THAT...
       if datalen < 1;
         return 0;
       endif;

       // Here we add any data sent to the end of our 'retdata' string:
       %subst(retdata: nextpos) = %subst(data:1:datalen);
       nextpos = nextpos + datalen;

       // We always return the amount of data that we wrote.   Note
       //  that if http-api sees that we didn't write as much data as
       //  it sent us, it'll abort the process with an error message.
       return datalen;
      /end-free
     p                 e


      ********************************************************
      *  Pull out the error message return code              *
      *  Lookup the corresponding error message, return      *
      *  in 'rmsg'                                           *
      ********************************************************
     pGetMsgText       b
     dGetMsgText       pi
     d rmsg                         128

     d                 ds                  inz
     d rcode                          4
     d x1                             9  0
     d x2                             9  0
     d xx                             2

     c/free
       if %subst(rmsg:1:8) <> 'APPROVED';
         if %subst(rmsg:1:8) = 'DECLINED';
           rmsg = %subst(rmsg:1:20);
         endif;
         x1 = %checkr('0123456789':%trim(rmsg));
         rcode = %subst(%trim(rmsg): x1+1);
         if %len(%trim(rcode)) < 4;
           rcode = %subst('0000':1:4-%len(%trim(rcode))) + %trim(rcode);
         endif;
         if %tlookup(rcode:tabdc:tabdmsg);
           dc = rcode;
           rmsg = tabdmsg;
         elseif rcode >= '9000' and rcode <= '9999';
           dc = rcode;
           rmsg = 'The host encountered an internal error';
         else;
           rmsg = '!!! Unknown return code (' + rcode + ') !!!';
         endif;
       endif;
       return;
      /end-free
     p                 e

** Decline/error codes   From ECHOnline website
0001The card must be referred to the issuer before the transaction can be 
approved
0003The merchant submitting the request is not supported by the acquirer
0004The card# has been listed on the Warning Bulletin (counterfeit, fraud, 
other)
0005The transaction was declined by the issuer without definition or 
reason
0012The transaction request presented is not supported or is invalid for 
this card#
0013The amount is below minimum or above maximum the issuer allows
0014Invalid card number
0015Invalid issuer
0030The transaction was not formatted properly
0041The card has been reported lost
0043The card has been reported stolen
0051Over credit limit
0054The card is expired
0055Incorrect PIN
0057The card does not support this type of transaction
0058Merchant's account doesn't support this type of transaction
0061Daily withdrawal limit exceeded
0062The card has been restricted (restricted card)
0063The card has been restricted (security violation)
0065The allowed number of daily transactions has been exceeded
0075The allowed number of PIN retries has been exceeded
0076The "to" (credit) acct does not exist or is not associated with the 
card
0077The "from" (debit) acct does not exist or is not associated with the 
card
0078The "from" (debit) or "to" (credit) acct does not exist or is not 
associated with the card
0084The authorization life cycle is above or below limits established by 
the issuer
0091The bank is not available to authorize this transaction
0092The transaction does not contain enough info to be routed
0094The host has detected a duplicate transmission
0096A system error has occurred or the files required for authorization 
are not available
1000An unrecoverable error has occurred in the ECHOnline processing
1001The merchant account (IDOCKET.COM LLC) has been closed
1002Services for this system are not available
1003The e-mail function is not available
1012The host computer received an invalid transaction code
1013The ECHO-ID is invalid
1015The credit card number that was sent to the host computer was invalid
1016The card has expired or the expiration date was invalid
1017The dollar amt was less that 1.00 or greater than the max for this 
card
1019The state code was invalid
1021The merchant or card holder is not allowed to perform that kind of 
transaction
1024The authorization number presented with this transaction is invalid
1025The reference number presented with this transaction is invalid
1029The contract number presented with this transaction is incorrect
1030The inventory data presented with this transaction is not ASCII 
printable
1508Invalid or missing order_type
1509The merchant is not approved to submit this order_type
1510The merchant is not approved to submit this transaction_type
1511Duplication transaction attempt (check the counter value)
1599A system error occurred while validation the transaction input
1801Address matches; ZIP does not match
18029-digit ZIP matches; address does not match
18035-digit ZIP matches; address does not match
1804Issuer unavailable; cannot verify
1805Retry; system is currently unable to process
1806Issuer does not support AVS
1807Nothing matches
1808Invalid AVS only response
1809Street address match. Postal code not verified (incompatible formats)
1810Street address and postal code not verified (incompatible formats)
1811Street address and postal code match
1812Address information not verified for international transaction
1813Street address and postal code match
1814Postal code match.  Street address not verified (incompatible formats)
1897The host returned an invalid response
1898The host unexpectedly disconnected
1899Timeout waiting for host response
2071Call VISA to get a voice authorization number for this transaction
2072Call MasterCard to get a voice authorization number for this 
transaction
2073Call Carte Blanche to get a voice authorization number for this 
transaction
2074Call Diners Club to get a voice authorization number for this 
transaction
2075Call AMEX to get a voice authorization number for this transaction
2076Call Discover to get a voice authorization number for this transaction
2078Call ECHO Customer Support for approval; problem with merchant acct
2079Call ECHO Customer Support for approval; problem with merchant acct
3001The host did not receive an ACK from the terminal after sending trans 
response
3002The host disconnected after the terminal replied 3 times to host with 
NAK
3003The line dropped before the host could send a response to the terminal
3005The line dropped while the host was sending the response to the 
terminal
3007The host received ACK from terminal but line dropped before host sent 
the EOT
3011The line was up and carrier detected, but terminal did respond to the 
ENQ
3012The line disconnected while the host was receiving data from the 
terminal
3013The host disconnected after receiving 3 transmission with bad LRC from 
terminal
3014The line disconnected during input data wait in Mutli-Trans Mode
3015The host encountered a full queue and discarded the input data
8999ECHOnline response is either missing or incomplete.  Check ECHONet.

================end===============

Tom Hightower
Solutions, Inc
http://www.simas.com





Scott Klement <sk@xxxxxxxxxxxxxxxx>
Sent by: owner-ftpapi@xxxxxxxxxxxxx
07/21/2004 10:56 AM
Please respond to ftpapi

 
        To:     ftpapi@xxxxxxxxxxxxx
        cc: 
        Subject:        RE: HTTPAPI examples


Sender: Scott Klement <sk@xxxxxxxxxxxxxxxx>


>
> The whole RPG program is about 400 lines - is it OK to post it here?
>

Yeah, go ahead.
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubsribe from the list send mail
to majordomo@xxxxxxxxxxxxx with the body: unsubscribe ftpapi mymailaddr
-----------------------------------------------------------------------



-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubsribe from the list send mail
to majordomo@xxxxxxxxxxxxx with the body: unsubscribe ftpapi mymailaddr
-----------------------------------------------------------------------