7 Replies Latest reply on Mar 29, 2018 11:36 AM by Mahmoud_Rabie

    How to call a Payment gateway REST API from Oracle apex

    Munir Mahmud

      I'm trying to implement a payment gateway with oracle Apex 5.1. I have all the setup Oracle apex 5.1, Database 11gR2, ORDS 3.0.9 with ssl enabled. I need to call a REST API of a payment gateway provider with 12 parameters. How can I achieve this. I'm not much familiar with this payment gateway functionality . I expect some one will guide me to implement a payment gateway in oracle apex.

       

      What I have the API Link and parameter. How to start the process I'm not sure. My first target is to call their Payment Gateway.

       

      I have created a branch to redirect this url under function returning URL I put this code.

       

      declare

      v_url varchar2(32767);

      l_clob clob;

      v_store_id varchar2(1000);

      v_store_passwd varchar2(1000);

      v_total_amount number;

      v_currency varchar2(20);

      v_tran_id varchar2(1000);

      v_success_url varchar2(2000);

      v_fail_url varchar2(2000);

      v_cancel_url varchar2(2000);

      v_emi_option number;

      v_cus_name varchar2(200);

      v_cus_email varchar2(100);

      v_cus_phone varchar2(200);

       

      begin

      v_store_id             :=UTL_URL.Escape(:P3_STORE_ID,TRUE);

      v_store_passwd         :=UTL_URL.Escape(:P3_STORE_PASSWD,TRUE);

      v_total_amount         :=UTL_URL.Escape(:P3_TOTAL_AMOUNT,TRUE);

      v_currency             :=UTL_URL.Escape(:P3_CURRENCY,TRUE);

      v_tran_id              :=UTL_URL.Escape(:P3_TRAN_ID,TRUE);

      v_success_url          :=UTL_URL.Escape(:P3_SUCCESS_URL,TRUE);

      v_fail_url             :=UTL_URL.Escape(:P3_FAIL_URL,TRUE);

      v_cancel_url           :=UTL_URL.Escape(:P3_CANCEL_URL,TRUE);

      v_emi_option           :=UTL_URL.Escape(:P3_EMI_OPTION,TRUE);

      v_cus_name             :=UTL_URL.Escape(:P3_FIRSTNAME,TRUE);

      v_cus_email            :=UTL_URL.Escape(:P3_EMAIL,TRUE);

      v_cus_phone            :=UTL_URL.Escape(:P3_PHONE,TRUE);

       

      v_url :='https://sandbox.XXXXXXXXXXXX/api.php?'

      ||'store_id='||v_store_id

      ||'&'||'store_passwd='||v_store_passwd

      ||'&'||'total_amount='||v_total_amount

      ||'&'||'currency='||v_currency

      ||'&'||'tran_id='||v_tran_id

      ||'&'||'success_url='||v_success_url

      ||'&'||'fail_url='||v_fail_url

      ||'&'||'cancel_url='||v_cancel_url

      ||'&'||'emi_option='||v_emi_option

      ||'&'||'cus_name='||v_cus_name

      ||'&'||'cus_email='||v_cus_email

      ||'&'||'cus_phone='||v_cus_phone;

       

       

      l_clob := apex_web_service.make_rest_request(p_url => v_url,

                                                   p_http_method => 'POST',

                                                   p_wallet_path => 'D:\app\oracle\product\11.2.0\dbhome_1\BIN\owm\wallets\Administrator',

                                                   p_wallet_pwd => 'WalletPasswd123');

                                                  

       

      return l_clob;   

         

      end;

       

      This is the initial code I have tried with Apex but no luck. It gives me error "wwv_flow.branch_func_returning_url_error. "Hoping someone will rescue me.

       

      Thanks

        • 1. Re: How to call a Payment gateway REST API from Oracle apex
          Pavel_p

          Hi,

          you described quite precisely what does not work, however some documentation would be highly helpful. It's very unlikely that anyone could help you to invoke the service with absolutely no understanding how the service is defined.

          Just two things that look suspicious... PUT/POST methods usually take input parameters in a request body as a JSON/XML object, not as URL parameters and is it really necessary to escape input items?

          Regards,

          Pavel

          • 2. Re: How to call a Payment gateway REST API from Oracle apex
            Munir Mahmud

            Hi Pavel,

             

            Thanks once again you came first to rescue me! . Actually As haven't  much dig into deep into payment gateway issue I got different solution in different blog. May be I mixed up. However, I need it very seriously . What is your suggestion and recommendation Any consultant like you to guide me through rest of the process to implement successfully.

            • 3. Re: How to call a Payment gateway REST API from Oracle apex
              Pavel_p

              Well, payment gateways usually have some documentation, so if possible send a link as a first step. Is it by any chance a public GW?

              • 4. Re: How to call a Payment gateway REST API from Oracle apex
                Mahmoud_Rabie

                Hi Munir

                 

                First of all, please provide us with documentation and the detailed error messages.

                 

                As Pavel said

                payment gateways usually have some documentation, so if possible send a link as a first step

                 

                FYI, here is the first-step working sample code for initiating a payment request in a local payment gateway. Maybe you missed something like:

                apex_web_service.g_request_headers

                p_username

                p_parm_name

                p_parm_value

                 

                or it gives you some ideas.

                create or replace FUNCTION  "initiate_payment_request" ( p_amount in NUMBER,
                                                                           p_description in VARCHAR2,
                                                                           p_username in VARCHAR2,
                                                                           p_apiuser in VARCHAR2)
                return CLOB
                is
                    base_url varchar2(150);
                    success_url varchar2(150);
                    fail_url varchar2(150);
                    l_clob    CLOB;
                
                begin
                    base_url := 'https://api.MYPAYMENTGATEWAY.com/v1/payments';   
                   
                    apex_web_service.g_request_headers(1).name := 'Content-Type';
                  apex_web_service.g_request_headers(1).value := 'application/x-www-form-urlencoded';
                
                  success_url := 'https://MYDOMAIN/ords/f?p=MYAPPID:MYPAGE';
                  fail_url := 'https://MYDOMAIN/ords/f?p=MYAPPID:MYPAGE';
                
                    l_clob := APEX_WEB_SERVICE.make_rest_request(
                                p_url => base_url,  
                        p_wallet_path => 'file:/opt/app/oracle/product/12.1.0/dbhome_1/owm/wallets/oracle',
                                p_wallet_pwd => 'MYWALLETPASSWORD',
                                p_http_method => 'POST', 
                                p_username => p_apiuser,
                                p_parm_name   => APEX_UTIL.string_to_table('amount^currency^source[type]^source[username]^source[success_url]^source[fail_url]^description', p_separator => '^'),   
                                p_parm_value  => APEX_UTIL.string_to_table( p_amount || '^MYCURRENCY^creditcard^' || p_username || '^' || success_url || '^' || fail_url || '^' || p_description, p_separator => '^' ));
                      
                    return l_clob;
                end;
                

                 

                I hope that helps you.

                 

                Regards

                Mahmoud

                • 5. Re: How to call a Payment gateway REST API from Oracle apex
                  Munir Mahmud

                  Though It is a Public gateway however you have some credentials to test in sandbox. If you kindly provide me your mail address I can send you details with API documentation and credentials. My  email address is here mahmud.munir@gmail.com

                   

                  Here is their Documentation Link.

                   

                  https://developer.sslcommerz.com/docs.html

                  • 6. Re: How to call a Payment gateway REST API from Oracle apex
                    Munir Mahmud

                    Hi Mahmoud,

                     

                    Thanks for your reply and effort. I send documentation to Pavel . Could you please share your mail address to me so that I can share credentials to you. my mail address is mahmud.munir@gmail.com

                    • 7. Re: How to call a Payment gateway REST API from Oracle apex
                      Mahmoud_Rabie

                      I sent an email. Please reply with your credentials and make sure that you have added a wallet to the https API of that payment gateway.