Git Product home page Git Product logo

affirm's Introduction

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

affirm's People

Contributors

cbartlett avatar dependabot[bot] avatar embold-tyler avatar hknaksu avatar opti avatar peterberkenbosch avatar spectator avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

affirm's Issues

Request for Update to Faraday 2.0

Hi Affirm team!

We've encountered a challenge related to dependency conflicts while attempting to update Faraday to a version greater than 2.0. Currently, Affirm relies on an older version, specifically faraday ~> 0.9.1, while another dependency in our projects needs a version greater than 2.0.

Updating Faraday to a version beyond 2.0 will require an update of faraday-middleware, as the latter has been deprecated and is not compatible with Faraday 2.0.

Would you consider updating dependencies for this gem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.