Class: GoCardlessPro::Services::RedirectFlowsService

Inherits:
BaseService
  • Object
show all
Defined in:
lib/gocardless_pro/services/redirect_flows_service.rb

Overview

Service for making requests to the RedirectFlow endpoints

Instance Method Summary collapse

Methods inherited from BaseService

#initialize, #make_request, #sub_url

Constructor Details

This class inherits a constructor from GoCardlessPro::Services::BaseService

Instance Method Details

#complete(identity, options = {}) ⇒ Object

This creates a [customer](#core-endpoints-customers), [customer bank account](#core-endpoints-customer-bank-accounts), and [mandate](#core-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



82
83
84
85
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
# File 'lib/gocardless_pro/services/redirect_flows_service.rb', line 82

def complete(identity, options = {})
  path = sub_url('/redirect_flows/:identity/actions/complete', {
                   '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::RedirectFlow.new(unenvelope_body(response.body), response)
end

#create(options = {}) ⇒ Object

Creates a redirect flow object which can then be used to redirect your customer to the GoCardless hosted payment pages. Example URL: /redirect_flows



17
18
19
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
# File 'lib/gocardless_pro/services/redirect_flows_service.rb', line 17

def create(options = {})
  path = '/redirect_flows'

  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::RedirectFlow.new(unenvelope_body(response.body), response)
end

#get(identity, options = {}) ⇒ Object

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



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/gocardless_pro/services/redirect_flows_service.rb', line 54

def get(identity, options = {})
  path = sub_url('/redirect_flows/:identity', {
                   'identity' => identity,
                 })

  options[:retry_failures] = true

  response = make_request(:get, path, options)

  return if response.body.nil?

  Resources::RedirectFlow.new(unenvelope_body(response.body), response)
end