Class: GoCardlessPro::Services::PayerAuthorisationsService

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

Overview

Service for making requests to the PayerAuthorisation 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

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

Confirms the Payer Authorisation, indicating that the resources are ready to be created. A Payer Authorisation cannot be confirmed if it hasn’t been submitted yet.

<p class=“notice”>

The main use of the confirm endpoint is to enable integrators to acknowledge

the end of the setup process.

They might want to make the payers go through some other steps after they go

through our flow or make them go through the necessary verification mechanism (upcoming feature). </p> Example URL: /payer_authorisations/:identity/actions/confirm

Parameters:

  • identity

    # Unique identifier, beginning with “PA”.

  • options (Hash) (defaults to: {})

    parameters as a hash, under a params key.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/gocardless_pro/services/payer_authorisations_service.rb', line 161

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

#create(options = {}) ⇒ Object

Creates a Payer Authorisation. The resource is saved to the database even if incomplete. An empty array of incomplete_fields means that the resource is valid. The ID of the resource is used for the other actions. This endpoint has been designed this way so you do not need to save any payer data on your servers or the browser while still being able to implement a progressive solution, such as a multi-step form. Example URL: /payer_authorisations

Parameters:

  • options (Hash) (defaults to: {})

    parameters as a hash, under a params key.



41
42
43
44
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
# File 'lib/gocardless_pro/services/payer_authorisations_service.rb', line 41

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

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

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

Retrieves the details of a single existing Payer Authorisation. It can be used for polling the status of a Payer Authorisation. Example URL: /payer_authorisations/:identity

Parameters:

  • identity

    # Unique identifier, beginning with “PA”.

  • options (Hash) (defaults to: {})

    parameters as a hash, under a params key.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gocardless_pro/services/payer_authorisations_service.rb', line 19

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

  options[:retry_failures] = true

  response = make_request(:get, path, options)

  return if response.body.nil?

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

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

Submits all the data previously pushed to this PayerAuthorisation for verification. This time, a 200 HTTP status is returned if the resource is valid and a 422 error response in case of validation errors. After it is successfully submitted, the Payer Authorisation can no longer be edited. Example URL: /payer_authorisations/:identity/actions/submit

Parameters:

  • identity

    # Unique identifier, beginning with “PA”.

  • options (Hash) (defaults to: {})

    parameters as a hash, under a params key.



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
139
140
141
142
143
144
# File 'lib/gocardless_pro/services/payer_authorisations_service.rb', line 112

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

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

Updates a Payer Authorisation. Updates the Payer Authorisation with the request data. Can be invoked as many times as needed. Only fields present in the request will be modified. An empty array of incomplete_fields means that the resource is valid. This endpoint has been designed this way so you do not need to save any payer data on your servers or the browser while still being able to implement a progressive solution, such a multi-step form. <p class=“notice”> Note that in order to update the ‘metadata` attribute values it must be sent completely as it overrides the previously existing values. </p> Example URL: /payer_authorisations/:identity

Parameters:

  • identity

    # Unique identifier, beginning with “PA”.

  • options (Hash) (defaults to: {})

    parameters as a hash, under a params key.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/gocardless_pro/services/payer_authorisations_service.rb', line 86

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