diff --git a/app/controllers/foodcourt/qrpay_controller.rb b/app/controllers/foodcourt/qrpay_controller.rb index 6f8d47cc..dc9de678 100644 --- a/app/controllers/foodcourt/qrpay_controller.rb +++ b/app/controllers/foodcourt/qrpay_controller.rb @@ -213,33 +213,38 @@ class Foodcourt::QrpayController < BaseFoodcourtController end end - qr_str = "00020101021226480015com.mmqrpay.www0115223743000377032020600000052045814530310454075000.005802MM5908Code2LAB6006Yangon61051101062730125ORDER_1747826957_5ae9cb900523MMQR1075L175919500000010813PAY_BY_QRCODE64300002MY0109ကုဒ်တူလက်0207ရန်ကုန်6304AD40"; - @string_to_encode = qr_str + @paymethod = PaymentMethodSetting.find_by(payment_method: "MMQR") - qrcode = RQRCode::QRCode.new(@string_to_encode) - @qr_svg = qrcode.as_svg( - color: "000", # Hex color for the QR code modules (black) - shape_rendering: "crispEdges", # Renders sharp edges - module_size: 2, # Size of each module (dot/square) - standalone: true, # Outputs a complete SVG document - use_path: true # Modern SVG path rendering - ) + @merchant = KbzMerchant.new(@paymethod) - png_data = qrcode.as_png( - bit_depth: 1, - border_modules: 4, - color_mode: ChunkyPNG::COLOR_GRAYSCALE, - color: 'black', - file: nil, - fill: 'white', - module_px_size: 8, # Pixel size of each module - resize_exactly_to: false, - resize_gte_to: false, - size: 240 # Approximate size of the image in pixels (e.g., 240x240) - ).to_s + @response = @merchant.create_order(amount: @sale_data.grand_total, merch_order_id: @sale_data.receipt_no) + @qr_string = @response['qrCode'] - ActionCable.server.broadcast('second_display_view_channel', { data: qr_str, qr_svg: @qr_svg }) + qrcode = RQRCode::QRCode.new(@qr_string) + + @qr_svg = qrcode.as_svg( + color: "000", + shape_rendering: "crispEdges", + module_size: 2, + standalone: true, + use_path: true + ) + + # png_data = qrcode.as_png( + # bit_depth: 1, + # border_modules: 4, + # color_mode: ChunkyPNG::COLOR_GRAYSCALE, + # color: 'black', + # file: nil, + # fill: 'white', + # module_px_size: 8, # Pixel size of each module + # resize_exactly_to: false, + # resize_gte_to: false, + # size: 240 # Approximate size of the image in pixels (e.g., 240x240) + # ).to_s + + ActionCable.server.broadcast('second_display_view_channel', { data: @qr_string, qr_svg: @qr_svg }) end end end diff --git a/app/services/kbz_merchant.rb b/app/services/kbz_merchant.rb index a7c3d9ae..6441d5a3 100644 --- a/app/services/kbz_merchant.rb +++ b/app/services/kbz_merchant.rb @@ -5,20 +5,18 @@ class KbzMerchant def initialize(payment_method) @payment_method = payment_method - @api_url = payment_method.test_mode? ? - 'http://api.kbzpay.com/payment/gateway/uat/precreate' : - 'https://api.kbzpay.com/payment/gateway/precreate' + @api_url ='http://api.kbzpay.com/payment/gateway/uat/precreate' end - def create_order(transaction_params) - payload = build_payload(transaction_params) + def create_order(amount:, merch_order_id:) + payload = build_payload(amount, merch_order_id) response = send_request(payload) handle_response(response) end private - def build_payload(params) + def build_payload(amount, merch_order_id, timeout='120m') base_params = { method: 'kbz.payment.precreate', timestamp: Time.now.utc.to_i.to_s, @@ -27,13 +25,13 @@ class KbzMerchant sign_type: 'SHA256', version: '1.0', biz_content: { - appid: @payment_method.appid, - merch_code: @payment_method.merch_code, - merch_order_id: params[:merch_order_id], + appid: @payment_method.gateway_url, + merch_code: @payment_method.merchant_account_id, + merch_order_id: merch_order_id, trade_type: 'PAY_BY_QRCODE', - total_amount: params[:total_amount].to_s, + total_amount: amount.to_s, trans_currency: 'MMK', - timeout_express: params[:timeout] || '120m' + timeout_express: timeout || '120m' }.compact } @@ -53,11 +51,10 @@ class KbzMerchant end def generate_signature(flattened_params) - key = 'uatfoodcourt@12' sorted_params = flattened_params.except('sign', 'sign_type').sort string_a = sorted_params.map { |k, v| "#{k}=#{v}" }.join('&') puts "String a: #{string_a}" - string_to_sign = "#{string_a}&key=#{key}" + string_to_sign = "#{string_a}&key=#{@payment_method.auth_token}" puts "String to sign: #{string_to_sign}" Digest::SHA256.hexdigest(string_to_sign).upcase end @@ -78,8 +75,8 @@ class KbzMerchant body: { Request: payload }.to_json, timeout: 15 ) - - puts "Response: #{response}" + response.body + # puts "Response: #{response}" rescue HTTParty::Error => e raise PaymentError, "HTTP error: #{e.message}" rescue SocketError => e @@ -89,7 +86,7 @@ class KbzMerchant def handle_response(response) - json_response = JSON.parse(response.body) + json_response = JSON.parse(response) if json_response.dig('Response', 'result') == 'SUCCESS' json_response['Response'] else diff --git a/app/views/foodcourt/second_display/_second_display.html.erb b/app/views/foodcourt/second_display/_second_display.html.erb index 5986da6b..56d31bcc 100644 --- a/app/views/foodcourt/second_display/_second_display.html.erb +++ b/app/views/foodcourt/second_display/_second_display.html.erb @@ -1,57 +1,125 @@
| # | Items | -QTY | -Price | +QTY | +Price |
|---|