| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * InterKassa driver for the Omnipay PHP payment processing library | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @link      https://github.com/hiqdev/omnipay-interkassa | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @package   omnipay-interkassa | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @license   MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | namespace Omnipay\InterKassa\Tests\Message; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Omnipay\InterKassa\Message\CompletePurchaseRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Omnipay\InterKassa\Message\CompletePurchaseResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Omnipay\InterKassa\Stubs\CompletePurchaseResponseStub; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Omnipay\Tests\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Symfony\Component\HttpFoundation\Request as HttpRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Omnipay\Common\Exception\InvalidResponseException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 20 |  | View Code Duplication | 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 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.