Skip to content

Commit

Permalink
Merge branch 'master' into persist-charge-for-successful-payment-intent
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmamonchik committed Nov 1, 2023
2 parents 1120c22 + a3a8f9c commit dff89d6
Show file tree
Hide file tree
Showing 130 changed files with 7,353 additions and 1,463 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/rspec_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby

name: Tests

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
test:

runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.6', '2.7', '3.0']

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
# uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run tests
run: bundle exec rspec
3 changes: 2 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
--colour --format documentation
--colour
--format progress
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

55 changes: 40 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,47 @@
### 3.0.2 (Next)
### Unreleased

* Your contribution here.
- [#806](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/806) - Remove `payment_method_types` from required arguments for `Stripe::Checkout::Session`
- [#806](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/806) - Raise more helpful exception when Stripe::Price cannot be found within a `Stripe::Checkout::Session` `line_items` argument.


### 3.1.0.rc3 (pre-release 2021-07-14)

- [#785](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/785): `Stripe::Product` no longer requires `type`. [@TastyPi](https://github.com/TastyPi)
- [#784](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/784): Fix "Wrong number of arguments" error in tests. [@TastyPi](https://github.com/TastyPi)
- [#782](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/782): Support expanding `setup_intent` in `Stripe::Checkout::Session`. [@TastyPi](https://github.com/TastyPi)

### 3.1.0.rc2 (pre-release 2021-03-03)

- [#767](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/767): Fixes tests and more [@lpsBetty](https://github.com/lpsBetty)

### 3.1.0.rc1 (pre-release 2021-02-17)

- [#765](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/765): Properly set the status of a trialing subscription. [@csalvato](https://github.com/csalvato)
- [#764](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/764): Fixes erroneous error message when fetching upcoming invoices. [@csalvato](https://github.com/csalvato)
- [#762](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/762): Support Stripe Connect with Customers by adding stripe_account header namespace for customer object [@csalvato](https://github.com/csalvato)
- [#755](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/755): Add allowed params to subscriptions [@dominikdarnel ](https://github.com/dominikdarnel)
- [#748](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/758): Support Prices - [@hidenba](https://github.com/hidenba) and [@jamesprior](https://github.com/jamesprior).
- [#747](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/747/files): Fix ruby 2.7 deprecation warnings. Adds Ruby 3.0.0 compatibility. [@coding-chimp](https://github.com/coding-chimp)
- [#715](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/715): Added application_fee_amount to mock charge object - [@espen](https://github.com/espen)
- [#709](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/709): Remove unnecessary check on customer's currency - [@coorasse](https://github.com/coorasse)

### 3.0.1 (TBD)
* Added Changelog file
* [#640](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/640): Support Payment Intent status requires_capture - [@theodorton](https://github.com/theodorton).
* [#685](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/685): Adds support for pending_invoice_item_interval - [@joshcass](https://github.com/joshcass).
* [#682](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/682): Prevent customer metadata from being overwritten with each update - [@sethkrasnianski](https://github.com/sethkrasnianski).
* [#679](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/679): Fix for [#678](https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues/678) Add active filter to Data::List - [@rnmp](https://github.com/rnmp).
* [#668](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/668): Fix for [#665](https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues/665) Allow to remove discount from customer - [@mnin](https://github.com/mnin).
* [#667](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/667):
Remove empty and duplicated methods from payment methods - [@mnin](https://github.com/mnin).
* [#664](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/664): Bugfix: pass through PaymentIntent amount to mocked Charge - [@typeoneerror](https://github.com/typeoneerror).
* [#654](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/654): fix for [#626](https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues/626) Added missing decline codes - [@iCreateJB](https://github.com/iCreateJB).
* [#648](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/648): Initial implementation of checkout session API - [@fauxparse](https://github.com/fauxparse).
* [#644](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/644): Allow payment_behavior attribute on subscription create - [@j15e](https://github.com/j15e).

- Added Changelog file
- [#640](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/640): Support Payment Intent status requires_capture - [@theodorton](https://github.com/theodorton).
- [#685](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/685): Adds support for pending_invoice_item_interval - [@joshcass](https://github.com/joshcass).
- [#682](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/682): Prevent customer metadata from being overwritten with each update - [@sethkrasnianski](https://github.com/sethkrasnianski).
- [#679](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/679): Fix for [#678](https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues/678) Add active filter to Data::List - [@rnmp](https://github.com/rnmp).
- [#668](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/668): Fix for [#665](https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues/665) Allow to remove discount from customer - [@mnin](https://github.com/mnin).
- [#667](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/667):
Remove empty and duplicated methods from payment methods - [@mnin](https://github.com/mnin).
- [#664](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/664): Bugfix: pass through PaymentIntent amount to mocked Charge - [@typeoneerror](https://github.com/typeoneerror).
- [#654](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/654): fix for [#626](https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues/626) Added missing decline codes - [@iCreateJB](https://github.com/iCreateJB).
- [#648](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/648): Initial implementation of checkout session API - [@fauxparse](https://github.com/fauxparse).
- [#644](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/644): Allow payment_behavior attribute on subscription create - [@j15e](https://github.com/j15e).

### 3.0.0 (2019-12-17)

##### the main thing is:
- [#658](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/658) Make the gem compatible with Stripe Gem v.5

- [#658](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/658) Make the gem compatible with Stripe Gem v.5
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ end

group :test do
gem 'rake'
gem 'dotenv'
end

gemspec
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# stripe-ruby-mock [![Build Status](https://travis-ci.org/stripe-ruby-mock/stripe-ruby-mock.png?branch=master)](https://travis-ci.org/stripe-ruby-mock/stripe-ruby-mock) [![Gitter chat](https://badges.gitter.im/rebelidealist/stripe-ruby-mock.png)](https://gitter.im/rebelidealist/stripe-ruby-mock)
# stripe-ruby-mock [![Tests](https://github.com/stripe-ruby-mock/stripe-ruby-mock/actions/workflows/rspec_tests.yml/badge.svg)](https://github.com/stripe-ruby-mock/stripe-ruby-mock/actions/workflows/rspec_tests.yml)

* Homepage: https://github.com/stripe-ruby-mock/stripe-ruby-mock
* Issues: https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues
Expand Down Expand Up @@ -29,7 +29,7 @@ version `3.0.0` has [breaking changes](https://github.com/stripe-ruby-mock/strip

### Requirements

* ruby >= 2.4.0
* ruby >= 2.6.0
* stripe >= 5.0.0

### Specifications
Expand Down Expand Up @@ -406,6 +406,8 @@ Patches are welcome and greatly appreciated! If you're contributing to fix a pro
be sure to write tests that illustrate the problem being fixed.
This will help ensure that the problem remains fixed in future updates.

Note: You may need to `ulimit -n 4048` before running the test suite to get all tests to pass.

## Copyright

Copyright (c) 2013 Gilbert
Expand Down
6 changes: 5 additions & 1 deletion lib/stripe_mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
require 'stripe_mock/request_handlers/validators/param_validators.rb'

require 'stripe_mock/request_handlers/account_links.rb'
require 'stripe_mock/request_handlers/express_login_links.rb'
require 'stripe_mock/request_handlers/accounts.rb'
require 'stripe_mock/request_handlers/external_accounts.rb'
require 'stripe_mock/request_handlers/balance.rb'
Expand All @@ -63,6 +64,8 @@
require 'stripe_mock/request_handlers/invoice_items.rb'
require 'stripe_mock/request_handlers/orders.rb'
require 'stripe_mock/request_handlers/plans.rb'
require 'stripe_mock/request_handlers/prices.rb'
require 'stripe_mock/request_handlers/promotion_codes.rb'
require 'stripe_mock/request_handlers/recipients.rb'
require 'stripe_mock/request_handlers/refunds.rb'
require 'stripe_mock/request_handlers/transfers.rb'
Expand All @@ -77,7 +80,6 @@
require 'stripe_mock/request_handlers/ephemeral_key.rb'
require 'stripe_mock/request_handlers/products.rb'
require 'stripe_mock/request_handlers/tax_rates.rb'
require 'stripe_mock/request_handlers/checkout.rb'
require 'stripe_mock/request_handlers/checkout_session.rb'
require 'stripe_mock/instance'

Expand All @@ -88,12 +90,14 @@
module StripeMock

@default_currency = 'usd'
@checkout_base = "https://checkout.stripe.com/pay/"
lib_dir = File.expand_path(File.dirname(__FILE__), '../..')
@webhook_fixture_path = './spec/fixtures/stripe_webhooks/'
@webhook_fixture_fallback_path = File.join(lib_dir, 'stripe_mock/webhook_fixtures')

class << self
attr_accessor :default_currency
attr_accessor :checkout_base
attr_accessor :webhook_fixture_path
end
end
2 changes: 1 addition & 1 deletion lib/stripe_mock/api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.start_client(port=4999)
return false if @state == 'live'
return @client unless @client.nil?

Stripe::StripeClient.send(:define_method, :execute_request) { |*args| StripeMock.redirect_to_mock_server(*args) }
Stripe::StripeClient.send(:define_method, :execute_request) { |*args, **keyword_args| StripeMock.redirect_to_mock_server(*args, **keyword_args) }
@client = StripeMock::Client.new(port)
@state = 'remote'
@client
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe_mock/api/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module StripeMock
def self.start
return false if @state == 'live'
@instance = instance = Instance.new
Stripe::StripeClient.send(:define_method, :execute_request) { |*args| instance.mock_request(*args) }
Stripe::StripeClient.send(:define_method, :execute_request) { |*args, **keyword_args| instance.mock_request(*args, **keyword_args) }
@state = 'local'
end

Expand Down
89 changes: 63 additions & 26 deletions lib/stripe_mock/api/webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def self.mock_webhook_payload(type, params = {})

fixture_file = File.join(@webhook_fixture_path, "#{type}.json")

unless File.exists?(fixture_file)
unless File.exist?(fixture_file)
unless Webhooks.event_list.include?(type)
raise UnsupportedRequestError.new "Unsupported webhook event `#{type}` (Searched in #{@webhook_fixture_path})"
end
Expand Down Expand Up @@ -37,55 +37,92 @@ def self.mock_webhook_event(type, params={})
module Webhooks
def self.event_list
@__list = [
'account.updated',
'account.application.deauthorized',
'account.external_account.created',
'account.external_account.updated',
'account.external_account.deleted',
'account.external_account.updated',
'account.updated',
'balance.available',
'charge.succeeded',
'charge.updated',
'charge.failed',
'charge.refunded',
'charge.dispute.created',
'charge.dispute.updated',
'charge.captured',
'charge.dispute.closed',
'charge.dispute.created',
'charge.dispute.funds_reinstated',
'charge.dispute.funds_withdrawn',
'charge.dispute.updated',
'charge.failed',
'charge.refund.updated',
'charge.refunded',
'charge.succeeded',
'charge.updated',
'checkout.session.completed',
'checkout.session.completed.payment_mode',
'checkout.session.completed.setup_mode',
'coupon.created',
'coupon.deleted',
'customer.created',
'customer.deleted',
'customer.discount.created',
'customer.discount.deleted',
'customer.discount.updated',
'customer.source.created',
'customer.source.deleted',
'customer.source.updated',
'customer.created',
'customer.updated',
'customer.deleted',
'customer.subscription.created',
'customer.subscription.updated',
'customer.subscription.deleted',
'customer.subscription.trial_will_end',
'customer.discount.created',
'customer.discount.updated',
'customer.discount.deleted',
'customer.subscription.updated',
'customer.updated',
'invoice.created',
'invoice.updated',
'invoice.payment_succeeded',
'invoice.finalized',
'invoice.paid',
'invoice.payment_action_required',
'invoice.payment_failed',
'invoice.payment_succeeded',
'invoice.upcoming',
'invoice.updated',
'invoiceitem.created',
'invoiceitem.updated',
'invoiceitem.deleted',
'payment_intent.succeeded',
'invoiceitem.updated',
'mandate.updated',
'payment_intent.amount_capturable_updated',
'payment_intent.canceled',
'payment_intent.created',
'payment_intent.payment_failed',
'payment_intent.processing',
'payment_intent.requires_action',
'payment_intent.succeeded',
'payment_link.created',
'payment_link.updated',
'payment_method.attached',
'payment_method.detached',
'payout.created',
'payout.paid',
'payout.updated',
'plan.created',
'plan.updated',
'plan.deleted',
'plan.updated',
'price.created',
'price.deleted',
'price.updated',
'product.created',
'product.updated',
'product.deleted',
'coupon.created',
'coupon.deleted',
'product.updated',
'quote.accepted',
'quote.canceled',
'quote.created',
'quote.finalized',
'setup_intent.canceled',
'setup_intent.created',
'setup_intent.setup_failed',
'setup_intent.succeeded',
'subscription_schedule.canceled',
'subscription_schedule.created',
'subscription_schedule.released',
'subscription_schedule.updated',
'transfer.created',
'transfer.failed',
'transfer.paid',
'transfer.updated',
'transfer.failed'
'transfer.updated'
]
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/stripe_mock/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def mock_request(method, url, api_key: nil, params: {}, headers: {})
@pipe.mock_request(method, url, api_key: api_key, params: params, headers: headers).tap {|result|
response, api_key = result
if response.is_a?(Hash) && response[:error_raised] == 'invalid_request'
raise Stripe::InvalidRequestError.new(*response[:error_params])
args, keyword_args = response[:error_params].first(2), response[:error_params].last
raise Stripe::InvalidRequestError.new(*args, **keyword_args)
end
}
end
Expand Down

0 comments on commit dff89d6

Please sign in to comment.