Module: StripeMock::RequestHandlers::SetupIntents
- Included in:
- Instance
- Defined in:
- lib/stripe_mock/request_handlers/setup_intents.rb
Constant Summary collapse
- ALLOWED_PARAMS =
[ :confirm, :customer, :description, :metadata, :on_behalf_of, :payment_method, :payment_method_options, :payment_method_types, :return_url, :usage ]
Class Method Summary collapse
Instance Method Summary collapse
- #cancel_setup_intent(route, method_url, params, headers) ⇒ Object
- #capture_setup_intent(route, method_url, params, headers) ⇒ Object
- #confirm_setup_intent(route, method_url, params, headers) ⇒ Object
- #get_setup_intent(route, method_url, params, headers) ⇒ Object
- #get_setup_intents(route, method_url, params, headers) ⇒ Object
- #new_setup_intent(route, method_url, params, headers) ⇒ Object
- #update_setup_intent(route, method_url, params, headers) ⇒ Object
Class Method Details
.included(klass) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/stripe_mock/request_handlers/setup_intents.rb', line 17 def SetupIntents.included(klass) klass.add_handler 'post /v1/setup_intents', :new_setup_intent klass.add_handler 'get /v1/setup_intents', :get_setup_intents klass.add_handler 'get /v1/setup_intents/(.*)', :get_setup_intent klass.add_handler 'post /v1/setup_intents/(.*)/confirm', :confirm_setup_intent klass.add_handler 'post /v1/setup_intents/(.*)/cancel', :cancel_setup_intent klass.add_handler 'post /v1/setup_intents/(.*)', :update_setup_intent end |
Instance Method Details
#cancel_setup_intent(route, method_url, params, headers) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/stripe_mock/request_handlers/setup_intents.rb', line 91 def cancel_setup_intent(route, method_url, params, headers) route =~ method_url setup_intent = assert_existence :setup_intent, $1, setup_intents[$1] setup_intent[:status] = 'canceled' setup_intent end |
#capture_setup_intent(route, method_url, params, headers) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/stripe_mock/request_handlers/setup_intents.rb', line 75 def capture_setup_intent(route, method_url, params, headers) route =~ method_url setup_intent = assert_existence :setup_intent, $1, setup_intents[$1] setup_intent[:status] = 'succeeded' setup_intent end |
#confirm_setup_intent(route, method_url, params, headers) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/stripe_mock/request_handlers/setup_intents.rb', line 83 def confirm_setup_intent(route, method_url, params, headers) route =~ method_url setup_intent = assert_existence :setup_intent, $1, setup_intents[$1] setup_intent[:status] = 'succeeded' setup_intent end |
#get_setup_intent(route, method_url, params, headers) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/stripe_mock/request_handlers/setup_intents.rb', line 61 def get_setup_intent(route, method_url, params, headers) route =~ method_url setup_intent_id = $1 || params[:setup_intent] setup_intent = assert_existence :setup_intent, setup_intent_id, setup_intents[setup_intent_id] setup_intent = setup_intent.clone if params[:expand]&.include?("payment_method") setup_intent[:payment_method] = assert_existence :payment_method, setup_intent[:payment_method], payment_methods[setup_intent[:payment_method]] end setup_intent end |
#get_setup_intents(route, method_url, params, headers) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/stripe_mock/request_handlers/setup_intents.rb', line 48 def get_setup_intents(route, method_url, params, headers) params[:offset] ||= 0 params[:limit] ||= 10 clone = setup_intents.clone if params[:customer] clone.delete_if { |k, v| v[:customer] != params[:customer] } end Data.mock_list_object(clone.values, params) end |
#new_setup_intent(route, method_url, params, headers) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/stripe_mock/request_handlers/setup_intents.rb', line 26 def new_setup_intent(route, method_url, params, headers) id = new_id('si') status = params[:payment_method] ? 'requires_action' : 'requires_payment_method' setup_intents[id] = Data.mock_setup_intent( params.merge( id: id, status: status ) ) setup_intents[id].clone end |
#update_setup_intent(route, method_url, params, headers) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/stripe_mock/request_handlers/setup_intents.rb', line 40 def update_setup_intent(route, method_url, params, headers) route =~ method_url id = $1 setup_intent = assert_existence :setup_intent, id, setup_intents[id] setup_intents[id] = Util.rmerge(setup_intent, params.select { |k, v| ALLOWED_PARAMS.include?(k) }) end |