|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* InterKassa driver for the Omnipay PHP payment processing library |
|
5
|
|
|
* |
|
6
|
|
|
* @link https://github.com/hiqdev/omnipay-interkassa |
|
7
|
|
|
* @package omnipay-interkassa |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Omnipay\InterKassa\Tests\Message; |
|
13
|
|
|
|
|
14
|
|
|
use Omnipay\InterKassa\Message\CompletePurchaseRequest; |
|
15
|
|
|
use Omnipay\InterKassa\Message\CompletePurchaseResponse; |
|
16
|
|
|
use Omnipay\Tests\TestCase; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Request as HttpRequest; |
|
18
|
|
|
|
|
19
|
|
|
class CompletePurchaseResponseTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
protected $purse = '887ac1234c1eeee1488b156b'; |
|
22
|
|
|
protected $secret = 'Zp2zfdSJzbS61L32'; |
|
23
|
|
|
protected $payment_no = '1235151'; |
|
24
|
|
|
protected $description = 'Test Transaction long description'; |
|
25
|
|
|
protected $payway = 'visa_liqpay_merchant_usd'; |
|
26
|
|
|
protected $invoiceId = '5632156'; |
|
27
|
|
|
protected $transactionId = 'ID_123456'; |
|
28
|
|
|
protected $amount = '5.12'; |
|
29
|
|
|
protected $currency = 'USD'; |
|
30
|
|
|
protected $state = 'success'; |
|
31
|
|
|
protected $sign = '3Ra3gDluuAKUoGddlJTfrTJrQpjQHqbAbkUKB5k11y0='; |
|
32
|
|
|
protected $time = '2015-12-17 17:36:13'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param array $options |
|
36
|
|
|
* @return CompletePurchaseRequest |
|
37
|
|
|
*/ |
|
38
|
|
|
public function createRequest($options = []) |
|
39
|
|
|
{ |
|
40
|
|
|
$httpRequest = new HttpRequest([], array_merge([ |
|
41
|
|
|
'ik_co_id' => $this->purse, |
|
42
|
|
|
'ik_pm_no' => $this->payment_no, |
|
43
|
|
|
'ik_desc' => $this->description, |
|
44
|
|
|
'ik_pw_via' => $this->payway, |
|
45
|
|
|
'ik_am' => $this->amount, |
|
46
|
|
|
'ik_cur' => $this->currency, |
|
47
|
|
|
'ik_inv_id' => $this->invoiceId, |
|
48
|
|
|
'ik_trn_id' => $this->transactionId, |
|
49
|
|
|
'ik_inv_st' => $this->state, |
|
50
|
|
|
'ik_inv_prc' => $this->time, |
|
51
|
|
|
'ik_sign' => $this->sign, |
|
52
|
|
|
], $options)); |
|
53
|
|
|
|
|
54
|
|
|
$request = new CompletePurchaseRequest($this->getHttpClient(), $httpRequest); |
|
55
|
|
|
$request->initialize([ |
|
56
|
|
|
'secret' => $this->secret, |
|
57
|
|
|
]); |
|
58
|
|
|
|
|
59
|
|
|
return $request; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testSignException() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'Failed to validate signature'); |
|
65
|
|
|
$this->createRequest(['ik_wtf' => ':)'])->send(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testStateException() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'The payment was not success'); |
|
71
|
|
|
$this->createRequest(['ik_inv_st' => 'fail', 'ik_sign' => 'iVRccLMwsoTVEgXMMn+flZAus3dgIGgvB6orib5fAKk='])->send(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testSuccess() |
|
75
|
|
|
{ |
|
76
|
|
|
/** @var CompletePurchaseResponse $response */ |
|
77
|
|
|
$response = $this->createRequest()->send(); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertTrue($response->isSuccessful()); |
|
80
|
|
|
$this->assertSame($this->purse, $response->getCheckoutId()); |
|
81
|
|
|
$this->assertSame($this->invoiceId, $response->getTransactionId()); |
|
82
|
|
|
$this->assertSame($this->transactionId, $response->getTransactionReference()); |
|
83
|
|
|
$this->assertSame($this->amount, $response->getAmount()); |
|
84
|
|
|
$this->assertSame($this->currency, $response->getCurrency()); |
|
85
|
|
|
$this->assertSame(strtotime($this->time . ' Europe/Moscow'), $response->getTime()); |
|
86
|
|
|
$this->assertSame($this->payway, $response->getPayer()); |
|
87
|
|
|
$this->assertSame($this->state, $response->getState()); |
|
88
|
|
|
$this->assertSame($this->sign, $response->getSign()); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|