Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Calling https link that is not a web service

Stephen3
Participant
0 Likes
1,028

Hi All;

I have a need to call a credit card clearing house.  Specially the URL  https://secure.authorize.net:8080/gateway/transact.dll'

There is no WSDL or web service for this URL.

I am trying to use the method cl_http_client=>create_by_url but I can't seem to get it working.

Does anyone have any code samples they can share?


This is similar to this discussion http://scn.sap.com/thread/997210.How to call the URL with HTTPS connection with SSL certificate

I am using a Linux Red Hat 5 system with SAP ECC 6.0 EHP4.

Thanks


Stephen

5 REPLIES 5
Read only

UweFetzer_se38
Active Contributor
0 Likes
823

Hi Stephen,

can you please explain where your problem is?

The ABAP part (cl_http_client) or the Basis part (installing the SSL certificate)?

The test transaction is well documented here: http://developer.authorize.net/guides/DPM/wwhelp/wwhimpl/js/html/wwhelp.htm

Best regards

Read only

0 Likes
823

Hi Uwe;

My problem is the ABAP part.  There are number of sample code examples on the authorize.net website, but none for SAP ABAP.  Also, I am trying to use the AIM process described by Authorize.net.  You provided a link to the DPM process.  Is DPM a better process?

Stephen

Read only

0 Likes
823

Hi Stephen,

so you have already imported the SSL certificate?

The ABAP part for the test transactionis quite simple:

- create the client (with url = secure.authorize.net/gateway/transact.dll and  SCHEME = https)

- send a POST (with field x_test_request = "TRUE")

- receive the response

- close the connection

(code samples for CL_HTTP_CLIENT you can find all around SCN).

If the test transaction works for you, all other transactions should be no problem

Regards

Uwe

Read only

0 Likes
823

Hi Uwe,

How do I then pass the value like CC #, Amount - Shall I use   http_client->request->set_header_field method?

Thanks.

-Bharat

Read only

0 Likes
823

Hi Bharat;

Here is the code of the function module I used to call our credit card clearing house:

It reads the credit card number from the contact table associated with the customer master record.  This way a customer can have multiple credit cards on file.

FUNCTION Z_FI_AUTHORIZE_CC.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(USERNAME) TYPE  CHAR50
*"     REFERENCE(PASSWORD) TYPE  CHAR50
*"     REFERENCE(KUNNR) TYPE  KUNNR
*"     REFERENCE(GJAHR) TYPE  GJAHR OPTIONAL
*"     REFERENCE(BELNR) TYPE  BELNR_D OPTIONAL
*"     REFERENCE(XBLNR) TYPE  XBLNR1 OPTIONAL
*"     REFERENCE(BKTXT) TYPE  BKTXT OPTIONAL
*"     REFERENCE(DMBTR) TYPE  DMBTR
*"     VALUE(STEST) TYPE  CHAR1 OPTIONAL
*"     VALUE(URL) TYPE  STRING OPTIONAL
*"  EXPORTING
*"     REFERENCE(CCINS) TYPE  CCINS
*"     REFERENCE(CCNUM) TYPE  CCNUM
*"  CHANGING
*"     REFERENCE(ZCC_RES) TYPE  ZCC_RES
*"  EXCEPTIONS
*"      CLIENT_ERROR
*"      SEND_ERROR
*"      CC_NOT_FOUND
*"      DECRYPT_FAILED
*"      CUSTOMER_ERROR
*"----------------------------------------------------------------------

   DATA: client TYPE REF TO if_http_client.

   DATA: sstring    TYPE string,
         dummy      TYPE string,
         subrc      TYPE sysubrc,
         adrnr      TYPE ADRNR,
         ccdata     TYPE string,
         ilen       TYPE I,
*       url        TYPE string,
         ccfound    TYPE CHAR1,
         post_code1 TYPE AD_PSTCD1,
         ADRND      TYPE ADRND.

   DATA: ls_ccard_bin    TYPE ccardec_s_bin,
