Class: Workarea::Zipco::Gateway
- Inherits:
-
Object
- Object
- Workarea::Zipco::Gateway
- Defined in:
- lib/workarea/zipco/gateway.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #authorize(attrs, request_key = nil) ⇒ Object (also: #purchase)
- #capture(charge_id, amount, request_key = nil) ⇒ Object
- #create_order(order) ⇒ Object
-
#initialize(options = {}) ⇒ Gateway
constructor
A new instance of Gateway.
- #refund(charge_id, amount, request_key = nil) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Gateway
Returns a new instance of Gateway.
6 7 8 9 |
# File 'lib/workarea/zipco/gateway.rb', line 6 def initialize( = {}) requires!(, :secret_key, :api_version) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/workarea/zipco/gateway.rb', line 4 def @options end |
Instance Method Details
#authorize(attrs, request_key = nil) ⇒ Object Also known as: purchase
20 21 22 23 24 25 26 27 28 |
# File 'lib/workarea/zipco/gateway.rb', line 20 def (attrs, request_key = nil) response = connection.post do |req| req.url "merchant/v1/charges" req.body = attrs.to_json req.headers["Idempotency-Key"] = request_key end Zipco::Response.new(response) end |
#capture(charge_id, amount, request_key = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/workarea/zipco/gateway.rb', line 31 def capture(charge_id, amount, request_key = nil) body = { amount: amount.to_f } response = connection.post do |req| req.url "merchant/v1/charges/#{charge_id}/capture" req.body = body.to_json req.headers["Idempotency-Key"] = request_key end Zipco::Response.new(response) end |
#create_order(order) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/workarea/zipco/gateway.rb', line 11 def create_order(order) response = connection.post do |req| req.url "merchant/v1/checkouts" req.body = order.to_json end Zipco::Response.new(response) end |
#refund(charge_id, amount, request_key = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/workarea/zipco/gateway.rb', line 45 def refund(charge_id, amount, request_key = nil) reason = "Web Refund" body = { charge_id: charge_id, reason: reason, amount: amount.to_f } response = connection.post do |req| req.url "merchant/v1/refunds" req.body = body.to_json req.headers["Idempotency-Key"] = request_key end Zipco::Response.new(response) end |