|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Omnipay\Postfinance\Message; |
| 4 | + |
| 5 | +use Omnipay\Common\CreditCard; |
| 6 | +use Omnipay\Tests\TestCase; |
| 7 | + |
| 8 | +class PurchaseRequestTest extends TestCase |
| 9 | +{ |
| 10 | + /** |
| 11 | + * @var PurchaseRequest |
| 12 | + */ |
| 13 | + private $request; |
| 14 | + |
| 15 | + public function setUp() |
| 16 | + { |
| 17 | + parent::setUp(); |
| 18 | + |
| 19 | + $this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); |
| 20 | + } |
| 21 | + |
| 22 | + public function testGetDataWithoutCard() |
| 23 | + { |
| 24 | + $this->request->initialize(array( |
| 25 | + 'pspId' => 'testPspId', |
| 26 | + 'language' => 'en_US', |
| 27 | + 'shaIn' => 'MyShaInSecret', |
| 28 | + 'amount' => '12.00', |
| 29 | + 'currency' => 'CHF', |
| 30 | + 'transactionId' => '123', |
| 31 | + 'description' => 'Order Description', |
| 32 | + 'returnUrl' => 'https://www.example.com/return', |
| 33 | + 'cancelUrl' => 'https://www.example.com/cancel', |
| 34 | + 'title' => 'My shop title' |
| 35 | + )); |
| 36 | + |
| 37 | + $expected = array( |
| 38 | + 'PSPID' => 'testPspId', |
| 39 | + 'LANGUAGE' => 'en_US', |
| 40 | + // Currency has to be converted to integer, so 12.00 becomes 1200 |
| 41 | + 'AMOUNT' => 1200, |
| 42 | + 'CURRENCY' => 'CHF', |
| 43 | + // transactionId maps to ORDERID |
| 44 | + 'ORDERID' => '123', |
| 45 | + // description maps to COM |
| 46 | + 'COM' => 'Order Description', |
| 47 | + 'ACCEPTURL' => 'https://www.example.com/return', |
| 48 | + 'CANCELURL' => 'https://www.example.com/cancel', |
| 49 | + 'EXCEPTIONURL' => null, |
| 50 | + 'DECLINEURL' => null, |
| 51 | + 'OPERATION' => null, |
| 52 | + 'TITLE' => 'My shop title' |
| 53 | + ); |
| 54 | + |
| 55 | + $this->assertEquals($expected, $this->request->getData()); |
| 56 | + } |
| 57 | + |
| 58 | + public function testGetDataWithCard() |
| 59 | + { |
| 60 | + $this->request->initialize(array( |
| 61 | + 'pspId' => 'testPspId', |
| 62 | + 'language' => 'en_US', |
| 63 | + 'shaIn' => 'MyShaInSecret', |
| 64 | + 'amount' => '12.00', |
| 65 | + 'currency' => 'CHF', |
| 66 | + 'transactionId' => '123', |
| 67 | + 'description' => 'Order Description', |
| 68 | + 'returnUrl' => 'https://www.example.com/return', |
| 69 | + 'cancelUrl' => 'https://www.example.com/cancel' |
| 70 | + )); |
| 71 | + |
| 72 | + $card = new CreditCard(array( |
| 73 | + 'name' => 'Hans Muster', |
| 74 | + 'address1' => 'Teststrasse 123', |
| 75 | + 'address2' => 'Postfach 321', |
| 76 | + 'city' => 'Bern', |
| 77 | + 'country' => 'CH', |
| 78 | + 'postcode' => '3000', |
| 79 | + 'phone' => '098 765 43 21', |
| 80 | + 'email' => 'test@test.ch', |
| 81 | + )); |
| 82 | + $this->request->setCard($card); |
| 83 | + |
| 84 | + $expected = array( |
| 85 | + 'PSPID' => 'testPspId', |
| 86 | + 'LANGUAGE' => 'en_US', |
| 87 | + // Currency has to be converted to integer, so 12.00 becomes 1200 |
| 88 | + 'AMOUNT' => 1200, |
| 89 | + 'CURRENCY' => 'CHF', |
| 90 | + // transactionId maps to ORDERID |
| 91 | + 'ORDERID' => '123', |
| 92 | + // description maps to COM |
| 93 | + 'COM' => 'Order Description', |
| 94 | + 'ACCEPTURL' => 'https://www.example.com/return', |
| 95 | + 'CANCELURL' => 'https://www.example.com/cancel', |
| 96 | + 'EXCEPTIONURL' => null, |
| 97 | + 'DECLINEURL' => null, |
| 98 | + 'OPERATION' => null, |
| 99 | + |
| 100 | + // Credit card data |
| 101 | + 'CN' => 'Hans Muster', |
| 102 | + 'EMAIL' => 'test@test.ch', |
| 103 | + 'OWNERADDRESS' => 'Teststrasse 123 / Postfach 321', |
| 104 | + 'OWNERZIP' => '3000', |
| 105 | + 'OWNERTOWN' => 'Bern', |
| 106 | + 'OWNERCTY' => 'CH', |
| 107 | + 'OWNERTELNO' => '098 765 43 21' |
| 108 | + ); |
| 109 | + |
| 110 | + $this->assertEquals($expected, $this->request->getData()); |
| 111 | + } |
| 112 | + |
| 113 | +} |
0 commit comments