*        l_mask_ccnum    TYPE ccnum,
*        l_ccnum         TYPE ccnum,
*        l_origin        TYPE ccardec_origin,
*        ccard_guid      TYPE CCARDEC_GUID,
         STABIX          LIKE SY-TABIX.

   DATA: T_VCNUM LIKE VCNUM OCCURS 0 WITH HEADER LINE,
         T_VCKUN LIKE VCKUN OCCURS 0 WITH HEADER LINE.

* Macro definition
* Add a character &1 to the token, used by parse_token subroutine
DEFINE: ADD_CHAR_TO_TOKEN.
   IF I_TOKENLEN < I_MAX.
     C_TOKEN+I_TOKENLEN(1) = &1.
     I_TOKENLEN = I_TOKENLEN + 1.
   ENDIF.
END-OF-DEFINITION.


*  IF STEST = 'X'.
*    url = 'https://test.authorize.net/gateway/transact.dll'.
*  ELSE.
*    url = 'https://secure.authorize.net/gateway/transact.dll'.
*  ENDIF.

   IF url = ''.
     url = 'https://secure.authorize.net/gateway/transact.dll'.
   ENDIF.

   CALL FUNCTION 'SD_CCARD_READ_DB'
     EXPORTING
       I_KUNNR               = KUNNR
     TABLES
       T_VCNUM               = T_VCNUM
       T_VCKUN               = T_VCKUN
    EXCEPTIONS
      VCKUN_NOT_FOUND       = 1
      OTHERS                = 2.

   IF SY-SUBRC <> 0.
     ZCC_RES-REASON_TEXT = 'Credit card not found for customer.'.
     RAISE CC_NOT_FOUND.
     EXIT.
   ENDIF.

   CCFOUND = ''.

   IF BKTXT = ''.
     CCFOUND = 'X'.
     READ TABLE T_VCKUN WITH KEY CCDEF = 'X'.
     IF SY-SUBRC <> 0" No default, use first card on file
       STABIX = 1.
     ELSE.
       STABIX = SY-TABIX.
     ENDIF.
   ELSE.
     LOOP AT T_VCKUN.
       ilen = strlen( t_vckun-ccnum ).
       ilen = ilen - 4.
       IF t_vckun-ccnum+ilen(4) = BKTXT.
         STABIX = SY-TABIX.
         CCFOUND = 'X'.
         EXIT.
       ENDIF.
     ENDLOOP.
   ENDIF.

   IF CCFOUND = ''.
     ZCC_RES-REASON_TEXT = 'Credit card not found for customer.'.
     RAISE CC_NOT_FOUND.
     EXIT.
   ENDIF.

   READ TABLE T_VCNUM INDEX STABIX.

   CCINS = T_VCNUM-CCINS.
   CCNUM = T_VCNUM-CCNUM.

   IF SY-SUBRC <> 0.
     ZCC_RES-REASON_TEXT = 'Credit card not found for customer.'.
     RAISE CC_NOT_FOUND.
     EXIT.
   ENDIF.

   SELECT SINGLE ADRNR INTO ADRNR FROM KNA1 WHERE KUNNR = KUNNR.

   IF sy-subrc <> 0.
     ZCC_RES-REASON_TEXT = 'Address not found for customer.'.
     RAISE CUSTOMER_ERROR.
     EXIT.
   ENDIF.

   SELECT SINGLE * FROM ADRC WHERE ADDRNUMBER = ADRNR
                               AND DATE_FROM <= SY-DATUM
                               AND DATE_TO >= SY-DATUM.

   post_code1 = adrc-post_code1.

* Get Zip code from Contact if contact exists.
   select single ADRND into (ADRND) from KNVK where KUNNR = KUNNR
                                              and pafkt = '02'.

   IF SY-SUBRC = 0.
     SELECT SINGLE * FROM ADRC WHERE ADDRNUMBER = ADRND
                                 AND DATE_FROM <= SY-DATUM
                                 AND DATE_TO >= SY-DATUM.
     post_code1 = adrc-post_code1.
   ELSE.
     select single ADRND into (ADRND) from KNVK where KUNNR = KUNNR
                                                  and pafkt = '10'.
     IF SY-SUBRC = 0.
       SELECT SINGLE * FROM ADRC WHERE ADDRNUMBER = ADRND
                                 AND DATE_FROM <= SY-DATUM
                                 AND DATE_TO >= SY-DATUM.
       post_code1 = adrc-post_code1.
     ENDIF.
   ENDIF.



