0.0
No commit activity in last 3 years
No release in over 3 years
An upgrade/port of ActiveMerchant's credit card class
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0.0
>= 0
~> 1.5.1
>= 0
~> 1.2.8
>= 4.0.0.alpha4
~> 2.1.0
~> 2.3.0
= 0.3.5
~> 0.6.0

Runtime

 Project Readme

credit_officer¶ ↑

An ActiveModel port of ActiveMerchant’s credit card validations.

Use only with Rails 3/ActiveModel supported applications

The Basics¶ ↑

Use this library so that you can validate credit card information before sending it to your payment processor

Checks credit card number formats, checksums, and other required details. Supports i18n for better message customization

cc = CreditOfficer::CreditCard.new({
  :number => "411111111111111",
  :provider_name => "visa",
  :name_on_card => "John Doe",
  :expiration_year => 2010,
  :expiration_month => 1,
  :verification_value => "343"
}).valid? => true

cc.number = ""
cc.valid? => false 
cc.errors.full_messages => ["Number can't be blank"]

Configuring verification¶ ↑

If you want to turn requiring verification values off, make it so:

CreditOfficer::CreditCard.require_verification_value = false
cc = CreditOfficer::CreditCard.new({
  :number => "411111111111111",
  :provider_name => "visa",
  :name_on_card => "John Doe",
  :expiration_year => 2010,
  :expiration_month => 1,
  :verification_value => ""
}).valid? => true

Configuring Providers¶ ↑

Want to only support certain credit cards and card number formats? Make it so:

CreditOfficer::CreditCard.supported_providers = [
  'mastercard',
  'amex'
]

cc = CreditOfficer::CreditCard.new({
  :number => "411111111111111",
  :provider_name => "visa",
  :name_on_card => "John Doe",
  :expiration_year => 2010,
  :expiration_month => 1,
  :verification_value => ""
}).valid? => false

Deriving provider names¶ ↑

Most of the time, you can derive the credit card provider (Mastercard, AMEX, Visa, etc) based on the format of the card number. By default, credit officer attempts to derive this provider name automatically

cc = CreditOfficer::CreditCard.new({
  :number => "411111111111111",
  :name_on_card => "John Doe",
  :expiration_year => 2010,
  :expiration_month => 1,
}).valid? => true

cc.provider_name => visa

You can toggle this so that the user must provide a valid provider name like so:

CreditOfficer::CreditCard.automatically_derive_provider_name = false

You can manually attempt the provider name like so (this will set the provider name according to your number):

cc.derive_provider_name

i18n¶ ↑

Error messages can be customized with i18n translations

credit_officer:
  errors:
     messages:
       expired: "is expired"
       exceeds_recent_future: "is not a valid year"
       invalid_format: "is not a valid card number"
       unsupported_provider: "is not supported"
       invalid_issue_number: "is not valid"
       futuristic_start_date: "is in the future"

Why?¶ ↑

ActiveMerchant has a ton of functionality and it’s a great library. I just wanted the ability to validate information before sending it to a payment processor. I don’t want all the payment processor logic, etc bloating my applications. Lean, simple, extensible, and up to date - that’s how I like it!

I’ve also added some of the niceties that an activemodel compliant architecture provides (i18n, for example)

A note on persistence¶ ↑

Do not store this data yourself unless you absolutely must. Your payment processors should have a way for you to transmit this information and have them store it for you. Otherwise, you’re beholden to all kinds of PCI compliance issues.

Contributing to credit_officer¶ ↑

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2010 Dan Pickett. See LICENSE.txt for further details.