Class: DkPaymentGateway::QrPayment
- Inherits:
-
Object
- Object
- DkPaymentGateway::QrPayment
- Defined in:
- lib/dk_payment_gateway/qr_payment.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#generate_qr(params) ⇒ Hash
Generate QR Code for payment transaction.
-
#initialize(client) ⇒ QrPayment
constructor
A new instance of QrPayment.
-
#save_qr_image(base64_image, file_path) ⇒ Object
Decode base64 QR image and save to file.
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
#client ⇒ Object (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)
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
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 |