class GoCardless::Services::RedirectFlowService

Service for making requests to the RedirectFlow endpoints

Public Instance Methods

complete(identity, options = {}, custom_headers = {}) click to toggle source

This creates a [customer](developer.gocardless.com/pro/#api-endpoints-customers), [customer bank account](developer.gocardless.com/pro/#api-endpoints-customer-bank-account), and [mandate](developer.gocardless.com/pro/#api-endpoints-mandates) using the details supplied by your customer and returns the ID of the created mandate.

This will return a ‘redirect_flow_incomplete` error if your customer has not yet been redirected back to your site, and a `redirect_flow_already_completed` error if your integration has already completed this flow. It will return a `bad_request` error if the `session_token` differs to the one supplied when the redirect flow was created. Example URL: /redirect_flows/:identity/actions/complete

@param identity # Unique identifier, beginning with “RE” @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters. Else, they will be the body of the request.

# File lib/gocardless-pro/services/redirect_flow_service.rb, line 61
def complete(identity, options = {}, custom_headers = {})
  path = sub_url('/redirect_flows/:identity/actions/complete',           'identity' => identity)

  new_options = {}
  new_options['data'] = options
  options = new_options
  response = make_request(:post, path, options, custom_headers)

  Resources::RedirectFlow.new(unenvelope_body(response.body))
end
create(options = {}, custom_headers = {}) click to toggle source

Creates a redirect flow object which can then be used to redirect your customer to the GoCardless Pro hosted payment pages. Example URL: /redirect_flows @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters. Else, they will be the body of the request.

# File lib/gocardless-pro/services/redirect_flow_service.rb, line 18
def create(options = {}, custom_headers = {})
  path = '/redirect_flows'
  new_options = {}
  new_options[envelope_key] = options
  options = new_options
  response = make_request(:post, path, options, custom_headers)

  Resources::RedirectFlow.new(unenvelope_body(response.body))
end
get(identity, options = {}, custom_headers = {}) click to toggle source

Returns all details about a single redirect flow Example URL: /redirect_flows/:identity

@param identity # Unique identifier, beginning with “RE” @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters. Else, they will be the body of the request.

# File lib/gocardless-pro/services/redirect_flow_service.rb, line 34
def get(identity, options = {}, custom_headers = {})
  path = sub_url('/redirect_flows/:identity',           'identity' => identity)

  response = make_request(:get, path, options, custom_headers)

  Resources::RedirectFlow.new(unenvelope_body(response.body))
end
unenvelope_body(body) click to toggle source

Unenvelope the response of the body using the service’s ‘envelope_key`

@param body [Hash]

# File lib/gocardless-pro/services/redirect_flow_service.rb, line 75
def unenvelope_body(body)
  body[envelope_key] || body['data']
end

Private Instance Methods

envelope_key() click to toggle source

return the key which API responses will envelope data under

# File lib/gocardless-pro/services/redirect_flow_service.rb, line 82
def envelope_key
  'redirect_flows'
end
sub_url(url, param_map) click to toggle source

take a URL with placeholder params and substitute them out for the acutal value @param url [String] the URL with placeholders in @param param_map [Hash] a hash of placeholders and their actual values

# File lib/gocardless-pro/services/redirect_flow_service.rb, line 89
def sub_url(url, param_map)
  param_map.reduce(url) do |new_url, (param, value)|
    new_url.gsub(":#{param}", value)
  end
end