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 CreditCardFormatting

#format

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



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

def authorize(money, creditcard, options = {})
  raise "Stripe does not support separate authorization and capture"
end

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



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

def capture(money, identification, options = {})
  raise "Stripe does not support separate authorization and capture"
end

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

To create a charge on a card or a token, call

purchase(money, card_hash_or_token, { ... })

To create a charge on a customer, call

purchase(money, nil, { :customer => id, ... })

Raises:

  • (ArgumentError)


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 45

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

  add_amount(post, money, options)
  add_creditcard(post, creditcard, options)
  add_customer(post, options)
  post[:description] = options[:description] || options[:email]
  add_flags(post, options)

  meta = generate_meta(options)

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

  commit(:post, 'charges', post, meta)
end

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



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

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

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

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

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



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 82

def store(creditcard, options = {})
  post = {}
  add_creditcard(post, creditcard, options)
  post[:description] = options[:description]
  post[:email] = options[:email]

  meta = generate_meta(options)
  path = if options[:customer]
    "customers/#{CGI.escape(options[:customer])}"
  else
    'customers'
  end

  commit(:post, path, post, meta)
end

#unstore(customer_id, options = {}) ⇒ Object



103
104
105
106
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 103

def unstore(customer_id, options = {})
  meta = generate_meta(options)
  commit(:delete, "customers/#{CGI.escape(customer_id)}", nil, meta)
end

#update(customer_id, creditcard, options = {}) ⇒ Object



98
99
100
101
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 98

def update(customer_id, creditcard, options = {})
  options = options.merge(:customer => customer_id)
  store(creditcard, options)
end

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



69
70
71
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 69

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