Class: Runa::Order
Constant Summary collapse
- PATH =
'/order'
- DELIVERY_METHODS =
{ direct: 'direct', email: 'email' }.freeze
- DELIVERY_FORMATS =
{ code: 'raw', url: 'url-instant' }.freeze
Constants inherited from Response
Instance Attribute Summary collapse
-
#code ⇒ Object
response/success.
-
#created_at ⇒ Object
response/success.
-
#currency ⇒ Object
response/success.
-
#distribution_type ⇒ Object
request/payload.
-
#external_ref ⇒ Object
request/payload.
-
#face_value ⇒ Object
request/payload.
-
#items ⇒ Object
response/success.
-
#order_id ⇒ Object
response/success.
-
#payment_method ⇒ Object
response/success.
-
#payment_type ⇒ Object
request/payload.
-
#product_code ⇒ Object
request/payload.
-
#redemption_url ⇒ Object
response/success.
-
#status ⇒ Object
response/success.
-
#total_discount ⇒ Object
response/success.
-
#total_price ⇒ Object
response/success.
Attributes inherited from Response
#error_code, #error_details, #error_string
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Order
constructor
A new instance of Order.
- #parse(response) ⇒ Object
- #payload ⇒ Object
-
#post(ctx) ⇒ Object
Create a new order POST /v2/order.
Methods inherited from Response
Constructor Details
#initialize(params = {}) ⇒ Order
Returns a new instance of Order.
16 17 18 19 20 21 |
# File 'lib/runa/models/order.rb', line 16 def initialize(params = {}) super(params) # default/fallback: 'direct'/'raw' @delivery_method = params[:delivery_method] || DELIVERY_METHODS[:direct] @delivery_format = params[:delivery_format] || DELIVERY_FORMATS[:code] end |
Instance Attribute Details
#code ⇒ Object
response/success
13 14 15 |
# File 'lib/runa/models/order.rb', line 13 def code @code end |
#created_at ⇒ Object
response/success
13 14 15 |
# File 'lib/runa/models/order.rb', line 13 def created_at @created_at end |
#currency ⇒ Object
response/success
10 11 12 |
# File 'lib/runa/models/order.rb', line 10 def currency @currency end |
#distribution_type ⇒ Object
request/payload
10 11 12 |
# File 'lib/runa/models/order.rb', line 10 def distribution_type @distribution_type end |
#external_ref ⇒ Object
request/payload
10 11 12 |
# File 'lib/runa/models/order.rb', line 10 def external_ref @external_ref end |
#face_value ⇒ Object
request/payload
10 11 12 |
# File 'lib/runa/models/order.rb', line 10 def face_value @face_value end |
#items ⇒ Object
response/success
13 14 15 |
# File 'lib/runa/models/order.rb', line 13 def items @items end |
#order_id ⇒ Object
response/success
13 14 15 |
# File 'lib/runa/models/order.rb', line 13 def order_id @order_id end |
#payment_method ⇒ Object
response/success
13 14 15 |
# File 'lib/runa/models/order.rb', line 13 def payment_method @payment_method end |
#payment_type ⇒ Object
request/payload
10 11 12 |
# File 'lib/runa/models/order.rb', line 10 def payment_type @payment_type end |
#product_code ⇒ Object
request/payload
10 11 12 |
# File 'lib/runa/models/order.rb', line 10 def product_code @product_code end |
#redemption_url ⇒ Object
response/success
13 14 15 |
# File 'lib/runa/models/order.rb', line 13 def redemption_url @redemption_url end |
#status ⇒ Object
response/success
13 14 15 |
# File 'lib/runa/models/order.rb', line 13 def status @status end |
#total_discount ⇒ Object
response/success
13 14 15 |
# File 'lib/runa/models/order.rb', line 13 def total_discount @total_discount end |
#total_price ⇒ Object
response/success
13 14 15 |
# File 'lib/runa/models/order.rb', line 13 def total_price @total_price end |
Instance Method Details
#parse(response) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/runa/models/order.rb', line 51 def parse(response) super(response) if @payload['status'].eql?(STATUS[:failed]) @status = @payload['status'] unless @payload['type'].blank? @type = @payload['type'] end unless @payload['message'].blank? @message = @payload['message'] end unless @payload['help'].blank? @help = @payload['help'] end end # set valid data if @payload['status'] && @payload['status'].eql?(STATUS[:completed]) @status = @payload['status'] @total_price = @payload['total_price'] @items = @payload['items'] @redemption_url = @items.first['redemption_url'] end @order_id = @payload['id'] self end |
#payload ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/runa/models/order.rb', line 23 def payload { payment_method: { type: @payment_type, currency: @currency }, items: [ { face_value: @face_value, distribution_method: { type: @distribution_type }, products: { type: "SINGLE", value: @product_code } } ], } end |
#post(ctx) ⇒ Object
Create a new order POST /v2/order
46 47 48 49 |
# File 'lib/runa/models/order.rb', line 46 def post(ctx) response = ctx.request(:post, PATH, payload, @external_ref) parse(response) end |