Class: GoCardlessPro::Services::BillingRequestsService
- Inherits:
-
BaseService
- Object
- BaseService
- GoCardlessPro::Services::BillingRequestsService
- Defined in:
- lib/gocardless_pro/services/billing_requests_service.rb
Overview
Service for making requests to the BillingRequest endpoints
Instance Method Summary collapse
-
#all(options = {}) ⇒ Object
Get a lazily enumerated list of all the items returned.
-
#cancel(identity, options = {}) ⇒ Object
Immediately cancels a billing request, causing all billing request flows to expire.
-
#collect_bank_account(identity, options = {}) ⇒ Object
If the billing request has a pending
collect_bank_accountaction, this endpoint can be used to collect the details in order to complete it. -
#collect_customer_details(identity, options = {}) ⇒ Object
If the billing request has a pending
collect_customer_detailsaction, this endpoint can be used to collect the details in order to complete it. -
#confirm_payer_details(identity, options = {}) ⇒ Object
This is needed when you have mandate_request.
-
#create(options = {}) ⇒ Object
Example URL: /billing_requests.
-
#fulfil(identity, options = {}) ⇒ Object
If a billing request is ready to be fulfilled, call this endpoint to cause it to fulfil, executing the payment.
-
#get(identity, options = {}) ⇒ Object
Fetches a billing request Example URL: /billing_requests/:identity.
-
#list(options = {}) ⇒ Object
Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your billing_requests.
-
#notify(identity, options = {}) ⇒ Object
Notifies the customer linked to the billing request, asking them to authorise it.
Methods inherited from BaseService
#initialize, #make_request, #sub_url
Constructor Details
This class inherits a constructor from GoCardlessPro::Services::BaseService
Instance Method Details
#all(options = {}) ⇒ Object
Get a lazily enumerated list of all the items returned. This is simmilar to the list method but will paginate for you automatically.
Otherwise they will be the body of the request.
35 36 37 38 39 40 |
# File 'lib/gocardless_pro/services/billing_requests_service.rb', line 35 def all( = {}) Paginator.new( service: self, options: ).enumerator end |
#cancel(identity, options = {}) ⇒ Object
Immediately cancels a billing request, causing all billing request flows to expire. Example URL: /billing_requests/:identity/actions/cancel
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/gocardless_pro/services/billing_requests_service.rb', line 266 def cancel(identity, = {}) path = sub_url('/billing_requests/: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::BillingRequest.new(unenvelope_body(response.body), response) end |
#collect_bank_account(identity, options = {}) ⇒ Object
If the billing request has a pending collect_bank_account action, this endpoint can be used to collect the details in order to complete it.
The endpoint takes the same payload as Customer Bank Accounts, but check the bank account is valid for the billing request scheme before creating and attaching it. Example URL: /billing_requests/:identity/actions/collect_bank_account
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/gocardless_pro/services/billing_requests_service.rb', line 151 def collect_bank_account(identity, = {}) path = sub_url('/billing_requests/:identity/actions/collect_bank_account', '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::BillingRequest.new(unenvelope_body(response.body), response) end |
#collect_customer_details(identity, options = {}) ⇒ Object
If the billing request has a pending collect_customer_details action, this endpoint can be used to collect the details in order to complete it.
The endpoint takes the same payload as Customers, but checks that the customer fields are populated correctly for the billing request scheme.
Whatever is provided to this endpoint is used to update the referenced customer, and will take effect immediately after the request is successful. Example URL: /billing_requests/:identity/actions/collect_customer_details
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/gocardless_pro/services/billing_requests_service.rb', line 108 def collect_customer_details(identity, = {}) path = sub_url('/billing_requests/:identity/actions/collect_customer_details', '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::BillingRequest.new(unenvelope_body(response.body), response) end |
#confirm_payer_details(identity, options = {}) ⇒ Object
This is needed when you have mandate_request. As a scheme compliance rule we are required to allow the payer to crosscheck the details entered by them and confirm it. Example URL: /billing_requests/:identity/actions/confirm_payer_details
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/gocardless_pro/services/billing_requests_service.rb', line 228 def confirm_payer_details(identity, = {}) path = sub_url('/billing_requests/:identity/actions/confirm_payer_details', '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::BillingRequest.new(unenvelope_body(response.body), response) end |
#create(options = {}) ⇒ Object
Example URL: /billing_requests
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 70 71 72 73 74 75 |
# File 'lib/gocardless_pro/services/billing_requests_service.rb', line 45 def create( = {}) path = '/billing_requests' 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::BillingRequest.new(unenvelope_body(response.body), response) end |
#fulfil(identity, options = {}) ⇒ Object
If a billing request is ready to be fulfilled, call this endpoint to cause it to fulfil, executing the payment. Example URL: /billing_requests/:identity/actions/fulfil
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/gocardless_pro/services/billing_requests_service.rb', line 189 def fulfil(identity, = {}) path = sub_url('/billing_requests/:identity/actions/fulfil', '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::BillingRequest.new(unenvelope_body(response.body), response) end |
#get(identity, options = {}) ⇒ Object
Fetches a billing request Example URL: /billing_requests/:identity
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/gocardless_pro/services/billing_requests_service.rb', line 82 def get(identity, = {}) path = sub_url('/billing_requests/:identity', 'identity' => identity) [:retry_failures] = true response = make_request(:get, path, ) return if response.body.nil? Resources::BillingRequest.new(unenvelope_body(response.body), response) end |
#list(options = {}) ⇒ Object
Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your billing_requests. Example URL: /billing_requests
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gocardless_pro/services/billing_requests_service.rb', line 17 def list( = {}) path = '/billing_requests' [:retry_failures] = true response = make_request(:get, path, ) ListResponse.new( response: response, unenveloped_body: unenvelope_body(response.body), resource_class: Resources::BillingRequest ) end |
#notify(identity, options = {}) ⇒ Object
Notifies the customer linked to the billing request, asking them to authorise it. Currently, the customer can only be notified by email. Example URL: /billing_requests/:identity/actions/notify
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/gocardless_pro/services/billing_requests_service.rb', line 305 def notify(identity, = {}) path = sub_url('/billing_requests/:identity/actions/notify', '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::BillingRequest.new(unenvelope_body(response.body), response) end |