Payabli Ruby Library

fern shield

The Payabli Ruby library provides convenient access to the Payabli APIs from Ruby.

Table of Contents

Documentation

API reference documentation is available here.

Reference

A full reference for this library is available here.

Changelog

The changelog for the official Payabli Ruby SDK is available on the Payabli Docs site. See Ruby SDK Changelog for more information.

Getting Started

Visit the Payabli Docs site to get started with the official Payabli Ruby SDK. See Use the Ruby SDK for more information.

Passing Query Parameters

client = Payabli::Client.new(
    api_key: "API_KEY",
    base_url: Payabli::Environment::SANDBOX
)

entry_point = "ENTRYPOINT"

result = client.query.list_customers(
  request_options: {
    additional_query_parameters: {
      "email(ct)": "test@example.com",
    }
  }, 
  **{
    entry: entry_point,
  }
)

puts result.to_h

Usage

Instantiate and use the client with the following:

require "payabli"

client = Payabli::Client.new(api_key: "<value>")

client.money_in.getpaid(
  customer_data: {
    customer_id: 4440
  },
  entry_point: "f743aed24a",
  ipaddress: "255.255.255.255",
  payment_details: {
    service_fee: 0,
    total_amount: 100
  },
  payment_method: {
    cardcvv: "999",
    cardexp: "02/27",
    card_holder: "John Cassian",
    cardnumber: "4111111111111111",
    cardzip: "12345",
    initiator: "payor",
    method_: "card"
  }
)

Environments

This SDK allows you to configure different environments or custom URLs for API requests. You can either use the predefined environments or specify your own custom URL.

Environments

require "payabli"

payabli = Payabli::Client.new(
    base_url: Payabli::Environment::SANDBOX
)

Custom URL

require "payabli"

client = Payabli::Client.new(
    base_url: "https://example.com"
)

Errors

Failed API calls will raise errors that can be rescued from granularly.

require "payabli"

client = Payabli::Client.new(
    base_url: "https://example.com"
)

begin
    result = client.money_in.getpaid
rescue Payabli::Errors::TimeoutError
    puts "API didn't respond before our timeout elapsed"
rescue Payabli::Errors::ServiceUnavailableError
    puts "API returned status 503, is probably overloaded, try again later"
rescue Payabli::Errors::ServerError
    puts "API returned some other 5xx status, this is probably a bug"
rescue Payabli::Errors::ResponseError => e
    puts "API returned an unexpected status other than 5xx: #{e.code} #{e.message}"
rescue Payabli::Errors::ApiError => e
    puts "Some other error occurred when calling the API: #{e.message}"
end

Advanced

Retries

The SDK is instrumented with automatic retries. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).

A request is deemed retryable when any of the following HTTP status codes is returned:

  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

Use the max_retries option to configure this behavior.

require "payabli"

client = Payabli::Client.new(
    base_url: "https://example.com",
    max_retries: 3  # Configure max retries (default is 2)
)

Timeouts

The SDK defaults to a 60 second timeout. Use the timeout option to configure this behavior.

require "payabli"

response = client.money_in.getpaid(
    ...,
    timeout: 30  # 30 second timeout
)

Additional Headers

If you would like to send additional headers as part of the request, use the additional_headers request option.

require "payabli"

response = client.money_in.getpaid(
    ...,
    request_options: {
        additional_headers: {
            "X-Custom-Header" => "custom-value"
        }
    }
)

Additional Query Parameters

If you would like to send additional query parameters as part of the request, use the additional_query_parameters request option.

require "payabli"

response = client.money_in.getpaid(
    ...,
    request_options: {
        additional_query_parameters: {
            "custom_param" => "custom-value"
        }
    }
)

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!