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



57
58
59
# File 'app/models/supercharged/charge/base.rb', line 57

def self.min_amount
  1
end

.with_token(token) ⇒ Object



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

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



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

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

#complete(options = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'app/models/supercharged/charge/base.rb', line 78

def complete(options = {})
  get_purchase_details

  response = process_purchase

  approve(amount) if response.success?

  response.success?
end

#gatewayObject



88
89
90
# File 'app/models/supercharged/charge/base.rb', line 88

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

#setup_purchase(options) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/supercharged/charge/base.rb', line 61

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