diff --git a/app/controllers/api/payment/callback_controller.rb b/app/controllers/api/payment/callback_controller.rb new file mode 100644 index 00000000..c2acb4d8 --- /dev/null +++ b/app/controllers/api/payment/callback_controller.rb @@ -0,0 +1,15 @@ +class Api::Payment::CallbackController < Api::ApiController + + skip_before_action :authenticate + + def kbzpay + Rails.logger.info params[:Request] + callback_value = params[:Request] + trade_status = params[:Request][:trade_status] + total_amount = params[:Request][:total_amount] + if trade_status == "PAY_SUCCESS" + merch_order_id = params[:Request][:merch_order_id] + end + end + +end diff --git a/app/controllers/api/payment/mobilepayment_controller.rb b/app/controllers/api/payment/mobilepayment_controller.rb index 42ab5919..220cbbeb 100644 --- a/app/controllers/api/payment/mobilepayment_controller.rb +++ b/app/controllers/api/payment/mobilepayment_controller.rb @@ -28,7 +28,7 @@ class Api::Payment::MobilepaymentController < Api::ApiController new_total = Sale.get_rounding_adjustment(saleObj.grand_total) rounding_adj = new_total-saleObj.grand_total saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) - + end end end @@ -41,7 +41,7 @@ class Api::Payment::MobilepaymentController < Api::ApiController @cash ={"change_amount"=>sale_payment[3],"balance_amount"=>sale_payment[4] ,"receipt_url"=>''} end @out = true,@cash - + else @out =false,"Something wrong!" sale_payment = SalePayment.new @@ -53,8 +53,4 @@ class Api::Payment::MobilepaymentController < Api::ApiController end - def kbz_pay - - end - end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 3b9fda76..4f99a8a6 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -104,9 +104,16 @@ class Origami::PaymentsController < BaseOrigamiController #TODO :: KBZPAY ( QR ) # On/Off setting ( show or not qr ) - qrCode = "00020101021202021110500346KBZ005ab0ed5c1ed09d1c4585ff1313170389160831435294600062000040732kp1e78f7efddca190042638341afb88d50200006KBZPay0106KBZPay5303MMK5802MM62170813PAY_BY_QRCODE64060002my6304FBBD" + # qrCode = "00020101021202021110500346KBZ005ab0ed5c1ed09d1c4585ff1313170389160831435294600062000040732kp1e78f7efddca190042638341afb88d50200006KBZPay0106KBZPay5303MMK5802MM62170813PAY_BY_QRCODE64060002my6304FBBD" kbz_pay_status = PaymentMethodSetting.where(:payment_method => 'KBZPay').last - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, kbz_pay_status, qrCode, cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil,other_amount,nil,nil,nil) + + status = false + if kbz_pay_status + + status, qr = KbzPay.pay(sale_data.grand_total, sale_data.receipt_no) + end + + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, status, qr, cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil,other_amount,nil,nil,nil) result = { :filepath => filename, diff --git a/app/models/sale.rb b/app/models/sale.rb index 8b245b54..b6f98b2a 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -206,7 +206,7 @@ class Sale < ApplicationRecord end end - link_order_sale(order.id) + # link_order_sale(order.id) end self.save! @@ -735,9 +735,11 @@ class Sale < ApplicationRecord saleOrder = SaleOrder.where("sale_id=? and order_id=?", self.id, order_id).take if saleOrder.nil? - sale_order = SaleOrder.new - sale = sale_order.create_sale_order(self.id, order_id) + saleOrder = SaleOrder.new + # sale = saleOrder.create_sale_order(self.id, order_id) end + + sale = saleOrder.create_sale_order(self.id, order_id) # if (SaleOrder.where("sale_id = #{self.id} and order_id=#{order_id}").nil?) # SaleOrder.create(:sale_id => self.id, :order_id => order_id) # end diff --git a/app/models/sale_order.rb b/app/models/sale_order.rb index fd2b9239..e3b86f02 100755 --- a/app/models/sale_order.rb +++ b/app/models/sale_order.rb @@ -7,11 +7,11 @@ class SaleOrder < ApplicationRecord belongs_to :sale belongs_to :order - def create_sale_order(sale, order) - sale_order = SaleOrder.new - sale_order.sale_id = sale - sale_order.order_id = order - sale_order.save! + def create_sale_order(sale_id, order_id) + # sale_order = SaleOrder.new + self.sale_id = sale_id + self.order_id = order_id + self.save! end def self.sync_sale_order_records(sale_orders) diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 00068313..445a3f84 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -1,4 +1,5 @@ # require 'prawn/qrcode' +require 'prawn/measurement_extensions' class ReceiptBillPdf < Prawn::Document include ActionView::Helpers::NumberHelper @@ -685,10 +686,14 @@ class ReceiptBillPdf < Prawn::Document end def pay_by_kbzpay(status, qr_code) - if status == 'Paid' + if status == 'Frt' + move_down line_move + move_down line_move + text "KBZ Pay", :size => self.header_font_size+2, :align => :center + move_down line_move + print_qr_code(qr_code, pos: [30, cursor], extent: 160, stroke: false, dot: 1000) + # stroke_horizontal_rule move_down line_move - print_qr_code(qr_code, pos: [20, cursor], extent: 200, stroke: true) - stroke_horizontal_rule end end