10 use Omnipay\Tests\TestCase;
12 class ExpressAuthorizeRequestTest
extends TestCase
19 public function setUp()
24 $this->request->initialize(
27 'returnUrl' =>
'https://www.example.com/return',
28 'cancelUrl' =>
'https://www.example.com/cancel',
35 $this->request->initialize(array(
38 'transactionId' =>
'111',
39 'description' =>
'Order Description',
40 'returnUrl' =>
'https://www.example.com/return',
41 'cancelUrl' =>
'https://www.example.com/cancel',
42 'subject' =>
'demo@example.com',
43 'headerImageUrl' =>
'https://www.example.com/header.jpg',
47 'addressOverride' => 0,
48 'brandName' =>
'Dunder Mifflin Paper Company, Inc.',
49 'customerServiceNumber' =>
'1-801-FLOWERS',
52 $data = $this->request->getData();
54 $this->assertSame(
'10.00', $data[
'PAYMENTREQUEST_0_AMT']);
55 $this->assertSame(
'AUD', $data[
'PAYMENTREQUEST_0_CURRENCYCODE']);
56 $this->assertSame(
'111', $data[
'PAYMENTREQUEST_0_INVNUM']);
57 $this->assertSame(
'Order Description', $data[
'PAYMENTREQUEST_0_DESC']);
58 $this->assertSame(
'https://www.example.com/return', $data[
'RETURNURL']);
59 $this->assertSame(
'https://www.example.com/cancel', $data[
'CANCELURL']);
60 $this->assertSame(
'demo@example.com', $data[
'SUBJECT']);
61 $this->assertSame(
'https://www.example.com/header.jpg', $data[
'HDRIMG']);
62 $this->assertSame(0, $data[
'NOSHIPPING']);
63 $this->assertSame(0, $data[
'ALLOWNOTE']);
64 $this->assertSame(
'EN', $data[
'LOCALECODE']);
65 $this->assertSame(0, $data[
'ADDROVERRIDE']);
66 $this->assertSame(
'Dunder Mifflin Paper Company, Inc.', $data[
'BRANDNAME']);
67 $this->assertSame(
'1-801-FLOWERS', $data[
'CUSTOMERSERVICENUMBER']);
72 $this->request->initialize(array(
75 'transactionId' =>
'111',
76 'description' =>
'Order Description',
77 'returnUrl' =>
'https://www.example.com/return',
78 'cancelUrl' =>
'https://www.example.com/cancel',
79 'subject' =>
'demo@example.com',
80 'headerImageUrl' =>
'https://www.example.com/header.jpg',
83 'addressOverride' => 1,
84 'brandName' =>
'Dunder Mifflin Paper Company, Inc.',
85 'maxAmount' => 123.45,
86 'logoImageUrl' =>
'https://www.example.com/logo.jpg',
87 'borderColor' =>
'CCCCCC',
89 'customerServiceNumber' =>
'1-801-FLOWERS',
90 'sellerPaypalAccountId' =>
'billing@example.com',
95 'address1' =>
'123 NW Blvd',
96 'address2' =>
'Lynx Lane',
100 'postcode' =>
'66605',
101 'phone' =>
'555-555-5555',
102 'email' =>
'test@email.com',
104 $this->request->setCard($card);
107 'METHOD' =>
'SetExpressCheckout',
112 'PAYMENTREQUEST_0_PAYMENTACTION' =>
'Authorization',
113 'SOLUTIONTYPE' =>
null,
114 'LANDINGPAGE' =>
null,
118 'PAYMENTREQUEST_0_AMT' =>
'10.00',
119 'PAYMENTREQUEST_0_CURRENCYCODE' =>
'AUD',
120 'PAYMENTREQUEST_0_INVNUM' =>
'111',
121 'PAYMENTREQUEST_0_DESC' =>
'Order Description',
122 'RETURNURL' =>
'https://www.example.com/return',
123 'CANCELURL' =>
'https://www.example.com/cancel',
124 'SUBJECT' =>
'demo@example.com',
125 'HDRIMG' =>
'https://www.example.com/header.jpg',
126 'PAYMENTREQUEST_0_SHIPTONAME' =>
'John Doe',
127 'PAYMENTREQUEST_0_SHIPTOSTREET' =>
'123 NW Blvd',
128 'PAYMENTREQUEST_0_SHIPTOSTREET2' =>
'Lynx Lane',
129 'PAYMENTREQUEST_0_SHIPTOCITY' =>
'Topeka',
130 'PAYMENTREQUEST_0_SHIPTOSTATE' =>
'KS',
131 'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' =>
'USA',
132 'PAYMENTREQUEST_0_SHIPTOZIP' =>
'66605',
133 'PAYMENTREQUEST_0_SHIPTOPHONENUM' =>
'555-555-5555',
134 'EMAIL' =>
'test@email.com',
135 'BRANDNAME' =>
'Dunder Mifflin Paper Company, Inc.',
137 'PAYMENTREQUEST_0_TAXAMT' =>
null,
138 'PAYMENTREQUEST_0_SHIPPINGAMT' =>
null,
139 'PAYMENTREQUEST_0_HANDLINGAMT' =>
null,
140 'PAYMENTREQUEST_0_SHIPDISCAMT' =>
null,
141 'PAYMENTREQUEST_0_INSURANCEAMT' =>
null,
142 'LOGOIMG' =>
'https://www.example.com/logo.jpg',
143 'CARTBORDERCOLOR' =>
'CCCCCC',
144 'LOCALECODE' =>
'EN',
145 'CUSTOMERSERVICENUMBER' =>
'1-801-FLOWERS',
146 'PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID' =>
'billing@example.com',
149 $this->assertEquals($expected, $this->request->getData());
154 $this->request->setItems(array(
155 array(
'name' =>
'Floppy Disk',
'description' =>
'MS-DOS',
'quantity' => 2,
'price' => 10,
'code' =>
'123456'),
156 array(
'name' =>
'CD-ROM',
'description' =>
'Windows 95',
'quantity' => 1,
'price' => 40),
159 $data = $this->request->getData();
160 $this->assertSame(
'Floppy Disk', $data[
'L_PAYMENTREQUEST_0_NAME0']);
161 $this->assertSame(
'MS-DOS', $data[
'L_PAYMENTREQUEST_0_DESC0']);
162 $this->assertSame(2, $data[
'L_PAYMENTREQUEST_0_QTY0']);
163 $this->assertSame(
'10.00', $data[
'L_PAYMENTREQUEST_0_AMT0']);
164 $this->assertSame(
'123456', $data[
'L_PAYMENTREQUEST_0_NUMBER0']);
166 $this->assertSame(
'CD-ROM', $data[
'L_PAYMENTREQUEST_0_NAME1']);
167 $this->assertSame(
'Windows 95', $data[
'L_PAYMENTREQUEST_0_DESC1']);
168 $this->assertSame(1, $data[
'L_PAYMENTREQUEST_0_QTY1']);
169 $this->assertSame(
'40.00', $data[
'L_PAYMENTREQUEST_0_AMT1']);
171 $this->assertSame(
'60.00', $data[
'PAYMENTREQUEST_0_ITEMAMT']);
176 $this->request->initialize(array(
179 'transactionId' =>
'111',
180 'description' =>
'Order Description',
181 'returnUrl' =>
'https://www.example.com/return',
182 'cancelUrl' =>
'https://www.example.com/cancel',
183 'subject' =>
'demo@example.com',
184 'headerImageUrl' =>
'https://www.example.com/header.jpg',
187 'addressOverride' => 0,
188 'brandName' =>
'Dunder Mifflin Paper Company, Inc.',
189 'taxAmount' =>
'2.00',
190 'shippingAmount' =>
'5.00',
191 'handlingAmount' =>
'1.00',
192 'shippingDiscount' =>
'-1.00',
193 'insuranceAmount' =>
'3.00',
196 $data = $this->request->getData();
197 $this->assertSame(
'2.00', $data[
'PAYMENTREQUEST_0_TAXAMT']);
198 $this->assertSame(
'5.00', $data[
'PAYMENTREQUEST_0_SHIPPINGAMT']);
199 $this->assertSame(
'1.00', $data[
'PAYMENTREQUEST_0_HANDLINGAMT']);
200 $this->assertSame(
'-1.00', $data[
'PAYMENTREQUEST_0_SHIPDISCAMT']);
201 $this->assertSame(
'3.00', $data[
'PAYMENTREQUEST_0_INSURANCEAMT']);
206 $this->assertSame($this->request, $this->request->setHeaderImageUrl(
'https://www.example.com/header.jpg'));
207 $this->assertSame(
'https://www.example.com/header.jpg', $this->request->getHeaderImageUrl());
209 $data = $this->request->getData();
210 $this->assertEquals(
'https://www.example.com/header.jpg', $data[
'HDRIMG']);
215 $this->request->setMaxAmount(321.54);
217 $this->assertSame(321.54, $this->request->getMaxAmount());
219 $data = $this->request->getData();
221 $this->assertSame(321.54, $data[
'MAXAMT']);
229 'transactionId' =>
'111',
230 'description' =>
'Order Description',
231 'returnUrl' =>
'https://www.example.com/return',
232 'cancelUrl' =>
'https://www.example.com/cancel',
233 'subject' =>
'demo@example.com',
234 'headerImageUrl' =>
'https://www.example.com/header.jpg',
236 'addressOverride' => 0,
237 'brandName' =>
'Dunder Mifflin Paper Company, Incy.',
240 $shippingOptions = array(
247 $this->request->initialize(array_merge($baseData, array(
248 'callback' =>
'https://www.example.com/calculate-shipping',
249 'shippingOptions' => $shippingOptions,
252 $data = $this->request->getData();
253 $this->assertSame(
'https://www.example.com/calculate-shipping', $data[
'CALLBACK']);
256 $this->assertSame(
'First Class', $data[
'L_SHIPPINGOPTIONNAME0']);
257 $this->assertSame(
'1.20', $data[
'L_SHIPPINGOPTIONAMOUNT0']);
258 $this->assertSame(
'1', $data[
'L_SHIPPINGOPTIONISDEFAULT0']);
259 $this->assertSame(
'1-2 days', $data[
'L_SHIPPINGOPTIONLABEL0']);
261 $this->assertSame(
'Second Class', $data[
'L_SHIPPINGOPTIONNAME1']);
262 $this->assertSame(
'0.70', $data[
'L_SHIPPINGOPTIONAMOUNT1']);
263 $this->assertSame(
'0', $data[
'L_SHIPPINGOPTIONISDEFAULT1']);
264 $this->assertSame(
'3-5 days', $data[
'L_SHIPPINGOPTIONLABEL1']);
266 $this->assertSame(
'International', $data[
'L_SHIPPINGOPTIONNAME2']);
267 $this->assertSame(
'3.50', $data[
'L_SHIPPINGOPTIONAMOUNT2']);
268 $this->assertSame(
'0', $data[
'L_SHIPPINGOPTIONISDEFAULT2']);
271 $this->request->initialize(array_merge($baseData, array(
272 'callback' =>
'https://www.example.com/calculate-shipping',
273 'callbackTimeout' => 10,
274 'shippingOptions' => $shippingOptions,
277 $data = $this->request->getData();
278 $this->assertSame(
'https://www.example.com/calculate-shipping', $data[
'CALLBACK']);
279 $this->assertSame(10, $data[
'CALLBACKTIMEOUT']);
287 'transactionId' =>
'111',
288 'description' =>
'Order Description',
289 'returnUrl' =>
'https://www.example.com/return',
290 'cancelUrl' =>
'https://www.example.com/cancel',
291 'subject' =>
'demo@example.com',
292 'headerImageUrl' =>
'https://www.example.com/header.jpg',
294 'addressOverride' => 0,
295 'brandName' =>
'Dunder Mifflin Paper Company, Incy.',
298 $shippingOptions = array(
305 $this->request->initialize(array_merge($baseData, array(
306 'callback' =>
'https://www.example.com/calculate-shipping',
307 'shippingOptions' => $shippingOptions,
310 $this->expectException(InvalidRequestException::class);
311 $this->expectExceptionMessage(
'One of the supplied shipping options must be set as default');
313 $this->request->getData();
321 $this->request->initialize($baseData);
323 $this->expectException(InvalidRequestException::class);
324 $this->expectExceptionMessage(
'The amount parameter is required');
326 $this->request->getData();
335 $this->request->initialize($baseData);
337 $this->expectException(InvalidRequestException::class);
338 $this->expectExceptionMessage(
'The returnUrl parameter is required');
340 $this->request->getData();
348 'transactionId' =>
'111',
349 'description' =>
'Order Description',
350 'returnUrl' =>
'https://www.example.com/return',
351 'cancelUrl' =>
'https://www.example.com/cancel',
352 'subject' =>
'demo@example.com',
353 'headerImageUrl' =>
'https://www.example.com/header.jpg',
355 'addressOverride' => 0,
356 'brandName' =>
'Dunder Mifflin Paper Company, Incy.',
359 $this->request->initialize(array_merge($baseData, array(
360 'callback' =>
'https://www.example.com/calculate-shipping',
366 $this->expectException(InvalidRequestException::class);
368 $this->request->getData();
374 $this->request->setBillingAgreement($billingAgreement);
376 $data = $this->request->getData();
378 $this->assertSame(
'MerchantInitiatedBillingSingleAgreement', $data[
'L_BILLINGTYPE0']);
379 $this->assertSame(
'Some Stuff', $data[
'L_BILLINGAGREEMENTDESCRIPTION0']);
385 $this->request->setBillingAgreement($billingAgreement);
387 $data = $this->request->getData();
389 $this->assertSame(
'MerchantInitiatedBilling', $data[
'L_BILLINGTYPE0']);
390 $this->assertSame(
'Some Stuff', $data[
'L_BILLINGAGREEMENTDESCRIPTION0']);
395 $billingAgreement =
new BillingAgreement(
true,
'Some Stuff',
'InstantOnly',
'Some custom annotation');
396 $this->request->setBillingAgreement($billingAgreement);
398 $data = $this->request->getData();
400 $this->assertSame(
'MerchantInitiatedBilling', $data[
'L_BILLINGTYPE0']);
401 $this->assertSame(
'Some Stuff', $data[
'L_BILLINGAGREEMENTDESCRIPTION0']);
402 $this->assertSame(
'InstantOnly', $data[
'L_PAYMENTTYPE0']);
403 $this->assertSame(
'Some custom annotation', $data[
'L_BILLINGAGREEMENTCUSTOM0']);
411 $this->expectException(InvalidRequestException::class);
412 $this->expectExceptionMessage(
"The 'paymentType' parameter can be only 'Any' or 'InstantOnly'");
414 $billingAgreement =
new BillingAgreement(
false,
'Some Stuff',
'BadType',
'Some custom annotation');