I am working on the integration of Paypal Express payments. I am adapting a Standard checkout and I am using the active-merchant gem. Set up should be something like response=gateway.setup_purchase(price, details)
, where details are all the parameter which PayPal requires. The express gateway requires a return_url and cancel_return_url.
When I try to execute the payment through a submit button I get:
Order xx failed with error message undefined method `thank_you_checkout_url' for #<Order:0x1081e1bb8>
In my order model I have the following parts:
#app/models/order.rb
def process
process_with_active_merchant
save!
self.status == 'processed'
end
private
def process_with_active_merchant
ActiveMerchant::Billing::Base.mode = :test
gateway = ActiveMerchant::Billing::PaypalExpressGateway.new(
:login => 'sandbox-account',
:password => 'sandbox-password',
:signature => "sandbox-secret"
params = {
:order_id => self.id,
:email => email,
:address => { :address1 => ship_to_address,
:city => ship_to_city,
:country => ship_to_country,
:zip => ship_to_postal_code
} ,
:description => 'Books',
:ip => customer_ip,
:return_url => thank_you_checkout_url(@order), # return here if payment success
:cancel_return_url => index_checkout_url(@order) # return here if payment failed
}
response = gateway.setup_purchase((@order.total * 100).round(2), params)
if response.success?
self.status = 'processed'
else
self.error_message = response.message
self.status = 'failed'
end
end
The method is called in the checkout controller
def place_order
@order = Order.new(params[:order])
@order.customer_ip = request.remote_ip
populate_order
...
@order.process
...
end
def thank_you
...
end
How can I get this to work? Thank you in advance!
Aucun commentaire:
Enregistrer un commentaire