Class: ActiveMerchant::Billing::StripeGateway
- Inherits:
-
Gateway
- Object
- Gateway
- ActiveMerchant::Billing::StripeGateway
show all
- Defined in:
- lib/active_merchant/billing/gateways/stripe.rb
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
-
#authorize(money, creditcard, options = {}) ⇒ Object
-
#capture(money, authorization, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ StripeGateway
constructor
A new instance of StripeGateway.
-
#purchase(money, creditcard, options = {}) ⇒ Object
To create a charge on a card or a token, call.
-
#refund(money, identification, options = {}) ⇒ Object
-
#store(creditcard, options = {}) ⇒ Object
-
#unstore(customer_id, options = {}) ⇒ Object
-
#update(customer_id, creditcard, options = {}) ⇒ Object
-
#void(identification, options = {}) ⇒ Object
Methods inherited from Gateway
#card_brand, card_brand, inherited, supports?, #test?
#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
38
39
40
41
42
43
44
|
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 38
def authorize(money, creditcard, options = {})
post = create_post_for_auth_or_purchase(money, creditcard, options)
post[:capture] = "false"
meta = generate_meta(options)
commit(:post, 'charges', post, meta)
end
|
#capture(money, authorization, options = {}) ⇒ Object
60
61
62
|
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 60
def capture(money, authorization, options = {})
commit(:post, "charges/#{CGI.escape(authorization)}/capture", {:amount => amount(money)})
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, ... })
53
54
55
56
57
58
|
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 53
def purchase(money, creditcard, options = {})
post = create_post_for_auth_or_purchase(money, creditcard, options)
meta = generate_meta(options)
commit(:post, 'charges', post, meta)
end
|
#refund(money, identification, options = {}) ⇒ Object
68
69
70
71
72
73
74
75
|
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 68
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 77
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
98
99
100
101
|
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 98
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
93
94
95
96
|
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 93
def update(customer_id, creditcard, options = {})
options = options.merge(:customer => customer_id)
store(creditcard, options)
end
|
#void(identification, options = {}) ⇒ Object
64
65
66
|
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 64
def void(identification, options = {})
commit(:post, "charges/#{CGI.escape(identification)}/refund", {})
end
|