class GoCardlessPro::Services::OutboundPaymentsService
Service for making requests to the OutboundPayment endpoints
Public Instance Methods
Source
# File lib/gocardless_pro/services/outbound_payments_service.rb, line 207 def all(options = {}) Paginator.new( service: self, options: options ).enumerator end
Get a lazily enumerated list of all the items returned. This is similar to the ‘list` method but will paginate for you automatically.
@param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters. Otherwise they will be the body of the request.
Source
# File lib/gocardless_pro/services/outbound_payments_service.rb, line 132 def approve(identity, options = {}) path = sub_url('/outbound_payments/:identity/actions/approve', { 'identity' => identity }) params = options.delete(:params) || {} options[:params] = {} options[:params]['data'] = params options[:retry_failures] = false begin response = make_request(:post, path, options) # 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::OutboundPayment.new(unenvelope_body(response.body), response) end
Approves an outbound payment. Only outbound payments with the “pending_approval” status can be approved. Example URL: /outbound_payments/:identity/actions/approve
@param identity # Unique identifier of the outbound payment. @param options [Hash] parameters as a hash, under a params key.
Source
# File lib/gocardless_pro/services/outbound_payments_service.rb, line 92 def cancel(identity, options = {}) path = sub_url('/outbound_payments/:identity/actions/cancel', { 'identity' => identity }) params = options.delete(:params) || {} options[:params] = {} options[:params]['data'] = params options[:retry_failures] = false begin response = make_request(:post, path, options) # 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::OutboundPayment.new(unenvelope_body(response.body), response) end
Cancels an outbound payment. Only outbound payments with either ‘verifying`, `pending_approval`, or `scheduled` status can be cancelled. Once an outbound payment is `executing`, the money moving process has begun and cannot be reversed. Example URL: /outbound_payments/:identity/actions/cancel
@param identity # Unique identifier of the outbound payment. @param options [Hash] parameters as a hash, under a params key.
Source
# File lib/gocardless_pro/services/outbound_payments_service.rb, line 16 def create(options = {}) path = '/outbound_payments' params = options.delete(:params) || {} options[:params] = {} options[:params][envelope_key] = params options[:retry_failures] = true begin response = make_request(:post, path, options) # 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::OutboundPayment.new(unenvelope_body(response.body), response) end
Example URL: /outbound_payments @param options [Hash] parameters as a hash, under a params key.
Source
# File lib/gocardless_pro/services/outbound_payments_service.rb, line 171 def get(identity, options = {}) path = sub_url('/outbound_payments/:identity', { 'identity' => identity }) options[:retry_failures] = true response = make_request(:get, path, options) return if response.body.nil? Resources::OutboundPayment.new(unenvelope_body(response.body), response) end
Fetches an outbound_payment by ID Example URL: /outbound_payments/:identity
@param identity # Unique identifier of the outbound payment. @param options [Hash] parameters as a hash, under a params key.
Source
# File lib/gocardless_pro/services/outbound_payments_service.rb, line 189 def list(options = {}) path = '/outbound_payments' options[:retry_failures] = true response = make_request(:get, path, options) ListResponse.new( response: response, unenveloped_body: unenvelope_body(response.body), resource_class: Resources::OutboundPayment ) end
Returns a [cursor-paginated](api-usage-cursor-pagination) list of outbound payments. Example URL: /outbound_payments @param options [Hash] parameters as a hash, under a params key.
Source
# File lib/gocardless_pro/services/outbound_payments_service.rb, line 219 def update(identity, options = {}) path = sub_url('/outbound_payments/:identity', { 'identity' => identity }) params = options.delete(:params) || {} options[:params] = {} options[:params][envelope_key] = params options[:retry_failures] = true response = make_request(:put, path, options) return if response.body.nil? Resources::OutboundPayment.new(unenvelope_body(response.body), response) end
Updates an outbound payment object. This accepts only the metadata parameter. Example URL: /outbound_payments/:identity
@param identity # Unique identifier of the outbound payment. @param options [Hash] parameters as a hash, under a params key.
Source
# File lib/gocardless_pro/services/outbound_payments_service.rb, line 52 def withdraw(options = {}) path = '/outbound_payments/withdrawal' params = options.delete(:params) || {} options[:params] = {} options[:params]['data'] = params options[:retry_failures] = false begin response = make_request(:post, path, options) # 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::OutboundPayment.new(unenvelope_body(response.body), response) end
Creates an outbound payment to your verified business bank account as the recipient. Example URL: /outbound_payments/withdrawal @param options [Hash] parameters as a hash, under a params key.
Private Instance Methods
Source
# File lib/gocardless_pro/services/outbound_payments_service.rb, line 247 def envelope_key 'outbound_payments' end
return the key which API responses will envelope data under
Source
# File lib/gocardless_pro/services/outbound_payments_service.rb, line 242 def unenvelope_body(body) body[envelope_key] || body['data'] end
Unenvelope the response of the body using the service’s ‘envelope_key`
@param body [Hash]