fix
This commit is contained in:
@@ -1,14 +1,11 @@
|
|||||||
class Api::Payment::MobilepaymentController < Api::ApiController
|
class Api::Payment::MobilepaymentController < Api::ApiController
|
||||||
|
|
||||||
# skip_before_action :authenticate
|
# skip_before_action :authenticate
|
||||||
|
|
||||||
def cash
|
def cash
|
||||||
|
|
||||||
cash = params[:cash]
|
cash = params[:cash]
|
||||||
sale_id = params[:sale_id]
|
sale_id = params[:sale_id]
|
||||||
member_info = nil
|
|
||||||
type = params[:type]
|
|
||||||
tax_type = params[:tax_type]
|
|
||||||
path = request.fullpath
|
|
||||||
latest_order_no = nil
|
|
||||||
cashier_id = params[:cashier_id]
|
cashier_id = params[:cashier_id]
|
||||||
|
|
||||||
current_user = Employee.find(cashier_id)
|
current_user = Employee.find(cashier_id)
|
||||||
@@ -47,7 +44,17 @@ class Api::Payment::MobilepaymentController < Api::ApiController
|
|||||||
|
|
||||||
else
|
else
|
||||||
@out =false,"Something wrong!"
|
@out =false,"Something wrong!"
|
||||||
|
sale_payment = SalePayment.new
|
||||||
|
sale_payment = sale_payment.process_payment(saleObj, current_user, cash, "cash")
|
||||||
|
if sale_payment[0]
|
||||||
|
@cash = {"change_amount"=>sale_payment[3],"balance_amount"=>sale_payment[4] ,"receipt_url"=>''}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def kbz_pay
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
54
app/models/kbz_pay.rb
Normal file
54
app/models/kbz_pay.rb
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
class KbzPay
|
||||||
|
|
||||||
|
def self.pay(amount, receipt_no)
|
||||||
|
|
||||||
|
datetime = DateTime.now.strftime("%d%m%Y%H%M")
|
||||||
|
kbz_app_id = "kp1e78f7efddca190042638341afb88d"
|
||||||
|
kbz_merch_code = "200004"
|
||||||
|
kbz_method = 'kbz.payment.precreate'
|
||||||
|
kbz_trade_type = "PAY_BY_QRCODE"
|
||||||
|
kbz_api_key = "code2lab123456"
|
||||||
|
kbz_version = "1.0"
|
||||||
|
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+"¬ify_url="+ kbz_callback_url + "×tamp="+datetime+"&total_amount="+amount.to_s+"&trade_type="+kbz_trade_type+"&trans_currency="+ kbz_currency+"&version="+kbz_version+"&key="+kbz_api_key
|
||||||
|
|
||||||
|
Rails.logger.info params
|
||||||
|
sign = Digest::SHA256.hexdigest(params)
|
||||||
|
str = {"timestamp": datetime,
|
||||||
|
"method": kbz_method,
|
||||||
|
"notify_url": kbz_callback_url,
|
||||||
|
"nonce_str": nounce_str.to_s,
|
||||||
|
"sign_type": "SHA256",
|
||||||
|
"sign": sign,
|
||||||
|
"version": kbz_version,
|
||||||
|
"biz_content": {
|
||||||
|
"merch_order_id": receipt_no,
|
||||||
|
"merch_code": kbz_merch_code,
|
||||||
|
"appid": kbz_app_id,
|
||||||
|
"trade_type": kbz_trade_type,
|
||||||
|
"total_amount": amount.to_s,
|
||||||
|
"trans_currency": kbz_currency
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result = HTTParty.post(kbz_provider_url,
|
||||||
|
:body => { :Request => str}.to_json,
|
||||||
|
:headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
|
||||||
|
)
|
||||||
|
Rails.logger.info result
|
||||||
|
if result['Response']['result'] == "SUCCESS"
|
||||||
|
#TODO QR return
|
||||||
|
qr = result['Response']['qrCode']
|
||||||
|
return true, qr
|
||||||
|
else
|
||||||
|
return false, result['Response']
|
||||||
|
puts result['Response']
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -90,6 +90,8 @@ class SalePayment < ApplicationRecord
|
|||||||
payment_status,membership_data = dinga_payment
|
payment_status,membership_data = dinga_payment
|
||||||
when "GiftVoucher"
|
when "GiftVoucher"
|
||||||
payment_status = giftvoucher_payment
|
payment_status = giftvoucher_payment
|
||||||
|
when "KbzPay"
|
||||||
|
payment_status = giftvoucher_payment
|
||||||
else
|
else
|
||||||
puts "it was something else"
|
puts "it was something else"
|
||||||
end
|
end
|
||||||
@@ -582,6 +584,15 @@ class SalePayment < ApplicationRecord
|
|||||||
return payment_status
|
return payment_status
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def kbz_payment
|
||||||
|
payment_status = false
|
||||||
|
status, response = KbzPay.pay(amount, receipt_no)
|
||||||
|
if status
|
||||||
|
payment_status = true
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def sale_update_payment_status(paid_amount,check_foc = false)
|
def sale_update_payment_status(paid_amount,check_foc = false)
|
||||||
#update amount_outstanding
|
#update amount_outstanding
|
||||||
self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f
|
self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f
|
||||||
|
|||||||
@@ -1,2 +1,10 @@
|
|||||||
json.set! :status, @out[0]
|
# json.set! :status, @out[0]
|
||||||
json.set! :data, @out[1]
|
# json.set! :data, @out[1]
|
||||||
|
#
|
||||||
|
|
||||||
|
if @cash
|
||||||
|
json.status true
|
||||||
|
else
|
||||||
|
json.status false
|
||||||
|
json.data @cash
|
||||||
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user