#144 Active Merchant Basics
Active Merchant is a great library for handling credit card transactions. In this episode I will show you the basics of using it to communicate with PayPal's gateway.
- Download:
- source code
- mp4
- m4v
- webm
- ogv
Very, nice! I cant wait for the recurrent billing episode :)
Good job!
Beautiful! Thanks, Ryan!
Very interesting! Much simpler than the gateway I use now. Thanks Ryan!
Does the credit function use PayPal's "refund" operation (where fees are also refunded) or is it seen as another transaction (another set of fees)?
When my project is ready,I will click the "PayPal Donate" here at RailsCasts =)
Activemerchant is a nice library for abstracting away the differences between Gateways.
I second the Paypal donate button increase. I've been watching these for a long time and I never noticed it before.
Great episode Ryan. One of your best!
@Hubert, there wasn't a conflict with PeepCode sponsorship in the past, I just hadn't looked into Active Merchant enough back then to do an episode on it.
AFAIK PeepCode doesn't have a screencast on Active Merchant, but they do have a PDF book which I highly recommend. It's difficult to find adequate documentation on the subject.
@Jeffrey, that's a good question. I know Active Merchant itself provides two ways to handle credits. One is based on an existing transaction, and another is using a credit card number which will be treated as its own separate transaction (payment in reverse).
I'm assuming if you supply the authorization code when issuing the credit, it will treat it as a refund through PayPal but I have yet to test it.
This is so useful to me. I have the Peepcode but seeing coding in action just works for me.
Many, many thanks for it.
Another nice screencast. very useful again. Thanks Ryan
@Brian, you can find my Amazon wish list here if you like. :)
http://www.amazon.com/gp/registry/wishlist/1MLM280E2D
Great stuff and great timing! When do you think the next episode will be up! Thank you thank you!
Hi, thanks for another great screencast! I only see one possible problem when using gateway.authorize&capture:
Say you checked on a valid authorize. A few days later you decide to ship the item and do a gateway.capture(...) and during those days between you did the authorize and the capture the shopping client maxed out his credit. What happens then?
Or in other words shouldn't the capture member give back another true/false upon successful completion of the actual funds just as in gateway.purchase?
I should probably read more on active merchand and find the answer myself. Would be nice if you could elaborate on that edge case where the client maxes out his cards between authorize and capture method calls.
Or is authorise(1000, ... ) able to stop the client from going below 10$ of credit when he wants to try and max out because of the dangling authorise made earlier?
Maybe this has been asked/answered a thousand times before, in which I apologize for my ignorance ;)
Yes, Railscasts brings much joy to an otherwise bland Monday morning :)
@Ryan,
I'm pretty sure you are beyond needing "Beginning Ruby". Unless it is a gift for someone else? Sometimes the things you do on your screencasts still look like magic to me, and I've been writing Ruby for a couple of years now.
Awesome screencast Ryan. Any chance on recurring billing for software as a service?
For those of you interested in Rails commerce, you should check out the open source Spree project[1].
[1] http://spreehq.org
@alex same doubt as you.
Would be legal or possible to program a monthly "gateway.purchase" of the same value and same credit card?
@Gustavo,
You have to be careful about storing credit card info in your system (they are many requirements, you can find some info here: http://usa.visa.com/merchants/risk_management/cisp_merchants.html )
The safest way to do reoccurring billing is using something that some providers offer that stores the credit card info on their servers and just returns a sort of key to you that allows you to adjust amounts, remaining payments, etc. I did this for Authorize.net and it was pretty simple.
If you go that route, ActiveMerchant has some methods that make it pretty simple to handle (update_recurring for example). http://github.com/Shopify/active_merchant/blob/2b1c6d8e960b06ac98ea223280ff6e81f30174a1/lib/active_merchant/billing/gateways/authorize_net.rb for reference.
Methods like this are only available if the gateway supports it (and only a few do, and some (all?) charge a bit more for it), so you do have to do some research, but it is worth it if you plan to use reoccurring billing (not every app requires it).
http://wiki.github.com/Shopify/active_merchant/gatewayfeaturematrix
I only have experience with Authorize.net, so I can't speak about the rest, but in general expect another fee every time you turn around ($5/month for reoccurring billing, $5/month as a "statement fee", 2.5%/transaction, $0.20/transaction for this, $0.05/transaction for that, $0.05/transaction for this other thing, $20/month for this, oh, and a $20/month minimum in case that 2.5% is less than that per month, etc. Once you get past that, it's not too bad.
@Jeffrey Lee,
PayPal only supports referenced credits, which are based on a previous transaction. Some other gateways do support non-referenced credits by passing in a credit card object as the second argument to the credit() method. You'll have to check with your gateway provider and ActiveMerchant to see what your gateway supports.
@Carl,
You're responsible for those requirements as soon as you receive any cardholder data on your servers even if you don't store the card numbers.
Not storing card numbers does save you from section 3 of the PCI DSS, which is a complex section due to all of the encryption requirements, etc. Not having a load of cardholder data on your servers would also hopefully lessen the impact of a security breach on your servers.
@Cody,
I didn't mean to come across that you didn't have those requirements, but that they become more extensive if you do store the data. Sorry for not making that more explicit (it sounded right in my head at the time).
What about an episode on SAML
Is there a way to integrate activemerchant with offline payment via paypal website payments standard?
Hi... it is really nice and good railscasts.. thanks for helping us... i have blogged about this topic..
Can you post a link to your blog?
A big warning: US only at the beginning would be fine. Outside the US there are no gateways integrated in ActiveMerchent and it is the only program I know that has absolutely no documentation (except from the headers - not a single useful line of a comment). So it is absolutely useless for non-US companies. Even if you don't use PayPal as US company you have to guess what class might do the job and try some options, ... - because of the complete lack of documentation.
As great as your screencasts are (I watched them all) - as useless ist ActiveMerchant.
I am looking forward on useful screencasts :)
I am getting some errors like this--"Security header is not valid."
Not sure why I am seeing this, but when I do this exercise I receive the error:
Error: There's an error with this transaction. Please enter a complete billing address.
Did something change in the PayPal API to require billing address? Why did your example work without this information?
fyi, I just posted a screencast on my new SaasRamp plugin for doing recurring billing for software as a service (saas)
http://www.vaporbase.com/postings/SaasRamp_Screencast
Anyone knows if the Activemerchant works with RBSWorldpay ?
So I am trying out your code exactly sans your credentials and I am getting the following error:
Error: There's an error with this transaction. Please enter a complete billing address.
How come it worked in your example?
Same error as 34 & 37
"There's an error with this transaction. Please enter a complete billing address."
I get the same "Please enter a complete billing address", somebody found a solution? may be there is nothing bo ship :S
Try this for the "complete billing address error"
Add the billing_address hash after the ip address.
if credit_card.valid?
response = gateway.purchase(1000, credit_card,
:ip => "127.0.0.1",
:billing_address => {
:name => 'Test User',
:company => '',
:address1 => '123 S Main St',
:address2 => '',
:city => 'Akron',
:state => 'OH',
:country => 'US',
:zip => '44333',
:phone => '(310)555-5555'
}
)
I did this for Authorize.net and it was pretty simple.
If you get error: There's an error with this transaction. Please enter a complete billing address, you will need to accept the billing agreement on your paypal account (one of the steps in the setup process)
I just setup ActiveMerchant with PayPal Website Payments Pro (US) to do recurring payments for a project I'm working on. If anyone wants to see how I wrapped the PayPal recurring API resources, I posted it all on my blog:
http://blog.matthodan.com/how-to-add-support-for-paypal-website-payment
why am i getting the following error...
Error: This transaction cannot be processed due to an invalid merchant configuration.
nice
I get the following error:
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.9/lib/active_support/xml_mini/rexml.rb:20:in `parse': uninitialized constant ActiveSupport::XmlMini_REXML::StringIO (NameError)
This error propagates from the "gateway.authorize()" call. Any idea what's wrong with my setup? Thanks.
Hi,
I too get the same error as vinaya has mentioned.
/Ruby/Gems/1.8/gems/activesupport-3.0.9/lib/active_support/xml_mini/rexml.rb:20:in `parse': uninitialized constant ActiveSupport::XmlMini_REXML::StringIO (NameError)
Please let me know if you find any fix for this issue?
Thanks for another great rails cast! over two years old and still great.
In case anyone else needs it, apparently the steps for getting credentials has changed. for up-to-date steps on getting the API access credentials, go here.
I got following Error
Error: This transaction cannot be processed due to an invalid merchant configuration.
Is there a way to use acitivemerchant's PayPal Payments Standard functionality, without specifying credit card information? I want the user to enter their credit card info on PayPal's site, not mine. Express Checkout use to let users pay with credit cards, but no longer allows it. I've looked at activemerchant's source code and it expects either a credit_card hash or a billing agreement ID, but maybe there is some way to fake it out so that PayPal will ask for the credit card info?
Thanks
Me too got the error message "There's an error with this transaction. Please enter a complete billing address." but it seems there's no :billing_address option in credit card settings http://activemerchant.rubyforge.org/classes/ActiveMerchant/Billing/CreditCard.html
any ideas?
I got following Error:
Error: A field was longer or shorter than the server allows.
@Nguyen Duc Giang.
add a billing address to your purchase.
response = gateway.purchase(1000, credit_card, :ip => "127.0.0.1", :billing_address => {
:name => "Test Guy",
:address1 => "123 W 423 E",
:city => "Somewhere",
:state => "CA",
:country => "US",
:zip => "88888"
}
I got following Error:
Error: A field was longer or shorter than the server allows.
Here my code:
require 'rubygems'
require 'active_merchant'
ActiveMerchant::Billing::Base.mode = :test
credit_card = ActiveMerchant::Billing::CreditCard.new(
:number => '4111286234782053',
:month => '6',
:year => '2018',
:first_name => 'xxxx',
:last_name => 'xxxxxxx',
:verification_value => '123'
)
gateway = ActiveMerchant::Billing::TrustCommerceGateway.new(
:login => "xxxxxxxxxxxxxx.xxxxxxx.com",
:password => "xxxxxxxxxx",
:signature => "xxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxx"
)
response = gateway.purchase(1000, credit_card, :ip => "127.0.0.1", :billing_address => {
:name => "Test Guy",
:address1 => "123 W 423 E",
:city => "Somewhere",
:state => "CA",
:country => "US",
:zip => "88888"
}
For error: "This transaction cannot be processed due to an invalid merchant configuration."
Go to developer.paypal.com, register with your normal PayPal account, tab Applications than click on Sandbox Accounts, find your seller account click on him and hit profile.
Under profile tab change Account type to Business-Pro.
Update for anyone watching this, use these updates in purchase.rb: