I'm trying to create a custom omnipay driver for a local gateway called creditguard. For this gateway you need to post the data to the endpoint and get back a redirect url for the payment form.
My question is how do you post and get the response before making the purchase?
Edit:
Gateway.php
class Gateway extends AbstractGateway
{
public function getName()
{
return 'Creditguard';
}
public function getDefaultParameters()
{
return array();
}
public function getEndpoint()
{
return 'https://verifonetest.creditguard.co.il/xpo/Relay';
}
public function purchase(array $parameters = array())
{
return $this->createRequest('\Nirz\Creditguard\Message\PurchaseRequest', $parameters);
}
public function completePurchase(array $parameters = array())
{
return $this->createRequest('\Nirz\Creditguard\Message\CompletePurchaseRequest', $parameters);
}
}
PurchaseRequest.php
class PurchaseRequest extends AbstractRequest
{
protected $liveEndpoint = 'https://verifonetest.creditguard.co.il/xpo/Relay';
protected $testEndpoint = 'https://verifonetest.creditguard.co.il/xpo/Relay';
public function getData()
{
$this->validate('amount');
// Either the nodifyUrl or the returnUrl can be provided.
// The returnUrl is deprecated, as strictly this is a notifyUrl.
if (!$this->getNotifyUrl()) {
$this->validate('returnUrl');
}
$data = array();
$data['user'] = 'user';
$data['password'] = 'password';
$data['tid'] = '11111111';
$data['mid'] = '111111';
$data['amount'] = '20000';
$data['int_in'] = '<ashrait>
<request>
<version>1000</version>
<language>HEB</language>
<dateTime></dateTime>
<command>doDeal</command>
<doDeal>
<terminalNumber>'.$data['tid'].'</terminalNumber>
<mainTerminalNumber/>
<cardNo>CGMPI</cardNo>
<total>'.$data['amount'].'</total>
<transactionType>Debit</transactionType>
<creditType>RegularCredit</creditType>
<currency>ILS</currency>
<transactionCode>Phone</transactionCode>
<authNumber/>
<numberOfPayments/>
<firstPayment/>
<periodicalPayment/>
<validation>TxnSetup</validation>
<dealerNumber/>
<user>'. $data['user'] .'</user>
<mid>'.$data['mid'].'</mid>
<uniqueid>'.time().rand(100,1000).'</uniqueid>
<mpiValidation>autoComm</mpiValidation>
<email>[email protected]</email>
<clientIP/>
<customerData>
<userData1/>
<userData2/>
<userData3/>
<userData4/>
<userData5/>
<userData6/>
<userData7/>
<userData8/>
<userData9/>
<userData10/>
</customerData>
</doDeal>
</request>
</ashrait>';
return $data;
}
public function sendData($data)
{
// $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data);
return $this->response = new PurchaseResponse($this, $data);
}
public function getEndpoint()
{
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
}
}
PurchaseResponse.php
class PurchaseResponse extends AbstractResponse implements RedirectResponseInterface
{
public function isSuccessful()
{
return false;
}
public function isRedirect()
{
return true;
}
public function getRedirectUrl()
{
// return $this->getRequest()->getEndpoint().'?'.http_build_query($this->data);
return $this->getRequest()->data['mpiHostedPageUrl'];
// return isset($this->data['mpiHostedPageUrl']) ? $this->data['mpiHostedPageUrl'] : null;
}
public function getRedirectMethod()
{
return 'GET';
}
public function getRedirectData()
{
return [];
}
}
Not sure how to get the response's mpiHostedPageUrl so I can redirect to the correct url.
Assuming this is the payment gateway documentation in question.
You just go ahead and make the transaction request, the customer won't be charged as they'll have to authorise it on the next page by entering in their payment details.
The response of that transaction request contains an element
mpiHostedPageUrl
, which you can see on page 13 of that document, that contains the URL you need to get from the response to provide the redirect.