fix : qr code generation to be dynamic
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user