0.01
Low commit activity in last 3 years
A long-lived project that still receives updates
Ruby client library for Affirm.com API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0

Runtime

~> 1.0, >= 1.0.0
 Project Readme

Build Status Code Climate

Affirm

Affirm gem is a simple Ruby wrapper for Affirm.com API. Please check Affirm API documentation for more details.

Installation

Add this line to your application's Gemfile:

gem 'affirm-ruby', require: 'affirm'

And then execute:

$ bundle

Or install it yourself as:

$ gem install affirm-ruby

Configuration

Affirm.configure do |config|
  config.public_api_key  = "ABC"
  config.private_api_key = "XYZ"
  config.environment     = :sandbox # or :production (default if not specified)
end

Usage

To authorize a charge checkout_token is required. This token gets POSTed to user_confirmation_url that is setup in Checkout JavaScript object.

Affirm::Charge.authorize(checkout_token)

The rest of the API uses charge_id which is received as id after charge is authorized.

Read charge

Affirm::Charge.find("TEST-AL04-UVGR")

Capture charge

Affirm::Charge.capture("TEST-ALO4-UVGR")

Void charge

Affirm::Charge.void("TEST-ALO4-UVGR")

Refund charge

Affirm::Charge.refund("TEST-ALO4-UVGR", amount: 500)

Update charge

Affirm::Charge.update("TEST-ALO4-UVGR",
  order_id: "CUSTOM_ORDER_ID",
  shipping_carrier: "USPS",
  shipping_confirmation: "1Z23223"
)

Failed response will return error object as a plain ruby object with values coerced in corresponding types.

The same will happen for all successful responses described (not in full) in server integration guide.

Example

response = Affirm::Charge.authorize(checkout_token)
if response.success?
  charge_id = response.id
  # save charge_id
else
  puts response.error.message
end

Contributing

  1. Fork it ( https://github.com/spectator/affirm/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request