Skip to content

Commit dc42b14

Browse files
Added docs.
1 parent 9f9a676 commit dc42b14

File tree

6 files changed

+411
-0
lines changed

6 files changed

+411
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
/phpunit.xml.dist export-ignore
99
/.scrutinizer.yml export-ignore
1010
/.styleci.yml export-ignore
11+
/docs export-ignore
1112
/tests export-ignore
1213
/.editorconfig export-ignore

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,25 @@ Cài đặt Omnipay MoMo thông qua [Composer](https://getcomposer.org):
2525
```bash
2626
composer require phpviet/omnipay-momo
2727
```
28+
## Cách sử dụng
29+
30+
### Tích hợp sẵn trên các framework phổ biến hiện tại
31+
32+
- [`Laravel`](https://github.com/phpviet/laravel-omnipay)
33+
- [`Symfony`](https://github.com/phpviet/symfony-omnipay)
34+
- [`Yii`](https://github.com/phpviet/yii-omnipay)
35+
36+
hoặc nếu bạn muốn sử dụng không dựa trên framework thì tiếp tục xem tiếp.
37+
38+
### Cách sử dụng các gateway
39+
40+
- [`All In One`](docs/AllInOne.md)
41+
- [`App In App`](docs/AppInApp.md)
42+
- [`POS`](docs/POS.md)
43+
- [`QRCode`](docs/QRCode.md)
44+
45+
## Dành cho nhà phát triển
46+
47+
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,
48+
chúng tôi rất hoan nghênh! Hãy tạo các `issue` để đóng góp ý tưởng cho phiên bản kế tiếp hoặc tạo `PR`
49+
để đóng góp phần thiếu sót hoặc sai sót. Cảm ơn!

docs/AllInOne.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
All In One Gateway
2+
-------------------
3+
4+
Để nắm sơ lược về khái niệm và cách sử dụng các **Omnipay** gateways bạn hãy truy cập vào [đây](https://omnipay.thephpleague.com/)
5+
để kham khảo.
6+
7+
## Khởi tạo gateway:
8+
9+
```php
10+
use Omnipay\Omnipay;
11+
12+
$gateway = Omnipay::create('MoMo_AllInOne');
13+
$gateway->setAccessKey('Do MoMo cấp.');
14+
$gateway->setPartnerCode('Do MoMo cấp.');
15+
$gateway->setSecretKey('Do MoMo cấp.');
16+
```
17+
18+
Gateway khởi tạo ở trên dùng để tạo các yêu cầu xử lý đến MoMo hoặc dùng để nhận yêu cầu do MoMo gửi đến.
19+
20+
## Tạo yêu cầu thanh toán:
21+
22+
```php
23+
$response = $gateway->purchase([
24+
'amount' => 20000,
25+
'returnUrl' => 'http://domaincuaban.com/thanh-toan-thanh-cong/',
26+
'notifyUrl' => 'http://domaincuaban.com/ipn/',
27+
'orderId' => 'Mã đơn hàng',
28+
'requestId' => 'Mã request id, gợi ý nên xài uuid4',
29+
])->send();
30+
31+
if ($response->isRedirect()) {
32+
$redirectUrl = $response->getRedirectUrl();
33+
34+
// TODO: chuyển khách sang trang MoMo để thanh toán
35+
}
36+
```
37+
38+
Kham khảo thêm các tham trị khi tạo yêu cầu và MoMo trả về tại [đây](https://developers.momo.vn/#/docs/aio/?id=ph%c6%b0%c6%a1ng-th%e1%bb%a9c-thanh-to%c3%a1n).
39+
40+
## Kiểm tra thông tin `returnUrl` khi khách được MoMo redirect về:
41+
42+
```php
43+
$response = $gateway->completePurchase()->send();
44+
45+
if ($response->isSuccessful()) {
46+
// TODO: xử lý kết quả và hiển thị.
47+
print $response->amount;
48+
print $response->orderId;
49+
50+
var_dump($response->getData()); // toàn bộ data do MoMo gửi sang.
51+
52+
} else {
53+
54+
print $response->getMessage();
55+
}
56+
```
57+
58+
Kham khảo thêm các tham trị khi MoMo trả về tại [đây](https://developers.momo.vn/#/docs/aio/?id=th%c3%b4ng-tin-tham-s%e1%bb%91).
59+
60+
## Kiểm tra thông tin `notifyUrl` do MoMo gửi sang:
61+
62+
```php
63+
$response = $gateway->notification()->send();
64+
65+
if ($response->isSuccessful()) {
66+
// TODO: xử lý kết quả và hiển thị.
67+
print $response->amount;
68+
print $response->orderId;
69+
70+
var_dump($response->getData()); // toàn bộ data do MoMo gửi sang.
71+
72+
} else {
73+
74+
print $response->getMessage();
75+
}
76+
```
77+
78+
Kham khảo thêm các tham trị khi MoMo gửi sang tại [đây](https://developers.momo.vn/#/docs/aio/?id=th%c3%b4ng-tin-tham-s%e1%bb%91).
79+
80+
## Kiểm tra trạng thái giao dịch:
81+
82+
```php
83+
$response = $gateway->queryTransaction([
84+
'orderId' => '123',
85+
'requestId' => '456',
86+
])->send();
87+
88+
if ($response->isSuccessful()) {
89+
// TODO: xử lý kết quả và hiển thị.
90+
print $response->amount;
91+
print $response->orderId;
92+
93+
var_dump($response->getData()); // toàn bộ data do MoMo gửi về.
94+
95+
} else {
96+
97+
print $response->getMessage();
98+
}
99+
```
100+
101+
Kham khảo thêm các tham trị khi tạo yêu cầu và MoMo trả về tại [đây](https://developers.momo.vn/#/docs/aio/?id=ki%e1%bb%83m-tra-tr%e1%ba%a1ng-th%c3%a1i-giao-d%e1%bb%8bch).
102+
103+
## Yêu cầu hoàn tiền:
104+
105+
```php
106+
$response = $gateway->refund([
107+
'orderId' => '123',
108+
'requestId' => '999',
109+
'transId' => 321,
110+
'amount' => 50000,
111+
])->send();
112+
113+
if ($response->isSuccessful()) {
114+
// TODO: xử lý kết quả và hiển thị.
115+
print $response->amount;
116+
print $response->orderId;
117+
118+
var_dump($response->getData()); // toàn bộ data do MoMo gửi về.
119+
120+
} else {
121+
122+
print $response->getMessage();
123+
}
124+
```
125+
126+
Kham khảo thêm các tham trị khi tạo yêu cầu và MoMo trả về tại [đây](https://developers.momo.vn/#/docs/aio/?id=ho%c3%a0n-ti%e1%bb%81n-giao-d%e1%bb%8bch).
127+
128+
## Kiểm tra trạng thái hoàn tiền:
129+
130+
```php
131+
$response = $gateway->queryRefund([
132+
'orderId' => '123',
133+
'requestId' => '321',
134+
])->send();
135+
136+
if ($response->isSuccessful()) {
137+
// TODO: xử lý kết quả và hiển thị.
138+
print $response->amount;
139+
print $response->orderId;
140+
141+
var_dump($response->getData()); // toàn bộ data do MoMo gửi về.
142+
143+
} else {
144+
145+
print $response->getMessage();
146+
}
147+
```
148+
149+
Kham khảo thêm các tham trị khi tạo yêu cầu và MoMo trả về tại [đây](https://developers.momo.vn/#/docs/aio/?id=ki%e1%bb%83m-tra-tr%e1%ba%a1ng-th%c3%a1i-ho%c3%a0n-ti%e1%bb%81n).
150+
151+
## Phương thức hổ trợ debug:
152+
153+
Một số phương thức chung hổ trợ debug khi `isSuccessful()` trả về `FALSE`:
154+
155+
```php
156+
print $response->getCode(); // mã báo lỗi do MoMo gửi sang.
157+
print $response->getMessage(); // câu thông báo lỗi do MoMo gửi sang.
158+
```
159+
160+
Kham khảo bảng báo lỗi `getCode()` chi tiết tại [đây](https://developers.momo.vn/#/docs/aio/?id=b%e1%ba%a3ng-m%c3%a3-l%e1%bb%97i).

docs/AppInApp.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
App In App Gateway
2+
-------------------
3+
4+
Để nắm sơ lược về khái niệm và cách sử dụng các **Omnipay** gateways bạn hãy truy cập vào [đây](https://omnipay.thephpleague.com/)
5+
để kham khảo.
6+
7+
## Khởi tạo gateway:
8+
9+
```php
10+
use Omnipay\Omnipay;
11+
12+
$gateway = Omnipay::create('MoMo_AppInApp');
13+
$gateway->setPublicKey('Do MoMo cấp.');
14+
$gateway->setAccessKey('Do MoMo cấp.');
15+
$gateway->setPartnerCode('Do MoMo cấp.');
16+
$gateway->setSecretKey('Do MoMo cấp.');
17+
```
18+
19+
## Tạo yêu cầu thanh toán:
20+
21+
```php
22+
$response = $gateway->purchase([
23+
'customerNumber' => '0909113911',
24+
'appData' => '999999',
25+
'partnerRefId' => 99,
26+
'amount' => 40000,
27+
])->send();
28+
29+
if ($response->isSuccessful()) {
30+
// TODO: xử lý đơn hàng và tạo request confirm.
31+
32+
print $response->amount;
33+
34+
var_dump($response->getData()); // Trả về toàn bộ dữ liệu do MoMo trả về.
35+
} else {
36+
37+
print $response->getMessage();
38+
}
39+
```
40+
41+
Kham khảo thêm các tham trị khi tạo yêu cầu và MoMo trả về tại [đây](https://developers.momo.vn/#/docs/app_in_app?id=x%e1%bb%ad-l%c3%bd-thanh-to%c3%a1n).
42+
43+
## Confirm giao dịch:
44+
45+
```php
46+
$response = $gateway->payConfirm([
47+
"partnerRefId" => "Merchant123556666",
48+
"requestType" => "capture",
49+
"requestId" => "1512529262248",
50+
"momoTransId" => "12436514111",
51+
"customerNumber" => "0963181714",
52+
])->send();
53+
54+
if ($response->isSuccessful()) {
55+
// TODO: trả về response cho MoMo
56+
57+
print $response->amount;
58+
59+
var_dump($response->getData()); // Trả về toàn bộ dữ liệu do MoMo trả về.
60+
} else {
61+
62+
print $response->getMessage();
63+
}
64+
```
65+
66+
Kham khảo thêm các tham trị khi tạo yêu cầu và MoMo trả về tại [đây](https://developers.momo.vn/#/docs/app_in_app?id=x%c3%a1c-nh%e1%ba%adn-giao-d%e1%bb%8bch).
67+
68+
## Phương thức hổ trợ debug:
69+
70+
Một số phương thức chung hổ trợ debug khi `isSuccessful()` trả về `FALSE`:
71+
72+
```php
73+
print $response->getCode(); // mã báo lỗi do MoMo gửi sang.
74+
print $response->getMessage(); // câu thông báo lỗi do MoMo gửi sang.
75+
```
76+
77+
Kham khảo bảng báo lỗi `getCode()` chi tiết tại [đây](https://developers.momo.vn/#/docs/aio/?id=b%e1%ba%a3ng-m%c3%a3-l%e1%bb%97i).

docs/POS.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
POS Gateway
2+
------------
3+
4+
Để nắm sơ lược về khái niệm và cách sử dụng các **Omnipay** gateways bạn hãy truy cập vào [đây](https://omnipay.thephpleague.com/)
5+
để kham khảo.
6+
7+
## Khởi tạo gateway:
8+
9+
```php
10+
use Omnipay\Omnipay;
11+
12+
$gateway = Omnipay::create('MoMo_POS');
13+
$gateway->setPublicKey('Do MoMo cấp.');
14+
$gateway->setAccessKey('Do MoMo cấp.');
15+
$gateway->setPartnerCode('Do MoMo cấp.');
16+
$gateway->setSecretKey('Do MoMo cấp.');
17+
```
18+
19+
## Tạo yêu cầu thanh toán:
20+
21+
```php
22+
$response = $gateway->purchase([
23+
"partnerRefId" => "Merchant123556666",
24+
"amount" => 30000,
25+
"paymentCode" => "MM627755248085056826",
26+
"storeId" => "001",
27+
"storeName" => "Cửa hàng 01 của đối tác",
28+
])->send();
29+
30+
if ($response->isSuccessful()) {
31+
// TODO: xử lý đơn hàng và tạo request confirm.
32+
33+
print $response->amount;
34+
35+
var_dump($response->getData()); // Trả về toàn bộ dữ liệu do MoMo trả về.
36+
} else {
37+
38+
print $response->getMessage();
39+
}
40+
```
41+
42+
Kham khảo thêm các tham trị khi tạo yêu cầu và MoMo trả về tại [đây](https://developers.momo.vn/#/docs/pos_payment?id=x%e1%bb%ad-l%c3%bd-thanh-to%c3%a1n).
43+
44+
## Confirm giao dịch:
45+
46+
```php
47+
$response = $gateway->payConfirm([
48+
"partnerRefId" => "Merchant123556666",
49+
"requestType" => "capture",
50+
"requestId" => "1512529262248",
51+
"momoTransId" => "12436514111",
52+
"customerNumber" => "0963181714",
53+
])->send();
54+
55+
if ($response->isSuccessful()) {
56+
// TODO: trả về response cho MoMo
57+
58+
print $response->amount;
59+
60+
var_dump($response->getData()); // Trả về toàn bộ dữ liệu do MoMo trả về.
61+
} else {
62+
63+
print $response->getMessage();
64+
}
65+
```
66+
67+
Kham khảo thêm các tham trị khi tạo yêu cầu và MoMo trả về tại [đây](https://developers.momo.vn/#/docs/pos_payment?id=x%c3%a1c-nh%e1%ba%adn-giao-d%e1%bb%8bch).
68+
69+
## Phương thức hổ trợ debug:
70+
71+
Một số phương thức chung hổ trợ debug khi `isSuccessful()` trả về `FALSE`:
72+
73+
```php
74+
print $response->getCode(); // mã báo lỗi do MoMo gửi sang.
75+
print $response->getMessage(); // câu thông báo lỗi do MoMo gửi sang.
76+
```
77+
78+
Kham khảo bảng báo lỗi `getCode()` chi tiết tại [đây](https://developers.momo.vn/#/docs/aio/?id=b%e1%ba%a3ng-m%c3%a3-l%e1%bb%97i).

0 commit comments

Comments
 (0)