Class: Workarea::Affirm::Gateway

Inherits:
Object
  • Object
show all
Defined in:
lib/workarea/affirm/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
10
# File 'lib/workarea/affirm/gateway.rb', line 6

def initialize(options = {})
  @public_key = options[:public_key]
  @private_key = options[:private_key]
  @test = options[:test]
end

Instance Attribute Details

#private_keyObject (readonly)

Returns the value of attribute private_key.



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

def private_key
  @private_key
end

#public_keyObject (readonly)

Returns the value of attribute public_key.



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

def public_key
  @public_key
end

#testObject (readonly)

Returns the value of attribute test.



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

def test
  @test
end

Instance Method Details

#authorize(token, order_id) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/workarea/affirm/gateway.rb', line 20

def authorize(token, order_id)
  body = {
    checkout_token: token,
    order_id: order_id
  }
  response = connection.post do |req|
    req.url "/api/v2/charges"
    req.body = body.to_json
  end

  Affirm::Response.new(response)
end

#capture(charge_id, amount, order_id) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/workarea/affirm/gateway.rb', line 33

def capture(charge_id, amount, order_id)
  body = {
    amount:  amount.cents,
    order_id: order_id
  }
  response = connection.post do |req|
    req.url "api/v2/charges/#{charge_id}/capture"
    req.body = body.to_json
  end

  Affirm::Response.new(response)
end

#get_checkout(token) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/workarea/affirm/gateway.rb', line 12

def get_checkout(token)
    response = connection.get do |req|
    req.url "/api/v2/checkout/#{token}"
  end

  Affirm::Response.new(response)
end

#refund(charge_id, amount) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/workarea/affirm/gateway.rb', line 46

def refund(charge_id, amount)
  body = {
    amount:  amount.cents,
    type: "refund"
  }

  response = connection.post do |req|
    req.url "/api/v2/charges/#{charge_id}/refund"
    req.body = body.to_json
  end

  Affirm::Response.new(response)
end

#void(charge_id) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/workarea/affirm/gateway.rb', line 60

def void(charge_id)
  response = connection.post do |req|
    req.url "/api/v2/charges/#{charge_id}/void"
  end

  Affirm::Response.new(response)
end