Customize Paypal Express Overview Page Using ActiveMerchant

I use ActiveMerchant to give my rail application access to Paypal Express Checkout. I would like to include order information on the review page as described here: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECCustomizing

Can this be done?

Currently, my controller code is as follows:

def paypal #currently, options is unused, I'm not sure where to send this info options = { :L_NAME0=>"Tickets", :L_QTY0=>@payment.quantity, :L_DESC0=>"Tickets for #{@payment.event_name}", :L_AMT0=>@payment.unit_price } #the actual code that gets used setup_response = gateway.setup_purchase(@payment.amount, :ip=> request.remote_ip, :return_url=> url_for(:action=>:confirm, :id=>@payment.id, :only_path=>false), :cancel_return_url => url_for(:action=>:show, :id=>@payment.id, :only_path=>false) ) redirect_to gateway.redirect_url_for(setup_response.token) end 

If what I'm trying to do is perhaps what I need to change?

+6
ruby-on-rails paypal activemerchant
source share
4 answers

@Soleone I'm trying your solution, but not working for me.

 xml.tag! 'n2:OrderDescription', options[:description] xml.tag! 'n2:Name', options[:name] xml.tag! 'n2:Description', options[:desc] xml.tag! 'n2:Amount', options[:amount] xml.tag! 'n2:Quantity', options[:quantity] 

I think the xml structure is wrong, there are several order elements, so you should like

 xml.tag! 'n2:OrderItems' do xml.tag! 'n2:OrderItem' do xml.tag! 'n2:Name', options[:name] xml.tag! 'n2:Description', options[:desc] xml.tag! 'n2:Amount', options[:amount] xml.tag! 'n2:Quantity', options[:quantity] end end 

But actually I do not know the correct structure, searching now.

==== Update

I found SOAP api doc, https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_soap_r_SetExpressCheckout#id09BHC0QF07Q

 xml.tag! 'n2:PaymentDetails' do xml.tag! 'n2:PaymentDetailsItem' do xml.tag! 'n2:Name', options[:name] xml.tag! 'n2:Description', options[:desc] xml.tag! 'n2:Amount', options[:amount] xml.tag! 'n2:Quantity', options[:quantity] end end 

But also does not work, who can help?

===== UPDATE ====

I tried the method of adding the PaymentDetails parameter, but it still seems to not work, I found the SetExpressCheckoutReq xml scheme, http://www.visualschema.com/vs/paypal/SetExpressCheckoutReq/ , there is no PaymentDetails definition that did this before. I am hope for your help.

====== FINAL =========

I fixed this problem, the new version of ActiveMerchant supports viewing order details, and mwagg clicked a patch about it, you guys can use this version https://github.com/mwagg/active_merchant

+4
source share

Make sure you have an activemerchant version of at least 1.12.0 .

  EXPRESS_GATEWAY.setup_purchase (220,
   : items => [{: name => "Tickets",: quantity => 22,: description => "Tickets for 232323",: amount => 10}],
   : return_url => 'example.com',
   : cancel_return_url => 'example.com'
 )

Hope this helps :)

+11
source share

You can see the available options in this table (only the middle column applies since activemerchant uses the SOAP API):

https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECCustomizing#id086NA300I5Z__id086NAC0J0PN

To better understand how activemerchant works, perhaps he looks directly at the implementation. You can see the relevant parameters inserted into the SOAP XML request (currently), starting at line 98 where OrderTotal inserted:

https://github.com/Shopify/active_merchant/blob/master/lib/active_merchant/billing/gateways/paypal_express.rb#L98

Notice how the parameters are extracted from the options hash so that you can see the correct character for each of them here.

In your case, when you specified the following parameters, you would do it as follows:

 def paypal options = { :name => "Tickets", :quantity => @payment.quantity, :description => "Tickets for #{@payment.event_name}", :amount => @payment.unit_price :ip => request.remote_ip, :return_url => url_for(:action=>:confirm, :id=>@payment.id, :only_path=>false), :cancel_return_url => url_for(:action=>:show, :id=>@payment.id, :only_path=>false) } # the actual code that gets used setup_response = gateway.setup_purchase(@payment.amount, options) redirect_to gateway.redirect_url_for(setup_response.token) end 

Please note: The fields name , quantity and amount are not currently supported in activemerchant. You will have to shell out the repository and paste them yourself and use your copy of the project. It is very simple when you look at the code and see how it is done with others.

For example, to add the order name, number of elements and unit price, you must put these lines after the OrderDescription is inserted:

  xml.tag! 'n2:Name', options[:name] xml.tag! 'n2:Amount', options[:amount] xml.tag! 'n2:Quantity', options[:quantity] 

Hope this helps!

UPDATE:

Well, I think, according to the XML schema for the SOAP API, it looks like you should specify it like it does in activemerchant:

 xml.tag! 'n2:PaymentDetails' do items = options[:items] || [] items.each do |item| xml.tag! 'n2:PaymentDetailsItem' do xml.tag! 'n2:Name', item[:name] xml.tag! 'n2:Description', item[:desc] xml.tag! 'n2:Amount', item[:amount] xml.tag! 'n2:Quantity', item[:quantity] end end end 

And you will pass all your elements in your Rails application as follows:

 options = { :items => [ { :name => "Tickets", :quantity => @payment.quantity, :description => "Tickets for #{@payment.event_name}", :amount => @payment.unit_price }, { :name => "Other product", :quantity => @other_payment.quantity, :description => "Something else for #{@other_payment.event_name}", :amount => @other_payment.unit_price } ] :ip => request.remote_ip, :return_url => url_for(:action=>:confirm, :id=>@payment.id, :only_path=>false), :cancel_return_url => url_for(:action=>:show, :id=>@payment.id, :only_path=>false) } 

Hope everything will be better, good luck!

+3
source share

I also had problems getting this to work. The solution is that the sum of all items should be the subtotal of the order, where the total, shipping, handling and tax should be combined with the total value of the order. My PayPal controller is as follows:

 def begin_paypal # ... options = express_options(@order) # ... response = EXPRESS_GATEWAY.setup_purchase(@order.gross_price_in_cent, options) redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token) end private def express_options order options = {} options[:ip] = request.remote_ip options[:order_id] = order.bearbeitungsnummer # subtotal, shipping, handling and tax must sum up to the orders total value # subtotal must be the sum of all amounts of all items options[:subtotal] = order.gross_price_in_cent options[:shipping] = 0 options[:handling] = 0 options[:tax] = 0 options[:items] = order.line_items.map do |line_item| { :name => line_item.product.name, :number => line_item.product.kcode, :quantity => line_item.quantity, :description => line_item.product.beschreibung, :amount => line_item.gross_price_in_cent, :url => nil } end # ... end 

Works fine

+1
source share

All Articles