class VoucherifySdk::OrdersApi

Attributes

api_client[RW]

Public Class Methods

new(api_client = ApiClient.default) click to toggle source
# File lib/VoucherifySdk/api/orders_api.rb, line 19
def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Public Instance Methods

create_order(opts = {}) click to toggle source

Create Order Creates an order object and triggers an order creation event. 📘 Upsert Mode If you pass an id or a source_id that already exists in the order database, Voucherify will return a related order object with updated fields. @param [Hash] opts the optional parameters @option opts [OrdersCreateRequestBody] :orders_create_request_body Specify the order parameters. @return [OrdersCreateResponseBody]

# File lib/VoucherifySdk/api/orders_api.rb, line 27
def create_order(opts = {})
  data, _status_code, _headers = create_order_with_http_info(opts)
  data
end
create_order_export(opts = {}) click to toggle source

Create Orders Export Creates a downloadable CSV file containing a list of orders. The parameters listed in the payload resembles headers in the CSV file. To include a parameter to the file, add it to the parameters.fields object in the request body. The available filters are all order object attributes. Additionally, any metadata defined in the metadata schema can be exported. Passing an empty JSON will generate a file containing three default fields: id, source_id, and status. The fields array is an array of strings containing the data in the export. These fields define the headers in the CSV file. The array can be a combination of any of the following available fields:

@param [Hash] opts the optional parameters @option opts [OrdersExportCreateRequestBody] :orders_export_create_request_body Specify which order parameters you would like to export. @return [OrdersExportCreateResponseBody]

# File lib/VoucherifySdk/api/orders_api.rb, line 91
def create_order_export(opts = {})
  data, _status_code, _headers = create_order_export_with_http_info(opts)
  data
end
get_order(order_id, opts = {}) click to toggle source

Get Order Retrieve an order. @param order_id [String] Unique Voucherify order ID or order source ID. @param [Hash] opts the optional parameters @return [OrdersGetResponseBody]

# File lib/VoucherifySdk/api/orders_api.rb, line 155
def get_order(order_id, opts = {})
  data, _status_code, _headers = get_order_with_http_info(order_id, opts)
  data
end
import_orders(opts = {}) click to toggle source

Import Orders

🚧 Historical orders  This endpoint should only be used to import historical orders into Voucherify. For on-going synchronization, the create order and update order endpoints should be used. This is critical because this endpoint does not store events or launch distributions. # Limitations ## Import volume There can be only a single on-going order import per tenant per project at a given time. The user can schedule more imports but those extra imports will be scheduled to run in sequence one by one.   ## Maximum count of orders in single import There is a 2000 limit but we might decide to change it to a lower / higher value at any given time depending if we find this value is too high or too low with time. # Notifications There are no notifications on the Dashboard because this import is launched via the API. # Triggered actions    If you import orders with customers, then a logic will be scheduled responsible for placing these customers into segments and refreshing the segments summary. Consequently, this update will trigger  - **customers entering into segments**  - **distributions** based on any rules tied to customer entering segment(s) - **earning rules** based on the customer entering segment(s) # What is not triggered 1. No webhooks are triggered during the import of orders - for both orders and upserted products / skus.   2. Distributions based on Order Update, Order Paid, Order Created and Order Cancelled. In other words if you have a distribution based on Order Paid and you import an order with a PAID status, the distribution is not going to be triggered.     3. No events are created during the import of orders - for both orders and upserted products / skus. In other words you wont see any events in the Activity tab in the Dashboard such as Order created or Order paid. If you are additionally upserting products / skus, then you wont see the Product created events listed, etc.    4. Earning rules based on Order Paid wont be triggered. This API request starts a process that affects Voucherify data in bulk.  In case of small jobs (like bulk update) the request is put into a queue and processed once every other bulk request placed in the queue prior to this request is finished. However, when the job takes a longer time (like vouchers generation) then it is processed in small portions in a round-robin fashion. When there is a list of vouchers generation scheduled, then they will all have the IN_PROGRESS status shortly. This way, small jobs added just after scheduling big jobs of the same type will be processed in a short time window.  The result will return the async ID. You can verify the status of your request via this API request.

@param [Hash] opts the optional parameters @option opts [Array<OrdersImportCreateRequestBodyItem>] :orders_import_create_request_body_item The request body is sent in the form of an array of order objects. @return [OrdersImportCreateResponseBody]

# File lib/VoucherifySdk/api/orders_api.rb, line 214
def import_orders(opts = {})
  data, _status_code, _headers = import_orders_with_http_info(opts)
  data
end
list_orders(opts = {}) click to toggle source

