Class: Payabli::TokenStorage::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



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

def initialize(client:)
  @client = client
end

Instance Method Details

#add_method(request_options: {}, **params) ⇒ Payabli::Types::AddMethodResponse

Saves a payment method for reuse. This call exchanges sensitive payment information for a token that can be used to process future transactions. The ReferenceId value in the response is the storedMethodId to use with transactions.

Examples:

client.token_storage.add_method(
  customer_data: {
    customer_id: 4440
  },
  entry_point: "8cfec329267",
  fallback_auth: true,
  fallback_auth_amount: 100,
  method_description: "Primary Visa card",
  payment_method: {
    cardcvv: "123",
    cardexp: "12/29",
    card_holder: "John Doe",
    cardnumber: "4111111111111111",
    cardzip: "12345",
    method_: "card"
  },
  source: "api"
)

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):

  • :ach_validation (Boolean, nil)
  • :create_anonymous (Boolean, nil)
  • :force_customer_creation (Boolean, nil)
  • :temporary (Boolean, nil)
  • :idempotency_key (String, nil)

Returns:



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
83
84
85
86
# File 'lib/payabli/token_storage/client.rb', line 51

def add_method(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  query_param_names = %i[ach_validation create_anonymous force_customer_creation temporary]
  query_params = {}
  query_params["achValidation"] = params[:ach_validation] if params.key?(:ach_validation)
  query_params["createAnonymous"] = params[:create_anonymous] if params.key?(:create_anonymous)
  query_params["forceCustomerCreation"] = params[:force_customer_creation] if params.key?(:force_customer_creation)
  query_params["temporary"] = params[:temporary] if params.key?(:temporary)
  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: request_options[:base_url],
    method: "POST",
    path: "TokenStorage/add",
    headers: headers,
    query: query_params,
    body: Payabli::Types::RequestTokenStorage.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::AddMethodResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_method(request_options: {}, **params) ⇒ Payabli::Types::GetMethodResponse

Retrieves details for a saved payment method.

Examples:

client.token_storage.get_method(
  method_id: "32-8877drt00045632-678",
  card_expiration_format: 1,
  include_temporary: false
)

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):

  • :method_id (String)
  • :card_expiration_format (Integer, nil)
  • :include_temporary (Boolean, nil)

Returns:



109
110
111
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
# File 'lib/payabli/token_storage/client.rb', line 109

def get_method(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["cardExpirationFormat"] = params[:card_expiration_format] if params.key?(:card_expiration_format)
  query_params["includeTemporary"] = params[:include_temporary] if params.key?(:include_temporary)

  headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }])
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "TokenStorage/#{URI.encode_uri_component(params[:method_id].to_s)}",
    headers: headers,
    query: query_params,
    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::GetMethodResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#remove_method(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponsePaymethodDelete

Deletes a saved payment method.

Examples:

client.token_storage.remove_method(method_id: "32-8877drt00045632-678")

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):

  • :method_id (String)

Returns:



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

def remove_method(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: request_options[:base_url],
    method: "DELETE",
    path: "TokenStorage/#{URI.encode_uri_component(params[:method_id].to_s)}",
    headers: headers,
    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::PayabliApiResponsePaymethodDelete.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#update_method(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponsePaymethodDelete

Updates a saved payment method.

Examples:

client.token_storage.update_method(
  method_id: "32-8877drt00045632-678",
  customer_data: {
    customer_id: 4440
  },
  entry_point: "8cfec329267",
  fallback_auth: true,
  payment_method: {
    cardcvv: "123",
    cardexp: "12/29",
    card_holder: "John Doe",
    cardnumber: "4111111111111111",
    cardzip: "12345",
    method_: "card"
  }
)

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):

  • :method_id (String)
  • :ach_validation (Boolean, nil)

Returns:



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
194
195
196
197
198
199
200
201
# File 'lib/payabli/token_storage/client.rb', line 169

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

  query_param_names = %i[ach_validation]
  query_params = {}
  query_params["achValidation"] = params[:ach_validation] if params.key?(:ach_validation)
  params = params.except(*query_param_names)

  headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }])
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PUT",
    path: "TokenStorage/#{URI.encode_uri_component(params[:method_id].to_s)}",
    headers: headers,
    query: query_params,
    body: Payabli::Types::RequestTokenStorage.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::PayabliApiResponsePaymethodDelete.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end