Paypal and odoo stumbling blocks

and how to get them out of the way

Benjamin Bachmann
 

What is the problem

When using odoo and its ecommerce online shop you can use different payment acquirers such as Paypal. But sometimes you will get errors and the order will get not through or get validated all the way, and this is not because you did something wrong in your code on your website.  We had this problem a lot of other odoo developers too, as you can see on github.

We looked at the code and tried al lot of solutions for our customers, until we found the solution.

Here is an example what our logs showed then we tried to get the verification from Paypal then trying to to get an order through the Paypal acquirer : 

INFO production werkzeug: 127.0.0.1 - - [01/Dec/2014 00:00:00] "POST /calendar/notify HTTP/1.0" 200 -
INFO production openerp.addons.payment_paypal.controllers.main: Beginning Paypal IPN form_feedback with post data {'address_city': u'Neustadt',
'address_country': u'Germany',
'address_country_code': u'DE',
'address_name': u'Max Musterman',
'address_state': u'',
'address_status': u'unconfirmed',
'address_street': u'Musterstarsse 8',
'address_zip': u'12345,
'business': u'paypal@shop.de',
'charset': u'windows-1252',
'custom': u'{"return_url": "/shop/payment/validate"}',
'first_name': u'Max',
'handling_amount': u'0.00',
'ipn_track_id': u'123456789',
'item_name': u'ITEM',
'item_number': u'123456789',
'last_name': u'Musterman',
'mc_currency': u'EUR',
'mc_fee': u'9.99',
'mc_gross': u'100.00',
'notify_version': u'3.8',
'payer_email': u'maxmusterman@demo.net',
'payer_id': u'123456789',
'payer_status': u'verified',
'payment_date': u'00:00:00 Dec 01, 2014 PST',
'payment_fee': u'',
'payment_gross': u'',
'payment_status': u'Completed',
'payment_type': u'instant',
'protection_eligibility': u'Eligible',
'quantity': u'1',
'receiver_email': u'paypal@shop.de',
'receiver_id': u'123456789',
'residence_country': u'DE',
'shipping': u'0.00',
'tax': u'0.00',
'transaction_subject': u'{"return_url": "/shop/payment/validate"}',
'txn_id': u'123456789',
'txn_type': u'web_accept',
'verify_sign': u'acbdefg123456789'}
WARNING production openerp.addons.payment_paypal.controllers.main: Paypal: answered INVALID on data verification

As you can see all the necessary information are supplied but in the end we got an invalid verification on the data. 

This means that the order is not automatically confirmed and you have to manually check if the customer has payed the order.

The solution

UTF-8 encoding

Many developers struggled with this problem and we tried a lot of solutions to fix this issue. We then found a comment on github that may have to do something with the encoding of the verification from Paypal.

The standard encoding that Paypal uses by default is windows-1252 and this does not fit odoo.

I provided some screenshots where to find this setting in your Paypal account.

First you have to go to your Profile Summary and then you have to choose Language Encoding

Here you have to choose More Options.

UTF-8 encoding

Encoding otions

Here you have to set the encoding to UTF-8 in order to get odoo working and to not get an invalid response back.

a successful order

After stetting the encoding to UTF-8 we did a test purchase using the Paypal acquirer and crossed our fingers. As you can see the log now showed no warnings and a validated data information in the end.

The order went through and was automatically confirmed. 


INFO production werkzeug: 127.0.0.1 - - [01/Dec/2014 00:00:00] "POST /shop/payment/transaction/1 HTTP/1.0" 200 -
INFO production openerp.addons.payment_paypal.controllers.main: Beginning Paypal DPN form_feedback with post data {'address_city': u'Neustadt',
'address_country': u'Germany',
'address_country_code': u'DE',
'address_name': u'Max Musterman',
'address_state': u'',
'address_status': u'unconfirmed',
'address_street': u'Musterstarsse 8',
'address_zip': u'12345',
'auth': u'abcdefg123456789',
'business': u'paypal@shop.de',
'charset': u'UTF-8',
'custom': u'{"return_url": "/shop/payment/validate"}',
'first_name': u'Max',
'form_charset': u'UTF-8',
'handling_amount': u'0.00',
'item_name': u'ITEM',
'item_number': u'123456789',
'last_name': u'Musterman',
'mc_currency': u'EUR',
'mc_fee': u'9.99',
'mc_gross': u'100.00',
'notify_version': u'3.8',
'payer_email': u'maxmusterman@demo.net',
'payer_id': u'123456789',
'payer_status': u'verified',
'payment_date': u'00:00:00 Dec 01, 2014 PST',
'payment_fee': u'',
'payment_gross': u'',
'payment_status': u'Completed',
'payment_type': u'instant',
'protection_eligibility': u'Eligible',
'quantity': u'1',
'receiver_email': u'aypal@shop.de',
'receiver_id': u'123456789',
'residence_country': u'DE',
'shipping': u'0.00',
'tax': u'0.00',
'test_ipn': u'1',
'transaction_subject': u'{"return_url": "/shop/payment/validate"}',
'txn_id': u'123456789',
'txn_type': u'web_accept',
'verify_sign': u'abcdefg123456789'}
INFO production openerp.addons.payment_paypal.controllers.main: Paypal: validated data
INFO production openerp.addons.payment_paypal.models.paypal: Validated Paypal payment for tx 123456789: set as done

The odoo Sales backend also now gives you all the information such as transactions ids, sales confirmation, partner reference, and confirmed sales order.

If you stumbled also over this problem I hope you could use this solution and it helped you to solve your odoo/paypal problems.

Thanks to the odoo community and the community on githup to solve this issue.

About Benjamin Bachmann

The Mac expert and code maniac/ Recently started his path into the python and Odoo world/ Likes his coffee cold, but we love him anyway.