Class: StripeMock::Instance
- Inherits:
-
Object
- Object
- StripeMock::Instance
- Includes:
- RequestHandlers::Accounts, RequestHandlers::Cards, RequestHandlers::Charges, RequestHandlers::Coupons, RequestHandlers::Customers, RequestHandlers::Disputes, RequestHandlers::Events, RequestHandlers::Helpers, RequestHandlers::InvoiceItems, RequestHandlers::Invoices, RequestHandlers::Orders, RequestHandlers::ParamValidators, RequestHandlers::Plans, RequestHandlers::Recipients, RequestHandlers::Sources, RequestHandlers::Subscriptions, RequestHandlers::Tokens, RequestHandlers::Transfers
- Defined in:
- lib/stripe_mock/instance.rb
Constant Summary collapse
- @@handlers =
Handlers are ordered by priority
[]
Instance Attribute Summary collapse
-
#accounts ⇒ Object
readonly
Returns the value of attribute accounts.
-
#bank_tokens ⇒ Object
readonly
Returns the value of attribute bank_tokens.
-
#charges ⇒ Object
readonly
Returns the value of attribute charges.
-
#coupons ⇒ Object
readonly
Returns the value of attribute coupons.
-
#customers ⇒ Object
readonly
Returns the value of attribute customers.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#disputes ⇒ Object
readonly
Returns the value of attribute disputes.
-
#error_queue ⇒ Object
Returns the value of attribute error_queue.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#invoice_items ⇒ Object
readonly
Returns the value of attribute invoice_items.
-
#invoices ⇒ Object
readonly
Returns the value of attribute invoices.
-
#orders ⇒ Object
readonly
Returns the value of attribute orders.
-
#plans ⇒ Object
readonly
Returns the value of attribute plans.
-
#recipients ⇒ Object
readonly
Returns the value of attribute recipients.
-
#subscriptions ⇒ Object
readonly
Returns the value of attribute subscriptions.
-
#transfers ⇒ Object
readonly
Returns the value of attribute transfers.
Class Method Summary collapse
Instance Method Summary collapse
- #generate_webhook_event(event_data) ⇒ Object
-
#initialize ⇒ Instance
constructor
A new instance of Instance.
- #mock_request(method, url, api_key, params = {}, headers = {}, api_base_url = nil) ⇒ Object
Methods included from RequestHandlers::Tokens
#create_token, #get_token, included
Methods included from RequestHandlers::Transfers
#cancel_transfer, #get_all_transfers, #get_transfer, included, #new_transfer
Methods included from RequestHandlers::Recipients
#get_recipient, included, #new_recipient, #update_recipient
Methods included from RequestHandlers::Plans
#delete_plan, #get_plan, included, #list_plans, #new_plan, #update_plan
Methods included from RequestHandlers::Orders
#get_order, included, #list_orders, #new_order, #pay_order, #update_order
Methods included from RequestHandlers::InvoiceItems
#delete_invoice_item, #get_invoice_item, included, #list_invoice_items, #new_invoice_item, #update_invoice_item
Methods included from RequestHandlers::Invoices
#get_invoice, #get_invoice_line_items, included, #list_invoices, #new_invoice, #pay_invoice, #upcoming_invoice, #update_invoice
Methods included from RequestHandlers::Events
included, #list_events, #retrieve_event
Methods included from RequestHandlers::Disputes
#close_dispute, #get_dispute, included, #list_disputes, #update_dispute
Methods included from RequestHandlers::Coupons
#delete_coupon, #get_coupon, included, #list_coupons, #new_coupon
Methods included from RequestHandlers::Customers
#delete_customer, #get_customer, included, #list_customers, #new_customer, #update_customer
Methods included from RequestHandlers::Subscriptions
#cancel_subscription, #create_subscription, included, #retrieve_subscription, #retrieve_subscriptions, #update_subscription
Methods included from RequestHandlers::Sources
#create_source, #delete_source, included, #retrieve_source, #retrieve_sources, #update_source
Methods included from RequestHandlers::Cards
#create_recipient_card, #delete_recipient_card, included, #retrieve_recipient_card, #retrieve_recipient_cards
Methods included from RequestHandlers::Charges
#capture_charge, #create_refund, #get_charge, #get_charges, included, #new_charge, #refund_charge, #update_charge
Methods included from RequestHandlers::Accounts
#get_account, included, #list_accounts, #new_account, #update_account
Methods included from RequestHandlers::ParamValidators
Methods included from RequestHandlers::Helpers
#add_card_to, #add_card_to_object, #add_coupon_to_customer, #add_refund_to_charge, #add_subscription_to_customer, #card_from_params, #custom_subscription_params, #delete_card_from, #delete_subscription_from_customer, #generate_bank_token, #generate_card_token, #get_bank_by_token, #get_card, #get_card_by_token, #get_customer_subscription, #get_ending_time, #retrieve_object_cards, #validate_card, #verify_trial_end
Constructor Details
#initialize ⇒ Instance
Returns a new instance of Instance.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/stripe_mock/instance.rb', line 45 def initialize @accounts = {} @bank_tokens = {} @card_tokens = {} @customers = {} @charges = {} @coupons = {} @disputes = Data.mock_disputes(['dp_05RsQX2eZvKYlo2C0FRTGSSA','dp_15RsQX2eZvKYlo2C0ERTYUIA', 'dp_25RsQX2eZvKYlo2C0ZXCVBNM', 'dp_35RsQX2eZvKYlo2C0QAZXSWE', 'dp_45RsQX2eZvKYlo2C0EDCVFRT', 'dp_55RsQX2eZvKYlo2C0OIKLJUY', 'dp_65RsQX2eZvKYlo2C0ASDFGHJ', 'dp_75RsQX2eZvKYlo2C0EDCXSWQ', 'dp_85RsQX2eZvKYlo2C0UJMCDET', 'dp_95RsQX2eZvKYlo2C0EDFRYUI']) @events = {} @invoices = {} @invoice_items = {} @orders = {} @plans = {} @recipients = {} @transfers = {} @subscriptions = {} @debug = false @error_queue = ErrorQueue.new @id_counter = 0 @balance_transaction_counter = 0 # This is basically a cache for ParamValidators @base_strategy = TestStrategies::Base.new end |
Instance Attribute Details
#accounts ⇒ Object (readonly)
Returns the value of attribute accounts.
39 40 41 |
# File 'lib/stripe_mock/instance.rb', line 39 def accounts @accounts end |
#bank_tokens ⇒ Object (readonly)
Returns the value of attribute bank_tokens.
39 40 41 |
# File 'lib/stripe_mock/instance.rb', line 39 def bank_tokens @bank_tokens end |
#charges ⇒ Object (readonly)
Returns the value of attribute charges.
39 40 41 |
# File 'lib/stripe_mock/instance.rb', line 39 def charges @charges end |
#coupons ⇒ Object (readonly)
Returns the value of attribute coupons.
39 40 41 |
# File 'lib/stripe_mock/instance.rb', line 39 def coupons @coupons end |
#customers ⇒ Object (readonly)
Returns the value of attribute customers.
39 40 41 |
# File 'lib/stripe_mock/instance.rb', line 39 def customers @customers end |
#debug ⇒ Object
Returns the value of attribute debug.
43 44 45 |
# File 'lib/stripe_mock/instance.rb', line 43 def debug @debug end |
#disputes ⇒ Object (readonly)
Returns the value of attribute disputes.
39 40 41 |
# File 'lib/stripe_mock/instance.rb', line 39 def disputes @disputes end |
#error_queue ⇒ Object
Returns the value of attribute error_queue.
43 44 45 |
# File 'lib/stripe_mock/instance.rb', line 43 def error_queue @error_queue end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
39 40 41 |
# File 'lib/stripe_mock/instance.rb', line 39 def events @events end |
#invoice_items ⇒ Object (readonly)
Returns the value of attribute invoice_items.
39 40 41 |
# File 'lib/stripe_mock/instance.rb', line 39 def invoice_items @invoice_items end |
#invoices ⇒ Object (readonly)
Returns the value of attribute invoices.
39 40 41 |
# File 'lib/stripe_mock/instance.rb', line 39 def invoices @invoices end |
#orders ⇒ Object (readonly)
Returns the value of attribute orders.
39 40 41 |
# File 'lib/stripe_mock/instance.rb', line 39 def orders @orders end |
#plans ⇒ Object (readonly)
Returns the value of attribute plans.
39 40 41 |
# File 'lib/stripe_mock/instance.rb', line 39 def plans @plans end |
#recipients ⇒ Object (readonly)
Returns the value of attribute recipients.
39 40 41 |
# File 'lib/stripe_mock/instance.rb', line 39 def recipients @recipients end |
#subscriptions ⇒ Object (readonly)
Returns the value of attribute subscriptions.
39 40 41 |
# File 'lib/stripe_mock/instance.rb', line 39 def subscriptions @subscriptions end |
#transfers ⇒ Object (readonly)
Returns the value of attribute transfers.
39 40 41 |
# File 'lib/stripe_mock/instance.rb', line 39 def transfers @transfers end |
Class Method Details
.add_handler(route, name) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/stripe_mock/instance.rb', line 10 def self.add_handler(route, name) @@handlers << { :route => %r{^#{route}$}, :name => name } end |
.handler_for_method_url(method_url) ⇒ Object
17 18 19 |
# File 'lib/stripe_mock/instance.rb', line 17 def self.handler_for_method_url(method_url) @@handlers.find {|h| method_url =~ h[:route] } end |
Instance Method Details
#generate_webhook_event(event_data) ⇒ Object
103 104 105 106 |
# File 'lib/stripe_mock/instance.rb', line 103 def generate_webhook_event(event_data) event_data[:id] ||= new_id 'evt' @events[ event_data[:id] ] = symbolize_names(event_data) end |
#mock_request(method, url, api_key, params = {}, headers = {}, api_base_url = nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/stripe_mock/instance.rb', line 71 def mock_request(method, url, api_key, params={}, headers={}, api_base_url=nil) return {} if method == :xtest api_key ||= Stripe.api_key # Ensure params hash has symbols as keys params = Stripe::Util.symbolize_names(params) method_url = "#{method} #{url}" if handler = Instance.handler_for_method_url(method_url) if @debug == true puts "- - - - " * 8 puts "[StripeMock req]::#{handler[:name]} #{method} #{url}" puts " #{params}" end if mock_error = @error_queue.error_for_handler_name(handler[:name]) @error_queue.dequeue raise mock_error else res = self.send(handler[:name], handler[:route], method_url, params, headers) puts " [res] #{res}" if @debug == true [res, api_key] end else puts "[StripeMock] Warning : Unrecognized endpoint + method : [#{method} #{url}]" puts "[StripeMock] params: #{params}" unless params.empty? [{}, api_key] end end |