You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+129-1Lines changed: 129 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ Thư viện hổ trợ tích cổng thanh toán VNPay phát triển trên nền
20
20
21
21
## Cài đặt
22
22
23
-
Cài đặt Omnipay VTCPay thông qua [Composer](https://getcomposer.org):
23
+
Cài đặt Omnipay VNPay thông qua [Composer](https://getcomposer.org):
24
24
25
25
```bash
26
26
composer require phpviet/omnipay-vnpay
@@ -37,6 +37,134 @@ hoặc nếu bạn muốn sử dụng không dựa trên framework thì tiếp t
37
37
38
38
### Khởi tạo gateway:
39
39
40
+
```php
41
+
use Omnipay\Omnipay;
42
+
43
+
$gateway = Omnipay::create('VNPay');
44
+
$gateway->initialize([
45
+
'vnp_TmnCode' => 'Do VNPay cấp',
46
+
'vnp_HashSecret' => 'Do VNPay cấp',
47
+
]);
48
+
```
49
+
50
+
Gateway khởi tạo ở trên dùng để tạo các yêu cầu xử lý đến VNPay hoặc dùng để nhận yêu cầu do VNPay gửi đến.
51
+
52
+
### Tạo yêu cầu thanh toán:
53
+
54
+
```php
55
+
$response = $gateway->purchase([
56
+
'vnp_TxnRef' => time(),
57
+
'vnp_OrderType' => 100000,
58
+
'vnp_OrderInfo' => time(),
59
+
'vnp_IpAddr' => '127.0.0.1',
60
+
'vnp_Amount' => 1000000,
61
+
'vnp_ReturnUrl' => 'https://github.com/phpviet',
62
+
])->send();
63
+
64
+
if ($response->isRedirect()) {
65
+
$redirectUrl = $response->getRedirectUrl();
66
+
67
+
// TODO: chuyển khách sang trang VNPay để thanh toán
68
+
}
69
+
```
70
+
71
+
Kham khảo thêm các tham trị khi tạo yêu cầu và VNPay trả về tại [đây](https://sandbox.vnpayment.vn/apis/docs/huong-dan-tich-hop/#t%E1%BA%A1o-url-thanh-to%C3%A1n).
72
+
73
+
74
+
### Kiểm tra thông tin `vnp_ReturnUrl` khi khách được VNPay redirect về:
75
+
76
+
```php
77
+
$response = $gateway->completePurchase()->send();
78
+
79
+
if ($response->isSuccessful()) {
80
+
// TODO: xử lý kết quả và hiển thị.
81
+
print $response->vnp_Amount;
82
+
print $response->vnp_TxnRef;
83
+
84
+
var_dump($response->getData()); // toàn bộ data do VNPay gửi sang.
85
+
86
+
} else {
87
+
88
+
print $response->getMessage();
89
+
}
90
+
```
91
+
92
+
Kham khảo thêm các tham trị khi VNPay trả về tại [đây](https://sandbox.vnpayment.vn/apis/docs/huong-dan-tich-hop/#code-returnurl).
93
+
94
+
### Kiểm tra thông tin `IPN` do VNPay gửi sang:
95
+
96
+
```php
97
+
$response = $gateway->notification()->send();
98
+
99
+
if ($response->isSuccessful()) {
100
+
// TODO: xử lý kết quả.
101
+
print $response->vnp_Amount;
102
+
print $response->vnp_TxnRef;
103
+
104
+
var_dump($response->getData()); // toàn bộ data do VNPay gửi sang.
105
+
106
+
} else {
107
+
108
+
print $response->getMessage();
109
+
}
110
+
```
111
+
112
+
Kham khảo thêm các tham trị khi VNPay gửi sang tại [đây](https://sandbox.vnpayment.vn/apis/docs/huong-dan-tich-hop/#code-ipn-url).
113
+
114
+
### Kiểm tra trạng thái giao dịch:
115
+
116
+
```php
117
+
$response = $gateway->queryTransaction([
118
+
'vnp_TransDate' => 20190705151126,
119
+
'vnp_TxnRef' => 1562314234,
120
+
'vnp_OrderInfo' => time(),
121
+
'vnp_IpAddr' => '127.0.0.1',
122
+
'vnp_TransactionNo' => 496558,
123
+
])->send();
124
+
125
+
if ($response->isSuccessful()) {
126
+
// TODO: xử lý kết quả và hiển thị.
127
+
print $response->getTransactionId();
128
+
print $response->getTransactionReference();
129
+
130
+
var_dump($response->getData()); // toàn bộ data do VNPay gửi về.
131
+
132
+
} else {
133
+
134
+
print $response->getMessage();
135
+
}
136
+
```
137
+
138
+
Kham khảo thêm các tham trị khi tạo yêu cầu và VNPay trả về tại [đây](https://goo.gl/FHdM5B).
139
+
140
+
### Yêu cầu hoàn tiền:
141
+
142
+
```php
143
+
$response = $gateway->refund([
144
+
'vnp_Amount' => 10000,
145
+
'vnp_TransactionType' => '03',
146
+
'vnp_TransDate' => 20190705151126,
147
+
'vnp_TxnRef' => 32321,
148
+
'vnp_OrderInfo' => time(),
149
+
'vnp_IpAddr' => '127.0.0.1',
150
+
'vnp_TransactionNo' => 496558,
151
+
])->send();
152
+
153
+
if ($response->isSuccessful()) {
154
+
// TODO: xử lý kết quả và hiển thị.
155
+
print $response->amount;
156
+
print $response->orderId;
157
+
158
+
var_dump($response->getData()); // toàn bộ data do VNPay gửi về.
159
+
160
+
} else {
161
+
162
+
print $response->getMessage();
163
+
}
164
+
```
165
+
166
+
Kham khảo thêm các tham trị khi tạo yêu cầu và VNPay trả về tại [đây](https://goo.gl/FHdM5B).
167
+
40
168
## Dành cho nhà phát triển
41
169
42
170
Nếu như bạn cảm thấy thư viện chúng tôi còn thiếu sót hoặc sai sót và bạn muốn đóng góp để phát triển chung,
0 commit comments