Skip to content

Commit

Permalink
Merge branch 'master' into verification-replaced-by-requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianoarruda committed Nov 26, 2023
2 parents ef0502c + 32b1ded commit 0573dd9
Show file tree
Hide file tree
Showing 92 changed files with 5,661 additions and 1,184 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.

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
1 change: 1 addition & 0 deletions lib/stripe_mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
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 Down
83 changes: 58 additions & 25 deletions lib/stripe_mock/api/webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,61 +37,94 @@ 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',
'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_intent.payment_failed',
'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',
'tax_rate.created',
'tax_rate.updated',
'transfer.created',
'transfer.failed',
'transfer.paid',
'transfer.updated',
'transfer.failed'
'transfer.updated'
]
end
end
Expand Down
50 changes: 46 additions & 4 deletions lib/stripe_mock/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ def self.mock_charge(params={})
},
receipt_email: nil,
receipt_number: nil,
receipt_url: nil,
refunded: false,
shipping: {},
statement_descriptor: "Charge #{charge_id}",
Expand Down Expand Up @@ -281,7 +282,8 @@ def self.mock_refund(params={})
charge: "ch_4fWhYjzQ23UFWT",
receipt_number: nil,
status: "succeeded",
reason: "requested_by_customer"
reason: "requested_by_customer",
receipt_url: nil
}.merge(params)
end

Expand Down Expand Up @@ -453,7 +455,8 @@ def self.mock_invoice(lines, params={})
next_payment_attempt: 1349825350,
charge: nil,
discount: nil,
subscription: nil
subscription: nil,
number: "6C41730-0001"
}.merge(params)
if invoice[:discount]
invoice[:total] = [0, invoice[:subtotal] - invoice[:discount][:coupon][:amount_off]].max if invoice[:discount][:coupon][:amount_off]
Expand Down Expand Up @@ -660,6 +663,44 @@ def self.mock_product(params={})
}.merge(params)
end

def self.mock_promotion_code(params={})
{
id: "mock_promo_abc123",
object: "promotion_code",
active: true,
code: "TESTCODE",
coupon: {
id: "mock_coupon_abc123",
object: "coupon",
amount_off: nil,
created: 1665773498,
currency: "usd",
duration: "repeating",
duration_in_months: 1,
livemode: false,
max_redemptions: nil,
metadata: {},
name: "Mock Coupon",
percent_off: 10.0,
redeem_by: nil,
times_redeemed: 0,
valid: true
},
created: 1665773499,
customer: nil,
expires_at: nil,
livemode: false,
max_redemptions: nil,
metadata: {},
restrictions: {
first_time_transaction: false,
minimum_amount: nil,
minimum_amount_currency: nil
},
times_redeemed: 0
}.merge(params)
end

def self.mock_recipient(cards, params={})
rp_id = params[:id] || "test_rp_default"
cards.each {|card| card[:recipient] = rp_id}
Expand Down Expand Up @@ -1262,9 +1303,10 @@ def self.mock_payment_method(params = {})
payment_method_id = params[:id] || 'pm_1ExEuFL2DI6wht39WNJgbybl'

type = params[:type].to_sym
last4 = params.dig(:card, :number)
data = {
card: {
brand: case params.dig(:card, :number)&.to_s
brand: case last4&.to_s
when /^4/, nil
'visa'
when /^5[1-5]/
Expand All @@ -1283,7 +1325,7 @@ def self.mock_payment_method(params = {})
fingerprint: 'Hr3Ly5z5IYxsokWA',
funding: 'credit',
generated_from: nil,
last4: params.dig(:card, :number)&.[](-4..) || '3155',
last4: last4.nil? ? '3155' : last4.to_s[-4..],
three_d_secure_usage: { supported: true },
wallet: nil
},
Expand Down
7 changes: 5 additions & 2 deletions lib/stripe_mock/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def self.handler_for_method_url(method_url)
include StripeMock::RequestHandlers::Plans
include StripeMock::RequestHandlers::Prices
include StripeMock::RequestHandlers::Products
include StripeMock::RequestHandlers::PromotionCodes
include StripeMock::RequestHandlers::Refunds
include StripeMock::RequestHandlers::Recipients
include StripeMock::RequestHandlers::Transfers
Expand All @@ -57,8 +58,9 @@ def self.handler_for_method_url(method_url)

attr_reader :accounts, :balance, :balance_transactions, :bank_tokens, :charges, :coupons, :customers,
:disputes, :events, :invoices, :invoice_items, :orders, :payment_intents, :payment_methods,
:setup_intents, :plans, :prices, :recipients, :refunds, :transfers, :payouts, :subscriptions, :country_spec,
:subscriptions_items, :products, :tax_rates, :checkout_sessions, :checkout_session_line_items
:setup_intents, :plans, :prices, :promotion_codes, :recipients, :refunds, :transfers, :payouts,
:subscriptions, :country_spec, :subscriptions_items, :products, :tax_rates, :checkout_sessions,
:checkout_session_line_items

attr_accessor :error_queue, :debug, :conversion_rate, :account_balance

Expand All @@ -83,6 +85,7 @@ def initialize
@plans = {}
@prices = {}
@products = {}
@promotion_codes = {}
@recipients = {}
@refunds = {}
@transfers = {}
Expand Down
23 changes: 17 additions & 6 deletions lib/stripe_mock/request_handlers/accounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ module Accounts
VALID_START_YEAR = 2009

def Accounts.included(klass)
klass.add_handler 'post /v1/accounts', :new_account
klass.add_handler 'get /v1/account', :get_account
klass.add_handler 'get /v1/accounts/(.*)', :get_account
klass.add_handler 'post /v1/accounts/(.*)', :update_account
klass.add_handler 'get /v1/accounts', :list_accounts
klass.add_handler 'post /oauth/deauthorize',:deauthorize
klass.add_handler 'post /v1/accounts', :new_account
klass.add_handler 'get /v1/account', :get_account
klass.add_handler 'get /v1/accounts/(.*)', :get_account
klass.add_handler 'post /v1/accounts/(.*)', :update_account
klass.add_handler 'get /v1/accounts', :list_accounts
klass.add_handler 'post /oauth/deauthorize', :deauthorize
klass.add_handler 'delete /v1/accounts/(.*)', :delete_account
end

def new_account(route, method_url, params, headers)
Expand Down Expand Up @@ -48,6 +49,16 @@ def deauthorize(route, method_url, params, headers)
Stripe::StripeObject.construct_from(:stripe_user_id => params[:stripe_user_id])
end

def delete_account(route, method_url, params, headers)
init_account
route =~ method_url
assert_existence :account, $1, accounts[$1]
accounts[$1] = {
id: accounts[$1][:id],
deleted: true
}
end

private

def init_account
Expand Down
1 change: 1 addition & 0 deletions lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def add_coupon_to_object(object, coupon)
attrs[:coupon] = coupon
attrs[:start] = Time.now.to_i
attrs[:end] = (DateTime.now >> coupon[:duration_in_months].to_i).to_time.to_i if coupon[:duration] == 'repeating'
attrs[:id] = new_id("di")
end

object[:discount] = Stripe::Discount.construct_from(discount_attrs)
Expand Down

0 comments on commit 0573dd9

Please sign in to comment.