Active Merchant moves currency decimal point

5 views
Skip to first unread message

Ryan

unread,
Jun 27, 2008, 10:34:02 AM6/27/08
to Active Merchant
Hi,

I have been developing a shopping cart with Active Merchant utilizing
PayPal as a gateway. I seem to have run into a problem with the
purchase amount. In both PayPal express and using the PayPal gateway
the purchase amount gets its decimal point moved two places to the
left. 200.00 becomes 2.00. I can't seem to figure out the solution. I
have included part of my code where BILL_AMOUNT is the purchase priced
passed to PayPal (I set it to a static value for testing). Perhaps I
need to format the value I am passing in a different way?

Any help or suggestions are appreciated.

Ryan



class PurchaseController < ApplicationController
include SslRequirement
ssl_required :index, :credit

before_filter :load_card

filter_parameter_logging :creditcard

# This amount will INCORRECTLY equal 5.12 once processed
BILL_AMOUNT = 512.00
# This amount will CORRECTLY equal 512.00 once processed BUT has
extra zeros added on
#BILL_AMOUNT = 51200.00

def index
#@totalamount = session[:pricetopay]
@totalamount = BILL_AMOUNT
@piecetitle = session[:itemtitle]
end

# Use the DirectPayment API
def credit
render :action => 'index' and return unless @creditcard.valid?

@response = paypal_gateway.purchase(BILL_AMOUNT, @creditcard,
:ip => request.remote_ip)

if @response.success?
@purchase = Purchase.create(:response => @response)
redirect_to :action => "complete", :id => @purchase
else
paypal_error(@response)
end
end

Cody Fauser

unread,
Jun 27, 2008, 11:15:21 AM6/27/08
to activem...@googlegroups.com
The amount provided to the gateway must be in cents.

--
Cody Fauser
http://shopify.com - e-commerce done right
http://www.codyfauser.com - blog
http://peepcode.com/products/activemerchant-pdf - ActiveMerchant PeepCode
http://www.oreilly.com/catalog/rjsrails - RJS Templates for Rails

Ryan

unread,
Jun 27, 2008, 2:04:02 PM6/27/08
to Active Merchant
Thanks, that fixed the problem.
Reply all
Reply to author
Forward
0 new messages