diff --git a/app/controllers/foodcourt/qrpay_controller.rb b/app/controllers/foodcourt/qrpay_controller.rb index eaf87b93..9532e53f 100644 --- a/app/controllers/foodcourt/qrpay_controller.rb +++ b/app/controllers/foodcourt/qrpay_controller.rb @@ -188,7 +188,7 @@ class Foodcourt::QrpayController < BaseFoodcourtController end @paymethod = PaymentMethodSetting.find_by(payment_method: "MMQR") - + if @paymethod.nil? raise "MMQR payment method not configured" end @@ -224,7 +224,7 @@ class Foodcourt::QrpayController < BaseFoodcourtController redirect_to foodcourt_food_court_path return end - + end end @@ -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] diff --git a/app/services/kbz_merchant.rb b/app/services/kbz_merchant.rb index a528997a..2e8fff2f 100644 --- a/app/services/kbz_merchant.rb +++ b/app/services/kbz_merchant.rb @@ -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 diff --git a/app/views/foodcourt/qrpay/init.html.erb b/app/views/foodcourt/qrpay/init.html.erb index 8124776f..5e14eef1 100644 --- a/app/views/foodcourt/qrpay/init.html.erb +++ b/app/views/foodcourt/qrpay/init.html.erb @@ -32,169 +32,169 @@
- <% if !@print_settings.nil? %> +<% if !@print_settings.nil? %> <% if @print_settings.precision.to_i > 0 precision = @print_settings.precision - else + else precision = 0 - end - #check delimiter - if @print_settings.delimiter + end + #check delimiter + if @print_settings.delimiter delimiter = "," - else + else delimiter = "" - end + end %> - <% end %> +<% end %> -
- <% if @error %> +
+ <% if @error %> - <% end %> + <% end %>
-
+
-
+
-
Receipt No : <%=@sale_data.receipt_no rescue ' '%>
-
Receipt Date : <%=@sale_data.receipt_date.strftime("%d/%m/%Y-%I:%M %p") rescue '-' %>
+
Receipt No : <%=@sale_data.receipt_no rescue ' '%>
+
Receipt Date : <%=@sale_data.receipt_date.strftime("%d/%m/%Y-%I:%M %p") rescue '-' %>
-
Table No : <%=@table_no%>
- -
Sale ID : <% if @sale_data %><%=@sale_data.sale_id %><% end %>
+
Table No : <%=@table_no%>
+ +
Sale ID : <% if @sale_data %><%=@sale_data.sale_id %><% end %>
-
+
Customer : <% if @cashier_type == 'quick_service' || @cashier_type == 'food_court' %> - - + + <% else %> - <%= @sale_data.customer.name%> + <%= @sale_data.customer.name%> <% end %>
-
Checkin Time : <%if !@checkin_time.nil?%><%= @checkin_time.strftime("%I:%M %p") %> - <%end%>
+
Checkin Time : <%if !@checkin_time.nil?%><%= @checkin_time.strftime("%I:%M %p") %> + <%end%>
-
+
-
+
- +
- - - - - - + + + + + + -
#ItemsQTYPrice#ItemsQTYPrice
+
-
-
+
+
- +
- <% sub_total = 0 - count = 0 - %> - <% @sale_data.sale_items.each do |sale_item| + <% sub_total = 0 + count = 0 + %> + <% @sale_data.sale_items.each do |sale_item| count += 1 %> <% sub_total += sale_item.price%> - - - + + + - - <%end %> - -
<%= count %><%=sale_item.product_name%>@<%=number_with_precision( sale_item.unit_price, precision: precision.to_i )%><%=sale_item.qty%><%= count %><%=sale_item.product_name%>@<%=number_with_precision( sale_item.unit_price, precision: precision.to_i )%><%=sale_item.qty%> <%=(number_with_precision(sale_item.price, precision: precision.to_i ))%>
-
-
-
- +
+
+ +
@@ -223,32 +223,32 @@ " id="server_mode">
-
+
">