Module: Supercharged::Charge::Base

Extended by:
ActiveSupport::Concern
Included in:
Charge
Defined in:
app/models/supercharged/charge/base.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#approve(real_amount) ⇒ Object

require implicit amount from gateway, not from user



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

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

#complete(options = {}) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'app/models/supercharged/charge/base.rb', line 84

def complete(options = {})
  get_purchase_details

  response = process_purchase

  approve(amount) if response.success?

  response.success?
end

#failObject



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

def fail
  self.state_event = "set_failed"
  save(validate: false)
end

#gatewayObject



94
95
96
# File 'app/models/supercharged/charge/base.rb', line 94

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

#min_amountObject



63
64
65
# File 'app/models/supercharged/charge/base.rb', line 63

def min_amount
  1
end

#setup_purchase(options) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/models/supercharged/charge/base.rb', line 67

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