Ruby wrapper for the Affirm Transactions API (/api/v1/transactions).
gem "affirm-ruby-v1", require: "affirm"Local path:
gem "affirm-ruby-v1", path: "../affirm-ruby-v1", require: "affirm"Affirm.configure do |config|
config.public_api_key = "ABC"
config.private_api_key = "XYZ"
config.environment = :sandbox # or :production
endresponse = Affirm::Charge.authorize(checkout_token, order.id)
# or
response = Affirm::Charge.authorize(checkout_token, order_id: order.id.to_s)Affirm::Charge.find(transaction_id)Affirm::Charge.capture(transaction_id)
Affirm::Charge.capture(transaction_id, amount: 5000) # partial captureAffirm::Charge.void(transaction_id)Affirm::Charge.refund(transaction_id, amount: 500)Affirm::Charge.update(transaction_id,
order_id: "CUSTOM_ORDER_ID",
shipping_carrier: "USPS",
shipping_confirmation: "1Z23223"
)if response.success?
response.id # Affirm transaction id (e.g. "AMLC-5X0W")
response.status # e.g. "authorized"
response.amount
response.checkout_id
response.order_id
response.authorization_expiration
else
response.error.message
end| Field | Type | Description |
|---|---|---|
id |
String | Transaction id — store this for capture/void/refund |
status |
String | e.g. authorized, captured, voided |
amount |
Integer | Amount in cents |
currency |
String | e.g. USD |
checkout_id |
String | Affirm checkout identifier |
order_id |
String | Your merchant order id |
authorization_expiration |
DateTime | When the authorization expires |
amount_refunded |
Integer | Refunded amount in cents |
events |
Array | Auth/capture/refund event history |
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Open a pull request
Released under the MIT license which is included in the MIT-LICENSE file.
Copyright (c) Hakan Aksu