Class: ActiveMerchant::Billing::StripeGateway
- Defined in:
- lib/active_merchant/billing/gateways/stripe.rb
Direct Known Subclasses
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
Instance Method Summary collapse
-
#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?
Methods included from CreditCardFormatting
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( = {}) requires!(, :login) @api_key = [: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, ... })
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, = {}) post = {} add_amount(post, money, ) add_creditcard(post, creditcard, ) add_customer(post, ) add_customer_data(post,) post[:description] = [:description] || [:email] add_flags(post, ) = () raise ArgumentError.new("Customer or Credit Card required.") if !post[:card] && !post[:customer] commit(:post, 'charges', post, ) 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, = {}) = () post = {} post[:amount] = amount(money) if money commit(:post, "charges/#{CGI.escape(identification)}/refund", post, ) 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, = {}) post = {} add_creditcard(post, creditcard, ) post[:description] = [:description] post[:email] = [:email] = () path = if [:customer] "customers/#{CGI.escape([:customer])}" else 'customers' end commit(:post, path, post, ) end |
#unstore(customer_id, options = {}) ⇒ Object
96 97 98 99 |
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 96 def unstore(customer_id, = {}) = () commit(:delete, "customers/#{CGI.escape(customer_id)}", nil, ) 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, = {}) = .merge(:customer => customer_id) store(creditcard, ) end |
#void(identification, options = {}) ⇒ Object
62 63 64 |
# File 'lib/active_merchant/billing/gateways/stripe.rb', line 62 def void(identification, = {}) commit(:post, "charges/#{CGI.escape(identification)}/refund", {}) end |