5 use Omnipay\Tests\GatewayTestCase;
24 public function setUp()
28 $this->gateway =
new ExpressGateway($this->getHttpClient(), $this->getHttpRequest());
30 $this->options = array(
32 'returnUrl' =>
'https://www.example.com/return',
33 'cancelUrl' =>
'https://www.example.com/cancel',
35 $this->voidOptions = array(
36 'transactionReference' =>
'ASDFASDFASDF',
42 $this->setMockHttpResponse(
'ExpressPurchaseSuccess.txt');
44 $response = $this->gateway->authorize($this->options)->send();
46 $this->assertInstanceOf(
'\Omnipay\PayPal\Message\ExpressAuthorizeResponse', $response);
47 $this->assertFalse($response->isPending());
48 $this->assertFalse($response->isSuccessful());
49 $this->assertTrue($response->isRedirect());
50 $this->assertEquals(
'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl());
55 $this->setMockHttpResponse(
'ExpressPurchaseFailure.txt');
57 $response = $this->gateway->authorize($this->options)->send();
59 $this->assertFalse($response->isPending());
60 $this->assertFalse($response->isSuccessful());
61 $this->assertFalse($response->isRedirect());
62 $this->assertNull($response->getTransactionReference());
63 $this->assertSame(
'This transaction cannot be processed. The amount to be charged is zero.', $response->getMessage());
68 $this->setMockHttpResponse(
'ExpressPurchaseSuccess.txt');
70 $response = $this->gateway->purchase($this->options)->send();
72 $this->assertInstanceOf(
'\Omnipay\PayPal\Message\ExpressAuthorizeResponse', $response);
73 $this->assertFalse($response->isPending());
74 $this->assertFalse($response->isSuccessful());
75 $this->assertTrue($response->isRedirect());
76 $this->assertEquals(
'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl());
81 $this->setMockHttpResponse(
'ExpressPurchaseFailure.txt');
83 $response = $this->gateway->purchase($this->options)->send();
85 $this->assertFalse($response->isPending());
86 $this->assertFalse($response->isSuccessful());
87 $this->assertFalse($response->isRedirect());
88 $this->assertNull($response->getTransactionReference());
89 $this->assertSame(
'This transaction cannot be processed. The amount to be charged is zero.', $response->getMessage());
94 $this->setMockHttpResponse(
'ExpressOrderSuccess.txt');
96 $response = $this->gateway->order($this->options)->send();
98 $this->assertInstanceOf(
'\Omnipay\PayPal\Message\ExpressAuthorizeResponse', $response);
99 $this->assertFalse($response->isPending());
100 $this->assertFalse($response->isSuccessful());
101 $this->assertTrue($response->isRedirect());
102 $this->assertEquals(
'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl());
107 $this->setMockHttpResponse(
'ExpressOrderFailure.txt');
109 $response = $this->gateway->order($this->options)->send();
111 $this->assertFalse($response->isPending());
112 $this->assertFalse($response->isSuccessful());
113 $this->assertFalse($response->isRedirect());
114 $this->assertNull($response->getTransactionReference());
115 $this->assertSame(
'This transaction cannot be processed. The amount to be charged is zero.', $response->getMessage());
120 $this->setMockHttpResponse(
'ExpressVoidSuccess.txt');
122 $response = $this->gateway->void($this->voidOptions)->send();
124 $this->assertInstanceOf(
'\Omnipay\PayPal\Message\Response', $response);
125 $this->assertTrue($response->isSuccessful());
126 $this->assertFalse($response->isRedirect());
127 $this->assertEquals(
'ASDFASDFASDF', $response->getTransactionReference());
132 $this->setMockHttpResponse(
'ExpressVoidFailure.txt');
134 $response = $this->gateway->void($this->voidOptions)->send();
136 $this->assertInstanceOf(
'\Omnipay\PayPal\Message\Response', $response);
137 $this->assertFalse($response->isSuccessful());
142 $options = array(
'token' =>
'abc123');
143 $request = $this->gateway->fetchCheckout(
$options);
145 $this->assertInstanceOf(
'\Omnipay\PayPal\Message\ExpressFetchCheckoutRequest', $request);
146 $this->assertSame(
'abc123', $request->getToken());
151 $this->setMockHttpResponse(
'ExpressCompletePurchaseFailureRedirect.txt');
153 $response = $this->gateway->completePurchase($this->options)->send();
155 $this->assertFalse($response->isPending());
156 $this->assertFalse($response->isSuccessful());
157 $this->assertTrue($response->isRedirect());
158 $this->assertEquals(
'ASDFASDFASDF', $response->getTransactionReference());
159 $this->assertSame(
'This transaction couldn\'t be completed. Please redirect your customer to PayPal.', $response->getMessage());
164 $this->setMockHttpResponse(
'ExpressPurchaseSuccess.txt');
166 $this->getHttpRequest()->query->replace(array(
167 'token' =>
'GET_TOKEN',
168 'PayerID' =>
'GET_PAYERID',
171 $response = $this->gateway->completePurchase(array(
176 $httpRequests = $this->getMockedRequests();
177 $httpRequest = $httpRequests[0];
178 parse_str((
string)$httpRequest->getBody(), $postData);
179 $this->assertSame(
'GET_TOKEN', $postData[
'TOKEN']);
180 $this->assertSame(
'GET_PAYERID', $postData[
'PAYERID']);
185 $this->setMockHttpResponse(
'ExpressPurchaseSuccess.txt');
188 $this->getHttpRequest()->query->replace(array(
189 'token' =>
'GET_TOKEN',
190 'PayerID' =>
'GET_PAYERID',
193 $response = $this->gateway->completePurchase(array(
196 'token' =>
'CUSTOM_TOKEN',
197 'payerid' =>
'CUSTOM_PAYERID',
200 $httpRequests = $this->getMockedRequests();
201 $httpRequest = $httpRequests[0];
202 parse_str((
string)$httpRequest->getBody(), $postData);
203 $this->assertSame(
'CUSTOM_TOKEN', $postData[
'TOKEN']);
204 $this->assertSame(
'CUSTOM_PAYERID', $postData[
'PAYERID']);
209 $transactionSearch = $this->gateway->transactionSearch(array(
210 'startDate' =>
'2015-01-01',
211 'endDate' =>
'2015-12-31',
214 $this->assertInstanceOf(
'\Omnipay\PayPal\Message\ExpressTransactionSearchRequest', $transactionSearch);
215 $this->assertInstanceOf(
'\DateTime', $transactionSearch->getStartDate());
216 $this->assertInstanceOf(
'\DateTime', $transactionSearch->getEndDate());