Skip to content

Commit ad41bbb

Browse files
author
Vladislav Veselinov
committed
Merge remote-tracking branch 'upstream/master'
2 parents 8d47699 + b097590 commit ad41bbb

11 files changed

+503
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Omnipay\Eway\Message;
13+
14+
/**
15+
* eWAY Rapid 3.0 Complete Purchase Request
16+
*/
17+
class RapidCompletePurchaseRequest extends RapidPurchaseRequest
18+
{
19+
public function getData()
20+
{
21+
return array('AccessCode' => $this->httpRequest->query->get('AccessCode'));
22+
}
23+
24+
public function getEndpoint()
25+
{
26+
return $this->getEndpointBase().'/GetAccessCodeResult.json';
27+
}
28+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Omnipay\Eway\Message;
13+
14+
use Omnipay\Common\Message\AbstractRequest;
15+
16+
/**
17+
* eWAY Rapid 3.0 Purchase Request
18+
*/
19+
class RapidPurchaseRequest extends AbstractRequest
20+
{
21+
protected $liveEndpoint = 'https://api.ewaypayments.com';
22+
protected $testEndpoint = 'https://api.sandbox.ewaypayments.com';
23+
24+
public function getApiKey()
25+
{
26+
return $this->getParameter('apiKey');
27+
}
28+
29+
public function setApiKey($value)
30+
{
31+
return $this->setParameter('apiKey', $value);
32+
}
33+
34+
public function getPassword()
35+
{
36+
return $this->getParameter('password');
37+
}
38+
39+
public function setPassword($value)
40+
{
41+
return $this->setParameter('password', $value);
42+
}
43+
44+
public function getData()
45+
{
46+
$this->validate('amount', 'returnUrl');
47+
48+
$data = array();
49+
$data['Method'] = 'ProcessPayment';
50+
$data['DeviceID'] = 'https://github.com/adrianmacneil/omnipay';
51+
$data['CustomerIP'] = $this->getClientIp();
52+
$data['RedirectUrl'] = $this->getReturnUrl();
53+
54+
$data['Payment'] = array();
55+
$data['Payment']['TotalAmount'] = $this->getAmountInteger();
56+
$data['Payment']['InvoiceNumber'] = $this->getTransactionId();
57+
$data['Payment']['InvoiceDescription'] = $this->getDescription();
58+
$data['Payment']['CurrencyCode'] = $this->getCurrency();
59+
60+
$data['Customer'] = array();
61+
if ($this->getCard()) {
62+
$data['Customer']['FirstName'] = $this->getCard()->getFirstName();
63+
$data['Customer']['LastName'] = $this->getCard()->getLastName();
64+
}
65+
66+
return $data;
67+
}
68+
69+
public function send()
70+
{
71+
$httpResponse = $this->httpClient->post($this->getEndpoint(), null, json_encode($this->getData()))
72+
->setAuth($this->getApiKey(), $this->getPassword())
73+
->send();
74+
75+
return $this->response = new RapidResponse($this, $httpResponse->json());
76+
}
77+
78+
public function getEndpoint()
79+
{
80+
return $this->getEndpointBase().'/CreateAccessCode.json';
81+
}
82+
83+
public function getEndpointBase()
84+
{
85+
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
86+
}
87+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Omnipay\Eway\Message;
13+
14+
use Omnipay\Common\Message\AbstractResponse;
15+
use Omnipay\Common\Message\RedirectResponseInterface;
16+
17+
/**
18+
* eWAY Rapid 3.0 Purchase Response
19+
*/
20+
class RapidResponse extends AbstractResponse implements RedirectResponseInterface
21+
{
22+
public function isSuccessful()
23+
{
24+
return isset($this->data['TransactionStatus']) && $this->data['TransactionStatus'];
25+
}
26+
27+
public function isRedirect()
28+
{
29+
return isset($this->data['FormActionURL']);
30+
}
31+
32+
public function getRedirectUrl()
33+
{
34+
return isset($this->data['FormActionURL']) ? $this->data['FormActionURL'] : null;
35+
}
36+
37+
public function getRedirectMethod()
38+
{
39+
return 'POST';
40+
}
41+
42+
public function getRedirectData()
43+
{
44+
if ($this->isRedirect()) {
45+
return array(
46+
'EWAY_ACCESSCODE' => $this->data['AccessCode'],
47+
);
48+
}
49+
}
50+
51+
public function getTransactionReference()
52+
{
53+
return isset($this->data['TransactionID']) ? (string) $this->data['TransactionID'] : null;
54+
}
55+
56+
public function getMessage()
57+
{
58+
return $this->getCode();
59+
}
60+
61+
public function getCode()
62+
{
63+
if (!empty($this->data['ResponseMessage'])) {
64+
return $this->data['ResponseMessage'];
65+
} elseif (!empty($this->data['Errors'])) {
66+
return $this->data['Errors'];
67+
}
68+
}
69+
}

src/Omnipay/Eway/RapidGateway.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Omnipay\Eway;
13+
14+
use Omnipay\Common\AbstractGateway;
15+
16+
/**
17+
* eWAY Rapid 3.0 Gateway
18+
*/
19+
class RapidGateway extends AbstractGateway
20+
{
21+
public function getName()
22+
{
23+
return 'eWAY Rapid 3.0';
24+
}
25+
26+
public function getDefaultParameters()
27+
{
28+
return array(
29+
'apiKey' => '',
30+
'password' => '',
31+
'testMode' => false,
32+
);
33+
}
34+
35+
public function getApiKey()
36+
{
37+
return $this->getParameter('apiKey');
38+
}
39+
40+
public function setApiKey($value)
41+
{
42+
return $this->setParameter('apiKey', $value);
43+
}
44+
45+
public function getPassword()
46+
{
47+
return $this->getParameter('password');
48+
}
49+
50+
public function setPassword($value)
51+
{
52+
return $this->setParameter('password', $value);
53+
}
54+
55+
public function purchase(array $parameters = array())
56+
{
57+
return $this->createRequest('\Omnipay\Eway\Message\RapidPurchaseRequest', $parameters);
58+
}
59+
60+
public function completePurchase(array $parameters = array())
61+
{
62+
return $this->createRequest('\Omnipay\Eway\Message\RapidCompletePurchaseRequest', $parameters);
63+
}
64+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Omnipay\Eway\Message;
13+
14+
use Omnipay\TestCase;
15+
16+
class RapidCompletePurchaseRequestTest extends TestCase
17+
{
18+
public function setUp()
19+
{
20+
$this->request = new RapidCompletePurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
21+
$this->request->initialize(array(
22+
'apiKey' => 'my api key',
23+
'password' => 'secret',
24+
));
25+
$this->getHttpRequest()->query->replace(array(
26+
'AccessCode' => 'F9802j0-O7sdVLnOcb_3IPryTxHDtKY8u_0pb10GbYq-Xjvbc-5Bc_LhI-oBIrTxTCjhOFn7Mq-CwpkLDja5-iu-Dr3DjVTr9u4yxSB5BckdbJqSA4WWydzDO0jnPWfBdKcWL',
27+
));
28+
}
29+
30+
public function testGetData()
31+
{
32+
$data = $this->request->getData();
33+
34+
$this->assertSame('F9802j0-O7sdVLnOcb_3IPryTxHDtKY8u_0pb10GbYq-Xjvbc-5Bc_LhI-oBIrTxTCjhOFn7Mq-CwpkLDja5-iu-Dr3DjVTr9u4yxSB5BckdbJqSA4WWydzDO0jnPWfBdKcWL', $data['AccessCode']);
35+
}
36+
37+
public function testSendSuccess()
38+
{
39+
$this->setMockHttpResponse('RapidCompletePurchaseRequestSuccess.txt');
40+
$response = $this->request->send();
41+
42+
$this->assertTrue($response->isSuccessful());
43+
$this->assertFalse($response->isRedirect());
44+
$this->assertNull($response->getRedirectUrl());
45+
$this->assertNull($response->getRedirectData());
46+
$this->assertSame('10204029', $response->getTransactionReference());
47+
$this->assertSame('A2000', $response->getMessage());
48+
$this->assertSame('A2000', $response->getCode());
49+
}
50+
51+
public function testSendFailure()
52+
{
53+
$this->setMockHttpResponse('RapidCompletePurchaseRequestFailure.txt');
54+
$response = $this->request->send();
55+
56+
$this->assertFalse($response->isSuccessful());
57+
$this->assertFalse($response->isRedirect());
58+
$this->assertNull($response->getRedirectUrl());
59+
$this->assertNull($response->getRedirectData());
60+
$this->assertNull($response->getTransactionReference());
61+
$this->assertSame('V6021', $response->getMessage());
62+
$this->assertSame('V6021', $response->getCode());
63+
}
64+
}

0 commit comments

Comments
 (0)