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 %>