views:

164

answers:

1

What's the best way to implement ActiveRecord's find() and save() methods for an ActiveMerchant ActiveMerchant::Billing::CreditCard object in a Ruby on Rails application?

I'd like my credit card objects to inherit from ActiveRecord and ActiveMerchant.

Caveat: I understand that saving credit card information to a database is always considered a bad idea, and that it's preferable to use a gateway that facilitates card storage for you. Presume that it's necessary and that suitable security standards are being met (PCI DSS, filesystem and database encryption, network separation etc).

+1  A: 

I've created a standard Rails ActiveRecord model using the following:

./script/generate model CreditCard first_name:string last_name:string number:string month:integer year:integer type:string start_month:integer start_year:integer issue_number:string

This matches the ActiveRecord definition of a credit card.

Also, ActiveMerchant provides ActiveMerchant::Billing::CreditCardMethods which, to quote the ActiveMerchant development team are:

Convenience methods that can be included into a custom Credit Card object, such as an ActiveRecord based Credit Card object.

I've included ActiveMerchant::Billing::CreditCardMethods in my credit card model, and will translate the validations to ensure my definition of a credit card matches ActiveMerchant's.

mlambie