Merge pull request #1991 from shazar-webkul/gli-3333
Fixed: Order confirmation mismatch on payment return
This commit is contained in:
@@ -106,31 +106,40 @@ class QloDuitkuPaymentReturnModuleFrontController extends ModuleFrontController
|
||||
$this->module->logger->log('After Cart Validation in return.', FileLogger::DEBUG);
|
||||
$objDuitkuTransaction->addCartLock((int) $idCart);
|
||||
if (!$res) {
|
||||
$objDuitkuTransaction->save();
|
||||
$objDuitkuTransaction->save();
|
||||
}
|
||||
|
||||
if ($this->module->validateOrder(
|
||||
(int) $idCart,
|
||||
$orderStatus,
|
||||
$cartAmount,
|
||||
$this->module->l('Duitku Payment', 'return'),
|
||||
null,
|
||||
$extraVars,
|
||||
(int) $id_currency,
|
||||
false,
|
||||
$objCustomer->secure_key
|
||||
)) {
|
||||
$statusResponse = $this->module->checkDuitkuTransactionStatus($merchantOrderId);
|
||||
$statusCode = isset($statusResponse['response']['statusCode']) ? $statusResponse['response']['statusCode'] : null;
|
||||
|
||||
$this->module->logger->log('Return Process Order created.', FileLogger::DEBUG);
|
||||
if ($statusResponse['status'] === true && ($statusCode == '00' || $statusCode == '01')) {
|
||||
if ($this->module->validateOrder(
|
||||
(int) $idCart,
|
||||
$orderStatus,
|
||||
$cartAmount,
|
||||
$this->module->l('Duitku Payment', 'return'),
|
||||
null,
|
||||
$extraVars,
|
||||
(int) $id_currency,
|
||||
false,
|
||||
$objCustomer->secure_key
|
||||
)) {
|
||||
|
||||
$url = $this->context->link->getPageLink('order-confirmation', true, null, [
|
||||
'id_cart' => $idCart,
|
||||
'id_module' => $this->module->id,
|
||||
'id_order' => Order::getOrderByCartId($idCart),
|
||||
'success' => 1,
|
||||
'key' => $objCustomer->secure_key,
|
||||
]);
|
||||
Tools::redirect($url);
|
||||
$this->module->logger->log('Return Process Order created.', FileLogger::DEBUG);
|
||||
|
||||
$url = $this->context->link->getPageLink('order-confirmation', true, null, [
|
||||
'id_cart' => $idCart,
|
||||
'id_module' => $this->module->id,
|
||||
'id_order' => Order::getOrderByCartId($idCart),
|
||||
'success' => 1,
|
||||
'key' => $objCustomer->secure_key,
|
||||
]);
|
||||
Tools::redirect($url);
|
||||
}
|
||||
} else {
|
||||
$this->module->logger->log('Duitku could not confirm transaction for merchantOrderId ' . $merchantOrderId, FileLogger::DEBUG);
|
||||
$objDuitkuTransaction->removeCartLock($idCart);
|
||||
Tools::redirect($this->context->link->getModuleLink('qloduitkupayment', 'error') . '?validation_err=1&id=' . $merchantOrderId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -446,6 +446,34 @@ class QloDuitkuPayment extends PaymentModule
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm a transaction's real status with Duitku's own server-to-server API, rather
|
||||
* than trusting the unsigned browser return redirect. Must be called at most once per
|
||||
* return hit - Duitku rate-limits repeated calls to this endpoint.
|
||||
*
|
||||
* @param string $merchantOrderId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function checkDuitkuTransactionStatus($merchantOrderId)
|
||||
{
|
||||
$merchantCode = Configuration::get('QDP_DUITKU_PAYMENT_MERCHANT_CODE');
|
||||
$apiKey = Configuration::get('QDP_DUITKU_PAYMENT_API_KEY');
|
||||
$signature = hash_hmac('sha256', $merchantCode . $merchantOrderId, $apiKey);
|
||||
|
||||
$params = array(
|
||||
'merchantCode' => $merchantCode,
|
||||
'merchantOrderId' => $merchantOrderId,
|
||||
'signature' => $signature,
|
||||
);
|
||||
|
||||
return QdpDuitkuServiceRequest::makeRequest(
|
||||
'transactionStatus',
|
||||
QdpDuitkuTransaction::QDP_CURL_REQUEST_TYPE_POST,
|
||||
$params
|
||||
);
|
||||
}
|
||||
|
||||
private function getCustomerPhone($customer, $addressId)
|
||||
{
|
||||
if (!empty($customer->phone)) {
|
||||
|
||||
Reference in New Issue
Block a user