Class: Portage::Ucp::Checkout

Inherits:
Data
  • Object
show all
Defined in:
lib/portage/ucp/value_objects.rb

Overview

schemas/shopping/checkout.json — requires ucp/id/line_items/status/ currency/totals/links. status is the real enum (incomplete, requires_escalation, ready_for_complete, complete_in_progress, completed, canceled) — not the old ad hoc "pending"/"completed" strings. order is the schema's optional order_confirmation — set once complete_checkout actually produces an order, nil otherwise. discounts — same dev.ucp.shopping.discount extension as Cart, above. fulfillment — the dev.ucp.shopping.fulfillment extension (optional, omitted from the wire payload when empty), same posture as Order#adjustments.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, status:, line_items:, currency:, totals:, links:, order: nil, discounts: Discounts.new, fulfillment: CheckoutFulfillment.new) ⇒ Checkout

Returns a new instance of Checkout.



417
418
419
420
# File 'lib/portage/ucp/value_objects.rb', line 417

def initialize(id:, status:, line_items:, currency:, totals:, links:, order: nil, discounts: Discounts.new,
               fulfillment: CheckoutFulfillment.new)
  super
end

Instance Attribute Details

#currencyObject (readonly)

Returns the value of attribute currency

Returns:

  • (Object)

    the current value of currency



415
416
417
# File 'lib/portage/ucp/value_objects.rb', line 415

def currency
  @currency
end

#discountsObject (readonly)

Returns the value of attribute discounts

Returns:

  • (Object)

    the current value of discounts



415
416
417
# File 'lib/portage/ucp/value_objects.rb', line 415

def discounts
  @discounts
end

#fulfillmentObject (readonly)

Returns the value of attribute fulfillment

Returns:

  • (Object)

    the current value of fulfillment



415
416
417
# File 'lib/portage/ucp/value_objects.rb', line 415

def fulfillment
  @fulfillment
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



415
416
417
# File 'lib/portage/ucp/value_objects.rb', line 415

def id
  @id
end

#line_itemsObject (readonly)

Returns the value of attribute line_items

Returns:

  • (Object)

    the current value of line_items



415
416
417
# File 'lib/portage/ucp/value_objects.rb', line 415

def line_items
  @line_items
end

Returns the value of attribute links

Returns:

  • (Object)

    the current value of links



415
416
417
# File 'lib/portage/ucp/value_objects.rb', line 415

def links
  @links
end

#orderObject (readonly)

Returns the value of attribute order

Returns:

  • (Object)

    the current value of order



415
416
417
# File 'lib/portage/ucp/value_objects.rb', line 415

def order
  @order
end

#statusObject (readonly)

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



415
416
417
# File 'lib/portage/ucp/value_objects.rb', line 415

def status
  @status
end

#totalsObject (readonly)

Returns the value of attribute totals

Returns:

  • (Object)

    the current value of totals



415
416
417
# File 'lib/portage/ucp/value_objects.rb', line 415

def totals
  @totals
end

Instance Method Details

#to_wire_hObject



422
423
424
425
426
427
428
429
# File 'lib/portage/ucp/value_objects.rb', line 422

def to_wire_h
  h = { "id" => id, "status" => status, "line_items" => line_items.map(&:to_wire_h),
        "currency" => currency, "totals" => totals.map(&:to_wire_h), "links" => links.map(&:to_wire_h) }
  h["order"] = order.to_wire_h if order
  h["discounts"] = discounts.to_wire_h unless discounts.empty?
  h["fulfillment"] = fulfillment.to_wire_h unless fulfillment.empty?
  h
end