|
3 | 3 | namespace Omnipay\PayPal\Message;
|
4 | 4 |
|
5 | 5 | use Omnipay\Common\CreditCard;
|
| 6 | +use Omnipay\PayPal\Support\InstantUpdateApi\ShippingOption; |
6 | 7 | use Omnipay\Tests\TestCase;
|
7 | 8 |
|
8 | 9 | class ExpressAuthorizeRequestTest extends TestCase
|
@@ -215,4 +216,158 @@ public function testMaxAmount()
|
215 | 216 |
|
216 | 217 | $this->assertSame(321.54, $data['MAXAMT']);
|
217 | 218 | }
|
| 219 | + |
| 220 | + public function testDataWithCallback() |
| 221 | + { |
| 222 | + $baseData = array( |
| 223 | + 'amount' => '10.00', |
| 224 | + 'currency' => 'AUD', |
| 225 | + 'transactionId' => '111', |
| 226 | + 'description' => 'Order Description', |
| 227 | + 'returnUrl' => 'https://www.example.com/return', |
| 228 | + 'cancelUrl' => 'https://www.example.com/cancel', |
| 229 | + |
| 230 | + 'headerImageUrl' => 'https://www.example.com/header.jpg', |
| 231 | + 'allowNote' => 0, |
| 232 | + 'addressOverride' => 0, |
| 233 | + 'brandName' => 'Dunder Mifflin Paper Company, Incy.', |
| 234 | + ); |
| 235 | + |
| 236 | + $shippingOptions = array( |
| 237 | + new ShippingOption('First Class', 1.20, true, '1-2 days'), |
| 238 | + new ShippingOption('Second Class', 0.70, false, '3-5 days'), |
| 239 | + new ShippingOption('International', 3.50), |
| 240 | + ); |
| 241 | + |
| 242 | + // with a default callback timeout |
| 243 | + $this->request->initialize(array_merge($baseData, array( |
| 244 | + 'callback' => 'https://www.example.com/calculate-shipping', |
| 245 | + 'shippingOptions' => $shippingOptions, |
| 246 | + ))); |
| 247 | + |
| 248 | + $data = $this->request->getData(); |
| 249 | + $this->assertSame('https://www.example.com/calculate-shipping', $data['CALLBACK']); |
| 250 | + $this->assertSame(ExpressAuthorizeRequest::DEFAULT_CALLBACK_TIMEOUT, $data['CALLBACKTIMEOUT']); |
| 251 | + |
| 252 | + $this->assertSame('First Class', $data['L_SHIPPINGOPTIONNAME0']); |
| 253 | + $this->assertSame('1.20', $data['L_SHIPPINGOPTIONAMOUNT0']); |
| 254 | + $this->assertSame('1', $data['L_SHIPPINGOPTIONISDEFAULT0']); |
| 255 | + $this->assertSame('1-2 days', $data['L_SHIPPINGOPTIONLABEL0']); |
| 256 | + |
| 257 | + $this->assertSame('Second Class', $data['L_SHIPPINGOPTIONNAME1']); |
| 258 | + $this->assertSame('0.70', $data['L_SHIPPINGOPTIONAMOUNT1']); |
| 259 | + $this->assertSame('0', $data['L_SHIPPINGOPTIONISDEFAULT1']); |
| 260 | + $this->assertSame('3-5 days', $data['L_SHIPPINGOPTIONLABEL1']); |
| 261 | + |
| 262 | + $this->assertSame('International', $data['L_SHIPPINGOPTIONNAME2']); |
| 263 | + $this->assertSame('3.50', $data['L_SHIPPINGOPTIONAMOUNT2']); |
| 264 | + $this->assertSame('0', $data['L_SHIPPINGOPTIONISDEFAULT2']); |
| 265 | + |
| 266 | + // with a defined callback timeout |
| 267 | + $this->request->initialize(array_merge($baseData, array( |
| 268 | + 'callback' => 'https://www.example.com/calculate-shipping', |
| 269 | + 'callbackTimeout' => 10, |
| 270 | + 'shippingOptions' => $shippingOptions, |
| 271 | + ))); |
| 272 | + |
| 273 | + $data = $this->request->getData(); |
| 274 | + $this->assertSame('https://www.example.com/calculate-shipping', $data['CALLBACK']); |
| 275 | + $this->assertSame(10, $data['CALLBACKTIMEOUT']); |
| 276 | + } |
| 277 | + |
| 278 | + public function testDataWithCallbackAndNoDefaultShippingOption() |
| 279 | + { |
| 280 | + $baseData = array( |
| 281 | + 'amount' => '10.00', |
| 282 | + 'currency' => 'AUD', |
| 283 | + 'transactionId' => '111', |
| 284 | + 'description' => 'Order Description', |
| 285 | + 'returnUrl' => 'https://www.example.com/return', |
| 286 | + 'cancelUrl' => 'https://www.example.com/cancel', |
| 287 | + |
| 288 | + 'headerImageUrl' => 'https://www.example.com/header.jpg', |
| 289 | + 'allowNote' => 0, |
| 290 | + 'addressOverride' => 0, |
| 291 | + 'brandName' => 'Dunder Mifflin Paper Company, Incy.', |
| 292 | + ); |
| 293 | + |
| 294 | + $shippingOptions = array( |
| 295 | + new ShippingOption('First Class', 1.20, false, '1-2 days'), |
| 296 | + new ShippingOption('Second Class', 0.70, false, '3-5 days'), |
| 297 | + new ShippingOption('International', 3.50), |
| 298 | + ); |
| 299 | + |
| 300 | + // with a default callback timeout |
| 301 | + $this->request->initialize(array_merge($baseData, array( |
| 302 | + 'callback' => 'https://www.example.com/calculate-shipping', |
| 303 | + 'shippingOptions' => $shippingOptions, |
| 304 | + ))); |
| 305 | + |
| 306 | + $this->setExpectedException( |
| 307 | + '\Omnipay\Common\Exception\InvalidRequestException', |
| 308 | + 'One of the supplied shipping options must be set as default' |
| 309 | + ); |
| 310 | + |
| 311 | + $this->request->getData(); |
| 312 | + } |
| 313 | + |
| 314 | + public function testNoAmount() |
| 315 | + { |
| 316 | + $baseData = array(// nothing here - should cause a certain exception |
| 317 | + ); |
| 318 | + |
| 319 | + $this->request->initialize($baseData); |
| 320 | + |
| 321 | + $this->setExpectedException( |
| 322 | + '\Omnipay\Common\Exception\InvalidRequestException', |
| 323 | + 'The amount parameter is required' |
| 324 | + ); |
| 325 | + |
| 326 | + $this->request->getData(); |
| 327 | + } |
| 328 | + |
| 329 | + public function testAmountButNoReturnUrl() |
| 330 | + { |
| 331 | + $baseData = array( |
| 332 | + 'amount' => 10.00, |
| 333 | + ); |
| 334 | + |
| 335 | + $this->request->initialize($baseData); |
| 336 | + |
| 337 | + $this->setExpectedException( |
| 338 | + '\Omnipay\Common\Exception\InvalidRequestException', |
| 339 | + 'The returnUrl parameter is required' |
| 340 | + ); |
| 341 | + |
| 342 | + $this->request->getData(); |
| 343 | + } |
| 344 | + |
| 345 | + public function testBadCallbackConfiguration() |
| 346 | + { |
| 347 | + $baseData = array( |
| 348 | + 'amount' => '10.00', |
| 349 | + 'currency' => 'AUD', |
| 350 | + 'transactionId' => '111', |
| 351 | + 'description' => 'Order Description', |
| 352 | + 'returnUrl' => 'https://www.example.com/return', |
| 353 | + 'cancelUrl' => 'https://www.example.com/cancel', |
| 354 | + |
| 355 | + 'headerImageUrl' => 'https://www.example.com/header.jpg', |
| 356 | + 'allowNote' => 0, |
| 357 | + 'addressOverride' => 0, |
| 358 | + 'brandName' => 'Dunder Mifflin Paper Company, Incy.', |
| 359 | + ); |
| 360 | + |
| 361 | + $this->request->initialize(array_merge($baseData, array( |
| 362 | + 'callback' => 'https://www.example.com/calculate-shipping', |
| 363 | + ))); |
| 364 | + |
| 365 | + // from the docblock on this exception - |
| 366 | + // Thrown when a request is invalid or missing required fields. |
| 367 | + // callback has been set but no shipping options so expect one of these: |
| 368 | + $this->setExpectedException('\Omnipay\Common\Exception\InvalidRequestException'); |
| 369 | + |
| 370 | + $this->request->getData(); |
| 371 | + } |
| 372 | + |
218 | 373 | }
|
0 commit comments