Skip to content

Repository files navigation

Build StatusCode 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.configuredo |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)ifresponse.success?charge_id=response.id# save charge_idelseputsresponse.error.messageend

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

About

Ruby wrapper for Affirm.com API

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages