9 use Omnipay\Tests\TestCase;
11 class ExpressInContextAuthorizeRequestTest
extends TestCase
18 public function setUp()
23 $this->request->initialize(
26 'returnUrl' =>
'https://www.example.com/return',
27 'cancelUrl' =>
'https://www.example.com/cancel',
34 $this->request->initialize(array(
37 'transactionId' =>
'111',
38 'description' =>
'Order Description',
39 'returnUrl' =>
'https://www.example.com/return',
40 'cancelUrl' =>
'https://www.example.com/cancel',
41 'subject' =>
'demo@example.com',
42 'headerImageUrl' =>
'https://www.example.com/header.jpg',
46 'addressOverride' => 0,
47 'brandName' =>
'Dunder Mifflin Paper Company, Inc.',
48 'customerServiceNumber' =>
'1-801-FLOWERS',
51 $data = $this->request->getData();
53 $this->assertSame(
'10.00', $data[
'PAYMENTREQUEST_0_AMT']);
54 $this->assertSame(
'AUD', $data[
'PAYMENTREQUEST_0_CURRENCYCODE']);
55 $this->assertSame(
'111', $data[
'PAYMENTREQUEST_0_INVNUM']);
56 $this->assertSame(
'Order Description', $data[
'PAYMENTREQUEST_0_DESC']);
57 $this->assertSame(
'https://www.example.com/return', $data[
'RETURNURL']);
58 $this->assertSame(
'https://www.example.com/cancel', $data[
'CANCELURL']);
59 $this->assertSame(
'demo@example.com', $data[
'SUBJECT']);
60 $this->assertSame(
'https://www.example.com/header.jpg', $data[
'HDRIMG']);
61 $this->assertSame(0, $data[
'NOSHIPPING']);
62 $this->assertSame(0, $data[
'ALLOWNOTE']);
63 $this->assertSame(
'EN', $data[
'LOCALECODE']);
64 $this->assertSame(0, $data[
'ADDROVERRIDE']);
65 $this->assertSame(
'Dunder Mifflin Paper Company, Inc.', $data[
'BRANDNAME']);
66 $this->assertSame(
'1-801-FLOWERS', $data[
'CUSTOMERSERVICENUMBER']);
71 $this->request->initialize(array(
74 'transactionId' =>
'111',
75 'description' =>
'Order Description',
76 'returnUrl' =>
'https://www.example.com/return',
77 'cancelUrl' =>
'https://www.example.com/cancel',
78 'subject' =>
'demo@example.com',
79 'headerImageUrl' =>
'https://www.example.com/header.jpg',
82 'addressOverride' => 1,
83 'brandName' =>
'Dunder Mifflin Paper Company, Inc.',
84 'maxAmount' => 123.45,
85 'logoImageUrl' =>
'https://www.example.com/logo.jpg',
86 'borderColor' =>
'CCCCCC',
88 'customerServiceNumber' =>
'1-801-FLOWERS',
89 'sellerPaypalAccountId' =>
'billing@example.com',
94 'address1' =>
'123 NW Blvd',
95 'address2' =>
'Lynx Lane',
99 'postcode' =>
'66605',
100 'phone' =>
'555-555-5555',
101 'email' =>
'test@email.com',
103 $this->request->setCard($card);
106 'METHOD' =>
'SetExpressCheckout',
111 'PAYMENTREQUEST_0_PAYMENTACTION' =>
'Authorization',
112 'SOLUTIONTYPE' =>
null,
113 'LANDINGPAGE' =>
null,
117 'PAYMENTREQUEST_0_AMT' =>
'10.00',
118 'PAYMENTREQUEST_0_CURRENCYCODE' =>
'AUD',
119 'PAYMENTREQUEST_0_INVNUM' =>
'111',
120 'PAYMENTREQUEST_0_DESC' =>
'Order Description',
121 'RETURNURL' =>
'https://www.example.com/return',
122 'CANCELURL' =>
'https://www.example.com/cancel',
123 'SUBJECT' =>
'demo@example.com',
124 'HDRIMG' =>
'https://www.example.com/header.jpg',
125 'PAYMENTREQUEST_0_SHIPTONAME' =>
'John Doe',
126 'PAYMENTREQUEST_0_SHIPTOSTREET' =>
'123 NW Blvd',
127 'PAYMENTREQUEST_0_SHIPTOSTREET2' =>
'Lynx Lane',
128 'PAYMENTREQUEST_0_SHIPTOCITY' =>
'Topeka',
129 'PAYMENTREQUEST_0_SHIPTOSTATE' =>
'KS',
130 'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' =>
'USA',
131 'PAYMENTREQUEST_0_SHIPTOZIP' =>
'66605',
132 'PAYMENTREQUEST_0_SHIPTOPHONENUM' =>
'555-555-5555',
133 'EMAIL' =>
'test@email.com',
134 'BRANDNAME' =>
'Dunder Mifflin Paper Company, Inc.',
136 'PAYMENTREQUEST_0_TAXAMT' =>
null,
137 'PAYMENTREQUEST_0_SHIPPINGAMT' =>
null,
138 'PAYMENTREQUEST_0_HANDLINGAMT' =>
null,
139 'PAYMENTREQUEST_0_SHIPDISCAMT' =>
null,
140 'PAYMENTREQUEST_0_INSURANCEAMT' =>
null,
141 'LOGOIMG' =>
'https://www.example.com/logo.jpg',
142 'CARTBORDERCOLOR' =>
'CCCCCC',
143 'LOCALECODE' =>
'EN',
144 'CUSTOMERSERVICENUMBER' =>
'1-801-FLOWERS',
145 'PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID' =>
'billing@example.com',
148 $this->assertEquals($expected, $this->request->getData());
153 $this->request->setItems(array(
154 array(
'name' =>
'Floppy Disk',
'description' =>
'MS-DOS',
'quantity' => 2,
'price' => 10,
'code' =>
'123456'),
155 array(
'name' =>
'CD-ROM',
'description' =>
'Windows 95',
'quantity' => 1,
'price' => 40),
158 $data = $this->request->getData();
159 $this->assertSame(
'Floppy Disk', $data[
'L_PAYMENTREQUEST_0_NAME0']);
160 $this->assertSame(
'MS-DOS', $data[
'L_PAYMENTREQUEST_0_DESC0']);
161 $this->assertSame(2, $data[
'L_PAYMENTREQUEST_0_QTY0']);
162 $this->assertSame(
'10.00', $data[
'L_PAYMENTREQUEST_0_AMT0']);
163 $this->assertSame(
'123456', $data[
'L_PAYMENTREQUEST_0_NUMBER0']);
165 $this->assertSame(
'CD-ROM', $data[
'L_PAYMENTREQUEST_0_NAME1']);
166 $this->assertSame(
'Windows 95', $data[
'L_PAYMENTREQUEST_0_DESC1']);
167 $this->assertSame(1, $data[
'L_PAYMENTREQUEST_0_QTY1']);
168 $this->assertSame(
'40.00', $data[
'L_PAYMENTREQUEST_0_AMT1']);
170 $this->assertSame(
'60.00', $data[
'PAYMENTREQUEST_0_ITEMAMT']);
175 $this->request->initialize(array(
178 'transactionId' =>
'111',
179 'description' =>
'Order Description',
180 'returnUrl' =>
'https://www.example.com/return',
181 'cancelUrl' =>
'https://www.example.com/cancel',
182 'subject' =>
'demo@example.com',
183 'headerImageUrl' =>
'https://www.example.com/header.jpg',
186 'addressOverride' => 0,
187 'brandName' =>
'Dunder Mifflin Paper Company, Inc.',
188 'taxAmount' =>
'2.00',
189 'shippingAmount' =>
'5.00',
190 'handlingAmount' =>
'1.00',
191 'shippingDiscount' =>
'-1.00',
192 'insuranceAmount' =>
'3.00',
195 $data = $this->request->getData();
196 $this->assertSame(
'2.00', $data[
'PAYMENTREQUEST_0_TAXAMT']);
197 $this->assertSame(
'5.00', $data[
'PAYMENTREQUEST_0_SHIPPINGAMT']);
198 $this->assertSame(
'1.00', $data[
'PAYMENTREQUEST_0_HANDLINGAMT']);
199 $this->assertSame(
'-1.00', $data[
'PAYMENTREQUEST_0_SHIPDISCAMT']);
200 $this->assertSame(
'3.00', $data[
'PAYMENTREQUEST_0_INSURANCEAMT']);
205 $this->assertSame($this->request, $this->request->setHeaderImageUrl(
'https://www.example.com/header.jpg'));
206 $this->assertSame(
'https://www.example.com/header.jpg', $this->request->getHeaderImageUrl());
208 $data = $this->request->getData();
209 $this->assertEquals(
'https://www.example.com/header.jpg', $data[
'HDRIMG']);
214 $this->request->setMaxAmount(321.54);
216 $this->assertSame(321.54, $this->request->getMaxAmount());
218 $data = $this->request->getData();
220 $this->assertSame(321.54, $data[
'MAXAMT']);
228 'transactionId' =>
'111',
229 'description' =>
'Order Description',
230 'returnUrl' =>
'https://www.example.com/return',
231 'cancelUrl' =>
'https://www.example.com/cancel',
232 'subject' =>
'demo@example.com',
233 'headerImageUrl' =>
'https://www.example.com/header.jpg',
235 'addressOverride' => 0,
236 'brandName' =>
'Dunder Mifflin Paper Company, Incy.',
239 $shippingOptions = array(
246 $this->request->initialize(array_merge($baseData, array(
247 'callback' =>
'https://www.example.com/calculate-shipping',
248 'shippingOptions' => $shippingOptions,
251 $data = $this->request->getData();
252 $this->assertSame(
'https://www.example.com/calculate-shipping', $data[
'CALLBACK']);
255 $this->assertSame(
'First Class', $data[
'L_SHIPPINGOPTIONNAME0']);
256 $this->assertSame(
'1.20', $data[
'L_SHIPPINGOPTIONAMOUNT0']);
257 $this->assertSame(
'1', $data[
'L_SHIPPINGOPTIONISDEFAULT0']);
258 $this->assertSame(
'1-2 days', $data[
'L_SHIPPINGOPTIONLABEL0']);
260 $this->assertSame(
'Second Class', $data[
'L_SHIPPINGOPTIONNAME1']);
261 $this->assertSame(
'0.70', $data[
'L_SHIPPINGOPTIONAMOUNT1']);
262 $this->assertSame(
'0', $data[
'L_SHIPPINGOPTIONISDEFAULT1']);
263 $this->assertSame(
'3-5 days', $data[
'L_SHIPPINGOPTIONLABEL1']);
265 $this->assertSame(
'International', $data[
'L_SHIPPINGOPTIONNAME2']);
266 $this->assertSame(
'3.50', $data[
'L_SHIPPINGOPTIONAMOUNT2']);
267 $this->assertSame(
'0', $data[
'L_SHIPPINGOPTIONISDEFAULT2']);
270 $this->request->initialize(array_merge($baseData, array(
271 'callback' =>
'https://www.example.com/calculate-shipping',
272 'callbackTimeout' => 10,
273 'shippingOptions' => $shippingOptions,
276 $data = $this->request->getData();
277 $this->assertSame(
'https://www.example.com/calculate-shipping', $data[
'CALLBACK']);
278 $this->assertSame(10, $data[
'CALLBACKTIMEOUT']);
286 'transactionId' =>
'111',
287 'description' =>
'Order Description',
288 'returnUrl' =>
'https://www.example.com/return',
289 'cancelUrl' =>
'https://www.example.com/cancel',
290 'subject' =>
'demo@example.com',
291 'headerImageUrl' =>
'https://www.example.com/header.jpg',
293 'addressOverride' => 0,
294 'brandName' =>
'Dunder Mifflin Paper Company, Incy.',
297 $shippingOptions = array(
304 $this->request->initialize(array_merge($baseData, array(
305 'callback' =>
'https://www.example.com/calculate-shipping',
306 'shippingOptions' => $shippingOptions,
309 $this->expectException(InvalidRequestException::class);
310 $this->expectExceptionMessage(
'One of the supplied shipping options must be set as default');
312 $this->request->getData();
320 $this->request->initialize($baseData);
322 $this->expectException(InvalidRequestException::class);
323 $this->expectExceptionMessage(
'The amount parameter is required');
325 $this->request->getData();
334 $this->request->initialize($baseData);
336 $this->expectException(InvalidRequestException::class);
337 $this->expectExceptionMessage(
'The returnUrl parameter is required');
339 $this->request->getData();
347 'transactionId' =>
'111',
348 'description' =>
'Order Description',
349 'returnUrl' =>
'https://www.example.com/return',
350 'cancelUrl' =>
'https://www.example.com/cancel',
351 'subject' =>
'demo@example.com',
352 'headerImageUrl' =>
'https://www.example.com/header.jpg',
354 'addressOverride' => 0,
355 'brandName' =>
'Dunder Mifflin Paper Company, Incy.',
358 $this->request->initialize(array_merge($baseData, array(
359 'callback' =>
'https://www.example.com/calculate-shipping',
365 $this->expectException(InvalidRequestException::class);
367 $this->request->getData();