Class: Xpost::Order
- Inherits:
-
Object
- Object
- Xpost::Order
- 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
-
#buyer_name ⇒ Object
Returns the value of attribute buyer_name.
-
#contact_number ⇒ Object
Returns the value of attribute contact_number.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#delivery_address ⇒ Object
Returns the value of attribute delivery_address.
-
#email ⇒ Object
Returns the value of attribute email.
-
#items ⇒ Object
Returns the value of attribute items.
-
#payment_method ⇒ Object
Returns the value of attribute payment_method.
-
#payment_provider ⇒ Object
Returns the value of attribute payment_provider.
-
#pickup_address ⇒ Object
Returns the value of attribute pickup_address.
-
#pickup_at ⇒ Object
Returns the value of attribute pickup_at.
-
#reference_id ⇒ Object
Returns the value of attribute reference_id.
-
#shipment ⇒ Object
Returns the value of attribute shipment.
-
#status ⇒ Object
Returns the value of attribute status.
-
#total ⇒ Object
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
- #add_item(item) ⇒ Object
- #attributes ⇒ Object
-
#cancellable? ⇒ Boolean
docs.quadx.xyz/#5f38afd0-66bb-468f-ab4e-993d4745a257 Sets the order status to canceled.
- #confirmable? ⇒ Boolean
- #has_delivery_address? ⇒ Boolean
- #has_items? ⇒ Boolean
- #has_payment_method? ⇒ Boolean
-
#initialize(options = {}) ⇒ Order
constructor
A new instance of Order.
- #order_items ⇒ Object
- #to_json ⇒ Object
-
#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.
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( = {}) @status = [:status] || "pending" @reference_id = [:reference_id] @email = [:email] @buyer_name = [:buyer_name] @contact_number = [:contact_number] @delivery_address = [:delivery_address] @items = [:items] || [] @shipment = [:shipment] @total = [:total] @currency = [:currency] @payment_method = [:payment_method] @payment_provider = [:payment_provider] @pickup_address = [:pickup_address] @pickup_at = [:pickup_at] end |
Instance Attribute Details
#buyer_name ⇒ Object
Returns the value of attribute buyer_name.
13 14 15 |
# File 'lib/xpost/order.rb', line 13 def buyer_name @buyer_name end |
#contact_number ⇒ Object
Returns the value of attribute contact_number.
13 14 15 |
# File 'lib/xpost/order.rb', line 13 def contact_number @contact_number end |
#currency ⇒ Object
Returns the value of attribute currency.
14 15 16 |
# File 'lib/xpost/order.rb', line 14 def currency @currency end |
#delivery_address ⇒ Object
Returns the value of attribute delivery_address.
15 16 17 |
# File 'lib/xpost/order.rb', line 15 def delivery_address @delivery_address end |
#email ⇒ Object
Returns the value of attribute email.
13 14 15 |
# File 'lib/xpost/order.rb', line 13 def email @email end |
#items ⇒ Object
Returns the value of attribute items.
16 17 18 |
# File 'lib/xpost/order.rb', line 16 def items @items end |
#payment_method ⇒ Object
Returns the value of attribute payment_method.
14 15 16 |
# File 'lib/xpost/order.rb', line 14 def payment_method @payment_method end |
#payment_provider ⇒ Object
Returns the value of attribute payment_provider.
14 15 16 |
# File 'lib/xpost/order.rb', line 14 def payment_provider @payment_provider end |
#pickup_address ⇒ Object
Returns the value of attribute pickup_address.
15 16 17 |
# File 'lib/xpost/order.rb', line 15 def pickup_address @pickup_address end |
#pickup_at ⇒ Object
Returns the value of attribute pickup_at.
15 16 17 |
# File 'lib/xpost/order.rb', line 15 def pickup_at @pickup_at end |
#reference_id ⇒ Object
Returns the value of attribute reference_id.
13 14 15 |
# File 'lib/xpost/order.rb', line 13 def reference_id @reference_id end |
#shipment ⇒ Object
Returns the value of attribute shipment.
16 17 18 |
# File 'lib/xpost/order.rb', line 16 def shipment @shipment end |
#status ⇒ Object
Returns the value of attribute status.
16 17 18 |
# File 'lib/xpost/order.rb', line 16 def status @status end |
#total ⇒ Object
Returns the value of attribute total.
14 15 16 |
# File 'lib/xpost/order.rb', line 14 def total @total end |
Class Method Details
.sample_order ⇒ Object
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 |
#attributes ⇒ Object
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.
81 82 83 |
# File 'lib/xpost/order.rb', line 81 def cancellable? true end |
#confirmable? ⇒ 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
91 92 93 |
# File 'lib/xpost/order.rb', line 91 def has_delivery_address? self.delivery_address.present? end |
#has_items? ⇒ 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
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_items ⇒ Object
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_json ⇒ Object
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.
87 88 89 |
# File 'lib/xpost/order.rb', line 87 def updatable? true end |