TOPIC:

Payment gateways 1 year 3 months ago #243302

  • Topic Author
  • Rokhi
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 111
  • Thanks: 1
curl_exec( $ch ) is what is returning the json data, the response is returning true (1) (I wondered what the 1 was after the json set)

I guess I need the CURLOPT_RETURNTRANSFER to return the NavigateURL etc for the header.

Now - to get that to work!

Please Log in or Create an account to join the conversation.

Payment gateways 1 year 3 months ago #243303

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 808
can you please check if it is accessed properly?

It should print the actual URL. If it is empty, then the response isn't read properly (json_decode's 2nd parameter was = true in the code before and therefore needs to be accessable this way.

If there is nothing printed and the page is just blank, then the NavigateURL hasn't been accessed properly from the json array.

Also please try using Joomla's setRedirect, I am not really font of using header() for this:
echo $json["NavigateURL"];
exit;
//JFactory::getApplication->redirect($json["NavigateURL"]);

Please Log in or Create an account to join the conversation.

Payment gateways 1 year 3 months ago #243309

  • Topic Author
  • Rokhi
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 111
  • Thanks: 1
$response = curl_exec( $ch ); prints
{"Success":true,"NavigateURL":"https://txn.apac.paywithpoli.com/?Token=J%2bpN9H9iZW4cmb%2bUeC7D5QaIOAwOqNqQ","ErrorCode":0,"ErrorMessage":null,"TransactionRefNo":"996476506780"}

to the screen

and $response only contains 1

json_decode($response, true) returns 1
so $json contains 1

I believe curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); is required to make curl_exec( $ch ); return the json string to $response, but it breaks the code.

Please Log in or Create an account to join the conversation.

Payment gateways 1 year 3 months ago #243310

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 808
Hm, this sounds weird. But try this instead:
ob_start();
curl_exec( $ch );
$response = ob_get_contents();
ob_end_clean();

Btw, I am still baffled that CURLOPT_RETURNTRANSFER throws an error for you.

Please Log in or Create an account to join the conversation.

Payment gateways 1 year 3 months ago #243311

  • Topic Author
  • Rokhi
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 111
  • Thanks: 1
OK, brilliant! I'm thru to the gateway

Please Log in or Create an account to join the conversation.

Payment gateways 1 year 3 months ago #243315

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 808
Ok, now we need to track the statuses (success, fail and cancelled).

For this we add the record id to every url back to our site:
"SuccessURL":'.json_encode(JURI::getInstance()->toString() . '&poli_return=true&poli_success=true') .'&record_id='.$this->record_id.',
"FailureURL":'.json_encode(JURI::getInstance()->toString() . '&poli_return=true&poli_success=false') .'&record_id='.$this->record_id.',
"CancellationURL":'.json_encode(JURI::getInstance()->toString() . '&poli_return=true&poli_cancel=true') .'&record_id='.$this->record_id.',
"NotificationURL":'.json_encode(JURI::getInstance()->toString() . '&poli_return=true&poli_notification=true') .'&record_id='.$this->record_id.' 

Then in your form add a hidden input field called "status" (name and title, lowercase).

Then in form => advanced => more options => form pieces => before form => click "custom" and add this (make sure to add your auth code here, too):
if( JRequest::getVar('poli_return', '') == 'true'  ){

    if(JRequest::getVar('poli_success', '') == 'true'){

        echo 'Your payment has been succeeded!';
    }
    else if(JRequest::getVar('poli_success', '') == 'false'){
        echo 'Your payment has failed';
    }
    else if(JRequest::getVar('poli_cancel', '') == 'true'){
        echo 'Your have cancelled the payment';
    }
    else if(JRequest::getVar('poli_notification', '') == 'true'){

        // here we are receiving and storing the nudge
        
        $token = JRequest::getVar('token','');
        
        if($token != ''){

            $auth = base64_encode('S61xxxxx:AuthCode1234');
            $header = array();
            $header[] = 'Authorization: Basic '.$auth;

            $ch = curl_init("https://poliapi.apac.paywithpoli.com/api/v2/Transaction/GetTransaction?token=".urlencode($token));
            //See the cURL documentation for more information: http://curl.haxx.se/docs/sslcerts.html
            //We recommend using this bundle: https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt
            //curl_setopt( $ch, CURLOPT_CAINFO, "ca-bundle.crt");
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
            curl_setopt( $ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
            curl_setopt( $ch, CURLOPT_HTTPHEADER, $header);
            curl_setopt( $ch, CURLOPT_HEADER, 0);
            curl_setopt( $ch, CURLOPT_POST, 0);
            curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 0);
            //curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

            ob_start();
            curl_exec( $ch );
            $response = ob_get_contents();
            ob_end_clean();
            curl_close ($ch);

            // updating "status" in the record
            $db = JFactory::getDbo();
            $db->setQuery("Update #__facileforms_subrecords Set `value` = " . $db->quote($response) . " Where s.`status` And s.record = " . JRequest::getInt('record_id', 0));
            $db->execute();

            @ob_end_clean();
            header("HTTP/1.1 200 OK");
            exit;
        }
    }
}

So what basically happens here is an output for the user when he is transferred back.
But it also stores the final payment conclusion that Poli sends through the notification URL we passed previously in the end submit piece.

Regards,
Markus

Please Log in or Create an account to join the conversation.

Time to create page: 0.053 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!