Module: LoyverseApi::Endpoints::Receipts

Included in:
Client
Defined in:
lib/loyverse_api/endpoints/receipts.rb

Instance Method Summary collapse

Instance Method Details

#create_receipt(receipt_date:, store_id:, line_items:, payments:, receipt_type: "SALE", employee_id: nil, customer_id: nil, note: nil, source: "API") ⇒ Hash

Create a new receipt

Parameters:

  • receipt_date (String, Time) —

    Receipt date in ISO 8601 format

  • store_id (String) —

    UUID of the store

  • line_items (Array<Hash>) —

    Array of line item hashes

  • payments (Array<Hash>) —

    Array of payment hashes

  • receipt_type (String) (defaults to: "SALE") —

    Type of receipt (default: "SALE")

  • employee_id (String) (defaults to: nil) —

    UUID of the employee (optional)

  • customer_id (String) (defaults to: nil) —

    UUID of the customer (optional)

  • note (String) (defaults to: nil) —

    Receipt note (optional)

  • source (String) (defaults to: "API") —

    Source of receipt (default: "API")

Returns:

  • (Hash) —

    Created receipt details



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
# File 'lib/loyverse_api/endpoints/receipts.rb', line 54

def create_receipt(
  receipt_date:,
  store_id:,
  line_items:,
  payments:,
  receipt_type: "SALE",
  employee_id: nil,
  customer_id: nil,
  note: nil,
  source: "API"
)
  body = {
    receipt_date: format_time(receipt_date),
    receipt_type: receipt_type,
    store_id: store_id,
    line_items: line_items,
    payments: payments,
    source: source
  }
  body[:employee_id] = employee_id if employee_id
  body[:customer_id] = customer_id if customer_id
  body[:note] = note if note

  post("receipts", body: body)
end

#create_refund(receipt_number, refund_date:, line_items:, payments:, employee_id: nil, note: nil) ⇒ Hash

Create a refund for a receipt

Parameters:

  • receipt_number (String, Integer) —

    Receipt number to refund

  • refund_date (String, Time) —

    Refund date in ISO 8601 format

  • line_items (Array<Hash>) —

    Array of line items to refund

  • payments (Array<Hash>) —

    Array of refund payments

  • employee_id (String) (defaults to: nil) —

    UUID of the employee (optional)

  • note (String) (defaults to: nil) —

    Refund note (optional)

Returns:

  • (Hash) —

    Created refund receipt details



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/loyverse_api/endpoints/receipts.rb', line 88

def create_refund(receipt_number, refund_date:, line_items:, payments:, employee_id: nil, note: nil)
  body = {
    refund_date: format_time(refund_date),
    line_items: line_items,
    payments: payments
  }
  body[:employee_id] = employee_id if employee_id
  body[:note] = note if note

  post("receipts/#{receipt_number}/refund", body: body)
end

#get_receipt(receipt_number) ⇒ Hash

Get a specific receipt by receipt number

Parameters:

  • receipt_number (String, Integer) —

    Receipt number (not UUID)

Returns:

  • (Hash) —

    Receipt details



7
8
9
# File 'lib/loyverse_api/endpoints/receipts.rb', line 7

def get_receipt(receipt_number)
  get("receipts/#{receipt_number}")
end

#list_receipts(limit: 100, **options) ⇒ Hash

List receipts

Parameters:

  • limit (Integer) (defaults to: 100) —

    Maximum number of results per page (default: 250)

  • options (Hash) —

    Optional filters

Options Hash (**options):

  • :receipt_numbers (Array<String, Integer>) —

    Array of specific receipt numbers

  • :since_receipt_number (String, Integer) —

    Return receipts after this number

  • :before_receipt_number (String, Integer) —

    Return receipts before this number

  • :store_id (String) —

    Filter by store UUID

  • :source (String) —

    Filter by source (e.g., "POS", "API")

  • :updated_at_min (String, Time) —

    Filter by minimum update time

  • :updated_at_max (String, Time) —

    Filter by maximum update time

  • :created_at_min (String, Time) —

    Filter by minimum creation time

  • :created_at_max (String, Time) —

    Filter by maximum creation time

  • :cursor (String) —

    Pagination cursor for next page

Returns:

  • (Hash) —

    Response with receipts array



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/loyverse_api/endpoints/receipts.rb', line 25

def list_receipts(limit: 100, **options)
  params = {
    limit: limit,
    receipt_numbers: options[:receipt_numbers] ? Array(options[:receipt_numbers]).join(",") : nil,
    since_receipt_number: options[:since_receipt_number],
    before_receipt_number: options[:before_receipt_number],
    store_id: options[:store_id],
    source: options[:source],
    cursor: options[:cursor],
    updated_at_min: format_time(options[:updated_at_min]),
    updated_at_max: format_time(options[:updated_at_max]),
    created_at_min: format_time(options[:created_at_min]),
    created_at_max: format_time(options[:created_at_max])
  }.compact

  get("receipts", params: params)
end