Class: Workarea::Zipco::Gateway

Inherits:
Object
  • Object
show all
Defined in:
lib/workarea/zipco/gateway.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  requires!(options, :secret_key, :api_version)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/workarea/zipco/gateway.rb', line 4

def options
  @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 authorize(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