witten
/
luminotes
Archived
1
0
Fork 0

Fixed a bug in which unicode characters in a customer's name prevented PayPal payments from going through properly.

This commit is contained in:
Dan Helfman 2009-05-19 12:02:22 -07:00
parent 4d4f2ecca6
commit e4104adb81
4 changed files with 47 additions and 3 deletions

2
NEWS
View File

@ -3,6 +3,8 @@
* Added a "start a new discussion" link to each discussion forum page.
* Updated Luminotes Server INSTALL file with instructions for setting the
http_url configuration setting.
* Fixed a bug in which special characters in a customer's name prevented
PayPal payments from going through properly.
1.6.11: April 28, 2009
* Rewrote the way that the toolbar is implemented, laying the groundwork for

View File

@ -1357,6 +1357,17 @@ class Users( object ):
TRANSACTION_ID_PATTERN = re.compile( u"^[a-zA-Z0-9]+$" )
@staticmethod
def urlencode( params ):
# unicode-safe wrapper for urllib.urlencode()
if isinstance( params, dict ):
params = params.items()
return urllib.urlencode(
[ ( key, isinstance( value, unicode ) and value.encode( "utf-8" ) or value )
for ( key, value ) in params ]
)
def __paypal_notify_download( self, params, product, item_number ):
# verify that quantity * the expected fee == mc_gross
fee = float( product[ u"fee" ] )
@ -1382,7 +1393,7 @@ class Users( object ):
raise Payment_error( u"invalid item_name", params )
params[ u"cmd" ] = u"_notify-validate"
encoded_params = urllib.urlencode( params )
encoded_params = self.urlencode( params )
# verify txn_type
txn_type = params.get( u"txn_type" )
@ -1481,7 +1492,7 @@ class Users( object ):
raise Payment_error( u"invalid period3", params )
params[ u"cmd" ] = u"_notify-validate"
encoded_params = urllib.urlencode( params )
encoded_params = self.urlencode( params )
# ask paypal to verify the request
request = urllib2.Request( self.PAYPAL_URL )

View File

@ -184,7 +184,11 @@ class Test_controller( object ):
dict. Return the result dict as returned by the invoked method.
"""
from urllib import urlencode
post_data = urlencode( form_args )
if isinstance( form_args, dict ):
form_args = form_args.items()
post_data = urlencode(
[ ( k, isinstance( v, unicode ) and v.encode( "utf-8" ) or v ) for ( k, v ) in form_args ]
)
if headers is None:
headers = []

View File

@ -1,3 +1,5 @@
# -*- coding: utf8 -*-
import re
import cherrypy
import smtplib
@ -3273,6 +3275,25 @@ class Test_users( Test_controller ):
def test_paypal_notify_payment( self ):
data = dict( self.PAYMENT_DATA )
data[ u"custom" ] = self.user.object_id
data[ u"last_name" ] = u"Uümlaut"
result = self.http_post( "/users/paypal_notify", data );
assert len( result ) == 1
assert result.get( u"session_id" )
assert Stub_urllib2.result == u"VERIFIED"
assert Stub_urllib2.headers.get( u"Content-type" ) == u"application/x-www-form-urlencoded"
assert Stub_urllib2.url.startswith( "https://" )
assert u"paypal.com" in Stub_urllib2.url
assert Stub_urllib2.encoded_params
# being notified of a mere payment should not change the user's rate plan
user = self.database.load( User, self.user.object_id )
assert user.rate_plan == 0
def test_paypal_notify_payment_unicode( self ):
data = dict( self.PAYMENT_DATA )
data[ u"custom" ] = self.user.object_id
data[ u"" ] = self.user.object_id
result = self.http_post( "/users/paypal_notify", data );
assert len( result ) == 1
@ -4677,6 +4698,12 @@ class Test_users( Test_controller ):
result = self.http_post( "/users/paypal_notify", data );
self.__assert_download_payment_success( result )
def test_paypal_notify_download_payment_unicode( self ):
data = dict( self.DOWNLOAD_PAYMENT_DATA )
data[ u"last_name" ] = u"Uümlaut"
result = self.http_post( "/users/paypal_notify", data );
self.__assert_download_payment_success( result )
def test_paypal_notify_download_payment_multiple_quantity( self ):
data = dict( self.DOWNLOAD_PAYMENT_DATA )
data[ u"mc_gross" ] = u"90.0"