Skip to content

Commit 8de212f

Browse files
authored
Merge pull request #23 from eileenmcnaughton/master
Eway Improvements to support transparent redirect & shared gateway recurring
2 parents 4801534 + bb28152 commit 8de212f

13 files changed

+256
-11
lines changed

.editorConfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
php:
4-
- 5.3
54
- 5.4
65
- 5.5
76
- 5.6

src/Message/AbstractRequest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
1616
{
1717
protected $liveEndpoint = 'https://api.ewaypayments.com';
1818
protected $testEndpoint = 'https://api.sandbox.ewaypayments.com';
19+
protected $action;
1920

2021
public function getApiKey()
2122
{
@@ -84,6 +85,22 @@ public function setInvoiceReference($value)
8485
return $this->setParameter('invoiceReference', $value);
8586
}
8687

88+
/**
89+
* @return string|NULL
90+
*/
91+
public function getAction()
92+
{
93+
return $this->action;
94+
}
95+
96+
/**
97+
* @param string $action
98+
*/
99+
public function setAction($action)
100+
{
101+
$this->action = $action;
102+
}
103+
87104
protected function getBaseData()
88105
{
89106
$data = array();
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* eWAY Rapid Shared Page Create Card Request
4+
*/
5+
6+
namespace Omnipay\Eway\Message;
7+
8+
/**
9+
* eWAY Rapid Shared Page Create Card Request
10+
*
11+
* Creates a payment URL using eWAY's Responsive Shared Page
12+
*
13+
* @link https://eway.io/api-v3/#responsive-shared-page
14+
*/
15+
class RapidCreateCardRequest extends RapidPurchaseRequest
16+
{
17+
public function getData()
18+
{
19+
$this->validate('returnUrl');
20+
21+
$data = $this->getBaseData();
22+
23+
$data['TransactionType'] = 'Purchase';
24+
$data['RedirectUrl'] = $this->getReturnUrl();
25+
26+
// Shared page parameters (optional)
27+
$data['CancelUrl'] = $this->getCancelUrl();
28+
29+
$data['Payment'] = array();
30+
31+
if ($this->getAction() === 'Purchase') {
32+
$data['Payment']['TotalAmount'] = (int) $this->getAmountInteger();
33+
$data['Payment']['InvoiceNumber'] = $this->getTransactionId();
34+
$data['Payment']['InvoiceDescription'] = $this->getDescription();
35+
$data['Payment']['CurrencyCode'] = $this->getCurrency();
36+
$data['Payment']['InvoiceReference'] = $this->getInvoiceReference();
37+
$data['Method'] = 'TokenPayment';
38+
} else {
39+
$data['Method'] = 'CreateTokenCustomer';
40+
$data['Payment']['TotalAmount'] = 0;
41+
}
42+
43+
return $data;
44+
}
45+
}

src/Message/RapidDirectAbstractRequest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ protected function getBaseData()
6262
if ($this->getCard()) {
6363
$data['Customer']['CardDetails'] = array();
6464
$data['Customer']['CardDetails']['Name'] = $this->getCard()->getName();
65-
$data['Customer']['CardDetails']['ExpiryMonth'] = $this->getCard()->getExpiryDate('m');
66-
$data['Customer']['CardDetails']['ExpiryYear'] = $this->getCard()->getExpiryDate('y');
65+
66+
if ($this->getCard()->getExpiryYear() && $this->getCard()->getExpiryMonth()) {
67+
// Expiry date not required if token present
68+
$data['Customer']['CardDetails']['ExpiryMonth'] = $this->getCard()->getExpiryDate('m');
69+
$data['Customer']['CardDetails']['ExpiryYear'] = $this->getCard()->getExpiryDate('y');
70+
}
6771
$data['Customer']['CardDetails']['CVN'] = $this->getCard()->getCvv();
6872

6973
if ($this->getEncryptedCardNumber()) {

src/Message/RapidDirectCreateCardRequest.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
namespace Omnipay\Eway\Message;
77

8+
use Omnipay\Eway\RapidDirectGateway;
9+
use Omnipay\Omnipay;
10+
811
/**
912
* eWAY Rapid Direct Create Card Request
1013
*
@@ -78,6 +81,25 @@ public function sendData($data)
7881
->setAuth($this->getApiKey(), $this->getPassword())
7982
->send();
8083

81-
return $this->response = new RapidDirectCreateCardResponse($this, $httpResponse->json());
84+
$this->response = new RapidDirectCreateCardResponse($this, $httpResponse->json());
85+
86+
if ($this->getAction() === 'Purchase' && $this->response->isSuccessful()) {
87+
/** @var RapidDirectGateway $purchaseGateway */
88+
$purchaseGateway = Omnipay::create('Eway_RapidDirect');
89+
$purchaseGateway->setApiKey($this->getApiKey());
90+
$purchaseGateway->setPassword($this->getPassword());
91+
$purchaseGateway->setTestMode($this->getTestMode());
92+
$purchaseResponse = $purchaseGateway->purchase(array(
93+
'amount' => $this->getAmount(),
94+
'currency' => $this->getCurrency(),
95+
'description' => $this->getDescription(),
96+
'transactionId' => $this->getTransactionId(),
97+
'card' => $this->getCard(),
98+
'cardReference' => $this->response->getCardReference(),
99+
))->send();
100+
$this->response->setPurchaseResponse($purchaseResponse);
101+
}
102+
103+
return $this->response;
82104
}
83105
}

src/Message/RapidDirectCreateCardResponse.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,47 @@
22
/**
33
* eWAY Rapid Direct Create Card Response
44
*/
5-
5+
66
namespace Omnipay\Eway\Message;
77

8+
use Omnipay\SecurePay\Message\DirectPostCompletePurchaseResponse;
9+
810
/**
911
* eWAY Rapid Direct Create Card Response
10-
*
11-
* This is the response class for Rapid Direct when creating
12+
*
13+
* This is the response class for Rapid Direct when creating
1214
* or updating a card
1315
*
1416
*/
1517
class RapidDirectCreateCardResponse extends RapidResponse
1618
{
19+
/**
20+
* @var DirectPostCompletePurchaseResponse
21+
*/
22+
protected $purchaseResponse;
23+
24+
/**
25+
* @return DirectPostCompletePurchaseResponse
26+
*/
27+
public function getPurchaseResponse()
28+
{
29+
return $this->purchaseResponse;
30+
}
31+
32+
/**
33+
* @param DirectPostCompletePurchaseResponse $purchaseResponse
34+
*/
35+
public function setPurchaseResponse($purchaseResponse)
36+
{
37+
$this->purchaseResponse = $purchaseResponse;
38+
}
39+
1740
public function isSuccessful()
1841
{
19-
return $this->data['ResponseMessage'] == 'A2000';
42+
if (!$this->getPurchaseResponse()) {
43+
return $this->data['ResponseMessage'] == 'A2000';
44+
} else {
45+
return ($this->data['ResponseMessage'] == 'A2000' && $this->purchaseResponse->isSuccessful());
46+
}
2047
}
2148
}

src/Message/RapidDirectPurchaseRequest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ public function getData()
8282
$data['Payment']['CurrencyCode'] = $this->getCurrency();
8383
$data['Payment']['InvoiceReference'] = $this->getInvoiceReference();
8484

85+
if (empty($data['Customer']['CardDetails']['CVN']) && $this->getCardReference()) {
86+
// We have a token and card is not present so treat as MOTO.
87+
$data['TransactionType'] = 'MOTO';
88+
}
89+
8590
if ($this->getCardReference()) {
8691
$data['Method'] = 'TokenPayment';
8792
} else {

src/Message/RapidResponse.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ public function getRedirectData()
3939
}
4040
}
4141

