Project

paysafe

0.01
A long-lived project that still receives updates
A Ruby interface to the Paysafe REST API.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 4, < 6
 Project Readme

The Paysafe Ruby Gem

Gem Version Tests

A well tested Ruby interface to the Paysafe REST API (formerly Optimal Payments). Requires Ruby 2.5 and up. Not all API actions are supported yet. Since the Paysafe API uses camelCase, this gem will handle converting to and from snake_case for you.

Installation

Add the following to your application's Gemfile:

gem 'paysafe'

Or install directly with gem install paysafe.

To try out the gem, just follow the Development section instructions as the built in setup script will direct you on how to provide the necessary API info.

Usage

Client Configuration

Create and configure a client with your API authentication.

client = Paysafe::REST::Client.new(
  api_key: 'your_api_key',
  api_secret: 'your_api_secret',
  test_mode: false, # to enable Production requests, default is `true`
  account_number: '1234', # used for the Card Payments API
  # Provide optional timeouts in seconds
  # timeout: { connect: 2, read: 5, write: 10 }
  # Or as a global timeout in seconds
  # timeout: 20
)

At a minimum the following options: api_key, api_secret, and test_mode should be specified. The account_number is only necessary for certain API's such as the Card Payments API.

Making Requests

Make an API request with a payload in the structure documented by the Paysafe REST API but using snake_case. The request payload will be converted to camelCase for you.

profile = client.customer_vault.create_profile(
  merchant_customer_id: '123',
  locale: 'en_US',
  card: {
    card_num: '4111111111111111',
    card_expiry: {
      month: 12,
      year: 2020
    }
  }
)

Handling Responses

Response data is in snake_case (converted from camelCase) typed with individual methods and predicates, including nested complex objects and array of objects as shown below:

profile.id?
# => true
profile.id
# => b088ac37...
profile.cards.first.card_expiry.year
# => 2020

Development

  1. git clone https://github.com/jackpocket/paysafe.git

  2. Run ./bin/setup to install dependencies and fill out API key/secret info

  3. Run ./bin/console for an interactive prompt with an authenticated client for you to experiment:

    profile = client.customer_vault.create_profile(merchant_customer_id: SecureRandom.uuid, locale: 'en_US')
    puts profile.id
    # => b088ac37...

All code is written in snake_case since requests and responses are converted to and from camelCase for you.

Tests

If the API key/secret info is different from what was used to record the cassettes, you'll need to run bundle exec rake test RECORD_MODE=all otherwise run bundle exec rake test.

Releasing

To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests for missing API support are welcome on GitHub at https://github.com/jackpocket/paysafe. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.