fix conflict

This commit is contained in:
Myat Zin Wai Maw
2019-08-05 11:41:44 +06:30
4 changed files with 48 additions and 38 deletions

View File

@@ -3,21 +3,22 @@ class KbzPay
KBZ_PAY = 'KBZPay'
def self.pay(amount, receipt_no, url, key, app_id, code)
shop = Shop.first
prefix = shop.shop_code
receipt_no = "#{prefix}#{receipt_no}"
datetime = DateTime.now.strftime("%d%m%Y%H%M")
kbz_app_id = app_id
kbz_merch_code = code
# kbz_app_id = "kp1e78f7efddca190042638341afb88d"
# kbz_merch_code = "200004"
kbz_merch_code = code
kbz_api_key = key
kbz_provider_url = "#{url}/precreate"
kbz_method = 'kbz.payment.precreate'
kbz_trade_type = "PAY_BY_QRCODE"
kbz_api_key = key
# kbz_api_key = "code2lab123456"
kbz_version = "1.0"
kbz_provider_url = url
# kbz_provider_url = "http://api.kbzpay.com/payment/gateway/uat/precreate"
kbz_currency = "MMK"
kbz_callback_url = "https://staging-v2.doemal.com/api/v3/ordering/kbz_callback"
nounce_str = SecureRandom.base64(32).first(32).upcase
params = "appid="+kbz_app_id+"&merch_code="+kbz_merch_code+"&merch_order_id="+receipt_no.to_s+"&method="+kbz_method+"&nonce_str="+nounce_str.to_s+"&notify_url="+ kbz_callback_url + "&timeout_express=20m&timestamp="+datetime+"&total_amount="+amount.to_s+"&trade_type="+kbz_trade_type+"&trans_currency="+ kbz_currency+"&version="+kbz_version+"&key="+kbz_api_key
@@ -48,29 +49,35 @@ class KbzPay
:headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
)
Rails.logger.info result
Rails.logger.info '===================================='
if result['Response']['result'] == "SUCCESS"
#TODO QR return
qr = result['Response']['qrCode']
return true, qr
else
# Rails.logger.debug result['Response']
return false, result['Response']
puts result['Response']
end
end
def self.query(receipt_no, current_user)
def self.query(receipt_no, current_user, url, key, app_id, code)
shop = Shop.first
prefix = shop.shop_code
receipt_no = "#{prefix}#{receipt_no}"
amount = 0
datetime = DateTime.now.strftime("%d%m%Y%H%M")
kbz_app_id = "kp1e78f7efddca190042638341afb88d"
kbz_merch_code = "200004"
kbz_app_id = app_id
kbz_merch_code = code
kbz_api_key = key
kbz_provider_url = "#{url}/queryorder"
kbz_method = 'kbz.payment.queryorder'
kbz_trade_type = "APP"
kbz_api_key = "code2lab123456"
kbz_trade_type = "PAY_BY_QRCODE"
kbz_version = "1.0"
kbz_provider_url = "http://api.kbzpay.com/payment/gateway/uat/queryorder"
kbz_currency = "MMK"
kbz_callback_url = "https://staging-v2.doemal.com/api/v3/ordering/kbz_callback"
nounce_str = SecureRandom.base64(32).first(32).upcase
params = "appid="+kbz_app_id+"&merch_code="+kbz_merch_code+"&merch_order_id="+receipt_no.to_s+"&method="+kbz_method+"&nonce_str="+nounce_str.to_s+"&timestamp="+datetime+"&version="+kbz_version+"&key="+kbz_api_key
@@ -101,6 +108,8 @@ class KbzPay
merch_order_id = result['Response']['merch_order_id']
cash = result['Response']['total_amount']
merch_order_id.slice! "#{prefix}"
sp = SalePayment.find(merch_order_id)
if !sp.nil?
if sp.payment_status == 'pending'

View File

@@ -62,29 +62,29 @@ class SaleItem < ApplicationRecord
item.save
menu_category = MenuCategory.get_menu_category(item.product_code) #get menu category for menu items
sale_item = SaleItem.new
sale_item.menu_category_code = menu_category.code ? menu_category.code : nil
sale_item.menu_category_name = menu_category.name
sale_item.product_code = item.product_code
sale_item.item_instance_code = item.item_instance_code
sale_item.product_name = item.product_name + " (#{type.upcase})"
sale_item.product_alt_name = item.product_alt_name
sale_item.account_id = item.account_id
sale_item.status = type
sale_item.remark = type
if type == "foc" || type == "promotion" || type == "void" || type == "waste" || type == "spoile"
sale_item.qty = qty * (-1)
else
sale_item.qty = qty
end
# sale_item = SaleItem.new
# sale_item.menu_category_code = menu_category.code ? menu_category.code : nil
# sale_item.menu_category_name = menu_category.name
# sale_item.product_code = item.product_code
# sale_item.item_instance_code = item.item_instance_code
# sale_item.product_name = item.product_name + " (#{type.upcase})"
# sale_item.product_alt_name = item.product_alt_name
# sale_item.account_id = item.account_id
# sale_item.status = type
# sale_item.remark = type
# if type == "foc" || type == "promotion" || type == "void" || type == "waste" || type == "spoile"
# sale_item.qty = qty * (-1)
# else
# sale_item.qty = qty
# end
sale_item.unit_price = item_price # * (-1)
sale_item.taxable_price = (price) * (-1)
sale_item.price = (price) * (-1)
# sale_item.unit_price = item_price # * (-1)
# sale_item.taxable_price = (price) * (-1)
# sale_item.price = (price) * (-1)
sale_item.is_taxable = 1
sale_item.sale_id = sale_id
sale_item.save
# sale_item.is_taxable = 1
# sale_item.sale_id = sale_id
# sale_item.save
sale = Sale.find(sale_id)
sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount)
end

View File

@@ -31,10 +31,11 @@ class SalePayment < ApplicationRecord
def self.get_kbz_pay_amount(sale_id, current_user)
amount = 0
kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last
sale_payment = SalePayment.where('sale_id=? and payment_method=? and payment_status!=?', sale_id, KbzPay::KBZ_PAY, 'dead').last
if !sale_payment.nil?
if !sale_payment.nil? and !kbz_pay_method.nil?
if sale_payment.payment_status == 'pending'
amount = KbzPay.query(sale_payment.id, current_user)
amount = KbzPay.query(sale_payment.id, current_user, kbz_pay_method.gateway_url, kbz_pay_method.auth_token, kbz_pay_method.merchant_account_id, kbz_pay_method.additional_parameters)
elsif sale_payment.payment_status == 'paid'
amount = sale_payment.payment_amount
end