Class: Jackpot::Gateway

Inherits:
Object
  • Object
show all
Defined in:
app/models/jackpot/gateway.rb

Overview

Small adapter for Active Merchant gateways Jackpot supports

Instance Method Summary (collapse)

Constructor Details

- (Gateway) initialize(adapted_gateway)

A new instance of Gateway



6
7
8
# File 'app/models/jackpot/gateway.rb', line 6

def initialize(adapted_gateway)
  @adapted_gateway = adapted_gateway
end

Instance Method Details

- (Object) authorize(amount_in_cents, credit_card_token)



11
12
13
# File 'app/models/jackpot/gateway.rb', line 11

def authorize(amount_in_cents, credit_card_token) 
  @adapted_gateway.authorize(amount_in_cents, credit_card_token)
end

- (Object) capture(money, authorization, options = {})



19
20
21
# File 'app/models/jackpot/gateway.rb', line 19

def capture(money, authorization, options = {})
  @adapted_gateway.capture(money, authorization, options) 
end

- (Object) process_payment(credit_card_token, amount_in_cents)



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/jackpot/gateway.rb', line 23

def process_payment(credit_card_token, amount_in_cents)
  if credit_card_token
    response = Jackpot::Base.gateway.authorize(amount_in_cents, credit_card_token)

    if response.success?
      billing_response = Jackpot::Base.gateway.capture(amount_in_cents, response.authorization).authorization
    else
      raise Jackpot::Errors::UnauthorizedPayment.new
    end
  else
    raise Jackpot::Errors::CustomerHasNoCardSaved.new
  end 
end

- (Object) store(card)



15
16
17
# File 'app/models/jackpot/gateway.rb', line 15

def store(card)
  @adapted_gateway.store(card)
end