Class: Supercharged::Charge::Base

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveModel::ForbiddenAttributesProtection
Defined in:
app/models/supercharged/charge/base.rb

Direct Known Subclasses

Charge

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.min_amountObject



53
54
55
# File 'app/models/supercharged/charge/base.rb', line 53

def self.min_amount
  1
end

.with_token(token) ⇒ Object



43
44
45
# File 'app/models/supercharged/charge/base.rb', line 43

def self.with_token(token)
  where(gateway_token: token).first
end

Instance Method Details

#approve(real_amount) ⇒ Object

require implicit amount from gateway, not from user



48
49
50
51
# File 'app/models/supercharged/charge/base.rb', line 48

def approve(real_amount)
  self.real_amount = real_amount
  set_ok!
end

#complete(options = {}) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'app/models/supercharged/charge/base.rb', line 74

def complete(options = {})
  get_purchase_details

  response = process_purchase

  approve(amount) if response.success?

  response.success?
end

#gatewayObject



84
85
86
# File 'app/models/supercharged/charge/base.rb', line 84

def gateway
  Supercharged::Helpers.gateway(gateway_name)
end

#setup_purchase(options) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/supercharged/charge/base.rb', line 57

def setup_purchase(options)
  response = gateway.setup_purchase(amount_in_cents,
    ip: options[:id],
    return_url: options[:return_url],
    cancel_return_url: options[:cancel_return_url]
  )

  if response.success?
    update_attributes!(
      gateway_token: response.token,
      ip_address: options[:id]
    )
  end

  response.token
end