Class: GoCardlessPro::Services::MandateImportsService
- Inherits:
-
BaseService
- Object
- BaseService
- GoCardlessPro::Services::MandateImportsService
- Defined in:
- lib/gocardless_pro/services/mandate_imports_service.rb
Overview
Service for making requests to the MandateImport endpoints
Instance Method Summary collapse
-
#cancel(identity, options = {}) ⇒ Object
Cancels the mandate import, which aborts the import process and stops the mandates being set up in GoCardless.
-
#create(options = {}) ⇒ Object
Mandate imports are first created, before mandates are added one-at-a-time, so this endpoint merely signals the start of the import process.
-
#get(identity, options = {}) ⇒ Object
Returns a single mandate import.
-
#submit(identity, options = {}) ⇒ Object
Submits the mandate import, which allows it to be processed by a member of the GoCardless team.
Methods inherited from BaseService
#initialize, #make_request, #sub_url
Constructor Details
This class inherits a constructor from GoCardlessPro::Services::BaseService
Instance Method Details
#cancel(identity, options = {}) ⇒ Object
Cancels the mandate import, which aborts the import process and stops the mandates being set up in GoCardless. Once the import has been cancelled, it can no longer have entries added to it. Mandate imports which have already been submitted or processed cannot be cancelled. Example URL: /mandate_imports/:identity/actions/cancel
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/gocardless_pro/services/mandate_imports_service.rb', line 131 def cancel(identity, = {}) path = sub_url('/mandate_imports/:identity/actions/cancel', { 'identity' => identity }) params = .delete(:params) || {} [:params] = {} [:params]['data'] = params [:retry_failures] = false begin response = make_request(:post, path, ) # Response doesn't raise any errors until #body is called response.tap(&:body) rescue InvalidStateError => e if e.idempotent_creation_conflict? case @api_service.on_idempotency_conflict when :raise raise IdempotencyConflict, e.error when :fetch return get(e.conflicting_resource_id) end end raise e end return if response.body.nil? Resources::MandateImport.new(unenvelope_body(response.body), response) end |
#create(options = {}) ⇒ Object
Mandate imports are first created, before mandates are added one-at-a-time, so this endpoint merely signals the start of the import process. Once you’ve finished adding entries to an import, you should [submit](#mandate-imports-submit-a-mandate-import) it. Example URL: /mandate_imports
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/gocardless_pro/services/mandate_imports_service.rb', line 20 def create( = {}) path = '/mandate_imports' params = .delete(:params) || {} [:params] = {} [:params][envelope_key] = params [:retry_failures] = true begin response = make_request(:post, path, ) # Response doesn't raise any errors until #body is called response.tap(&:body) rescue InvalidStateError => e if e.idempotent_creation_conflict? case @api_service.on_idempotency_conflict when :raise raise IdempotencyConflict, e.error when :fetch return get(e.conflicting_resource_id) end end raise e end return if response.body.nil? Resources::MandateImport.new(unenvelope_body(response.body), response) end |
#get(identity, options = {}) ⇒ Object
Returns a single mandate import. Example URL: /mandate_imports/:identity
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/gocardless_pro/services/mandate_imports_service.rb', line 57 def get(identity, = {}) path = sub_url('/mandate_imports/:identity', { 'identity' => identity }) [:retry_failures] = true response = make_request(:get, path, ) return if response.body.nil? Resources::MandateImport.new(unenvelope_body(response.body), response) end |
#submit(identity, options = {}) ⇒ Object
Submits the mandate import, which allows it to be processed by a member of the GoCardless team. Once the import has been submitted, it can no longer have entries added to it.
In our sandbox environment, to aid development, we automatically process mandate imports approximately 10 seconds after they are submitted. This will allow you to test both the “submitted” response and wait for the webhook to confirm the processing has begun. Example URL: /mandate_imports/:identity/actions/submit
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/gocardless_pro/services/mandate_imports_service.rb', line 86 def submit(identity, = {}) path = sub_url('/mandate_imports/:identity/actions/submit', { 'identity' => identity }) params = .delete(:params) || {} [:params] = {} [:params]['data'] = params [:retry_failures] = false begin response = make_request(:post, path, ) # Response doesn't raise any errors until #body is called response.tap(&:body) rescue InvalidStateError => e if e.idempotent_creation_conflict? case @api_service.on_idempotency_conflict when :raise raise IdempotencyConflict, e.error when :fetch return get(e.conflicting_resource_id) end end raise e end return if response.body.nil? Resources::MandateImport.new(unenvelope_body(response.body), response) end |