fix creditentail to be dynamic

This commit is contained in:
aungthetkhaing
2025-05-26 13:18:33 +06:30
parent 1768345299
commit da6a80a9bb

View File

@@ -5,24 +5,29 @@ class KbzMerchant
def initialize(payment_method) def initialize(payment_method)
@payment_method = payment_method @payment_method = payment_method
@url = @payment_method.gateway_url
json_params = @payment_method.additional_parameters.inspect.undump
params = JSON.parse(json_params)
@notify_url = params['notify_url']
@app_id = params['app_id']
end end
def create_order(amount:, merch_order_id:, timeout: '120m') def create_order(amount:, merch_order_id:, timeout: '120m')
api_url = 'http://api.kbzpay.com/payment/gateway/uat/precreate' api_url = "#{@url}/precreate"
payload = build_create_payload(amount, merch_order_id, timeout) payload = build_create_payload(amount, merch_order_id, timeout)
response = send_request(payload, api_url) response = send_request(payload, api_url)
handle_response(response) handle_response(response)
end end
def close_order(merch_order_id:) def close_order(merch_order_id:)
api_url ='http://api.kbzpay.com/payment/gateway/uat/closeorder' api_url = "#{@url}/closeorder"
payload = build_close_payload(merch_order_id) payload = build_close_payload(merch_order_id)
response = send_request(payload, api_url) response = send_request(payload, api_url)
handle_response(response) handle_response(response)
end end
def query_order(merch_order_id:) def query_order(merch_order_id:)
api_url = 'http://api.kbzpay.com/payment/gateway/uat/queryorder' api_url = "#{@url}/queryorder"
payload = build_query_payload(merch_order_id) payload = build_query_payload(merch_order_id)
response = send_request(payload, api_url) response = send_request(payload, api_url)
handle_response(response) handle_response(response)
@@ -31,18 +36,15 @@ class KbzMerchant
private private
def build_create_payload(amount, merch_order_id, timeout) def build_create_payload(amount, merch_order_id, timeout)
json_params = @payment_method.additional_parameters.inspect.undump
params = JSON.parse(json_params)
byebug
base_params = { base_params = {
method: 'kbz.payment.precreate', method: 'kbz.payment.precreate',
timestamp: Time.now.utc.to_i.to_s, timestamp: Time.now.utc.to_i.to_s,
nonce_str: SecureRandom.hex(16), nonce_str: SecureRandom.hex(16),
notify_url: params['notify_url'], notify_url: @notify_url,
sign_type: 'SHA256', sign_type: 'SHA256',
version: '1.0', version: '1.0',
biz_content: { biz_content: {
appid: @payment_method.gateway_url, appid: @app_id,
merch_code: @payment_method.merchant_account_id, merch_code: @payment_method.merchant_account_id,
merch_order_id: merch_order_id, merch_order_id: merch_order_id,
trade_type: 'PAY_BY_QRCODE', trade_type: 'PAY_BY_QRCODE',
@@ -64,7 +66,7 @@ class KbzMerchant
sign_type: 'SHA256', sign_type: 'SHA256',
version: '3.0', version: '3.0',
biz_content: { biz_content: {
appid: @payment_method.gateway_url, appid: @app_id,
merch_code: @payment_method.merchant_account_id, merch_code: @payment_method.merchant_account_id,
merch_order_id: merch_order_id merch_order_id: merch_order_id
}.compact }.compact