| @@ 20-103 (lines=84) @@ | ||
| 17 | use Symfony\Component\HttpFoundation\Request as HttpRequest; |
|
| 18 | use Omnipay\Common\Exception\InvalidResponseException; |
|
| 19 | ||
| 20 | class CompletePurchaseResponseTest extends TestCase |
|
| 21 | { |
|
| 22 | /** |
|
| 23 | * @var CompletePurchaseResponseStub |
|
| 24 | */ |
|
| 25 | protected $stub; |
|
| 26 | ||
| 27 | public function setUp() |
|
| 28 | { |
|
| 29 | parent::setUp(); |
|
| 30 | ||
| 31 | $this->stub = new CompletePurchaseResponseStub(); |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * @param array $options |
|
| 36 | * @return CompletePurchaseRequest |
|
| 37 | */ |
|
| 38 | public function createRequest($options = []) |
|
| 39 | { |
|
| 40 | $stub = $this->stub; |
|
| 41 | ||
| 42 | $httpRequest = new HttpRequest([], array_merge([ |
|
| 43 | 'ik_co_id' => $stub->purse, |
|
| 44 | 'ik_pm_no' => $stub->payment_no, |
|
| 45 | 'ik_desc' => $stub->description, |
|
| 46 | 'ik_pw_via' => $stub->payway, |
|
| 47 | 'ik_am' => $stub->amount, |
|
| 48 | 'ik_cur' => $stub->currency, |
|
| 49 | 'ik_inv_id' => $stub->transactionId, |
|
| 50 | 'ik_inv_st' => $stub->state, |
|
| 51 | 'ik_inv_prc' => $stub->time, |
|
| 52 | 'ik_sign' => $stub->sign, |
|
| 53 | ], $options)); |
|
| 54 | ||
| 55 | $request = new CompletePurchaseRequest($this->getHttpClient(), $httpRequest); |
|
| 56 | $request->initialize([ |
|
| 57 | 'checkoutId' => $stub->purse, |
|
| 58 | 'signAlgorithm' => $stub->signAlgorithm, |
|
| 59 | 'signKey' => $stub->signKey, |
|
| 60 | ]); |
|
| 61 | ||
| 62 | return $request; |
|
| 63 | } |
|
| 64 | ||
| 65 | public function testSignException() |
|
| 66 | { |
|
| 67 | $this->expectException(InvalidResponseException::class); |
|
| 68 | $this->expectExceptionMessage('Failed to validate signature'); |
|
| 69 | $this->createRequest([ |
|
| 70 | 'ik_co_id' => $this->stub->purse, |
|
| 71 | 'ik_wtf' => ':)', |
|
| 72 | ])->send(); |
|
| 73 | } |
|
| 74 | ||
| 75 | public function testStateException() |
|
| 76 | { |
|
| 77 | $this->expectException(InvalidResponseException::class); |
|
| 78 | $this->expectExceptionMessage('The payment was not success'); |
|
| 79 | $this->createRequest([ |
|
| 80 | 'ik_co_id' => $this->stub->purse, |
|
| 81 | 'ik_inv_st' => 'fail', |
|
| 82 | 'ik_sign' => 'ElWhUp/CjjSXF0ZjNIKbOk+WjpQ9/KIeowD0TjTshw0=', |
|
| 83 | ])->send(); |
|
| 84 | } |
|
| 85 | ||
| 86 | public function testSuccess() |
|
| 87 | { |
|
| 88 | /** @var CompletePurchaseResponse $response */ |
|
| 89 | $response = $this->createRequest()->send(); |
|
| 90 | $stub = $this->stub; |
|
| 91 | ||
| 92 | $this->assertTrue($response->isSuccessful()); |
|
| 93 | $this->assertSame($stub->purse, $response->getCheckoutId()); |
|
| 94 | $this->assertSame($stub->payment_no, $response->getTransactionId()); |
|
| 95 | $this->assertSame($stub->transactionId, $response->getTransactionReference()); |
|
| 96 | $this->assertSame($stub->amount, $response->getAmount()); |
|
| 97 | $this->assertSame($stub->currency, $response->getCurrency()); |
|
| 98 | $this->assertSame(strtotime($stub->time) - 3 * 60 * 60, strtotime($response->getTime())); |
|
| 99 | $this->assertSame($stub->payway, $response->getPayer()); |
|
| 100 | $this->assertSame($stub->state, $response->getState()); |
|
| 101 | $this->assertSame($stub->sign, $response->getSign()); |
|
| 102 | } |
|
| 103 | } |
|
| 104 | ||
| @@ 19-101 (lines=83) @@ | ||
| 16 | use Symfony\Component\HttpFoundation\Request as HttpRequest; |
|
| 17 | use Omnipay\Common\Exception\InvalidResponseException; |
|
| 18 | ||
| 19 | class OldCompletePurchaseResponseTest extends CompletePurchaseResponseTest |
|
| 20 | { |
|
| 21 | /** |
|
| 22 | * @var OldCompletePurchaseResponseStub |
|
| 23 | */ |
|
| 24 | protected $stub; |
|
| 25 | ||
| 26 | public function setUp() |
|
| 27 | { |
|
| 28 | parent::setUp(); |
|
| 29 | ||
| 30 | $this->stub = new OldCompletePurchaseResponseStub(); |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * @param array $options |
|
| 35 | * @return OldCompletePurchaseRequest |
|
| 36 | */ |
|
| 37 | public function createRequest($options = []) |
|
| 38 | { |
|
| 39 | $stub = $this->stub; |
|
| 40 | ||
| 41 | $httpRequest = new HttpRequest([], array_merge([ |
|
| 42 | 'ik_shop_id' => $stub->purse, |
|
| 43 | 'ik_payment_id' => $stub->payment_no, |
|
| 44 | 'ik_payment_desc' => $stub->description, |
|
| 45 | 'ik_payment_amount' => $stub->amount, |
|
| 46 | 'ik_payment_timestamp' => $stub->time, |
|
| 47 | 'ik_sign_hash' => $stub->sign, |
|
| 48 | 'ik_payment_state' => $stub->state, |
|
| 49 | 'ik_trans_id' => $stub->transactionId, |
|
| 50 | 'ik_paysystem_alias' => $stub->payway, |
|
| 51 | ], $options)); |
|
| 52 | ||
| 53 | $request = new OldCompletePurchaseRequest($this->getHttpClient(), $httpRequest); |
|
| 54 | $request->initialize([ |
|
| 55 | 'checkoutId' => $stub->purse, |
|
| 56 | 'signAlgorithm' => $stub->signAlgorithm, |
|
| 57 | 'signKey' => $stub->signKey, |
|
| 58 | ]); |
|
| 59 | ||
| 60 | return $request; |
|
| 61 | } |
|
| 62 | ||
| 63 | public function testSignException() |
|
| 64 | { |
|
| 65 | $this->expectException(InvalidResponseException::class); |
|
| 66 | $this->expectExceptionMessage('Failed to validate signature'); |
|
| 67 | $this->createRequest([ |
|
| 68 | 'ik_shop_id' => $this->stub->purse, |
|
| 69 | 'ik_wtf' => ':)', |
|
| 70 | ])->send(); |
|
| 71 | } |
|
| 72 | ||
| 73 | public function testStateException() |
|
| 74 | { |
|
| 75 | $this->expectException(InvalidResponseException::class); |
|
| 76 | $this->expectExceptionMessage('The payment was not success'); |
|
| 77 | $this->createRequest([ |
|
| 78 | 'ik_shop_id' => $this->stub->purse, |
|
| 79 | 'ik_payment_state' => 'fail', |
|
| 80 | 'ik_sign_hash' => 'IL/KyMotmW5XeL2g86kYGlVJXOYTO+HAsuSzudI0qHE=', |
|
| 81 | ])->send(); |
|
| 82 | } |
|
| 83 | ||
| 84 | public function testSuccess() |
|
| 85 | { |
|
| 86 | /** @var OldCompletePurchaseResponse $response */ |
|
| 87 | $response = $this->createRequest()->send(); |
|
| 88 | $stub = $this->stub; |
|
| 89 | ||
| 90 | $this->assertTrue($response->isSuccessful()); |
|
| 91 | $this->assertSame($stub->purse, $response->getCheckoutId()); |
|
| 92 | $this->assertSame($stub->payment_no, $response->getTransactionId()); |
|
| 93 | $this->assertSame($stub->transactionId, $response->getTransactionReference()); |
|
| 94 | $this->assertSame($stub->amount, $response->getAmount()); |
|
| 95 | $this->assertSame($stub->currency, $response->getCurrency()); |
|
| 96 | $this->assertSame(strtotime($stub->time) - 3 * 60 * 60, strtotime($response->getTime())); |
|
| 97 | $this->assertSame($stub->payway, $response->getPayer()); |
|
| 98 | $this->assertSame($stub->state, $response->getState()); |
|
| 99 | $this->assertSame($stub->sign, $response->getSign()); |
|
| 100 | } |
|
| 101 | } |
|
| 102 | ||