Last active
March 8, 2016 21:04
-
-
Save a-leung/d16f2c48f10e65ef65bd to your computer and use it in GitHub Desktop.
Stripe Stripe-Mock refunding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'stripe', '1.31.0' | |
require 'stripe' | |
Stripe.api_key = <insert API key here> | |
token = Stripe::Token.create( | |
:card => { | |
:number => "4242424242424242", | |
:exp_month => 3, | |
:exp_year => 2017, | |
:cvc => "314" | |
} | |
) | |
charge_info = { | |
source: token['id'], | |
amount: 1000, | |
currency: 'usd' | |
} | |
charge = Stripe::Charge.create(charge_info) | |
refund1 = charge.refund(amount: 100) # => no error | |
puts refund1.amount_refunded # => 100 | |
refund2 = charge.refund(amount: 1000) # => `handle_api_error': Refund amount ($1.00) is greater than unrefunded amount on charge ($0.90) (Stripe::InvalidRequestError) | |
puts refund2.amount_refunded # ?? (exception occurred) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'stripe-ruby-mock', '2.2.2' | |
require 'stripe_mock' | |
Stripe.api_key = 'test_key' | |
StripeMock.start | |
stripe_helper = StripeMock.create_test_helper | |
token = stripe_helper.generate_card_token | |
charge_info = { | |
source: token, | |
amount: 1000, | |
currency: 'usd' | |
} | |
charge = Stripe::Charge.create(charge_info) | |
refund1 = charge.refund(amount: 100) # => no error | |
puts refund1.amount_refunded # => 100 | |
refund2 = charge.refund(amount: 1000) # => no error | |
puts refund2.amount_refunded # => 1100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment