Forums

Interfacing to a payment gateway

tshirley 19 Oct, 2015
Hi there,

I need to interface a form to a payment gateway. The gateway works now with a very simple call to a "Pay Now" button and this is fine, but I want to discover the result of the transaction so that I can decide what to do next.

The payment Gateway supplier has an API, the description is here :

https://eway.io/api-v3/?shell#responsive-shared-page

In particular the API calls for some authentication and then a script which uses "cURL" and json.

curl --request POST \
    --user 60CF3Ce97nRS1Z1Wp5m9kMmzHHEh8Rkuj31QCtVxjPWGYA9FymyqsK0Enm1P6mHJf0THbR:API-P4ss \
    --header 'Content-Type: application/json' \
    --data '{
        "Payment": {
           "TotalAmount": 100
        },
        "RedirectUrl": "http://www.eway.com.au",
        "CancelUrl": "http://www.eway.com.au",
        "Method": "ProcessPayment",
        "TransactionType": "Purchase"
        }' \
    https://api.sandbox.ewaypayments.com/AccessCodesShared


This is very basic but if I can get this part to work I expect the remaining calls can be handled easily.

I can see how this would work, but what I am not sure of is how or where to insert this code in my form. Custom Code I guess, but just doing that doesn't do anything, and there is obviously something else I need to do.

Unfortunately I am not skilled with JSON coding and I suspect this is where I need help.

If anyone can point me in the right direction I would very much appreciate it.

Cheers

Tim
calculus00 19 Oct, 2015
Hello tshirley,
I'm not a Chrono professional, but after checking your new post, I think that the following links may help:
Payment Gateway 'Trial' actions
P.S: I'm just an automated service😉
GreyHead 19 Oct, 2015
Hi Tim,

First - the *best* way to do this (though maybe not the easiest) is to use one of their PHP SDKs, that will give you full access to all the functionality.

Using cURL with JSON is much simpler.

First you need to use a Custom Code action in the form On Submit event and clean and collect it into an array. Then use the PHP json_encode() method to convert it to json It will be something like this
<?php
$json_data = array(
  'Payment' => array(
    'TotalAmount' => $form->data['amount'],
  }
  'RedirectUrl' => 'some_url',
  . . .
}
$form->data['json_data'] = json_encode($json_data);
?>

You ought then to be able to use the ChronoForms cURL action to send the code but I'm not sure that you can set the HeaderOption to JSON in the standard version :-(

You may need to add the CURL code to the Custom Code action - there's an example under the POST heading in this StackOverFlow answer.

Bob
tshirley 20 Oct, 2015
Thanks Bob,

I have got further with this, and I have been able to send a request to the gateway and receive a transaction code in response.

If I use a Redirect, the transaction code is returned but simply displayed. If I then paste this response to my browser, it works as I expect and goes to process in the gateway

If I use Curl, I get an error back:

[curl] => HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD, OPTIONS, TRACE
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Content-Length: 1293
Date: Tue, 20 Oct 2015 00:33:10 GMT
Connection: close
Set-Cookie: BIGipServerVirtServerPool-015-SSL=251857674.47873.0000; path=/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>405 - HTTP verb used to access this page is not allowed.</title>
<style type="text/css">
<!--
body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
fieldset{padding:0 15px 10px 15px;} 
h1{font-size:2.4em;margin:0;color:#FFF;}
h2{font-size:1.7em;margin:0;color:#CC0000;} 
h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} 
#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
background-color:#555555;}
#content{margin:0 0 0 2%;position:relative;}
.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
-->
</style>
</head>
<body>
<div id="header"><h1>Server Error</h1></div>
<div id="content">
 <div class="content-container"><fieldset>
  <h2>405 - HTTP verb used to access this page is not allowed.</h2>
  <h3>The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.</h3>
 </fieldset></div>
</div>
</body>
</html>


The curl parameters look like this:

CustomerID="87654321"
UserName="TestAccount"
Amount="10.00"
Currency="AUD"
ReturnURL="http://www.mysite/index.php?option=com_chronoforms5&chronoform=ewayreceipt"
CancelURL="http://www.mysite/index.php?option=com_chronoforms5&chronoform=ewayreceipt"


Sorry, a stupid question I expect.

Cheers
tshirley 20 Oct, 2015
I am also sending the manual for the gateway process as it may give more information.
tshirley 20 Oct, 2015
Answer
1 Likes
Hi Bob,

Problem solved, I have managed to interface to the API but using Custom Code as you suggested. Took a while but your links above finally gave me the clue. But at least now I have the full API at my disposal.

Many thanks.

Tim
This topic is locked and no more replies can be posted.