QRCode.md
July 5, 2019 · View on GitHub
QRCode Gateway
Khởi tạo gateway:
use Omnipay\Omnipay;
$gateway = Omnipay::create('MoMo_QRCode');
$gateway->initialize([
'accessKey' => 'Do MoMo cấp',
'partnerCode' => 'Do MoMo cấp',
'secretKey' => 'Do MoMo cấp',
]);
Kiểm tra thông tin notifyUrl do MoMo gửi sang:
$response = $gateway->notification()->send();
if ($response->isSuccessful()) {
// TODO: xử lý kết quả và confirm giao dịch với MoMo.
print $response->amount;
print $response->partnerRefId;
var_dump($response->getData()); // toàn bộ data do MoMo gửi sang.
} else {
print $response->getMessage();
}
Kham khảo thêm các tham trị khi MoMo gửi sang tại đây.
Confirm giao dịch:
$response = $gateway->payConfirm([
"partnerRefId" => "Merchant123556666",
"requestType" => "capture",
"requestId" => "1512529262248",
"momoTransId" => "12436514111",
"customerNumber" => "0963181714",
])->send();
if ($response->isSuccessful()) {
// TODO: trả về response cho MoMo
print $response->amount;
var_dump($response->getData()); // Trả về toàn bộ dữ liệu do MoMo trả về.
} else {
print $response->getMessage();
}
Kham khảo thêm các tham trị khi tạo yêu cầu và MoMo trả về tại đây.
Kiểm tra trạng thái giao dịch:
$response = $gateway->queryTransaction([
'partnerRefId' => '123',
'requestId' => '456',
])->send();
if ($response->isSuccessful()) {
// TODO: xử lý kết quả.
print $response->data['amount'];
var_dump($response->getData()); // toàn bộ data do MoMo gửi về.
} else {
print $response->getMessage();
}
Kham khảo thêm các tham trị khi tạo yêu cầu và MoMo trả về tại đây.
Yêu cầu hoàn tiền:
$response = $gateway->refund([
'partnerRefId' => '123',
'requestId' => '999',
'momoTransId' => 321,
'amount' => 50000,
])->send();
if ($response->isSuccessful()) {
// TODO: xử lý kết quả.
print $response->amount;
var_dump($response->getData()); // toàn bộ data do MoMo gửi về.
} else {
print $response->getMessage();
}
Kham khảo thêm các tham trị khi tạo yêu cầu và MoMo trả về tại đây.
Phương thức hổ trợ debug:
Một số phương thức chung hổ trợ debug khi isSuccessful() trả về FALSE:
print $response->getCode(); // mã báo lỗi do MoMo gửi sang.
print $response->getMessage(); // câu thông báo lỗi do MoMo gửi sang.
Kham khảo bảng báo lỗi getCode() chi tiết tại đây.