class Transbank::Patpass::PatpassComercio::Inscription

Constants

FIELDS
INSCRIPTION_STATUS_ENDPOINT
START_INSCRIPTION_ENDPOINT

Public Class Methods

default_integration_params() click to toggle source
# File lib/transbank/sdk/patpass/patpass_comercio/inscription.rb, line 67
def default_integration_params
  {
      api_key: Patpass::PatpassComercio::Base.api_key,
      commerce_code: Patpass::PatpassComercio::Base.commerce_code,
      integration_type: Patpass::PatpassComercio::Base::integration_type,
      base_url: Patpass::PatpassComercio::Base::current_integration_type_url
  }
end
start(url:, name:, first_last_name:, second_last_name:, rut:, service_id:, final_url:, max_amount:, phone_number:, mobile_number:, patpass_name:, person_email:, commerce_email:, address:, city:, options: nil) click to toggle source
# File lib/transbank/sdk/patpass/patpass_comercio/inscription.rb, line 17
def start(url:, name:, first_last_name:, second_last_name:, rut:, service_id:, final_url:, max_amount:,
  phone_number:, mobile_number:, patpass_name:, person_email:, commerce_email:, address:, city:, options: nil)
  api_key = options&.api_key || default_integration_params[:api_key]
  commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
  integration_type = options&.integration_type || default_integration_params[:integration_type]
  base_url = integration_type.nil? ? PatpassComercio::Base::integration_types[:TEST] : PatpassComercio::Base.integration_type_url(integration_type)

  body = {
      url: url,
      nombre: name,
      pApellido: first_last_name,
      sApellido: second_last_name,
      rut: rut,
      serviceId: service_id,
      finalUrl: final_url,
      commerceCode: commerce_code,
      montoMaximo: max_amount,
      telefonoFijo: phone_number,
      telefonoCelular: mobile_number,
      nombrePatPass: patpass_name,
      correoPersona: person_email,
      correoComercio: commerce_email,
      direccion: address,
      ciudad: city
  }
  url = base_url + START_INSCRIPTION_ENDPOINT
  headers = patpass_comercio_headers(commerce_code: commerce_code, api_key: api_key)
  resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
  resp_body = JSON.parse(resp.body)
  return ::Transbank::Patpass::PatpassComercio::InscriptionStartResponse.new(resp_body) if resp.kind_of? Net::HTTPSuccess
  raise Errors::InscriptionStartError.new(resp_body['description'], resp.code)
end
status(token: ,options: nil) click to toggle source
# File lib/transbank/sdk/patpass/patpass_comercio/inscription.rb, line 50
def status(token: ,options: nil)
  api_key = options&.api_key || default_integration_params[:api_key]
  commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
  integration_type = options&.integration_type || default_integration_params[:integration_type]
  base_url = integration_type.nil? ? PatpassComercio::Base::integration_types[:TEST] : PatpassComercio::Base.integration_type_url(integration_type)

  body = {
     token: token
  }
  url = base_url + INSCRIPTION_STATUS_ENDPOINT
  headers = patpass_comercio_headers(commerce_code: commerce_code, api_key: api_key)
  resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
  resp_body = JSON.parse(resp.body)
  return ::Transbank::Patpass::PatpassComercio::InscriptionStatusResponse.new(resp_body) if resp.kind_of? Net::HTTPSuccess
  raise Errors::InscriptionStatusError.new(resp_body['description'], resp.code)
end