| @@ 20-93 (lines=74) @@ | ||
| 17 | use Omnipay\Tests\TestCase; |
|
| 18 | use Symfony\Component\HttpFoundation\Request as HttpRequest; |
|
| 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 | 'signAlgorithm' => $stub->signAlgorithm, |
|
| 58 | 'signKey' => $stub->signKey, |
|
| 59 | ]); |
|
| 60 | ||
| 61 | return $request; |
|
| 62 | } |
|
| 63 | ||
| 64 | public function testSignException() |
|
| 65 | { |
|
| 66 | $this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'Failed to validate signature'); |
|
| 67 | $this->createRequest(['ik_wtf' => ':)'])->send(); |
|
| 68 | } |
|
| 69 | ||
| 70 | public function testStateException() |
|
| 71 | { |
|
| 72 | $this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'The payment was not success'); |
|
| 73 | $this->createRequest(['ik_inv_st' => 'fail', 'ik_sign' => 'ElWhUp/CjjSXF0ZjNIKbOk+WjpQ9/KIeowD0TjTshw0='])->send(); |
|
| 74 | } |
|
| 75 | ||
| 76 | public function testSuccess() |
|
| 77 | { |
|
| 78 | /** @var CompletePurchaseResponse $response */ |
|
| 79 | $response = $this->createRequest()->send(); |
|
| 80 | $stub = $this->stub; |
|
| 81 | ||
| 82 | $this->assertTrue($response->isSuccessful()); |
|
| 83 | $this->assertSame($stub->purse, $response->getCheckoutId()); |
|
| 84 | $this->assertSame($stub->payment_no, $response->getTransactionId()); |
|
| 85 | $this->assertSame($stub->transactionId, $response->getTransactionReference()); |
|
| 86 | $this->assertSame($stub->amount, $response->getAmount()); |
|
| 87 | $this->assertSame($stub->currency, $response->getCurrency()); |
|
| 88 | $this->assertSame($stub->timestamp, $response->getTime()); |
|
| 89 | $this->assertSame($stub->payway, $response->getPayer()); |
|
| 90 | $this->assertSame($stub->state, $response->getState()); |
|
| 91 | $this->assertSame($stub->sign, $response->getSign()); |
|
| 92 | } |
|
| 93 | } |
|
| 94 | ||
| @@ 19-92 (lines=74) @@ | ||
| 16 | use Omnipay\InterKassa\Stubs\OldCompletePurchaseResponseStub; |
|
| 17 | use Symfony\Component\HttpFoundation\Request as HttpRequest; |
|
| 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 | ||
| 52 | ], $options)); |
|
| 53 | ||
| 54 | $request = new OldCompletePurchaseRequest($this->getHttpClient(), $httpRequest); |
|
| 55 | $request->initialize([ |
|
| 56 | 'signAlgorithm' => $stub->signAlgorithm, |
|
| 57 | 'signKey' => $stub->signKey, |
|
| 58 | ]); |
|
| 59 | ||
| 60 | return $request; |
|
| 61 | } |
|
| 62 | ||
| 63 | public function testSignException() |
|
| 64 | { |
|
| 65 | $this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'Failed to validate signature'); |
|
| 66 | $this->createRequest(['ik_wtf' => ':)'])->send(); |
|
| 67 | } |
|
| 68 | ||
| 69 | public function testStateException() |
|
| 70 | { |
|
| 71 | $this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'The payment was not success'); |
|
| 72 | $this->createRequest(['ik_payment_state' => 'fail', 'ik_sign_hash' => 'IL/KyMotmW5XeL2g86kYGlVJXOYTO+HAsuSzudI0qHE='])->send(); |
|
| 73 | } |
|
| 74 | ||
| 75 | public function testSuccess() |
|
| 76 | { |
|
| 77 | /** @var OldCompletePurchaseResponse $response */ |
|
| 78 | $response = $this->createRequest()->send(); |
|
| 79 | $stub = $this->stub; |
|
| 80 | ||
| 81 | $this->assertTrue($response->isSuccessful()); |
|
| 82 | $this->assertSame($stub->purse, $response->getCheckoutId()); |
|
| 83 | $this->assertSame($stub->payment_no, $response->getTransactionId()); |
|
| 84 | $this->assertSame($stub->transactionId, $response->getTransactionReference()); |
|
| 85 | $this->assertSame($stub->amount, $response->getAmount()); |
|
| 86 | $this->assertSame($stub->currency, $response->getCurrency()); |
|
| 87 | $this->assertSame($stub->timestamp, $response->getTime()); |
|
| 88 | $this->assertSame($stub->payway, $response->getPayer()); |
|
| 89 | $this->assertSame($stub->state, $response->getState()); |
|
| 90 | $this->assertSame($stub->sign, $response->getSign()); |
|
| 91 | } |
|
| 92 | } |
|
| 93 | ||