1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/yiiviet/yii2-payment |
4
|
|
|
* @copyright Copyright (c) 2017 Yii2VN |
5
|
|
|
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php) |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace yiiviet\tests\unit\payment; |
9
|
|
|
|
10
|
|
|
use Yii; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class BaoKimTest |
14
|
|
|
* |
15
|
|
|
* @author Vuong Minh <[email protected]> |
16
|
|
|
* @since 1.0 |
17
|
|
|
*/ |
18
|
|
|
class BaoKimTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var \yiiviet\payment\baokim\PaymentGateway |
22
|
|
|
*/ |
23
|
|
|
public $gateway; |
24
|
|
|
|
25
|
|
|
public static function gatewayId(): string |
26
|
|
|
{ |
27
|
|
|
return 'BK'; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @expectedException \yii\base\InvalidConfigException |
32
|
|
|
* @expectedExceptionMessage cannot be blank |
33
|
|
|
*/ |
34
|
|
|
public function testPurchase() |
35
|
|
|
{ |
36
|
|
|
// valid |
37
|
|
|
$responseData = $this->purchase([ |
38
|
|
|
'order_id' => 2, |
39
|
|
|
'total_amount' => 500000, |
40
|
|
|
'url_success' => '/' |
41
|
|
|
]); |
42
|
|
|
|
43
|
|
|
$this->assertTrue($responseData->getIsOk()); |
44
|
|
|
$this->assertTrue(isset($responseData['redirect_url'])); |
45
|
|
|
|
46
|
|
|
// throws |
47
|
|
|
$this->purchase([ |
48
|
|
|
'order_id' => 1, |
49
|
|
|
'url_success' => '/' |
50
|
|
|
]); |
51
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @expectedException \yii\base\InvalidConfigException |
56
|
|
|
* @expectedExceptionMessage cannot be blank |
57
|
|
|
*/ |
58
|
|
|
public function testPurchasePro() |
59
|
|
|
{ |
60
|
|
|
$this->gateway->pro = true; |
61
|
|
|
// Valid |
62
|
|
|
$responseData = $this->purchase([ |
63
|
|
|
'bank_payment_method_id' => '128', |
64
|
|
|
'payer_name' => 'vxm', |
65
|
|
|
'payer_email' => '[email protected]', |
66
|
|
|
'payer_phone_no' => '0909113911', |
67
|
|
|
'order_id' => microtime(), |
68
|
|
|
'total_amount' => 500000, |
69
|
|
|
'url_success' => '/', |
70
|
|
|
]); |
71
|
|
|
$this->assertTrue($responseData->next_action === 'redirect'); |
72
|
|
|
|
73
|
|
|
// Throws |
74
|
|
|
$this->purchase([ |
75
|
|
|
'bank_payment_method_id' => '128', |
76
|
|
|
'payer_name' => 'vxm', |
77
|
|
|
'payer_email' => '[email protected]', |
78
|
|
|
'payer_phone_no' => '0909113911', |
79
|
|
|
'order_id' => time(), |
80
|
|
|
'url_success' => '/', |
81
|
|
|
]); |
82
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @expectedException \yii\base\InvalidConfigException |
87
|
|
|
* @expectedExceptionMessage cannot be blank |
88
|
|
|
*/ |
89
|
|
|
public function testQueryDR() |
90
|
|
|
{ |
91
|
|
|
// Valid |
92
|
|
|
$responseData = $this->queryDR(['transaction_id' => 1]); |
93
|
|
|
$this->assertTrue($responseData->getIsOk()); |
94
|
|
|
|
95
|
|
|
// Throws |
96
|
|
|
$this->queryDR([]); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testGetMerchantData() |
100
|
|
|
{ |
101
|
|
|
$merchantData = $this->gateway->getMerchantData(); |
102
|
|
|
$this->assertTrue(isset($merchantData['bank_payment_methods'], $merchantData['seller_account'])); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
View Code Duplication |
public function testVerifyRequestIPN() |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
$_POST = [ |
108
|
|
|
'business' => '[email protected]', |
109
|
|
|
'order_id' => 2, |
110
|
|
|
'total_amount' => 500000, |
111
|
|
|
'checksum' => 'c96f01e3fdb4ba665304e70c04d58ba8917f31fe', |
112
|
|
|
'merchant_id' => 647, |
113
|
|
|
'url_success' => '/' |
114
|
|
|
]; |
115
|
|
|
$responseData = $this->verifyRequestIPN(); |
116
|
|
|
$this->assertFalse($responseData); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
View Code Duplication |
public function testVerifyRequestPurchaseSuccess() |
|
|
|
|
120
|
|
|
{ |
121
|
|
|
$_GET = [ |
122
|
|
|
'business' => '[email protected]', |
123
|
|
|
'order_id' => 2, |
124
|
|
|
'total_amount' => 500000, |
125
|
|
|
'checksum' => 'c96f01e3fdb4ba665304e70c04d58ba8917f31fe', |
126
|
|
|
'merchant_id' => 647, |
127
|
|
|
'url_success' => '/' |
128
|
|
|
]; |
129
|
|
|
$responseData = $this->verifyRequestPurchaseSuccess(); |
130
|
|
|
$this->assertFalse($responseData); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
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.