Class: ActiveMerchant::Billing::StripeGateway

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

Direct Known Subclasses

WebpayGateway

Constant Summary collapse

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

#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
60
# 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)
  add_customer_data(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



66
67
68
69
70
71
72
73
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 66

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



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 75

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



96
97
98
99
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 96

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



91
92
93
94
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 91

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

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



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

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