Class: Payabli::Customer::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/payabli/customer/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



9
10
11
# File 'lib/payabli/customer/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#add_customer(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponseCustomerQuery

Creates a customer in an entrypoint. An identifier is required to create customer records. Change your identifier settings in Settings > Custom Fields in PartnerHub. If you don’t include an identifier, the record is rejected.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:



30
31
32
33
34
35
36
37
38
39
40
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
# File 'lib/payabli/customer/client.rb', line 30

def add_customer(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  path_param_names = %i[entry]
  body_params = params.except(*path_param_names)

  query_param_names = %i[force_customer_creation replace_existing]
  query_params = {}
  query_params["forceCustomerCreation"] = params[:force_customer_creation] if params.key?(:force_customer_creation)
  query_params["replaceExisting"] = params[:replace_existing] if params.key?(:replace_existing)
  params = params.except(*query_param_names)

  headers = {}
  headers["idempotencyKey"] = params[:idempotency_key] if params[:idempotency_key]

  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "Customer/single/#{URI.encode_uri_component(params[:entry].to_s)}",
    headers: headers,
    query: query_params,
    body: Payabli::Types::CustomerData.new(body_params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::PayabliApiResponseCustomerQuery.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#delete_customer(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponse00Responsedatanonobject

Delete a customer record.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :customer_id (Integer)

Returns:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/payabli/customer/client.rb', line 79

def delete_customer(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "DELETE",
    path: "Customer/#{URI.encode_uri_component(params[:customer_id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::PayabliApiResponse00Responsedatanonobject.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_customer(request_options: {}, **params) ⇒ Payabli::Types::CustomerQueryRecords

Retrieves a customer’s record and details.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :customer_id (Integer)

Returns:



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/payabli/customer/client.rb', line 113

def get_customer(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "Customer/#{URI.encode_uri_component(params[:customer_id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::CustomerQueryRecords.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

Links a customer to a transaction by ID.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :customer_id (Integer)
  • :trans_id (String)

Returns:



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/payabli/customer/client.rb', line 148

def link_customer_transaction(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "Customer/link/#{URI.encode_uri_component(params[:customer_id].to_s)}/#{URI.encode_uri_component(params[:trans_id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::PayabliApiResponse00Responsedatanonobject.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

Sends the consent opt-in email to the customer email address in the customer record.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :customer_id (Integer)

Returns:



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/payabli/customer/client.rb', line 182

def request_consent(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "Customer/#{URI.encode_uri_component(params[:customer_id].to_s)}/consent",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::PayabliApiResponse00Responsedatanonobject.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#update_customer(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponse00Responsedatanonobject

Update a customer record. Include only the fields you want to change.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :customer_id (Integer)

Returns:



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/payabli/customer/client.rb', line 216

def update_customer(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PUT",
    path: "Customer/#{URI.encode_uri_component(params[:customer_id].to_s)}",
    body: Payabli::Types::CustomerData.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::PayabliApiResponse00Responsedatanonobject.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end