Affirm gem is a simple Ruby wrapper for Affirm.com API. Please check Affirm API documentation for more details.
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
Affirm.configuredo |config|
config.public_api_key="ABC"config.private_api_key="XYZ"config.environment=:sandbox# or :production (default if not specified)endTo 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.
Affirm::Charge.find("TEST-AL04-UVGR")Affirm::Charge.capture("TEST-ALO4-UVGR")Affirm::Charge.void("TEST-ALO4-UVGR")Affirm::Charge.refund("TEST-ALO4-UVGR",amount: 500)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.
response=Affirm::Charge.authorize(checkout_token)ifresponse.success?charge_id=response.id# save charge_idelseputsresponse.error.messageend- Fork it ( https://github.com/spectator/affirm/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request