Class: Workarea::Afterpay::Gateway
- Inherits:
-
Object
- Object
- Workarea::Afterpay::Gateway
- Defined in:
- lib/workarea/afterpay/gateway.rb
Instance Attribute Summary collapse
-
#merchant_id ⇒ Object
readonly
Returns the value of attribute merchant_id.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
Instance Method Summary collapse
- #authorize(token, order_id, request_id) ⇒ Object
- #capture(payment_id, amount, request_id) ⇒ Object
- #create_order(order) ⇒ Object
- #get_configuration ⇒ Object
- #get_order(token) ⇒ Object
-
#initialize(merchant_id, secret_key, options = {}) ⇒ Gateway
constructor
A new instance of Gateway.
- #purchase(token, request_id) ⇒ Object
- #refund(afterpay_order_id, amount, request_id) ⇒ Object
- #void(payment_id) ⇒ Object
Constructor Details
#initialize(merchant_id, secret_key, options = {}) ⇒ Gateway
Returns a new instance of Gateway.
8 9 10 11 12 |
# File 'lib/workarea/afterpay/gateway.rb', line 8 def initialize(merchant_id, secret_key, = {}) @merchant_id = merchant_id @secret_key = secret_key @options = end |
Instance Attribute Details
#merchant_id ⇒ Object (readonly)
Returns the value of attribute merchant_id.
4 5 6 |
# File 'lib/workarea/afterpay/gateway.rb', line 4 def merchant_id @merchant_id end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/workarea/afterpay/gateway.rb', line 4 def @options end |
#secret_key ⇒ Object (readonly)
Returns the value of attribute secret_key.
4 5 6 |
# File 'lib/workarea/afterpay/gateway.rb', line 4 def secret_key @secret_key end |
Instance Method Details
#authorize(token, order_id, request_id) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/workarea/afterpay/gateway.rb', line 37 def (token, order_id, request_id) body = { token: token, request_id: request_id } response = connection.post do |req| req.url "/v2/payments/auth" req.body = body.to_json end Afterpay::Response.new(response) end |
#capture(payment_id, amount, request_id) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/workarea/afterpay/gateway.rb', line 50 def capture(payment_id, amount, request_id) body = { amount: { amount: amount.to_f, currency: amount.currency.iso_code }, request_id: request_id } response = connection.post do |req| req.url "/v2/payments/#{payment_id}/capture" req.body = body.to_json end Afterpay::Response.new(response) end |
#create_order(order) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/workarea/afterpay/gateway.rb', line 29 def create_order(order) response = connection.post do |req| req.url "/v2/checkouts" req.body = order.to_json end Afterpay::Response.new(response) end |
#get_configuration ⇒ Object
14 15 16 17 18 19 |
# File 'lib/workarea/afterpay/gateway.rb', line 14 def get_configuration response = connection.get do |req| req.url "/v2/configuration" end Afterpay::Response.new(response) end |
#get_order(token) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/workarea/afterpay/gateway.rb', line 21 def get_order(token) response = connection.get do |req| req.url "/v2/checkouts/#{token}" end Afterpay::Response.new(response) end |
#purchase(token, request_id) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/workarea/afterpay/gateway.rb', line 74 def purchase(token, request_id) body = { token: token, request_id: request_id } response = connection.post do |req| req.url "/v2/payments/capture" req.body = body.to_json end Afterpay::Response.new(response) end |
#refund(afterpay_order_id, amount, request_id) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/workarea/afterpay/gateway.rb', line 87 def refund(afterpay_order_id, amount, request_id) body = { requestId: request_id, amount: { amount: amount.to_f, currency: amount.currency.iso_code } } response = connection.post do |req| req.url "/v2/payments/#{afterpay_order_id}/refund" req.body = body.to_json end Afterpay::Response.new(response) end |