Skip to content

Commit 4801534

Browse files
authored
Merge pull request #21 from fryiee/SharedTokenRequests
Shared token requests
2 parents 6128d35 + 8928283 commit 4801534

10 files changed

+421
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 RapidSharedCreateCardRequest extends RapidSharedPurchaseRequest
16+
{
17+
public function getData()
18+
{
19+
$this->validate('returnUrl');
20+
21+
$data = $this->getBaseData();
22+
$data['Method'] = 'CreateTokenCustomer';
23+
$data['TransactionType'] = 'Purchase';
24+
$data['RedirectUrl'] = $this->getReturnUrl();
25+
26+
// Shared page parameters (optional)
27+
$data['CancelUrl'] = $this->getCancelUrl();
28+
$data['LogoUrl'] = $this->getLogoUrl();
29+
$data['HeaderText'] = $this->getHeaderText();
30+
$data['Language'] = $this->getLanguage();
31+
$data['CustomerReadOnly'] = $this->getCustomerReadOnly();
32+
$data['CustomView'] = $this->getCustomView();
33+
34+
$data['Payment'] = array();
35+
$data['Payment']['TotalAmount'] = 0;
36+
37+
return $data;
38+
}
39+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* eWAY Rapid Shared Page Update Card Request
4+
*/
5+
6+
namespace Omnipay\Eway\Message;
7+
8+
/**
9+
* eWAY Rapid Shared Page Update 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 RapidSharedUpdateCardRequest extends RapidSharedPurchaseRequest
16+
{
17+
public function getData()
18+
{
19+
$this->validate('returnUrl', 'cardReference');
20+
21+
$data = $this->getBaseData();
22+
$data['Method'] = 'UpdateTokenCustomer';
23+
$data['TransactionType'] = 'Purchase';
24+
$data['RedirectUrl'] = $this->getReturnUrl();
25+
26+
// Shared page parameters (optional)
27+
$data['CancelUrl'] = $this->getCancelUrl();
28+
$data['LogoUrl'] = $this->getLogoUrl();
29+
$data['HeaderText'] = $this->getHeaderText();
30+
$data['Language'] = $this->getLanguage();
31+
$data['CustomerReadOnly'] = $this->getCustomerReadOnly();
32+
$data['CustomView'] = $this->getCustomView();
33+
34+
$data['Payment'] = array();
35+
$data['Payment']['TotalAmount'] = 0;
36+
37+
$data['Customer']['TokenCustomerID'] = $this->getCardReference();
38+
39+
return $data;
40+
}
41+
}

src/RapidSharedGateway.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,14 @@ public function refund(array $parameters = array())
7373
{
7474
return $this->createRequest('\Omnipay\Eway\Message\RefundRequest', $parameters);
7575
}
76+
77+
public function createCard(array $parameters = array())
78+
{
79+
return $this->createRequest('\Omnipay\Eway\Message\RapidSharedCreateCardRequest', $parameters);
80+
}
81+
82+
public function updateCard(array $parameters = array())
83+
{
84+
return $this->createRequest('\Omnipay\Eway\Message\RapidSharedUpdateCardRequest', $parameters);
85+
}
7686
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
3+
namespace Omnipay\Eway\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class RapidSharedCreateCardRequestTest extends TestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->request = new RapidSharedCreateCardRequest($this->getHttpClient(), $this->getHttpRequest());
12+
$this->request->initialize(array(
13+
'apiKey' => 'my api key',
14+
'password' => 'secret',
15+
'returnUrl' => 'https://www.example.com/return',
16+
));
17+
}
18+
19+
public function testGetData()
20+
{
21+
$this->request->initialize(array(
22+
'apiKey' => 'my api key',
23+
'password' => 'secret',
24+
'returnUrl' => 'https://www.example.com/return',
25+
'card' => array(
26+
'title' => 'Mr',
27+
'firstName' => 'Patrick',
28+
'lastName' => 'Collison',
29+
'country' => 'AU',
30+
),
31+
));
32+
33+
$data = $this->request->getData();
34+
35+
$this->assertSame('Purchase', $data['TransactionType']);
36+
$this->assertSame('CreateTokenCustomer', $data['Method']);
37+
$this->assertSame('https://www.example.com/return', $data['RedirectUrl']);
38+
$this->assertSame(0, $data['Payment']['TotalAmount']);
39+
$this->assertSame('Mr', $data['Customer']['Title']);
40+
$this->assertSame('Patrick', $data['Customer']['FirstName']);
41+
$this->assertSame('Collison', $data['Customer']['LastName']);
42+
$this->assertSame('au', $data['ShippingAddress']['Country']);
43+
}
44+
45+
public function testSendSuccess()
46+
{
47+
$this->setMockHttpResponse('RapidSharedCreateCardRequestSuccess.txt');
48+
$response = $this->request->send();
49+
50+
$this->assertFalse($response->isSuccessful());
51+
$this->assertTrue($response->isRedirect());
52+
$this->assertSame('GET', $response->getRedirectMethod());
53+
$this->assertSame('https://secure.ewaypayments.com/sharedpayment?AccessCode=F9802j0-O7sdVLnOcb_3IPryTxHDtKY8u_0pb10GbYq-Xjvbc-5Bc_LhI-oBIrTxTCjhOFn7Mq-CwpkLDja5-iu-Dr3DjVTr9u4yxSB5BckdbJqSA4WWydzDO0jnPWfBdKcWL', $response->getRedirectUrl());
54+
$this->assertNull($response->getRedirectData());
55+
$this->assertNull($response->getTransactionReference());
56+
$this->assertNull($response->getMessage());
57+
$this->assertNull($response->getCode());
58+
$this->assertNotNull($response->getCardReference());
59+
}
60+
61+
public function testSendFailure()
62+
{
63+
$this->setMockHttpResponse('RapidSharedCreateCardRequestFailure.txt');
64+
$response = $this->request->send();
65+
66+
$this->assertFalse($response->isSuccessful());
67+
$this->assertFalse($response->isRedirect());
68+
$this->assertNull($response->getRedirectUrl());
69+
$this->assertNull($response->getRedirectData());
70+
$this->assertNull($response->getCardReference());
71+
$this->assertNull($response->getTransactionReference());
72+
$this->assertSame('V6042,V6043,V6044', $response->getCode());
73+
}
74+
75+
public function testCancelUrl()
76+
{
77+
$this->assertSame($this->request, $this->request->setCancelUrl('http://www.example.com'));
78+
$this->assertSame('http://www.example.com', $this->request->getCancelUrl());
79+
}
80+
81+
public function testLogoUrl()
82+
{
83+
$this->assertSame($this->request, $this->request->setLogoUrl('https://www.example.com/logo.jpg'));
84+
$this->assertSame('https://www.example.com/logo.jpg', $this->request->getLogoUrl());
85+
}
86+
87+
public function testHeaderText()
88+
{
89+
$this->assertSame($this->request, $this->request->setHeaderText('Header Text'));
90+
$this->assertSame('Header Text', $this->request->getHeaderText());
91+
}
92+
93+
public function testLanguage()
94+
{
95+
$this->assertSame($this->request, $this->request->setLanguage('EN'));
96+
$this->assertSame('EN', $this->request->getLanguage());
97+
}
98+
99+
public function testCustomerReadOnly()
100+
{
101+
$this->assertSame($this->request, $this->request->setCustomerReadOnly('true'));
102+
$this->assertSame('true', $this->request->getCustomerReadOnly());
103+
}
104+
105+
public function testCustomView()
106+
{
107+
$this->assertSame($this->request, $this->request->setCustomView('Bootstrap'));
108+
$this->assertSame('Bootstrap', $this->request->getCustomView());
109+
}
110+
111+
public function testVerifyCustomerPhone()
112+
{
113+
$this->assertSame($this->request, $this->request->setVerifyCustomerPhone('true'));
114+
$this->assertSame('true', $this->request->getVerifyCustomerPhone());
115+
}
116+
117+
public function testVerifyCustomerEmail()
118+
{
119+
$this->assertSame($this->request, $this->request->setVerifyCustomerEmail('true'));
120+
$this->assertSame('true', $this->request->getVerifyCustomerEmail());
121+
}
122+
123+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
3+
namespace Omnipay\Eway\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class RapidSharedUpdateCardRequestTest extends TestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->request = new RapidSharedUpdateCardRequest($this->getHttpClient(), $this->getHttpRequest());
12+
$this->request->initialize(array(
13+
'apiKey' => 'my api key',
14+
'password' => 'secret',
15+
'returnUrl' => 'https://www.example.com/return',
16+
'cardReference' => '123456789'
17+
));
18+
}
19+
20+
public function testGetData()
21+
{
22+
$this->request->initialize(array(
23+
'apiKey' => 'my api key',
24+
'password' => 'secret',
25+
'returnUrl' => 'https://www.example.com/return',
26+
'cardReference' => '123456789',
27+
'card' => array(
28+
'title' => 'Mr',
29+
'firstName' => 'Patrick',
30+
'lastName' => 'Collison',
31+
'country' => 'AU',
32+
),
33+
));
34+
35+
$data = $this->request->getData();
36+
37+
$this->assertSame('Purchase', $data['TransactionType']);
38+
$this->assertSame('UpdateTokenCustomer', $data['Method']);
39+
$this->assertSame('https://www.example.com/return', $data['RedirectUrl']);
40+
$this->assertSame(0, $data['Payment']['TotalAmount']);
41+
$this->assertSame('Mr', $data['Customer']['Title']);
42+
$this->assertSame('Patrick', $data['Customer']['FirstName']);
43+
$this->assertSame('Collison', $data['Customer']['LastName']);
44+
$this->assertSame('au', $data['ShippingAddress']['Country']);
45+
$this->assertSame('123456789', $data['Customer']['TokenCustomerID']);
46+
}
47+
48+
public function testSendSuccess()
49+
{
50+
$this->setMockHttpResponse('RapidSharedUpdateCardRequestSuccess.txt');
51+
$response = $this->request->send();
52+
53+
$this->assertFalse($response->isSuccessful());
54+
$this->assertTrue($response->isRedirect());
55+
$this->assertSame('GET', $response->getRedirectMethod());
56+
$this->assertSame('https://secure.ewaypayments.com/sharedpayment?AccessCode=F9802j0-O7sdVLnOcb_3IPryTxHDtKY8u_0pb10GbYq-Xjvbc-5Bc_LhI-oBIrTxTCjhOFn7Mq-CwpkLDja5-iu-Dr3DjVTr9u4yxSB5BckdbJqSA4WWydzDO0jnPWfBdKcWL', $response->getRedirectUrl());
57+
$this->assertNull($response->getRedirectData());
58+
$this->assertNull($response->getTransactionReference());
59+
$this->assertNull($response->getMessage());
60+
$this->assertNull($response->getCode());
61+
$this->assertNotNull($response->getCardReference());
62+
}
63+
64+
public function testSendFailure()
65+
{
66+
$this->setMockHttpResponse('RapidSharedUpdateCardRequestFailure.txt');
67+
$response = $this->request->send();
68+
69+
$this->assertFalse($response->isSuccessful());
70+
$this->assertFalse($response->isRedirect());
71+
$this->assertNull($response->getRedirectUrl());
72+
$this->assertNull($response->getRedirectData());
73+
$this->assertNull($response->getCardReference());
74+
$this->assertNull($response->getTransactionReference());
75+
$this->assertSame('V6040', $response->getCode());
76+
}
77+
78+
public function testCancelUrl()
79+
{
80+
$this->assertSame($this->request, $this->request->setCancelUrl('http://www.example.com'));
81+
$this->assertSame('http://www.example.com', $this->request->getCancelUrl());
82+
}
83+
84+
public function testLogoUrl()
85+
{
86+
$this->assertSame($this->request, $this->request->setLogoUrl('https://www.example.com/logo.jpg'));
87+
$this->assertSame('https://www.example.com/logo.jpg', $this->request->getLogoUrl());
88+
}
89+
90+
public function testHeaderText()
91+
{
92+
$this->assertSame($this->request, $this->request->setHeaderText('Header Text'));
93+
$this->assertSame('Header Text', $this->request->getHeaderText());
94+
}
95+
96+
public function testLanguage()
97+
{
98+
$this->assertSame($this->request, $this->request->setLanguage('EN'));
99+
$this->assertSame('EN', $this->request->getLanguage());
100+
}
101+
102+
public function testCustomerReadOnly()
103+
{
104+
$this->assertSame($this->request, $this->request->setCustomerReadOnly('true'));
105+
$this->assertSame('true', $this->request->getCustomerReadOnly());
106+
}
107+
108+
public function testCustomView()
109+
{
110+
$this->assertSame($this->request, $this->request->setCustomView('Bootstrap'));
111+
$this->assertSame('Bootstrap', $this->request->getCustomView());
112+
}
113+
114+
public function testVerifyCustomerPhone()
115+
{
116+
$this->assertSame($this->request, $this->request->setVerifyCustomerPhone('true'));
117+
$this->assertSame('true', $this->request->getVerifyCustomerPhone());
118+
}
119+
120+
public function testVerifyCustomerEmail()
121+
{
122+
$this->assertSame($this->request, $this->request->setVerifyCustomerEmail('true'));
123+
$this->assertSame('true', $this->request->getVerifyCustomerEmail());
124+
}
125+
126+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
HTTP/1.1 200 OK
2+
Cache-control: no-cache="set-cookie"
3+
Content-Type: application/json; charset=utf-8
4+
Date: Thu, 27 Jun 2013 05:22:52 GMT
5+
Set-Cookie: AWSELB=8361C96B088FEBBC7D3ABDFE8BA0FF6501B9705E7D00F53B19AA8D0E66C1AD34691F2170CBA3CC4FEE8666E2FB3C85D3B0E238FA2E93B31AAC1C98DFF4D0639139359FE706;PATH=/;MAX-AGE=86400
6+
X-EWAY-VIA: api-au.sandbox.ewaypayments.com/
7+
X-EWAY-VIA-FROM: http://api.sandbox.ewaypayments.com/CreateAccessCodeShared.json
8+
X-EWAY-VIA-HTTP-METHOD: POST
9+
X-EWAY-VIA-HTTP-STATUS: 200
10+
X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/CreateAccessCodeShared.json
11+
X-ID: AM-131
12+
X-Powered-By: eWAY
13+
X-Staging: AU
14+
Content-Length: 649
15+
Connection: keep-alive
16+
17+
{"AccessCode":null,"Customer":{"TokenCustomerID":null,"Reference":null,"Title":null,"FirstName":null,"LastName":null,"CompanyName":null,"JobDescription":null,"Street1":null,"Street2":null,"City":null,"State":null,"PostalCode":null,"Country":null,"Email":null,"Phone":null,"Mobile":null,"Comments":null,"Fax":null,"Url":null,"CardNumber":null,"CardStartMonth":null,"CardStartYear":null,"CardIssueNumber":null,"CardName":null,"CardExpiryMonth":null,"CardExpiryYear":null,"IsActive":false},"Payment":{"TotalAmount":0,"InvoiceNumber":null,"InvoiceDescription":null,"InvoiceReference":null,"CurrencyCode":"AUD"},"FormActionURL":null,"Errors":"V6042,V6043,V6044"}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
HTTP/1.1 200 OK
2+
Cache-control: no-cache="set-cookie"
3+
Content-Type: application/json; charset=utf-8
4+
Date: Wed, 26 Jun 2013 13:11:50 GMT
5+
Set-Cookie: AWSELB=8361C96B088FEBBC7D3ABDFE8BA0FF6501B9705E7D00F53B19AA8D0E66C1AD34691F2170CB4C6B4D750DDAD028ED5C0787DEB1569F57CC58B5923AA0229EC5B49BD7647A57;PATH=/;MAX-AGE=86400
6+
X-EWAY-VIA: api-au.sandbox.ewaypayments.com/
7+
X-EWAY-VIA-FROM: http://api.sandbox.ewaypayments.com/CreateAccessCodeShared.json
8+
X-EWAY-VIA-HTTP-METHOD: POST
9+
X-EWAY-VIA-HTTP-STATUS: 200
10+
X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/CreateAccessCodeShared.json
11+
X-ID: AM-143
12+
X-Powered-By: eWAY
13+
Content-Length: 1112
14+
Connection: keep-alive
15+
16+
{"SharedPaymentUrl":"https://secure.ewaypayments.com/sharedpayment?AccessCode=F9802j0-O7sdVLnOcb_3IPryTxHDtKY8u_0pb10GbYq-Xjvbc-5Bc_LhI-oBIrTxTCjhOFn7Mq-CwpkLDja5-iu-Dr3DjVTr9u4yxSB5BckdbJqSA4WWydzDO0jnPWfBdKcWL","AccessCode":"F9802j0-O7sdVLnOcb_3IPryTxHDtKY8u_0pb10GbYq-Xjvbc-5Bc_LhI-oBIrTxTCjhOFn7Mq-CwpkLDja5-iu-Dr3DjVTr9u4yxSB5BckdbJqSA4WWydzDO0jnPWfBdKcWL","Customer":{"TokenCustomerID":"","Reference":"","Title":"","FirstName":"","LastName":"","CompanyName":"","JobDescription":"","Street1":"","Street2":"","City":"","State":"","PostalCode":"","Country":"","Email":"","Phone":"","Mobile":"","Comments":"","Fax":"","Url":"","CardNumber":"","CardStartMonth":"","CardStartYear":"","CardIssueNumber":"","CardName":"","CardExpiryMonth":"","CardExpiryYear":"","IsActive":false},"Payment":{"TotalAmount":0,"InvoiceNumber":null,"InvoiceDescription":null,"InvoiceReference":null,"CurrencyCode":"AUD"},"FormActionURL":"https://secure.ewaypayments.com/AccessCode/F9802j0-O7sdVLnOcb_3IPryTxHDtKY8u_0pb10GbYq-Xjvbc-5Bc_LhI-oBIrTxTCjhOFn7Mq-CwpkLDja5-iu-Dr3DjVTr9u4yxSB5BckdbJqSA4WWydzDO0jnPWfBdKcWL","Errors":null}

0 commit comments

Comments
 (0)