Class: Wegift::Order
Constant Summary collapse
- PATH =
'/order-digital-card'
- DELIVERY_METHODS =
{ direct: 'direct', email: 'email' }.freeze
- DELIVERY_FORMATS =
{ code: 'raw', url: 'url-instant' }.freeze
Constants inherited from Response
Instance Attribute Summary collapse
-
#amount ⇒ Object
request/payload.
-
#barcode_format ⇒ Object
response/success.
-
#barcode_string ⇒ Object
response/success.
-
#code ⇒ Object
response/success.
-
#currency_code ⇒ Object
request/payload.
-
#cvc2 ⇒ Object
response/success.
-
#delivery_email ⇒ Object
request/payload.
-
#delivery_format ⇒ Object
request/payload.
-
#delivery_method ⇒ Object
request/payload.
-
#delivery_url ⇒ Object
response/success.
-
#expiry_date ⇒ Object
response/success.
-
#external_ref ⇒ Object
request/payload.
-
#notification_email ⇒ Object
request/payload.
-
#order_id ⇒ Object
response/success.
-
#pin ⇒ Object
response/success.
-
#product_code ⇒ Object
request/payload.
Attributes inherited from Response
#error_code, #error_details, #error_string, #status
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Order
constructor
A new instance of Order.
- #parse(response) ⇒ Object
- #payload ⇒ Object
-
#post(ctx) ⇒ Object
Order Digital Card POST /api/b2b-sync/v1/order-digital-card.
Methods inherited from Response
Constructor Details
#initialize(params = {}) ⇒ Order
Returns a new instance of Order.
18 19 20 21 22 23 |
# File 'lib/wegift/models/order.rb', line 18 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
#amount ⇒ Object
request/payload
10 11 12 |
# File 'lib/wegift/models/order.rb', line 10 def amount @amount end |
#barcode_format ⇒ Object
response/success
15 16 17 |
# File 'lib/wegift/models/order.rb', line 15 def @barcode_format end |
#barcode_string ⇒ Object
response/success
15 16 17 |
# File 'lib/wegift/models/order.rb', line 15 def @barcode_string end |
#code ⇒ Object
response/success
15 16 17 |
# File 'lib/wegift/models/order.rb', line 15 def code @code end |
#currency_code ⇒ Object
request/payload
10 11 12 |
# File 'lib/wegift/models/order.rb', line 10 def currency_code @currency_code end |
#cvc2 ⇒ Object
response/success
15 16 17 |
# File 'lib/wegift/models/order.rb', line 15 def cvc2 @cvc2 end |
#delivery_email ⇒ Object
request/payload
10 11 12 |
# File 'lib/wegift/models/order.rb', line 10 def delivery_email @delivery_email end |
#delivery_format ⇒ Object
request/payload
10 11 12 |
# File 'lib/wegift/models/order.rb', line 10 def delivery_format @delivery_format end |
#delivery_method ⇒ Object
request/payload
10 11 12 |
# File 'lib/wegift/models/order.rb', line 10 def delivery_method @delivery_method end |
#delivery_url ⇒ Object
response/success
15 16 17 |
# File 'lib/wegift/models/order.rb', line 15 def delivery_url @delivery_url end |
#expiry_date ⇒ Object
response/success
15 16 17 |
# File 'lib/wegift/models/order.rb', line 15 def expiry_date @expiry_date end |
#external_ref ⇒ Object
request/payload
10 11 12 |
# File 'lib/wegift/models/order.rb', line 10 def external_ref @external_ref end |
#notification_email ⇒ Object
request/payload
10 11 12 |
# File 'lib/wegift/models/order.rb', line 10 def notification_email @notification_email end |
#order_id ⇒ Object
response/success
15 16 17 |
# File 'lib/wegift/models/order.rb', line 15 def order_id @order_id end |
#pin ⇒ Object
response/success
15 16 17 |
# File 'lib/wegift/models/order.rb', line 15 def pin @pin end |
#product_code ⇒ Object
request/payload
10 11 12 |
# File 'lib/wegift/models/order.rb', line 10 def product_code @product_code end |
Instance Method Details
#parse(response) ⇒ Object
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/wegift/models/order.rb', line 45 def parse(response) super(response) # nested status/error object # assuming root "status" is always "SUCCESS" if "e_code" is set # { # "e_code": { # "error_code": "EC001", # "error_string": "Error retrieving E-Code from data processor", # "status": "ERROR" # }, # "error_code": null, # "error_details": null, # "error_string": null, # "order_id": 18, # "status": "SUCCESS" # } # override root "status" if set if @payload['e_code'] && @payload['e_code']['status'].eql?(STATUS[:error]) @status = @payload['e_code']['status'] unless @payload['e_code']['error_code'].blank? @error_code = @payload['e_code']['error_code'] end unless @payload['e_code']['error_string'].blank? @error_string = @payload['e_code']['error_string'] end unless @payload['e_code']['error_details'].blank? @error_details = @payload['e_code']['error_details'] end end # set valid data if @payload['e_code'] && @payload['e_code']['status'].eql?(STATUS[:success]) @code = @payload['e_code']['code'] @expiry_date = @payload['e_code']['expiry_date'] @pin = @payload['e_code']['pin'] @cvc2 = @payload['e_code']['cvc2'] @delivery_url = @payload['e_code']['delivery_url'] @barcode_string = @payload['e_code']['barcode_string'] @barcode_format = @payload['e_code']['barcode_format'] end @order_id = @payload['order_id'] self end |
#payload ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/wegift/models/order.rb', line 25 def payload { product_code: @product_code, currency_code: @currency_code, amount: @amount, delivery_method: @delivery_method, delivery_format: @delivery_format, notification_email: @notification_email, delivery_email: @delivery_email, external_ref: @external_ref } end |
#post(ctx) ⇒ Object
Order Digital Card POST /api/b2b-sync/v1/order-digital-card
40 41 42 43 |
# File 'lib/wegift/models/order.rb', line 40 def post(ctx) response = ctx.request(:post, PATH, payload) parse(response) end |