Class: Xpost::Order

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/xpost/order.rb

Constant Summary collapse

CONFIRMABLE_PARAMETERS =
Set[:status, :email, :buyer_name, :contact_number, :delivery_address, :items,
:shipment, :total, :currency, :payment_method, :payment_provider]
FOR_PICKUP_PARAMETERS =
Set[:pickup_address, :pickup_at]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Order

Returns a new instance of Order.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/xpost/order.rb', line 21

def initialize(options = {})
  @status           = options[:status]            || "pending"
  @reference_id     = options[:reference_id]
  @email            = options[:email]
  @buyer_name       = options[:buyer_name]
  @contact_number   = options[:contact_number]
  @delivery_address = options[:delivery_address]
  @items            = options[:items]             || []
  @shipment         = options[:shipment]
  @total            = options[:total]
  @currency         = options[:currency]
  @payment_method   = options[:payment_method]
  @payment_provider = options[:payment_provider]
  @pickup_address   = options[:pickup_address]
  @pickup_at        = options[:pickup_at]
end

Instance Attribute Details

#buyer_nameObject

Returns the value of attribute buyer_name.



13
14
15
# File 'lib/xpost/order.rb', line 13

def buyer_name
  @buyer_name
end

#contact_numberObject

Returns the value of attribute contact_number.



13
14
15
# File 'lib/xpost/order.rb', line 13

def contact_number
  @contact_number
end

#currencyObject

Returns the value of attribute currency.



14
15
16
# File 'lib/xpost/order.rb', line 14

def currency
  @currency
end

#delivery_addressObject

Returns the value of attribute delivery_address.



15
16
17
# File 'lib/xpost/order.rb', line 15

def delivery_address
  @delivery_address
end

#emailObject

Returns the value of attribute email.



13
14
15
# File 'lib/xpost/order.rb', line 13

def email
  @email
end

#itemsObject

Returns the value of attribute items.



16
17
18
# File 'lib/xpost/order.rb', line 16

def items
  @items
end

#payment_methodObject

Returns the value of attribute payment_method.



14
15
16
# File 'lib/xpost/order.rb', line 14

def payment_method
  @payment_method
end

#payment_providerObject

Returns the value of attribute payment_provider.



14
15
16
# File 'lib/xpost/order.rb', line 14

def payment_provider
  @payment_provider
end

#pickup_addressObject

Returns the value of attribute pickup_address.



15
16
17
# File 'lib/xpost/order.rb', line 15

def pickup_address
  @pickup_address
end

#pickup_atObject

Returns the value of attribute pickup_at.



15
16
17
# File 'lib/xpost/order.rb', line 15

def pickup_at
  @pickup_at
end

#reference_idObject

Returns the value of attribute reference_id.



13
14
15
# File 'lib/xpost/order.rb', line 13

def reference_id
  @reference_id
end

#shipmentObject

Returns the value of attribute shipment.



16
17
18
# File 'lib/xpost/order.rb', line 16

def shipment
  @shipment
end

#statusObject

Returns the value of attribute status.



16
17
18
# File 'lib/xpost/order.rb', line 16

def status
  @status
end

#totalObject

Returns the value of attribute total.



14
15
16
# File 'lib/xpost/order.rb', line 14

def total
  @total
end

Class Method Details

.sample_orderObject



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
# File 'lib/xpost/order.rb', line 38

def self.sample_order
  o = Xpost::Order.new
  o.email = "[email protected]"
  o.buyer_name = "John Doe"
  o.contact_number = "+6391712345678"
  o.shipment = "small-pouch"
  o.total = 1000
  o.currency = "PHP"
  o.payment_method = "cod"
  o.payment_provider = "lbcx"
  o.add_item(Xpost::Item.new(
    type: "product",
    description: "red shirt",
    amount: 1000,
    quantity: 1,
    metadata: "Small"
  ))
  o.delivery_address = Xpost::Address.new(
    name: "Bobby Axelrod",
    line_1: "BGC Corporate Centre",
    line_2: "5th floor",
    city: "Taguig",
    state: "Metro Manila",
    postal_code: "1634",
    country: "PH",
    company: "Axe Capital",
    title: "CEO",
    email: "[email protected]",
    phone_number: "12345678",
    mobile_number: "091712345678",
    fax_number: "12345678",
    district: "BGC",
    remarks: "Send ASAP"
  )
  o
end

Instance Method Details

#add_item(item) ⇒ Object



103
104
105
# File 'lib/xpost/order.rb', line 103

def add_item(item)
  self.items << item if item.valid?
end

#attributesObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/xpost/order.rb', line 115

def attributes
  {
    reference_id: self.reference_id,
    email: self.email,
    buyer_name: self.buyer_name,
    contact_number: self.contact_number,
    shipment: self.shipment,
    total: self.total,
    currency: self.currency,
    payment_method: self.payment_method,
    payment_provider: self.payment_provider,
    items: self.order_items,
    delivery_address: self.delivery_address.attributes,
    pickup_address: self.pickup_address.nil? ? nil : self.pickup_address.attributes,
    pickup_at: self.pickup_at
  }
end

#cancellable?Boolean

docs.quadx.xyz/#5f38afd0-66bb-468f-ab4e-993d4745a257 Sets the order status to canceled. An order can be canceled provided they have not passed the cutoff date and time as specified in the contract.

Returns:

  • (Boolean)


81
82
83
# File 'lib/xpost/order.rb', line 81

def cancellable?
  true
end

#confirmable?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/xpost/order.rb', line 75

def confirmable?
  self.valid? && self.has_delivery_address? && self.has_payment_method? && self.has_items?
end

#has_delivery_address?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/xpost/order.rb', line 91

def has_delivery_address?
  self.delivery_address.present?
end

#has_items?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/xpost/order.rb', line 99

def has_items?
  self.items.present? ? self.items.count > 0 : false
end

#has_payment_method?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/xpost/order.rb', line 95

def has_payment_method?
  self.total.present? && self.currency.present? && self.payment_method.present? && self.payment_provider.present?
end

#order_itemsObject



107
108
109
110
111
112
113
# File 'lib/xpost/order.rb', line 107

def order_items
  items = []
  self.items.each do |item|
    items << item.attributes
  end
  items
end

#to_jsonObject



133
134
135
# File 'lib/xpost/order.rb', line 133

def to_json
  self.attributes.to_json
end

#updatable?Boolean

docs.quadx.xyz/#c831dc25-2de4-36c5-c321-8e9db0fc2105 The following fields can be updated provided they have not passed the cutoff date and time as specified in the contract.

Returns:

  • (Boolean)


87
88
89
# File 'lib/xpost/order.rb', line 87

def updatable?
  true
end