Class: ActiveMerchant::Billing::StripeGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/stripe.rb

Constant Summary collapse

LIVE_URL =
'https://api.stripe.com/v1/'
AVS_CODE_TRANSLATOR =
{
  'line1: pass, zip: pass' => 'Y',
  'line1: pass, zip: fail' => 'A',
  'line1: pass, zip: unchecked' => 'B',
  'line1: fail, zip: pass' => 'Z',
  'line1: fail, zip: fail' => 'N',
  'line1: unchecked, zip: pass' => 'P',
  'line1: unchecked, zip: unchecked' => 'I'
}
CVC_CODE_TRANSLATOR =
{
  'pass' => 'M',
  'fail' => 'N',
  'unchecked' => 'P'
}

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, inherited, supports?, #test?

Methods included from Utils

#deprecated, generate_unique_id

Methods included from CreditCardFormatting

#format

Methods included from RequiresParameters

#requires!

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

Constructor Details

#initialize(options = {}) ⇒ StripeGateway

Returns a new instance of StripeGateway.



32
33
34
35
36
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 32

def initialize(options = {})
  requires!(options, :login)
  @api_key = options[:login]
  super
end

Instance Method Details

#authorize(money, creditcard, options = {}) ⇒ Object



52
53
54
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 52

def authorize(money, creditcard, options = {})
  purchase(money, creditcard, options.merge(:uncaptured => true))
end

#capture(money, identification, options = {}) ⇒ Object



56
57
58
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 56

def capture(money, identification, options = {})
  commit("charges/#{CGI.escape(identification)}/capture", {})
end

#purchase(money, creditcard, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 38

def purchase(money, creditcard, options = {})
  post = {}

  add_amount(post, money, options)
  add_creditcard(post, creditcard, options)
  add_customer(post, options)
  add_customer_data(post, options)
  add_flags(post, options)

  raise ArgumentError.new("Customer or Credit Card required.") if !post[:card] && !post[:customer]

  commit('charges', post)
end

#refund(money, identification, options = {}) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 64

def refund(money, identification, options = {})
  post = {}

  post[:amount] = amount(money) if money

  commit("charges/#{CGI.escape(identification)}/refund", post)
end

#store(creditcard, options = {}) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 72

def store(creditcard, options={})
  post = {}
  add_creditcard(post, creditcard, options)
  add_customer_data(post, options)

  if options[:customer]
    commit("customers/#{CGI.escape(options[:customer])}", post)
  else
    commit('customers', post)
  end
end

#void(identification, options = {}) ⇒ Object



60
61
62
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 60

def void(identification, options={})
  commit("charges/#{CGI.escape(identification)}/refund", {})
end