* Creation of new IF_HTTP_Client object
   CALL METHOD cl_http_client=>create_by_url
     EXPORTING
       url                = url
     IMPORTING
       client             = client
     EXCEPTIONS
       argument_not_found = 1
       plugin_not_active  = 2
       internal_error     = 3
       OTHERS             = 4.

   IF sy-subrc <> 0.
     raise client_error.
     EXIT.
   ENDIF.

   client->propertytype_accept_cookie = client->co_enabled.

* Set request protocol
   CALL METHOD client->request->set_header_field
     EXPORTING
       name  = '~server_protocol'
       value = 'HTTP/1.1'.

   sstring = username.
   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_login'
       value = sstring.

   sstring = password.
   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_tran_key'
       value = sstring.

   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_version'
       value = '3.1'.

   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_delim_data'
       value = 'TRUE'.

   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_delim_char'
       value = ','.

   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_encap_char'
       value = '"'.

   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_relay_response'
       value = 'FALSE'.

   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_type'
       value = 'AUTH_CAPTURE'.

   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_method'
       value = 'CC'.

   sstring = t_vcnum-ccnum.
   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_card_num'
       value = sstring.

* Format is MMYY
   concatenate t_vcnum-DATBI+4(2) t_vcnum-DATBI+2(2) INTO SSTRING.
   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_exp_date'
       value = sstring.

* TRUE OR FALSE
   IF STEST = 'X'.
     SSTRING = 'TRUE'.
   ELSE.
     SSTRING = 'FALSE'.
   ENDIF.
   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_test_request'
       value = sstring.

* Dollar amount
   sstring = dmbtr.
   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_amount'
       value = sstring.

   IF BELNR = '$1' or BELNR = ''.
     sstring = XBLNR.
   ELSE.
     sstring = belnr.
   ENDIF.

   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_invoice_num'
       value = sstring.

   sstring = 'OPENLANE Transaction'.

   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_description'
       value = sstring.

   sstring = t_vcnum-ccname.
   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_first_name'
       value = sstring.

   sstring = adrc-name1.
   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_company'
       value = sstring.

   sstring = adrc-street.
   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_address'
       value = sstring.

   sstring = adrc-city1.
   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_city'
       value = sstring.

   sstring = adrc-region.
   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_state'
       value = sstring.

   sstring = post_code1.
   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_zip'
       value = sstring.

   sstring = adrc-country.
   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_country'
       value = sstring.

   sstring = adrc-tel_number.
   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_phone'
       value = sstring.

   sstring = adrc-fax_number.
   CALL METHOD client->request->set_form_field
     EXPORTING
       name  = 'x_fax'
       value = sstring.

* Put in jump around call to do testing in SAP DEV
* Since Authorize only returns successfully call when
* the amount is $1.00.  Makes testing challenging.
   IF XBLNR <> 'SSHTEST'.

* Send the request
     client->send( ).

     CALL METHOD client->receive
       EXCEPTIONS
         http_communication_failure = 1
         http_invalid_state         = 2
         http_processing_failed     = 3
         OTHERS                     = 4.

     IF sy-subrc <> 0.
       CALL METHOD client->get_last_error
         IMPORTING
           code    = subrc
           message = dummy.

       CONCATENATE 'Error calling Authorize.Net - ' dummy into ZCC_RES-REASON_TEXT.
       raise send_error.
       EXIT.
     ENDIF.

* output data
     ccdata = client->response->get_cdata).

     PERFORM PARSE_STRING USING ccdata '"' CHANGING ZCC_RES.
*  PERFORM write_document.
   ELSE.
     ZCC_RES-CODE     = 1.
     ZCC_RES-TRANS_ID = 'SSHTEST'.
   ENDIF.

   CALL METHOD client->close
     EXCEPTIONS
       http_invalid_state = 1
       OTHERS             = 2.

ENDFUNCTION.

*----------------------------------------------------------------------*
* FORM PARSE_STRING                                                    *
*----------------------------------------------------------------------*
FORM PARSE_STRING USING    C_STRING C_DELIMITER
                   CHANGING T_STRUCTURE.
   DATA: C_TYPE          TYPE C,
         I_NUM_OF_FIELDS TYPE I,
         I_POS           TYPE I. " keeps track of the position in string

   FIELD-SYMBOLS: <F>.
