epopia-stripe-ruby-mock 2.5.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env +2 -0
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/.travis.yml +28 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +413 -0
- data/Rakefile +14 -0
- data/bin/stripe-mock-server +19 -0
- data/lib/stripe_mock.rb +95 -0
- data/lib/stripe_mock/api/account_balance.rb +14 -0
- data/lib/stripe_mock/api/bank_tokens.rb +13 -0
- data/lib/stripe_mock/api/card_tokens.rb +13 -0
- data/lib/stripe_mock/api/client.rb +41 -0
- data/lib/stripe_mock/api/conversion_rate.rb +14 -0
- data/lib/stripe_mock/api/debug.rb +11 -0
- data/lib/stripe_mock/api/errors.rb +65 -0
- data/lib/stripe_mock/api/global_id_prefix.rb +22 -0
- data/lib/stripe_mock/api/instance.rb +38 -0
- data/lib/stripe_mock/api/live.rb +15 -0
- data/lib/stripe_mock/api/server.rb +39 -0
- data/lib/stripe_mock/api/test_helpers.rb +24 -0
- data/lib/stripe_mock/api/webhooks.rb +88 -0
- data/lib/stripe_mock/client.rb +127 -0
- data/lib/stripe_mock/data.rb +1193 -0
- data/lib/stripe_mock/data/list.rb +73 -0
- data/lib/stripe_mock/error_queue.rb +27 -0
- data/lib/stripe_mock/errors/closed_client_connection_error.rb +9 -0
- data/lib/stripe_mock/errors/server_timeout_error.rb +12 -0
- data/lib/stripe_mock/errors/stripe_mock_error.rb +15 -0
- data/lib/stripe_mock/errors/uninitialized_instance_error.rb +9 -0
- data/lib/stripe_mock/errors/unstarted_state_error.rb +9 -0
- data/lib/stripe_mock/errors/unsupported_request_error.rb +4 -0
- data/lib/stripe_mock/instance.rb +237 -0
- data/lib/stripe_mock/request_handlers/accounts.rb +86 -0
- data/lib/stripe_mock/request_handlers/balance.rb +17 -0
- data/lib/stripe_mock/request_handlers/balance_transactions.rb +37 -0
- data/lib/stripe_mock/request_handlers/cards.rb +35 -0
- data/lib/stripe_mock/request_handlers/charges.rb +177 -0
- data/lib/stripe_mock/request_handlers/country_spec.rb +22 -0
- data/lib/stripe_mock/request_handlers/coupons.rb +35 -0
- data/lib/stripe_mock/request_handlers/customers.rb +137 -0
- data/lib/stripe_mock/request_handlers/disputes.rb +35 -0
- data/lib/stripe_mock/request_handlers/ephemeral_key.rb +13 -0
- data/lib/stripe_mock/request_handlers/events.rb +21 -0
- data/lib/stripe_mock/request_handlers/external_accounts.rb +55 -0
- data/lib/stripe_mock/request_handlers/helpers/bank_account_helpers.rb +14 -0
- data/lib/stripe_mock/request_handlers/helpers/card_helpers.rb +127 -0
- data/lib/stripe_mock/request_handlers/helpers/charge_helpers.rb +16 -0
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +17 -0
- data/lib/stripe_mock/request_handlers/helpers/external_account_helpers.rb +49 -0
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +119 -0
- data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +44 -0
- data/lib/stripe_mock/request_handlers/invoice_items.rb +45 -0
- data/lib/stripe_mock/request_handlers/invoices.rb +177 -0
- data/lib/stripe_mock/request_handlers/orders.rb +80 -0
- data/lib/stripe_mock/request_handlers/payment_intents.rb +203 -0
- data/lib/stripe_mock/request_handlers/payment_methods.rb +112 -0
- data/lib/stripe_mock/request_handlers/payouts.rb +32 -0
- data/lib/stripe_mock/request_handlers/plans.rb +42 -0
- data/lib/stripe_mock/request_handlers/products.rb +43 -0
- data/lib/stripe_mock/request_handlers/recipients.rb +60 -0
- data/lib/stripe_mock/request_handlers/refunds.rb +91 -0
- data/lib/stripe_mock/request_handlers/sources.rb +55 -0
- data/lib/stripe_mock/request_handlers/subscription_items.rb +36 -0
- data/lib/stripe_mock/request_handlers/subscriptions.rb +296 -0
- data/lib/stripe_mock/request_handlers/tax_rates.rb +36 -0
- data/lib/stripe_mock/request_handlers/tokens.rb +75 -0
- data/lib/stripe_mock/request_handlers/transfers.rb +65 -0
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +32 -0
- data/lib/stripe_mock/server.rb +93 -0
- data/lib/stripe_mock/test_strategies/base.rb +81 -0
- data/lib/stripe_mock/test_strategies/live.rb +40 -0
- data/lib/stripe_mock/test_strategies/mock.rb +27 -0
- data/lib/stripe_mock/util.rb +44 -0
- data/lib/stripe_mock/version.rb +4 -0
- data/lib/stripe_mock/webhook_fixtures/account.application.deauthorized.json +12 -0
- data/lib/stripe_mock/webhook_fixtures/account.external_account.created.json +27 -0
- data/lib/stripe_mock/webhook_fixtures/account.external_account.deleted.json +27 -0
- data/lib/stripe_mock/webhook_fixtures/account.external_account.updated.json +27 -0
- data/lib/stripe_mock/webhook_fixtures/account.updated.json +26 -0
- data/lib/stripe_mock/webhook_fixtures/balance.available.json +25 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.closed.json +22 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.created.json +22 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_reinstated.json +88 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_withdrawn.json +88 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.updated.json +25 -0
- data/lib/stripe_mock/webhook_fixtures/charge.failed.json +56 -0
- data/lib/stripe_mock/webhook_fixtures/charge.refunded.json +69 -0
- data/lib/stripe_mock/webhook_fixtures/charge.succeeded.json +55 -0
- data/lib/stripe_mock/webhook_fixtures/charge.updated.json +58 -0
- data/lib/stripe_mock/webhook_fixtures/coupon.created.json +23 -0
- data/lib/stripe_mock/webhook_fixtures/coupon.deleted.json +23 -0
- data/lib/stripe_mock/webhook_fixtures/customer.created.json +54 -0
- data/lib/stripe_mock/webhook_fixtures/customer.deleted.json +42 -0
- data/lib/stripe_mock/webhook_fixtures/customer.discount.created.json +28 -0
- data/lib/stripe_mock/webhook_fixtures/customer.discount.deleted.json +28 -0
- data/lib/stripe_mock/webhook_fixtures/customer.discount.updated.json +43 -0
- data/lib/stripe_mock/webhook_fixtures/customer.source.created.json +32 -0
- data/lib/stripe_mock/webhook_fixtures/customer.source.deleted.json +32 -0
- data/lib/stripe_mock/webhook_fixtures/customer.source.updated.json +36 -0
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +66 -0
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +65 -0
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.trial_will_end.json +65 -0
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +78 -0
- data/lib/stripe_mock/webhook_fixtures/customer.updated.json +57 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.created.json +71 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +105 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +112 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +74 -0
- data/lib/stripe_mock/webhook_fixtures/invoiceitem.created.json +21 -0
- data/lib/stripe_mock/webhook_fixtures/invoiceitem.deleted.json +21 -0
- data/lib/stripe_mock/webhook_fixtures/invoiceitem.updated.json +24 -0
- data/lib/stripe_mock/webhook_fixtures/plan.created.json +20 -0
- data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +20 -0
- data/lib/stripe_mock/webhook_fixtures/plan.updated.json +23 -0
- data/lib/stripe_mock/webhook_fixtures/transfer.created.json +89 -0
- data/lib/stripe_mock/webhook_fixtures/transfer.failed.json +89 -0
- data/lib/stripe_mock/webhook_fixtures/transfer.paid.json +89 -0
- data/lib/stripe_mock/webhook_fixtures/transfer.updated.json +92 -0
- data/lib/trollop.rb +782 -0
- data/spec/_dummy/webhooks/dummy.event.json +6 -0
- data/spec/api/instance_spec.rb +30 -0
- data/spec/fixtures/create_refund.yml +126 -0
- data/spec/fixtures/stripe_webhooks/account.updated.json +7 -0
- data/spec/fixtures/stripe_webhooks/custom.account.updated.json +5 -0
- data/spec/instance_spec.rb +100 -0
- data/spec/integration_examples/charge_token_examples.rb +51 -0
- data/spec/integration_examples/customer_card_examples.rb +42 -0
- data/spec/integration_examples/prepare_error_examples.rb +38 -0
- data/spec/list_spec.rb +140 -0
- data/spec/readme_spec.rb +75 -0
- data/spec/server_spec.rb +139 -0
- data/spec/shared_stripe_examples/account_examples.rb +96 -0
- data/spec/shared_stripe_examples/balance_examples.rb +11 -0
- data/spec/shared_stripe_examples/balance_transaction_examples.rb +63 -0
- data/spec/shared_stripe_examples/bank_examples.rb +229 -0
- data/spec/shared_stripe_examples/bank_token_examples.rb +59 -0
- data/spec/shared_stripe_examples/card_examples.rb +307 -0
- data/spec/shared_stripe_examples/card_token_examples.rb +185 -0
- data/spec/shared_stripe_examples/charge_examples.rb +510 -0
- data/spec/shared_stripe_examples/country_specs_examples.rb +18 -0
- data/spec/shared_stripe_examples/coupon_examples.rb +85 -0
- data/spec/shared_stripe_examples/customer_examples.rb +453 -0
- data/spec/shared_stripe_examples/dispute_examples.rb +98 -0
- data/spec/shared_stripe_examples/ephemeral_key_examples.rb +17 -0
- data/spec/shared_stripe_examples/error_mock_examples.rb +162 -0
- data/spec/shared_stripe_examples/external_account_examples.rb +170 -0
- data/spec/shared_stripe_examples/extra_features_examples.rb +36 -0
- data/spec/shared_stripe_examples/invoice_examples.rb +524 -0
- data/spec/shared_stripe_examples/invoice_item_examples.rb +69 -0
- data/spec/shared_stripe_examples/payment_intent_examples.rb +131 -0
- data/spec/shared_stripe_examples/payment_method_examples.rb +175 -0
- data/spec/shared_stripe_examples/payout_examples.rb +68 -0
- data/spec/shared_stripe_examples/plan_examples.rb +194 -0
- data/spec/shared_stripe_examples/product_example.rb +65 -0
- data/spec/shared_stripe_examples/recipient_examples.rb +118 -0
- data/spec/shared_stripe_examples/refund_examples.rb +472 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +1148 -0
- data/spec/shared_stripe_examples/subscription_items_examples.rb +75 -0
- data/spec/shared_stripe_examples/tax_rate_examples.rb +42 -0
- data/spec/shared_stripe_examples/transfer_examples.rb +130 -0
- data/spec/shared_stripe_examples/validation_examples.rb +19 -0
- data/spec/shared_stripe_examples/webhook_event_examples.rb +261 -0
- data/spec/spec_helper.rb +58 -0
- data/spec/stripe_mock_spec.rb +123 -0
- data/spec/support/stripe_examples.rb +42 -0
- data/spec/util_spec.rb +121 -0
- data/stripe-ruby-mock.gemspec +27 -0
- metadata +344 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module RequestHandlers
|
3
|
+
module ParamValidators
|
4
|
+
|
5
|
+
def validate_create_plan_params(params)
|
6
|
+
params[:id] = params[:id].to_s
|
7
|
+
|
8
|
+
@base_strategy.create_plan_params.keys.each do |name|
|
9
|
+
message =
|
10
|
+
if name == :amount
|
11
|
+
"Plans require an `#{name}` parameter to be set."
|
12
|
+
else
|
13
|
+
"Missing required param: #{name}."
|
14
|
+
end
|
15
|
+
raise Stripe::InvalidRequestError.new(message, name) if params[name].nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
if plans[ params[:id] ]
|
19
|
+
raise Stripe::InvalidRequestError.new("Plan already exists.", :id)
|
20
|
+
end
|
21
|
+
|
22
|
+
unless params[:amount].integer?
|
23
|
+
raise Stripe::InvalidRequestError.new("Invalid integer: #{params[:amount]}", :amount)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def require_param(param_name)
|
28
|
+
raise Stripe::InvalidRequestError.new("Missing required param: #{param_name}.", param_name.to_s, http_status: 400)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'drb/drb'
|
2
|
+
|
3
|
+
module StripeMock
|
4
|
+
class Server
|
5
|
+
def self.start_new(opts)
|
6
|
+
puts "Starting StripeMock server on port #{opts[:port] || 4999}"
|
7
|
+
|
8
|
+
host = opts.fetch :host,'0.0.0.0'
|
9
|
+
port = opts.fetch :port, 4999
|
10
|
+
|
11
|
+
DRb.start_service "druby://#{host}:#{port}", Server.new
|
12
|
+
DRb.thread.join
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
self.clear_data
|
17
|
+
end
|
18
|
+
|
19
|
+
def mock_request(*args)
|
20
|
+
begin
|
21
|
+
@instance.mock_request(*args)
|
22
|
+
rescue Stripe::InvalidRequestError => e
|
23
|
+
{
|
24
|
+
:error_raised => 'invalid_request',
|
25
|
+
:error_params => [
|
26
|
+
e.message, e.param, { http_status: e.http_status, http_body: e.http_body, json_body: e.json_body}
|
27
|
+
]
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_data(key)
|
33
|
+
@instance.send(key)
|
34
|
+
end
|
35
|
+
|
36
|
+
def destroy_resource(type, id)
|
37
|
+
@instance.send(type).delete(id)
|
38
|
+
end
|
39
|
+
|
40
|
+
def clear_data
|
41
|
+
@instance = Instance.new
|
42
|
+
end
|
43
|
+
|
44
|
+
def set_debug(toggle)
|
45
|
+
@instance.debug = toggle
|
46
|
+
end
|
47
|
+
|
48
|
+
def set_global_id_prefix(value)
|
49
|
+
StripeMock.global_id_prefix = value
|
50
|
+
end
|
51
|
+
|
52
|
+
def global_id_prefix
|
53
|
+
StripeMock.global_id_prefix
|
54
|
+
end
|
55
|
+
|
56
|
+
def generate_card_token(card_params)
|
57
|
+
@instance.generate_card_token(card_params)
|
58
|
+
end
|
59
|
+
|
60
|
+
def generate_bank_token(recipient_params)
|
61
|
+
@instance.generate_bank_token(recipient_params)
|
62
|
+
end
|
63
|
+
|
64
|
+
def generate_webhook_event(event_data)
|
65
|
+
@instance.generate_webhook_event(event_data)
|
66
|
+
end
|
67
|
+
|
68
|
+
def set_conversion_rate(value)
|
69
|
+
@instance.conversion_rate = value
|
70
|
+
end
|
71
|
+
|
72
|
+
def set_account_balance(value)
|
73
|
+
@instance.account_balance = value
|
74
|
+
end
|
75
|
+
|
76
|
+
def error_queue
|
77
|
+
@instance.error_queue
|
78
|
+
end
|
79
|
+
|
80
|
+
def debug?
|
81
|
+
@instance.debug
|
82
|
+
end
|
83
|
+
|
84
|
+
def ping
|
85
|
+
true
|
86
|
+
end
|
87
|
+
|
88
|
+
def upsert_stripe_object(object, attributes)
|
89
|
+
@instance.upsert_stripe_object(object, attributes)
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module TestStrategies
|
3
|
+
class Base
|
4
|
+
|
5
|
+
def create_plan_params(params={})
|
6
|
+
currency = params[:currency] || StripeMock.default_currency
|
7
|
+
{
|
8
|
+
:id => 'stripe_mock_default_plan_id',
|
9
|
+
:product => {
|
10
|
+
:name => 'StripeMock Default Plan ID'
|
11
|
+
},
|
12
|
+
:amount => 1337,
|
13
|
+
:currency => currency,
|
14
|
+
:interval => 'month'
|
15
|
+
}.merge(params)
|
16
|
+
end
|
17
|
+
|
18
|
+
def generate_card_token(card_params={})
|
19
|
+
card_data = { :number => "4242424242424242", :exp_month => 9, :exp_year => (Time.now.year + 5), :cvc => "999", :tokenization_method => nil }
|
20
|
+
card = StripeMock::Util.card_merge(card_data, card_params)
|
21
|
+
card[:fingerprint] = StripeMock::Util.fingerprint(card[:number]) if StripeMock.state == 'local'
|
22
|
+
|
23
|
+
stripe_token = Stripe::Token.create(:card => card)
|
24
|
+
stripe_token.id
|
25
|
+
end
|
26
|
+
|
27
|
+
def generate_bank_token(bank_account_params={})
|
28
|
+
currency = bank_account_params[:currency] || StripeMock.default_currency
|
29
|
+
bank_account = {
|
30
|
+
:country => "US",
|
31
|
+
:currency => currency,
|
32
|
+
:account_holder_name => "Jane Austen",
|
33
|
+
:account_holder_type => "individual",
|
34
|
+
:routing_number => "110000000",
|
35
|
+
:account_number => "000123456789"
|
36
|
+
}.merge(bank_account_params)
|
37
|
+
bank_account[:fingerprint] = StripeMock::Util.fingerprint(bank_account[:account_number]) if StripeMock.state == 'local'
|
38
|
+
|
39
|
+
stripe_token = Stripe::Token.create(:bank_account => bank_account)
|
40
|
+
stripe_token.id
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_coupon_params(params = {})
|
44
|
+
currency = params[:currency] || StripeMock.default_currency
|
45
|
+
{
|
46
|
+
id: '10BUCKS',
|
47
|
+
amount_off: 1000,
|
48
|
+
currency: currency,
|
49
|
+
max_redemptions: 100,
|
50
|
+
metadata: {
|
51
|
+
created_by: 'admin_acct_1'
|
52
|
+
},
|
53
|
+
duration: 'once'
|
54
|
+
}.merge(params)
|
55
|
+
end
|
56
|
+
|
57
|
+
def create_coupon_percent_of_params(params = {})
|
58
|
+
{
|
59
|
+
id: '25PERCENT',
|
60
|
+
percent_off: 25,
|
61
|
+
redeem_by: nil,
|
62
|
+
duration_in_months: 3,
|
63
|
+
duration: :repeating
|
64
|
+
}.merge(params)
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_coupon(params = {})
|
68
|
+
Stripe::Coupon.create create_coupon_params(params)
|
69
|
+
end
|
70
|
+
|
71
|
+
def delete_all_coupons
|
72
|
+
coupons = Stripe::Coupon.all
|
73
|
+
coupons.data.map(&:delete) if coupons.data.count > 0
|
74
|
+
end
|
75
|
+
|
76
|
+
def prepare_card_error
|
77
|
+
StripeMock.prepare_card_error(:card_error, :new_customer) if StripeMock.state == 'local'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module TestStrategies
|
3
|
+
class Live < Base
|
4
|
+
|
5
|
+
def create_plan(params={})
|
6
|
+
raise "create_plan requires an :id" if params[:id].nil?
|
7
|
+
delete_plan(params[:id])
|
8
|
+
Stripe::Plan.create create_plan_params(params)
|
9
|
+
end
|
10
|
+
|
11
|
+
def delete_plan(plan_id)
|
12
|
+
begin
|
13
|
+
plan = Stripe::Plan.retrieve(plan_id)
|
14
|
+
plan.delete
|
15
|
+
rescue Stripe::StripeError => e
|
16
|
+
# Do nothing; we just want to make sure this plan ceases to exists
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_coupon(params={})
|
21
|
+
delete_coupon create_coupon_params(params)[:id]
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete_coupon(id)
|
26
|
+
begin
|
27
|
+
coupon = Stripe::Coupon.retrieve(id)
|
28
|
+
coupon.delete
|
29
|
+
rescue Stripe::StripeError
|
30
|
+
# do nothing
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def upsert_stripe_object(object, attributes)
|
35
|
+
raise UnsupportedRequestError.new "Updating or inserting Stripe objects in Live mode not supported"
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module TestStrategies
|
3
|
+
class Mock < Base
|
4
|
+
|
5
|
+
def create_plan(params={})
|
6
|
+
Stripe::Plan.create create_plan_params(params)
|
7
|
+
end
|
8
|
+
|
9
|
+
def delete_plan(plan_id)
|
10
|
+
if StripeMock.state == 'remote'
|
11
|
+
StripeMock.client.destroy_resource('plans', plan_id)
|
12
|
+
elsif StripeMock.state == 'local'
|
13
|
+
StripeMock.instance.plans.delete(plan_id)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def upsert_stripe_object(object, attributes = {})
|
18
|
+
if StripeMock.state == 'remote'
|
19
|
+
StripeMock.client.upsert_stripe_object(object, attributes)
|
20
|
+
elsif StripeMock.state == 'local'
|
21
|
+
StripeMock.instance.upsert_stripe_object(object, attributes)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module Util
|
3
|
+
|
4
|
+
def self.rmerge(desh_hash, source_hash)
|
5
|
+
return source_hash if desh_hash.nil?
|
6
|
+
return nil if source_hash.nil?
|
7
|
+
|
8
|
+
desh_hash.merge(source_hash) do |key, oldval, newval|
|
9
|
+
if oldval.is_a?(Array) && newval.is_a?(Array)
|
10
|
+
oldval.fill(nil, oldval.length...newval.length)
|
11
|
+
oldval.zip(newval).map {|elems|
|
12
|
+
if elems[1].nil?
|
13
|
+
elems[0]
|
14
|
+
elsif elems[1].is_a?(Hash) && elems[1].is_a?(Hash)
|
15
|
+
rmerge(elems[0], elems[1])
|
16
|
+
else
|
17
|
+
[elems[0], elems[1]].compact
|
18
|
+
end
|
19
|
+
}.flatten
|
20
|
+
elsif oldval.is_a?(Hash) && newval.is_a?(Hash)
|
21
|
+
rmerge(oldval, newval)
|
22
|
+
else
|
23
|
+
newval
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.fingerprint(source)
|
29
|
+
Digest::SHA1.base64digest(source).gsub(/[^a-z]/i, '')[0..15]
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.card_merge(old_param, new_param)
|
33
|
+
if new_param[:number] ||= old_param[:number]
|
34
|
+
if new_param[:last4]
|
35
|
+
new_param[:number] = new_param[:number][0..-5] + new_param[:last4]
|
36
|
+
else
|
37
|
+
new_param[:last4] = new_param[:number][-4..-1]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
old_param.merge(new_param)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"created":1326853478,
|
3
|
+
"livemode":false,
|
4
|
+
"id":"evt_00000000000000",
|
5
|
+
"type":"account.external_account.created",
|
6
|
+
"object":"event",
|
7
|
+
"data":{
|
8
|
+
"object":{
|
9
|
+
"id":"ba_00000000000000",
|
10
|
+
"object":"bank_account",
|
11
|
+
"account":"acct_00000000000000",
|
12
|
+
"account_holder_name":"Jane Austen",
|
13
|
+
"account_holder_type":"individual",
|
14
|
+
"bank_name":"STRIPE TEST BANK",
|
15
|
+
"country":"US",
|
16
|
+
"currency":"eur",
|
17
|
+
"default_for_currency":false,
|
18
|
+
"fingerprint":"efGCBmiwp56O1lsN",
|
19
|
+
"last4":"6789",
|
20
|
+
"metadata":{
|
21
|
+
|
22
|
+
},
|
23
|
+
"routing_number":"110000000",
|
24
|
+
"status":"new"
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"created":1326853478,
|
3
|
+
"livemode":false,
|
4
|
+
"id":"evt_00000000000000",
|
5
|
+
"type":"account.external_account.deleted",
|
6
|
+
"object":"event",
|
7
|
+
"data":{
|
8
|
+
"object":{
|
9
|
+
"id":"ba_00000000000000",
|
10
|
+
"object":"bank_account",
|
11
|
+
"account":"acct_00000000000000",
|
12
|
+
"account_holder_name":"Jane Austen",
|
13
|
+
"account_holder_type":"individual",
|
14
|
+
"bank_name":"STRIPE TEST BANK",
|
15
|
+
"country":"US",
|
16
|
+
"currency":"eur",
|
17
|
+
"default_for_currency":false,
|
18
|
+
"fingerprint":"efGCBmiwp56O1lsN",
|
19
|
+
"last4":"6789",
|
20
|
+
"metadata":{
|
21
|
+
|
22
|
+
},
|
23
|
+
"routing_number":"110000000",
|
24
|
+
"status":"new"
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"created":1326853478,
|
3
|
+
"livemode":false,
|
4
|
+
"id":"evt_00000000000000",
|
5
|
+
"type":"account.external_account.updated",
|
6
|
+
"object":"event",
|
7
|
+
"data":{
|
8
|
+
"object":{
|
9
|
+
"id":"ba_00000000000000",
|
10
|
+
"object":"bank_account",
|
11
|
+
"account":"acct_00000000000000",
|
12
|
+
"account_holder_name":"Jane Austen",
|
13
|
+
"account_holder_type":"individual",
|
14
|
+
"bank_name":"STRIPE TEST BANK",
|
15
|
+
"country":"US",
|
16
|
+
"currency":"eur",
|
17
|
+
"default_for_currency":false,
|
18
|
+
"fingerprint":"efGCBmiwp56O1lsN",
|
19
|
+
"last4":"6789",
|
20
|
+
"metadata":{
|
21
|
+
|
22
|
+
},
|
23
|
+
"routing_number":"110000000",
|
24
|
+
"status":"new"
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
{
|
2
|
+
"created": 1326853478,
|
3
|
+
"livemode": false,
|
4
|
+
"id": "evt_00000000000000",
|
5
|
+
"type": "account.updated",
|
6
|
+
"object": "event",
|
7
|
+
"data": {
|
8
|
+
"object": {
|
9
|
+
"id": "acct_00000000000000",
|
10
|
+
"email": "test@stripe.com",
|
11
|
+
"statement_descriptor": "TEST",
|
12
|
+
"details_submitted": true,
|
13
|
+
"charge_enabled": false,
|
14
|
+
"payouts_enabled": false,
|
15
|
+
"currencies_supported": [
|
16
|
+
"USD"
|
17
|
+
],
|
18
|
+
"default_currency": "USD",
|
19
|
+
"country": "US",
|
20
|
+
"object": "account"
|
21
|
+
},
|
22
|
+
"previous_attributes": {
|
23
|
+
"details_submitted": false
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|