Class: Payabli::Customer::Client
- Inherits:
-
Object
- Object
- Payabli::Customer::Client
- Defined in:
- lib/payabli/customer/client.rb
Instance Method Summary collapse
-
#add_customer(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponseCustomerQuery
Creates a customer in an entrypoint.
-
#delete_customer(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponse00Responsedatanonobject
Delete a customer record.
-
#get_customer(request_options: {}, **params) ⇒ Payabli::Types::CustomerQueryRecords
Retrieves a customer's record and details.
- #initialize(client:) ⇒ void constructor
-
#link_customer_transaction(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponse00Responsedatanonobject
Links a customer to a transaction by ID.
-
#request_consent(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponse00Responsedatanonobject
Sends the consent opt-in email to the customer email address in the customer record.
-
#update_customer(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponse00Responsedatanonobject
Update a customer record.
Constructor Details
#initialize(client:) ⇒ void
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 the Payabli Portal. If you don't include an identifier, the record is rejected.
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 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/payabli/customer/client.rb', line 46 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] headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }]).merge(headers) request = Payabli::Internal::JSON::Request.new( base_url: [: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: ) 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.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/payabli/customer/client.rb', line 187 def delete_customer(request_options: {}, **params) params = Payabli::Internal::Types::Utils.normalize_keys(params) headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }]) request = Payabli::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "Customer/#{URI.encode_uri_component(params[:customer_id].to_s)}", headers: headers, 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.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/payabli/customer/client.rb', line 99 def get_customer(request_options: {}, **params) params = Payabli::Internal::Types::Utils.normalize_keys(params) headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }]) request = Payabli::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "Customer/#{URI.encode_uri_component(params[:customer_id].to_s)}", headers: headers, 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 |
#link_customer_transaction(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponse00Responsedatanonobject
Links a customer to a transaction by ID.
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/payabli/customer/client.rb', line 269 def link_customer_transaction(request_options: {}, **params) params = Payabli::Internal::Types::Utils.normalize_keys(params) headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }]) request = Payabli::Internal::JSON::Request.new( base_url: [: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)}", headers: headers, 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 |
#request_consent(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponse00Responsedatanonobject
Sends the consent opt-in email to the customer email address in the customer record.
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/payabli/customer/client.rb', line 226 def (request_options: {}, **params) params = Payabli::Internal::Types::Utils.normalize_keys(params) headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }]) request = Payabli::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "Customer/#{URI.encode_uri_component(params[:customer_id].to_s)}/consent", headers: headers, 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.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/payabli/customer/client.rb', line 147 def update_customer(request_options: {}, **params) params = Payabli::Internal::Types::Utils.normalize_keys(params) headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }]) request = Payabli::Internal::JSON::Request.new( base_url: [:base_url], method: "PUT", path: "Customer/#{URI.encode_uri_component(params[:customer_id].to_s)}", headers: headers, body: Payabli::Types::CustomerData.new(params).to_h, 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 |