42+
/**
43+
* Is the response a transparent redirect?
44+
*
45+
* @return boolean
46+
*/
47+
public function isTransparentRedirect()
48+
{
49+
return true;
50+
}
51+
4252
/**
4353
* Get a card reference (eWAY Token), for createCard requests.
4454
*
@@ -49,12 +59,32 @@ public function getCardReference()
4959
if (isset($this->data['Customer']['TokenCustomerID'])) {
5060
return $this->data['Customer']['TokenCustomerID'];
5161
}
62+
if (isset($this->data['TokenCustomerID'])) {
63+
// This format appears when creating a card and making a concurrent
64+
// payment using Shared or Transparent redirect methods.
65+
return $this->data['TokenCustomerID'];
66+
}
5267

5368
return null;
5469
}
5570

71+
/**
72+
* Get the transaction ID as generated by the merchant website.
73+
*
74+
* @return string
75+
*/
76+
public function getTransactionId()
77+
{
78+
return $this->data['InvoiceNumber'];
79+
}
80+
5681
/**
5782
* Get InvoiceNumber - merchant reference for a transaction
83+
*
84+
* @deprecated Omnipay standard interface is to return this when getTransactionId
85+
* is called
86+
*
87+
* @see https://github.com/thephpleague/omnipay#successful-response
5888
*/
5989
public function getInvoiceNumber()
6090
{

src/Message/RapidSharedCreateCardRequest.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,30 @@
1414
*/
1515
class RapidSharedCreateCardRequest extends RapidSharedPurchaseRequest
1616
{
17+
protected $action;
18+
19+
/**
20+
* @return string|NULL
21+
*/
22+
public function getAction()
23+
{
24+
return $this->action;
25+
}
26+
27+
/**
28+
* @param string $action
29+
*/
30+
public function setAction($action)
31+
{
32+
$this->action = $action;
33+
}
34+
1735
public function getData()
1836
{
1937
$this->validate('returnUrl');
2038

2139
$data = $this->getBaseData();
22-
$data['Method'] = 'CreateTokenCustomer';
40+
2341
$data['TransactionType'] = 'Purchase';
2442
$data['RedirectUrl'] = $this->getReturnUrl();
2543

@@ -32,7 +50,18 @@ public function getData()
3250
$data['CustomView'] = $this->getCustomView();
3351

3452
$data['Payment'] = array();
35-
$data['Payment']['TotalAmount'] = 0;
53+
54+
if ($this->getAction() === 'Purchase') {
55+
$data['Payment']['TotalAmount'] = (int) $this->getAmountInteger();
56+
$data['Payment']['InvoiceNumber'] = $this->getTransactionId();
57+
$data['Payment']['InvoiceDescription'] = $this->getDescription();
58+
$data['Payment']['CurrencyCode'] = $this->getCurrency();
59+
$data['Payment']['InvoiceReference'] = $this->getInvoiceReference();
60+
$data['Method'] = 'TokenPayment';
61+
} else {
62+
$data['Method'] = 'CreateTokenCustomer';
63+
$data['Payment']['TotalAmount'] = 0;
64+
}
3665

3766
return $data;
3867
}

0 commit comments

Comments
 (0)