Class: Tangocard::Order
- Inherits:
-
Object
- Object
- Tangocard::Order
- Defined in:
- lib/tangocard/order.rb
Instance Attribute Summary collapse
-
#account_identifier ⇒ Object
readonly
Returns the value of attribute account_identifier.
-
#amount_charged ⇒ Object
readonly
Returns the value of attribute amount_charged.
-
#customer ⇒ Object
readonly
Returns the value of attribute customer.
-
#delivered_at ⇒ Object
readonly
Returns the value of attribute delivered_at.
-
#denomination ⇒ Object
readonly
Returns the value of attribute denomination.
-
#external_id ⇒ Object
readonly
Returns the value of attribute external_id.
-
#order_id ⇒ Object
readonly
Returns the value of attribute order_id.
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
-
#recipient ⇒ Object
readonly
Returns the value of attribute recipient.
-
#reward ⇒ Object
readonly
Returns the value of attribute reward.
-
#reward_from ⇒ Object
readonly
Returns the value of attribute reward_from.
-
#reward_message ⇒ Object
readonly
Returns the value of attribute reward_message.
-
#reward_subject ⇒ Object
readonly
Returns the value of attribute reward_subject.
-
#sku ⇒ Object
readonly
Returns the value of attribute sku.
Class Method Summary collapse
-
.all(params = {}) ⇒ Object
Return an array of all orders.
-
.create(params) ⇒ Object
Create a new order.
-
.find(order_id) ⇒ Object
Find an order by order_id.
Instance Method Summary collapse
- #identifier ⇒ Object
-
#initialize(params, raw_response = nil) ⇒ Order
constructor
A new instance of Order.
Constructor Details
#initialize(params, raw_response = nil) ⇒ Order
Returns a new instance of Order.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/tangocard/order.rb', line 70 def initialize(params, raw_response = nil) @order_id = params['order_id'] @account_identifier = params['account_identifier'] @customer = params['customer'] @sku = params['sku'] @denomination = params['denomination'] || {} @amount_charged = params['amount_charged'] || {} = params['reward_message'] @reward_subject = params['reward_subject'] @reward_from = params['reward_from'] @delivered_at = params['delivered_at'] @recipient = params['recipient'] || {} @external_id = params['external_id'] @reward = params['reward'] || {} @raw_response = raw_response end |
Instance Attribute Details
#account_identifier ⇒ Object (readonly)
Returns the value of attribute account_identifier.
2 3 4 |
# File 'lib/tangocard/order.rb', line 2 def account_identifier @account_identifier end |
#amount_charged ⇒ Object (readonly)
Returns the value of attribute amount_charged.
2 3 4 |
# File 'lib/tangocard/order.rb', line 2 def amount_charged @amount_charged end |
#customer ⇒ Object (readonly)
Returns the value of attribute customer.
2 3 4 |
# File 'lib/tangocard/order.rb', line 2 def customer @customer end |
#delivered_at ⇒ Object (readonly)
Returns the value of attribute delivered_at.
2 3 4 |
# File 'lib/tangocard/order.rb', line 2 def delivered_at @delivered_at end |
#denomination ⇒ Object (readonly)
Returns the value of attribute denomination.
2 3 4 |
# File 'lib/tangocard/order.rb', line 2 def denomination @denomination end |
#external_id ⇒ Object (readonly)
Returns the value of attribute external_id.
2 3 4 |
# File 'lib/tangocard/order.rb', line 2 def external_id @external_id end |
#order_id ⇒ Object (readonly)
Returns the value of attribute order_id.
2 3 4 |
# File 'lib/tangocard/order.rb', line 2 def order_id @order_id end |
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
2 3 4 |
# File 'lib/tangocard/order.rb', line 2 def raw_response @raw_response end |
#recipient ⇒ Object (readonly)
Returns the value of attribute recipient.
2 3 4 |
# File 'lib/tangocard/order.rb', line 2 def recipient @recipient end |
#reward ⇒ Object (readonly)
Returns the value of attribute reward.
2 3 4 |
# File 'lib/tangocard/order.rb', line 2 def reward @reward end |
#reward_from ⇒ Object (readonly)
Returns the value of attribute reward_from.
2 3 4 |
# File 'lib/tangocard/order.rb', line 2 def reward_from @reward_from end |
#reward_message ⇒ Object (readonly)
Returns the value of attribute reward_message.
2 3 4 |
# File 'lib/tangocard/order.rb', line 2 def end |
#reward_subject ⇒ Object (readonly)
Returns the value of attribute reward_subject.
2 3 4 |
# File 'lib/tangocard/order.rb', line 2 def reward_subject @reward_subject end |
#sku ⇒ Object (readonly)
Returns the value of attribute sku.
2 3 4 |
# File 'lib/tangocard/order.rb', line 2 def sku @sku end |
Class Method Details
.all(params = {}) ⇒ Object
Return an array of all orders.
Example:
>> Tangocard::Order.all
=> [#<Tangocard::Order:0x007f9a6c4bca68 ...>, #<Tangocard::Order:0x007f9a6c4bca68 ...>, ...]
Arguments:
params: (Hash - optional, see https://www.tangocard.com/docs/raas-api/#list-orders for details)
27 28 29 30 31 32 33 34 |
# File 'lib/tangocard/order.rb', line 27 def self.all(params = {}) response = Tangocard::Raas.orders_index(params) if response.success? response.parsed_response['orders'].map{|o| new(o)} else [] end end |
.create(params) ⇒ Object
Create a new order. Raises Tangocard::OrderCreateFailedException on failure.
Example:
>> Tangocard::Order.create(params)
=> #<Tangocard::Order:0x007f9a6c4bca68 ...>
Arguments:
params: (Hash - see https://www.tangocard.com/docs/raas-api/#create-order for details)
61 62 63 64 65 66 67 68 |
# File 'lib/tangocard/order.rb', line 61 def self.create(params) response = Tangocard::Raas.create_order(params) if response.success? new(response.parsed_response['order'], response) else raise Tangocard::OrderCreateFailedException, "#{response.error_message} #{response.invalid_inputs}" end end |
.find(order_id) ⇒ Object
Find an order by order_id. Raises Tangocard::OrderNotFoundException on failure.
Example:
>> Tangocard::Order.find("113-08258652-15")
=> #<Tangocard::Order:0x007f9a6e3a90c0 @order_id="113-08258652-15", @account_identifier="ElliottTest", @customer="ElliottTest", @sku="APPL-E-1500-STD", @amount=1500, @reward_message="testing", @reward_subject="RaaS Sandbox Test", @reward_from="Elliott", @delivered_at="2013-08-15T17:42:18+00:00", @recipient={"name"=>"Elliott", "email"=>"[email protected]"}, @reward={"token"=>"520d12fa655b54.34581245", "number"=>"1111111111111256"}>
Arguments:
order_id: (String)
44 45 46 47 48 49 50 51 |
# File 'lib/tangocard/order.rb', line 44 def self.find(order_id) response = Tangocard::Raas.show_order({'order_id' => order_id}) if response.success? new(response.parsed_response['order'], response) else raise Tangocard::OrderNotFoundException, "#{response.error_message}" end end |
Instance Method Details
#identifier ⇒ Object
91 92 93 |
# File 'lib/tangocard/order.rb', line 91 def identifier @account_identifier end |