Class: Komoju::BarcodesApi
- Inherits:
-
Object
- Object
- Komoju::BarcodesApi
- Defined in:
- lib/komoju-sdk/api/barcodes_api.rb
Instance Attribute Summary collapse
-
#api_client ⇒ Object
Returns the value of attribute api_client.
Instance Method Summary collapse
-
#initialize(api_client = ApiClient.default) ⇒ BarcodesApi
constructor
A new instance of BarcodesApi.
-
#show_barcode(payment_id, opts = {}) ⇒ ShowBarcodeResponse
Barcode: Show Fetches the latest barcode for a konbini payment.
-
#show_barcode_with_http_info(payment_id, opts = {}) ⇒ Array<(ShowBarcodeResponse, Integer, Hash)>
Barcode: Show Fetches the latest barcode for a konbini payment.
Constructor Details
#initialize(api_client = ApiClient.default) ⇒ BarcodesApi
Returns a new instance of BarcodesApi.
19 20 21 |
# File 'lib/komoju-sdk/api/barcodes_api.rb', line 19 def initialize(api_client = ApiClient.default) @api_client = api_client end |
Instance Attribute Details
#api_client ⇒ Object
Returns the value of attribute api_client.
17 18 19 |
# File 'lib/komoju-sdk/api/barcodes_api.rb', line 17 def api_client @api_client end |
Instance Method Details
#show_barcode(payment_id, opts = {}) ⇒ ShowBarcodeResponse
Barcode: Show Fetches the latest barcode for a konbini payment. Barcodes can be displayed in your client application to give your customers a more convenient way to pay. Not all konbini payments are compatible with barcodes. If a payment is compatible, it will have a ‘barcode_url` field in its `payment_details` object, which is a reference to this endpoint. Newly created payments may not have a barcode available immediately. If the barcode is still being generated, the response will have a `status` of `pending` and a `retry_after` field indicating how many seconds to wait before you may retry the request. The barcodes can only be used for payment for a limited amount of time, by default this is 10 minutes. Subsequent requests to this endpoint will return the same barcode as long as it is still valid. After expiration, a new barcode will be generated and returned. <details> <summary>Fetching barcodes in JavaScript</summary> If you’re integrating barcodes on your website, the following JavaScript function can be used to fetch barcode data, handling the pending status and retrying. The ‘barcode_url` parameter is returned from Payments APIs when the payment is compatible with barcodes. “`javascript async function fetchBarcode(barcode_url) { const response = await fetch(barcode_url); if (!response.ok) { throw new Error( `Error fetching barcode: $Komoju::BarcodesApi.responseresponse.status $Komoju::BarcodesApi.responseresponse.statusText` ); } const { status, retry_after, …barcode } = await response.json(); if (status === ’ready’) { return barcode; } else if (status === ‘pending’) { await new Promise(resolve => setTimeout(resolve, retry_after * 1000)); return fetchBarcode(barcode_url); } else { throw new Error(‘Error fetching barcode: unexpected status $status`); } } “` </details>
27 28 29 30 |
# File 'lib/komoju-sdk/api/barcodes_api.rb', line 27 def (payment_id, opts = {}) data, _status_code, _headers = (payment_id, opts) data end |
#show_barcode_with_http_info(payment_id, opts = {}) ⇒ Array<(ShowBarcodeResponse, Integer, Hash)>
Barcode: Show Fetches the latest barcode for a konbini payment. Barcodes can be displayed in your client application to give your customers a more convenient way to pay. Not all konbini payments are compatible with barcodes. If a payment is compatible, it will have a `barcode_url` field in its `payment_details` object, which is a reference to this endpoint. Newly created payments may not have a barcode available immediately. If the barcode is still being generated, the response will have a `status` of `pending` and a `retry_after` field indicating how many seconds to wait before you may retry the request. The barcodes can only be used for payment for a limited amount of time, by default this is 10 minutes. Subsequent requests to this endpoint will return the same barcode as long as it is still valid. After expiration, a new barcode will be generated and returned. <details> <summary>Fetching barcodes in JavaScript</summary> If you're integrating barcodes on your website, the following JavaScript function can be used to fetch barcode data, handling the pending status and retrying. The `barcode_url` parameter is returned from Payments APIs when the payment is compatible with barcodes. ```javascript async function fetchBarcode(barcode_url) { const response = await fetch(barcode_url); if (!response.ok) { throw new Error( `Error fetching barcode: $Komoju::BarcodesApi.responseresponse.status $Komoju::BarcodesApi.responseresponse.statusText` ); } const { status, retry_after, …barcode } = await response.json(); if (status === 'ready') { return barcode; } else if (status === 'pending') { await new Promise(resolve => setTimeout(resolve, retry_after * 1000)); return fetchBarcode(barcode_url); } else { throw new Error(`Error fetching barcode: unexpected status $status`); } } ``` </details>
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/komoju-sdk/api/barcodes_api.rb', line 37 def (payment_id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: BarcodesApi.show_barcode ...' end # verify the required parameter 'payment_id' is set if @api_client.config.client_side_validation && payment_id.nil? fail ArgumentError, "Missing the required parameter 'payment_id' when calling BarcodesApi.show_barcode" end if @api_client.config.client_side_validation && payment_id.to_s.length > 25 fail ArgumentError, 'invalid value for "payment_id" when calling BarcodesApi.show_barcode, the character length must be smaller than or equal to 25.' end if @api_client.config.client_side_validation && payment_id.to_s.length < 25 fail ArgumentError, 'invalid value for "payment_id" when calling BarcodesApi.show_barcode, the character length must be great than or equal to 25.' end # resource path local_var_path = '/barcodes/{payment_id}'.sub('{' + 'payment_id' + '}', CGI.escape(payment_id.to_s)) # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept'] # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:debug_body] # return_type return_type = opts[:debug_return_type] || 'ShowBarcodeResponse' # auth_names auth_names = opts[:debug_auth_names] || ['api_key'] = opts.merge( :operation => :"BarcodesApi.show_barcode", :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) data, status_code, headers = @api_client.call_api(:GET, local_var_path, ) if @api_client.config.debugging @api_client.config.logger.debug "API called: BarcodesApi#show_barcode\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end |