FIXES
-m fallback query order when occuers wss error
This commit is contained in:
@@ -250,6 +250,48 @@ class Foodcourt::QrpayController < BaseFoodcourtController
|
|||||||
def test_pay
|
def test_pay
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_payment_status
|
||||||
|
receipt_no = params[:receipt_no]
|
||||||
|
|
||||||
|
if receipt_no.blank?
|
||||||
|
render json: { status: 'ERROR', message: "Receipt number is missing" }, status: :unprocessable_entity
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
@paymethod = PaymentMethodSetting.find_by(payment_method: "MMQR")
|
||||||
|
|
||||||
|
if @paymethod.nil?
|
||||||
|
render json: { status: 'CONFIG_ERROR', message: "MMQR payment method not configured" }, status: :ok
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
@merchant = KbzMerchant.new(@paymethod)
|
||||||
|
response = @merchant.query_order(merch_order_id: receipt_no)
|
||||||
|
|
||||||
|
|
||||||
|
if response[:data]['code'] == '0'
|
||||||
|
case response[:data]['trade_status']
|
||||||
|
when 'PAY_SUCCESS'
|
||||||
|
render json: { status: 'PAY_SUCCESS' }
|
||||||
|
else
|
||||||
|
render json: { status: response[:data]['trade_status'] || 'PENDING' }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
render json: {
|
||||||
|
status: 'KBZ_ERROR',
|
||||||
|
message: "KBZ Error #{response[:data]['code']}: #{response['msg']}"
|
||||||
|
}, status: :ok
|
||||||
|
end
|
||||||
|
|
||||||
|
rescue StandardError => e
|
||||||
|
render json: {
|
||||||
|
status: 'SERVER_ERROR',
|
||||||
|
message: "Payment check failed: #{e.message}"
|
||||||
|
}, status: :internal_server_error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def cancel
|
def cancel
|
||||||
# cancel orders and related
|
# cancel orders and related
|
||||||
sale_id = params[:sale_id]
|
sale_id = params[:sale_id]
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class KbzMerchant
|
|||||||
sign_type: 'SHA256',
|
sign_type: 'SHA256',
|
||||||
version: '3.0',
|
version: '3.0',
|
||||||
biz_content: {
|
biz_content: {
|
||||||
appid: @payment_method.gateway_url,
|
appid: @app_id,
|
||||||
merch_code: @payment_method.merchant_account_id,
|
merch_code: @payment_method.merchant_account_id,
|
||||||
merch_order_id: merch_order_id
|
merch_order_id: merch_order_id
|
||||||
}.compact
|
}.compact
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="container-fluid h-100">
|
<div class="container-fluid h-100">
|
||||||
<% if !@print_settings.nil? %>
|
<% if !@print_settings.nil? %>
|
||||||
<% if @print_settings.precision.to_i > 0
|
<% if @print_settings.precision.to_i > 0
|
||||||
precision = @print_settings.precision
|
precision = @print_settings.precision
|
||||||
else
|
else
|
||||||
@@ -45,9 +45,9 @@
|
|||||||
delimiter = ""
|
delimiter = ""
|
||||||
end
|
end
|
||||||
%>
|
%>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="row clearfix h-100">
|
<div class="row clearfix h-100">
|
||||||
<% if @error %>
|
<% if @error %>
|
||||||
<input type="hidden" name="error_message" id="error_message" value="<%= json_escape(@error.to_json) %>">
|
<input type="hidden" name="error_message" id="error_message" value="<%= json_escape(@error.to_json) %>">
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -223,12 +223,12 @@
|
|||||||
<input type="hidden" name="server_mode" value="<%=ENV["SERVER_MODE"]%>" id="server_mode">
|
<input type="hidden" name="server_mode" value="<%=ENV["SERVER_MODE"]%>" id="server_mode">
|
||||||
<input type="hidden" name="display_type" id="display_type" value="<%= @display_type%>">
|
<input type="hidden" name="display_type" id="display_type" value="<%= @display_type%>">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<input type="hidden" id="server_mode" value="<%= ENV["SERVER_MODE"] %>">
|
<input type="hidden" id="server_mode" value="<%= ENV["SERVER_MODE"] %>">
|
||||||
</div>
|
</div>
|
||||||
<div class="modal fade" id="voidModal" tabindex="-1" role="dialog">
|
<div class="modal fade" id="voidModal" tabindex="-1" role="dialog">
|
||||||
<div class="modal-dialog" role="document">
|
<div class="modal-dialog" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h4 class="modal-title" id="voidModalLabel">Please Enter Reason for Void</h4>
|
<h4 class="modal-title" id="voidModalLabel">Please Enter Reason for Void</h4>
|
||||||
@@ -248,7 +248,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script defer type="text/javascript">
|
<script defer type="text/javascript">
|
||||||
@@ -256,28 +256,14 @@ $(document).ready(function() {
|
|||||||
const $paymentWaiting = $('.payment-waiting');
|
const $paymentWaiting = $('.payment-waiting');
|
||||||
const amountToReceive = <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i) %>;
|
const amountToReceive = <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i) %>;
|
||||||
const receiptNo = $('#receipt_no').text();
|
const receiptNo = $('#receipt_no').text();
|
||||||
const cable = ActionCable.createConsumer("wss://juicecorner-0mo.sx-fc.app/cable");
|
let paymentProcessed = false;
|
||||||
|
let fallbackTimeout;
|
||||||
|
|
||||||
const subscription = cable.subscriptions.create(
|
function handlePaymentSuccess(){
|
||||||
{
|
if(paymentProcessed) return;
|
||||||
channel: "TestChannel",
|
paymentProcessed = true;
|
||||||
receipt_no: receiptNo
|
clearTimeout(fallbackTimeout);
|
||||||
},
|
|
||||||
{
|
|
||||||
connected() {
|
|
||||||
console.log("Nagato channel connected");
|
|
||||||
},
|
|
||||||
|
|
||||||
received(data) {
|
|
||||||
console.log("Received:", data);
|
|
||||||
|
|
||||||
if (data.status === "PAY_SUCCESS") {
|
|
||||||
$('#cancel-btn').hide();
|
$('#cancel-btn').hide();
|
||||||
this.handlePaymentSuccess();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
handlePaymentSuccess() {
|
|
||||||
$paymentWaiting.html(`
|
$paymentWaiting.html(`
|
||||||
<img src="/image/mmqr.webp" alt="MMQR Payment" style="max-width: 120px; margin-bottom: 10px;">
|
<img src="/image/mmqr.webp" alt="MMQR Payment" style="max-width: 120px; margin-bottom: 10px;">
|
||||||
<div class="payment-success text-center">
|
<div class="payment-success text-center">
|
||||||
@@ -313,20 +299,71 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkPaymentStatus() {
|
||||||
|
$.ajax({
|
||||||
|
url: '/foodcourt/qrpay/check_payment_status',
|
||||||
|
method: 'POST',
|
||||||
|
contentType: 'application/json',
|
||||||
|
headers: {
|
||||||
|
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
|
||||||
|
},
|
||||||
|
data: JSON.stringify({ receipt_no: receiptNo }),
|
||||||
|
success: function(response) {
|
||||||
|
if (response.status === "PAY_SUCCESS") {
|
||||||
|
handlePaymentSuccess();
|
||||||
|
} else if (response.status === "CONFIG_ERROR") {
|
||||||
|
clearTimeout(fallbackTimeout);
|
||||||
|
} else {
|
||||||
|
if (!paymentProcessed) {
|
||||||
|
fallbackTimeout = setTimeout(checkPaymentStatus, 5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
if (!paymentProcessed) {
|
||||||
|
fallbackTimeout = setTimeout(checkPaymentStatus, 5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const cable = ActionCable.createConsumer("wss://juicecorner-0mo.sx-fc.app/cable");
|
||||||
|
|
||||||
|
const subscription = cable.subscriptions.create(
|
||||||
|
{
|
||||||
|
channel: "TestChannel",
|
||||||
|
receipt_no: receiptNo
|
||||||
|
},
|
||||||
|
{
|
||||||
|
connected() {
|
||||||
|
console.log("Nagato channel connected");
|
||||||
|
fallbackTimeout = setTimeout(checkPaymentStatus, 60000);
|
||||||
|
},
|
||||||
|
|
||||||
|
received() {
|
||||||
|
console.log("Received:", data);
|
||||||
|
if (data.status === "PAY_SUCCESS" && !paymentProcessed) {
|
||||||
|
clearTimeout(fallbackTimeout);
|
||||||
|
handlePaymentSuccess();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
disconnected() {
|
||||||
|
console.log("Nagato channel disconnected");
|
||||||
|
fallbackTimeout = setTimeout(checkPaymentStatus, 60000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
function customer_display_view(data, status) {
|
function customer_display_view(data, status) {
|
||||||
$.post('/foodcourt/customer_view', {
|
$.post('/foodcourt/customer_view', {
|
||||||
data: data,
|
data: data,
|
||||||
status: status
|
status: status
|
||||||
}, function(result) {
|
}, function(result) {
|
||||||
// Optional success handler
|
|
||||||
}, 'json');
|
}, 'json');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cancel order
|
|
||||||
$('#cancel-btn').on('click', function(e) {
|
$('#cancel-btn').on('click', function(e) {
|
||||||
const postData = {
|
const postData = {
|
||||||
sale_id: "<%= @sale_data.sale_id %>"
|
sale_id: "<%= @sale_data.sale_id %>"
|
||||||
|
|||||||
@@ -750,6 +750,7 @@ scope "(:locale)", locale: /en|mm/ do
|
|||||||
post 'qrpay/cancel' => 'qrpay#cancel'
|
post 'qrpay/cancel' => 'qrpay#cancel'
|
||||||
get 'qrpay/test-payment' => 'qrpay#test_payment'
|
get 'qrpay/test-payment' => 'qrpay#test_payment'
|
||||||
post 'qrpay/process_payment' => 'qrpay#create'
|
post 'qrpay/process_payment' => 'qrpay#create'
|
||||||
|
post 'qrpay/check_payment_status' => 'qrpay#check_payment_status'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user