List Orders Returns a list of orders. @param [Hash] opts the optional parameters @option opts [Integer] :limit Limits the number of objects to be returned. The limit can range between 1 and 100 items. If no limit is set, it returns 10 items. @option opts [Integer] :page Which page of results to return. The lowest value is 1. @option opts [ParameterOrderListOrders] :order This is a property that controls the sorting direction of the results. Sort the results using one of the filtering options, where the dash - preceding a sorting option means sorting in a descending order. @return [OrdersListResponseBody]

# File lib/VoucherifySdk/api/orders_api.rb, line 280
def list_orders(opts = {})
  data, _status_code, _headers = list_orders_with_http_info(opts)
  data
end
update_order(order_id, opts = {}) click to toggle source

Update Order Updates the specified order by setting the values of the parameters passed in the request body. Any parameters not provided will be left unchanged. @param order_id [String] Unique Voucherify order ID or order source ID. @param [Hash] opts the optional parameters @option opts [OrdersUpdateRequestBody] :orders_update_request_body Specify the parameters of the order that are to be updated. @return [OrdersUpdateResponseBody]

# File lib/VoucherifySdk/api/orders_api.rb, line 345
def update_order(order_id, opts = {})
  data, _status_code, _headers = update_order_with_http_info(order_id, opts)
  data
end

Private Instance Methods

create_order_export_with_http_info(opts = {}) click to toggle source

Create Orders Export Creates a downloadable CSV file containing a list of orders. The parameters listed in the payload resembles headers in the CSV file. To include a parameter to the file, add it to the parameters.fields object in the request body. The available filters are all order object attributes. Additionally, any metadata defined in the metadata schema can be exported. Passing an empty JSON will generate a file containing three default fields: id, source_id, and status. The fields array is an array of strings containing the data in the export. These fields define the headers in the CSV file. The array can be a combination of any of the following available fields:

@param [Hash] opts the optional parameters @option opts [OrdersExportCreateRequestBody] :orders_export_create_request_body Specify which order parameters you would like to export. @return [Array<(OrdersExportCreateResponseBody, Integer, Hash)>] OrdersExportCreateResponseBody data, response status code and response headers

