Class: Komoju::BarcodesApi

Inherits:
Object
  • Object
show all
Defined in:
lib/komoju-sdk/api/barcodes_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_clientObject

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>

Parameters:

  • payment_id (String)

    Payment unique identifier

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



27
28
29
30
# File 'lib/komoju-sdk/api/barcodes_api.rb', line 27

def show_barcode(payment_id, opts = {})
  data, _status_code, _headers = show_barcode_with_http_info(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 &#x60;barcode_url&#x60; field in its &#x60;payment_details&#x60; 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 &#x60;status&#x60; of &#x60;pending&#x60; and a &#x60;retry_after&#x60; 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. &lt;details&gt; &lt;summary&gt;Fetching barcodes in JavaScript&lt;/summary&gt; If you&#39;re integrating barcodes on your website, the following JavaScript function can be used to fetch barcode data, handling the pending status and retrying. The &#x60;barcode_url&#x60; parameter is returned from Payments APIs when the payment is compatible with barcodes. &#x60;&#x60;&#x60;javascript async function fetchBarcode(barcode_url) { const response &#x3D; await fetch(barcode_url); if (!response.ok) { throw new Error( &#x60;Error fetching barcode: $Komoju::BarcodesApi.responseresponse.status $Komoju::BarcodesApi.responseresponse.statusText&#x60; ); } const { status, retry_after, …barcode } &#x3D; await response.json(); if (status &#x3D;&#x3D;&#x3D; &#39;ready&#39;) { return barcode; } else if (status &#x3D;&#x3D;&#x3D; &#39;pending&#39;) { await new Promise(resolve &#x3D;&gt; setTimeout(resolve, retry_after * 1000)); return fetchBarcode(barcode_url); } else { throw new Error(&#x60;Error fetching barcode: unexpected status $status&#x60;); } } &#x60;&#x60;&#x60; &lt;/details&gt;

Parameters:

  • payment_id (String)

    Payment unique identifier

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(ShowBarcodeResponse, Integer, Hash)>)

    ShowBarcodeResponse data, response status code and response headers



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 show_barcode_with_http_info(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']

  new_options = 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, new_options)
  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