Module: StripeMock::RequestHandlers::Sources

Included in:
Instance
Defined in:
lib/stripe_mock/request_handlers/sources.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/stripe_mock/request_handlers/sources.rb', line 5

def Sources.included(klass)
  klass.add_handler 'get /v1/customers/(.*)/sources', :retrieve_sources
  klass.add_handler 'post /v1/customers/(.*)/sources', :create_source
  klass.add_handler 'post /v1/customers/(.*)/sources/(.*)/verify', :verify_source
  klass.add_handler 'get /v1/customers/(.*)/sources/(.*)', :retrieve_source
  klass.add_handler 'delete /v1/customers/(.*)/sources/(.*)', :delete_source
  klass.add_handler 'post /v1/customers/(.*)/sources/(.*)', :update_source
end

Instance Method Details

#create_source(route, method_url, params, headers) ⇒ Object



14
15
16
17
18
# File 'lib/stripe_mock/request_handlers/sources.rb', line 14

def create_source(route, method_url, params, headers)
   = headers && headers[:stripe_account] || Stripe.api_key
  route =~ method_url
  add_source_to(:customer, $1, params, customers[])
end

#delete_source(route, method_url, params, headers) ⇒ Object



34
35
36
37
38
# File 'lib/stripe_mock/request_handlers/sources.rb', line 34

def delete_source(route, method_url, params, headers)
   = headers && headers[:stripe_account] || Stripe.api_key
  route =~ method_url
  delete_card_from(:customer, $1, $2, customers[])
end

#retrieve_source(route, method_url, params, headers) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/stripe_mock/request_handlers/sources.rb', line 26

def retrieve_source(route, method_url, params, headers)
   = headers && headers[:stripe_account] || Stripe.api_key
  route =~ method_url
  customer = assert_existence :customer, $1, customers[][$1]

  assert_existence :card, $2, get_card(customer, $2)
end

#retrieve_sources(route, method_url, params, headers) ⇒ Object



20
21
22
23
24
# File 'lib/stripe_mock/request_handlers/sources.rb', line 20

def retrieve_sources(route, method_url, params, headers)
   = headers && headers[:stripe_account] || Stripe.api_key
  route =~ method_url
  retrieve_object_cards(:customer, $1, customers[])
end

#update_source(route, method_url, params, headers) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/stripe_mock/request_handlers/sources.rb', line 40

def update_source(route, method_url, params, headers)
   = headers && headers[:stripe_account] || Stripe.api_key
  route =~ method_url
  customer = assert_existence :customer, $1, customers[][$1]

  card = assert_existence :card, $2, get_card(customer, $2)
  card.merge!(params)
  card
end

#verify_source(route, method_url, params, headers) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/stripe_mock/request_handlers/sources.rb', line 50

def verify_source(route, method_url, params, headers)
   = headers && headers[:stripe_account] || Stripe.api_key
  route =~ method_url
  customer = assert_existence :customer, $1, customers[][$1]

   = assert_existence :bank_account, $2, (customer, $2)
  
end