Class: Clearsale::OrderResponse
- Inherits:
-
Object
- Object
- Clearsale::OrderResponse
- Defined in:
- lib/clearsale/order_response.rb
Constant Summary collapse
- STATUS_MAP =
{ "APA" => :automatic_approval, "APM" => :manual_approval, "RPM" => :rejected_without_suspicion, "AMA" => :manual_analysis, "ERR" => :error, "NVO" => :waiting, "SUS" => :manual_rejection, "CAN" => :cancelled, "FRD" => :fraud, }
Instance Attribute Summary collapse
-
#order_id ⇒ Object
readonly
Returns the value of attribute order_id.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #approved? ⇒ Boolean
- #inexistent_order? ⇒ Boolean
-
#initialize(hash) ⇒ OrderResponse
constructor
A new instance of OrderResponse.
- #manual_analysis? ⇒ Boolean
- #rejected? ⇒ Boolean
Constructor Details
#initialize(hash) ⇒ OrderResponse
Returns a new instance of OrderResponse.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/clearsale/order_response.rb', line 25 def initialize(hash) response = hash.fetch(:orders, {}).fetch(:order, {}) if response.blank? @status = :inexistent_order else @order_id = response[:id].gsub(/[a-zA-Z]*/, '').to_i @score = response[:score].to_f @status = STATUS_MAP[response[:status]] end end |
Instance Attribute Details
#order_id ⇒ Object (readonly)
Returns the value of attribute order_id.
15 16 17 |
# File 'lib/clearsale/order_response.rb', line 15 def order_id @order_id end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
15 16 17 |
# File 'lib/clearsale/order_response.rb', line 15 def score @score end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
15 16 17 |
# File 'lib/clearsale/order_response.rb', line 15 def status @status end |
Class Method Details
.build_from_send_order(package) ⇒ Object
17 18 19 |
# File 'lib/clearsale/order_response.rb', line 17 def self.build_from_send_order(package) new(package.fetch(:package_status, {})) end |
.build_from_update(package) ⇒ Object
21 22 23 |
# File 'lib/clearsale/order_response.rb', line 21 def self.build_from_update(package) new(package.fetch(:clear_sale, {})) end |
Instance Method Details
#approved? ⇒ Boolean
37 38 39 |
# File 'lib/clearsale/order_response.rb', line 37 def approved? @status == :automatic_approval || @status == :manual_approval end |
#inexistent_order? ⇒ Boolean
49 50 51 |
# File 'lib/clearsale/order_response.rb', line 49 def inexistent_order? @status == :inexistent_order end |
#manual_analysis? ⇒ Boolean
45 46 47 |
# File 'lib/clearsale/order_response.rb', line 45 def manual_analysis? @status == :manual_analysis end |
#rejected? ⇒ Boolean
41 42 43 |
# File 'lib/clearsale/order_response.rb', line 41 def rejected? @status == :rejected_without_suspicion || @status == :fraud || @status == :manual_rejection end |