Class: QuickTravel::Checkout
- Defined in:
- lib/quick_travel/checkout.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#progress ⇒ Object
readonly
Slow checkouts will require a poll – use #status(checkout_id).
-
#redirect_url ⇒ Object
readonly
Provides the url to redirect the browser to when payment is via an external gateway.
-
#requires_poll ⇒ Object
readonly
Slow checkouts will require a poll – use #status(checkout_id).
Class Method Summary collapse
-
.attributes_for ⇒ Object
TODO Move to an external builder?.
- .build_checkout_for(&block) ⇒ Object
- .client_token(data) ⇒ Object
-
.create(data) ⇒ Object
Create a checkout in QuickTravel.
-
.status(id) ⇒ Object
Poll for status of checkout.
- .update(id, data) ⇒ Object
Instance Method Summary collapse
-
#completed? ⇒ Boolean
These methods are a bit ewwwwy…
- #id ⇒ Object
-
#successful? ⇒ Boolean
Successful OR processing…
- #to_h ⇒ Object
- #unsuccessful? ⇒ Boolean
Methods inherited from Adapter
all, belongs_to, find, has_many, #to_s
Methods included from InitFromHash
#define_readers, #initialize, #to_hash
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
13 14 15 |
# File 'lib/quick_travel/checkout.rb', line 13 def error @error end |
#progress ⇒ Object (readonly)
Slow checkouts will require a poll – use #status(checkout_id)
11 12 13 |
# File 'lib/quick_travel/checkout.rb', line 11 def progress @progress end |
#redirect_url ⇒ Object (readonly)
Provides the url to redirect the browser to when payment is via an external gateway
8 9 10 |
# File 'lib/quick_travel/checkout.rb', line 8 def redirect_url @redirect_url end |
#requires_poll ⇒ Object (readonly)
Slow checkouts will require a poll – use #status(checkout_id)
11 12 13 |
# File 'lib/quick_travel/checkout.rb', line 11 def requires_poll @requires_poll end |
Class Method Details
.attributes_for ⇒ Object
TODO Move to an external builder?
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/quick_travel/checkout.rb', line 48 def self.attributes_for attrs = yield attrs[:completed] = attrs['progress'] == 'completed' attrs[:successful] = attrs[:completed] attrs rescue AdapterError => e { completed: true, successful: false, error: e. } end |
.build_checkout_for(&block) ⇒ Object
43 44 45 |
# File 'lib/quick_travel/checkout.rb', line 43 def self.build_checkout_for(&block) new(attributes_for(&block)) end |
.client_token(data) ⇒ Object
15 16 17 |
# File 'lib/quick_travel/checkout.rb', line 15 def self.client_token(data) get_and_validate('/api/checkouts/client_token.json', data).symbolize_keys end |
.create(data) ⇒ Object
Create a checkout in QuickTravel
20 21 22 |
# File 'lib/quick_travel/checkout.rb', line 20 def self.create(data) build_checkout_for { post_and_validate('/api/checkouts.json', data) } end |
.status(id) ⇒ Object
Poll for status of checkout
While in progress returns:
progress: 'processing'
When complete:
progress: 'completed'
When failed, status :ok
successful: false
error: 'Reason for failure'
35 36 37 |
# File 'lib/quick_travel/checkout.rb', line 35 def self.status(id) build_checkout_for { get_and_validate("/api/checkouts/#{id}.json?v=1") } end |
.update(id, data) ⇒ Object
39 40 41 |
# File 'lib/quick_travel/checkout.rb', line 39 def self.update(id, data) build_checkout_for { put_and_validate("/api/checkouts/#{id}.json", data) } end |
Instance Method Details
#completed? ⇒ Boolean
These methods are a bit ewwwwy… We really have a tri-state: FAILED, SUCCEEDED, PROCESSING
…in process of fixing up users of this class
69 70 71 |
# File 'lib/quick_travel/checkout.rb', line 69 def completed? @completed end |
#id ⇒ Object
61 62 63 |
# File 'lib/quick_travel/checkout.rb', line 61 def id @checkout_id # This is the key QT returns end |
#successful? ⇒ Boolean
Successful OR processing… OMG.. :(
74 75 76 |
# File 'lib/quick_travel/checkout.rb', line 74 def successful? @successful end |
#to_h ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/quick_travel/checkout.rb', line 82 def to_h { checkout_id: id, progress: progress, completed: completed?, successful: successful?, requires_poll: requires_poll, redirect_url: redirect_url, error: error } end |
#unsuccessful? ⇒ Boolean
78 79 80 |
# File 'lib/quick_travel/checkout.rb', line 78 def unsuccessful? completed? && !successful? end |