# File lib/VoucherifySdk/api/orders_api.rb, line 101
        def create_order_export_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: OrdersApi.create_order_export ...'
  end
  # resource path
  local_var_path = '/v1/orders/export'

  # 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'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(opts[:'orders_export_create_request_body'])

  # return_type
  return_type = opts[:debug_return_type] || 'OrdersExportCreateResponseBody'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['X-App-Id', 'X-App-Token']

  new_options = opts.merge(
    :operation => :"OrdersApi.create_order_export",
    :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(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: OrdersApi#create_order_export\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end
create_order_with_http_info(opts = {}) click to toggle source

Create Order Creates an order object and triggers an order creation event. 📘 Upsert Mode If you pass an id or a source_id that already exists in the order database, Voucherify will return a related order object with updated fields. @param [Hash] opts the optional parameters @option opts [OrdersCreateRequestBody] :orders_create_request_body Specify the order parameters. @return [Array<(OrdersCreateResponseBody, Integer, Hash)>] OrdersCreateResponseBody data, response status code and response headers

# File lib/VoucherifySdk/api/orders_api.rb, line 37
        def create_order_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: OrdersApi.create_order ...'
  end
  # resource path
  local_var_path = '/v1/orders'

  # 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'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(opts[:'orders_create_request_body'])

  # return_type
  return_type = opts[:debug_return_type] || 'OrdersCreateResponseBody'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['X-App-Id', 'X-App-Token']

  new_options = opts.merge(
    :operation => :"OrdersApi.create_order",
    :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(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: OrdersApi#create_order\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end
get_order_with_http_info(order_id, opts = {}) click to toggle source

Get Order Retrieve an order. @param order_id [String] Unique Voucherify order ID or order source ID. @param [Hash] opts the optional parameters @return [Array<(OrdersGetResponseBody, Integer, Hash)>] OrdersGetResponseBody data, response status code and response headers

# File lib/VoucherifySdk/api/orders_api.rb, line 165
        def get_order_with_http_info(order_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: OrdersApi.get_order ...'
  end
  # resource path
  local_var_path = '/v1/orders/{orderId}'.sub('{' + 'orderId' + '}', CGI.escape(order_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'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'OrdersGetResponseBody'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['X-App-Id', 'X-App-Token']

  new_options = opts.merge(
    :operation => :"OrdersApi.get_order",
    :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: OrdersApi#get_order\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end
import_orders_with_http_info(opts = {}) click to toggle source

Import Orders

🚧 Historical orders  This endpoint should only be used to import historical orders into Voucherify. For on-going synchronization, the create order and update order endpoints should be used. This is critical because this endpoint does not store events or launch distributions. # Limitations ## Import volume There can be only a single on-going order import per tenant per project at a given time. The user can schedule more imports but those extra imports will be scheduled to run in sequence one by one.   ## Maximum count of orders in single import There is a 2000 limit but we might decide to change it to a lower / higher value at any given time depending if we find this value is too high or too low with time. # Notifications There are no notifications on the Dashboard because this import is launched via the API. # Triggered actions    If you import orders with customers, then a logic will be scheduled responsible for placing these customers into segments and refreshing the segments summary. Consequently, this update will trigger  - **customers entering into segments**  - **distributions** based on any rules tied to customer entering segment(s) - **earning rules** based on the customer entering segment(s) # What is not triggered 1. No webhooks are triggered during the import of orders - for both orders and upserted products / skus.   2. Distributions based on Order Update, Order Paid, Order Created and Order Cancelled. In other words if you have a distribution based on Order Paid and you import an order with a PAID status, the distribution is not going to be triggered.     3. No events are created during the import of orders - for both orders and upserted products / skus. In other words you wont see any events in the Activity tab in the Dashboard such as Order created or Order paid. If you are additionally upserting products / skus, then you wont see the Product created events listed, etc.    4. Earning rules based on Order Paid wont be triggered. This API request starts a process that affects Voucherify data in bulk.  In case of small jobs (like bulk update) the request is put into a queue and processed once every other bulk request placed in the queue prior to this request is finished. However, when the job takes a longer time (like vouchers generation) then it is processed in small portions in a round-robin fashion. When there is a list of vouchers generation scheduled, then they will all have the IN_PROGRESS status shortly. This way, small jobs added just after scheduling big jobs of the same type will be processed in a short time window.  The result will return the async ID. You can verify the status of your request via this API request.

@param [Hash] opts the optional parameters @option opts [Array<OrdersImportCreateRequestBodyItem>] :orders_import_create_request_body_item The request body is sent in the form of an array of order objects. @return [Array<(OrdersImportCreateResponseBody, Integer, Hash)>] OrdersImportCreateResponseBody data, response status code and response headers

# File lib/VoucherifySdk/api/orders_api.rb, line 224
        def import_orders_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: OrdersApi.import_orders ...'
  end
  # resource path
  local_var_path = '/v1/orders/import'

  # 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'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(opts[:'orders_import_create_request_body_item'])

  # return_type
  return_type = opts[:debug_return_type] || 'OrdersImportCreateResponseBody'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['X-App-Id', 'X-App-Token']

  new_options = opts.merge(
    :operation => :"OrdersApi.import_orders",
    :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(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: OrdersApi#import_orders\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end
list_orders_with_http_info(opts = {}) click to toggle source

List Orders Returns a list of orders. @param [Hash] opts the optional parameters @option opts [Integer] :limit Limits the number of objects to be returned. The limit can range between 1 and 100 items. If no limit is set, it returns 10 items. @option opts [Integer] :page Which page of results to return. The lowest value is 1. @option opts [ParameterOrderListOrders] :order This is a property that controls the sorting direction of the results. Sort the results using one of the filtering options, where the dash - preceding a sorting option means sorting in a descending order. @return [Array<(OrdersListResponseBody, Integer, Hash)>] OrdersListResponseBody data, response status code and response headers

# File lib/VoucherifySdk/api/orders_api.rb, line 292
        def list_orders_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: OrdersApi.list_orders ...'
  end
  # resource path
  local_var_path = '/v1/orders'

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
  query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?
  query_params[:'order'] = opts[:'order'] if !opts[:'order'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'OrdersListResponseBody'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['X-App-Id', 'X-App-Token']

  new_options = opts.merge(
    :operation => :"OrdersApi.list_orders",
    :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: OrdersApi#list_orders\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end
update_order_with_http_info(order_id, opts = {}) click to toggle source

Update Order Updates the specified order by setting the values of the parameters passed in the request body. Any parameters not provided will be left unchanged. @param order_id [String] Unique Voucherify order ID or order source ID. @param [Hash] opts the optional parameters @option opts [OrdersUpdateRequestBody] :orders_update_request_body Specify the parameters of the order that are to be updated. @return [Array<(OrdersUpdateResponseBody, Integer, Hash)>] OrdersUpdateResponseBody data, response status code and response headers

# File lib/VoucherifySdk/api/orders_api.rb, line 356
        def update_order_with_http_info(order_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: OrdersApi.update_order ...'
  end
  # resource path
  local_var_path = '/v1/orders/{orderId}'.sub('{' + 'orderId' + '}', CGI.escape(order_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'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(opts[:'orders_update_request_body'])

  # return_type
  return_type = opts[:debug_return_type] || 'OrdersUpdateResponseBody'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['X-App-Id', 'X-App-Token']

  new_options = opts.merge(
    :operation => :"OrdersApi.update_order",
    :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(:PUT, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: OrdersApi#update_order\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end