Class: DkPaymentGateway::QrPayment

Inherits:
Object
  • Object
show all
Defined in:
lib/dk_payment_gateway/qr_payment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ QrPayment

Returns a new instance of QrPayment.



7
8
9
# File 'lib/dk_payment_gateway/qr_payment.rb', line 7

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/dk_payment_gateway/qr_payment.rb', line 5

def client
  @client
end

Instance Method Details

#generate_qr(params) ⇒ Hash

Generate QR Code for payment transaction

If amount = 0, generates a Static QR (payer enters amount) If amount > 0, generates a Dynamic QR (amount is fixed)

Parameters:

  • params (Hash)

    QR generation parameters

Options Hash (params):

  • :request_id (String)

    Unique identifier for the request

  • :currency (String)

    Currency code (e.g., “BTN”)

  • :bene_account_number (String)

    Beneficiary account number

  • :amount (Numeric)

    Transaction amount (0 for static QR, >0 for dynamic QR)

  • :mcc_code (String)

    Merchant Category Code (ISO 18245)

  • :remarks (String)

    Optional notes or comments (optional)

Returns:

  • (Hash)

    Response containing base64 encoded QR image



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dk_payment_gateway/qr_payment.rb', line 25

def generate_qr(params)
  validate_qr_params!(params)

  request_body = build_qr_body(params)
  signature_headers = generate_signature_headers(request_body)

  response = client.post(
    '/v1/generate_qr',
    body: request_body.to_json,
    headers: signature_headers
  )

  validate_response!(response, 'QR Generation')
  response['response_data']
end

#save_qr_image(base64_image, file_path) ⇒ Object

Decode base64 QR image and save to file

Parameters:

  • base64_image (String)

    Base64 encoded image

  • file_path (String)

    Path to save the image



44
45
46
47
48
49
50
51
# File 'lib/dk_payment_gateway/qr_payment.rb', line 44

def save_qr_image(base64_image, file_path)
  require 'base64'

  image_data = Base64.decode64(base64_image)
  File.open(file_path, 'wb') { |f| f.write(image_data) }

  file_path
end