* make sure that t_structure is actually a structure
   CLEAR T_STRUCTURE.
   DESCRIBE FIELD T_STRUCTURE TYPE C_TYPE COMPONENTS I_NUM_OF_FIELDS.
   CHECK C_TYPE = 'u' OR C_TYPE = 'v'" structure or internal table
* extract each field content from the comma delimited string
   I_POS = 0.
   DO I_NUM_OF_FIELDS TIMES.
     ASSIGN COMPONENT SY-INDEX OF STRUCTURE T_STRUCTURE TO <F>.
     IF SY-SUBRC <> 0.
       EXIT.
     ENDIF.
     PERFORM PARSE_TOKEN USING C_STRING C_DELIMITER CHANGING I_POS <F>.
   ENDDO.
ENDFORM.                    "PARSE_STRING

*----------------------------------------------------------------------*
* FORM PARSE_TOKEN                                                     *
*----------------------------------------------------------------------*
FORM PARSE_TOKEN USING C_STRING VALUE(C_DELIMITER)
                  CHANGING I_POS C_TOKEN.
   DATA: I_FLDLEN     TYPE I,
         I_TOKENLEN   TYPE I,
         I_MAX        TYPE I,
         C_CHAR       TYPE C,
         c_first_char type c value 'X'.
   DATA: DELIMITER_ON.
   DATA: STR_LEN TYPE I.

   DATA: descr_ref type ref to cl_abap_typedescr.

   clear c_token.
*  DESCRIBE FIELD C_TOKEN LENGTH I_MAX IN CHARACTER MODE.
   descr_ref = cl_abap_typedescr=>describe_by_data( c_token ).
   I_MAX = descr_ref->length.
   I_FLDLEN = STRLEN( C_STRING ) - I_POS.
   STR_LEN  = STRLEN( C_STRING ).
   do i_fldlen times.
     C_CHAR = C_STRING+I_POS(1).
     I_POS = I_POS + 1.
* if comma is found and delimiter_on is not set, then the parsing is
* completed
     IF C_CHAR = ',' AND DELIMITER_ON IS INITIAL.
       exit.
* if delimiter_on is standby and next char is comma, exit.
     ELSEIF C_CHAR = ',' AND DELIMITER_ON = 'S'.
       EXIT.
     ELSEIF C_FIRST_CHAR = 'X' AND C_CHAR = ' '.
* skip leading blanks.
     else.
       IF C_DELIMITER <> ' '.
         IF DELIMITER_ON IS INITIAL.
           IF C_DELIMITER = C_CHAR.
             DELIMITER_ON = 'X'.
           ELSE.
             CLEAR C_DELIMITER.
             ADD_CHAR_TO_TOKEN C_CHAR.
           ENDIF.
* If the character is c_delimiter, set the delimiter_on to standby mode,
* if the next character is ',' the token parsing is completed.
* if the next character is c_delimiter, set delimiter_on back to 'X'
* and treat the next character as part of the token.
         ELSEIF DELIMITER_ON = 'X' AND C_DELIMITER = C_CHAR.
*         CLEAR delimiter_on.
           DELIMITER_ON = 'S'.          " delimiter_on standby
         ELSE.
           IF DELIMITER_ON = 'S'.       " if delimiter_on is standby and
             IF I_POS < STR_LEN.
               ADD_CHAR_TO_TOKEN C_DELIMITER.
               IF C_CHAR <> C_DELIMITER." the next chr is not delimiter
                 DELIMITER_ON = 'X'.
                 ADD_CHAR_TO_TOKEN C_CHAR.
               ENDIF.                   " treat as part of the token
             ENDIF.
           ELSE.
             ADD_CHAR_TO_TOKEN C_CHAR.
           ENDIF.
         ENDIF.
       ELSE.
         ADD_CHAR_TO_TOKEN C_CHAR.
       ENDIF.
     endif.
     CLEAR C_FIRST_CHAR.
   enddo.

ENDFORM.                    "PARSE_TOKEN