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
|
||||
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
|
||||
# cancel orders and related
|
||||
sale_id = params[:sale_id]
|
||||
|
||||
@@ -84,7 +84,7 @@ class KbzMerchant
|
||||
sign_type: 'SHA256',
|
||||
version: '3.0',
|
||||
biz_content: {
|
||||
appid: @payment_method.gateway_url,
|
||||
appid: @app_id,
|
||||
merch_code: @payment_method.merchant_account_id,
|
||||
merch_order_id: merch_order_id
|
||||
}.compact
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
</style>
|
||||
|
||||
<div class="container-fluid h-100">
|
||||
<% if !@print_settings.nil? %>
|
||||
<% if !@print_settings.nil? %>
|
||||
<% if @print_settings.precision.to_i > 0
|
||||
precision = @print_settings.precision
|
||||
else
|
||||
@@ -45,9 +45,9 @@
|
||||
delimiter = ""
|
||||
end
|
||||
%>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<div class="row clearfix h-100">
|
||||
<div class="row clearfix h-100">
|
||||
<% if @error %>
|
||||
<input type="hidden" name="error_message" id="error_message" value="<%= json_escape(@error.to_json) %>">
|
||||
<% end %>
|
||||
@@ -223,12 +223,12 @@
|
||||
<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%>">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" id="server_mode" value="<%= ENV["SERVER_MODE"] %>">
|
||||
</div>
|
||||
<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-header">
|
||||
<h4 class="modal-title" id="voidModalLabel">Please Enter Reason for Void</h4>
|
||||
@@ -248,7 +248,7 @@
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script defer type="text/javascript">
|
||||
@@ -256,28 +256,14 @@ $(document).ready(function() {
|
||||
const $paymentWaiting = $('.payment-waiting');
|
||||
const amountToReceive = <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i) %>;
|
||||
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(
|
||||
{
|
||||
channel: "TestChannel",
|
||||
receipt_no: receiptNo
|
||||
},
|
||||
{
|
||||
connected() {
|
||||
console.log("Nagato channel connected");
|
||||
},
|
||||
|
||||
received(data) {
|
||||
console.log("Received:", data);
|
||||
|
||||
if (data.status === "PAY_SUCCESS") {
|
||||
function handlePaymentSuccess(){
|
||||
if(paymentProcessed) return;
|
||||
paymentProcessed = true;
|
||||
clearTimeout(fallbackTimeout);
|
||||
$('#cancel-btn').hide();
|
||||
this.handlePaymentSuccess();
|
||||
}
|
||||
},
|
||||
|
||||
handlePaymentSuccess() {
|
||||
$paymentWaiting.html(`
|
||||
<img src="/image/mmqr.webp" alt="MMQR Payment" style="max-width: 120px; margin-bottom: 10px;">
|
||||
<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) {
|
||||
$.post('/foodcourt/customer_view', {
|
||||
data: data,
|
||||
status: status
|
||||
}, function(result) {
|
||||
// Optional success handler
|
||||
}, 'json');
|
||||
}
|
||||
|
||||
// Cancel order
|
||||
$('#cancel-btn').on('click', function(e) {
|
||||
const postData = {
|
||||
sale_id: "<%= @sale_data.sale_id %>"
|
||||
|
||||
@@ -750,6 +750,7 @@ scope "(:locale)", locale: /en|mm/ do
|
||||
post 'qrpay/cancel' => 'qrpay#cancel'
|
||||
get 'qrpay/test-payment' => 'qrpay#test_payment'
|
||||
post 'qrpay/process_payment' => 'qrpay#create'
|
||||
post 'qrpay/check_payment_status' => 'qrpay#check_payment_status'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user