Class: Payabli::GhostCard::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



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

def initialize(client:)
  @client = client
end

Instance Method Details

#create_ghost_card(request_options: {}, **params) ⇒ Payabli::Types::CreateGhostCardResponse

Creates a ghost card, a multi-use virtual debit card issued to a vendor for recurring or discretionary spend.

Unlike single-use virtual cards issued as part of a payout transaction, ghost cards aren't tied to a specific payout. They're issued directly to a vendor and can be reused up to a configurable number of times within the card's spending limits.

Only one ghost card can exist per vendor per paypoint. To issue a new card to the same vendor, cancel the existing card first.

Examples:

client.ghost_card.create_ghost_card(
  entry: "8cfec329267",
  vendor_id: 456,
  expense_limit: 500,
  amount: 500,
  max_number_of_uses: 3,
  exact_amount: false,
  expense_limit_period: "monthly",
  billing_cycle: "monthly",
  billing_cycle_day: "1",
  daily_transaction_count: 5,
  daily_amount_limit: 200,
  transaction_amount_limit: 100,
  mcc: "5411",
  tcc: "R",
  misc_1: "PO-98765",
  misc_2: "Dept-Finance"
)

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:



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
# File 'lib/payabli/ghost_card/client.rb', line 52

def create_ghost_card(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  request_data = Payabli::GhostCard::Types::CreateGhostCardRequestBody.new(params).to_h
  non_body_param_names = %w[entry]
  body = request_data.except(*non_body_param_names)

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

#update_card(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponse

Updates the status of a virtual card (including ghost cards) under a paypoint.

Examples:

client.ghost_card.update_card(
  entry: "8cfec329267",
  card_token: "gc_abc123def456",
  status: "Cancelled"
)

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:



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/payabli/ghost_card/client.rb', line 100

def update_card(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  request_data = Payabli::GhostCard::Types::UpdateCardRequestBody.new(params).to_h
  non_body_param_names = %w[entry]
  body = request_data.except(*non_body_param_names)

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