Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
support for billing email address
Browse files Browse the repository at this point in the history
  • Loading branch information
matejc committed Oct 17, 2013
1 parent e40ed56 commit 895a038
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
5 changes: 4 additions & 1 deletion docs/CHANGELOG.rst
Expand Up @@ -4,7 +4,10 @@ Changelog
1.5 (unreleased)
----------------

- Nothing changed yet.
- Support for billing email address (this is the users PayPal email address).
Prior to enable and disable code, this feature searches for username
(which is in fact users email address) and billing email address.
[matejc]


1.4 (2013-06-11)
Expand Down
21 changes: 19 additions & 2 deletions src/niteoweb/ipn/jvzoo/jvzoo.py
Expand Up @@ -50,8 +50,15 @@ def render(self):
# verify and parse post
self._verify_POST(params)
data = self._parse_POST(params)

user = self.get_user_by_email(data['email'])
if user:
username = user.getUserName()
else:
username = data['email']

logger.info("{0}: POST successfully parsed for '{1}'.".format(
api.user.get_current(), data['email']))
api.user.get_current(), username))

# call appropriate action in niteoweb.ipn.core
ipn = getAdapter(self.context, IIPN)
Expand All @@ -61,7 +68,7 @@ def render(self):
logger.info("{0}: Calling '{1}' in niteoweb.ipn.core.".format(
api.user.get_current(), action))
params = {
'email': data['email'],
'email': username, # username == email
'product_id': data['product_id'],
'trans_type': data['trans_type'],
'fullname': data.get('fullname'), # optional
Expand Down Expand Up @@ -125,3 +132,13 @@ def _parse_POST(self, params):
'affiliate': params['ctransaffiliate'],
'trans_type': params['ctransaction'],
}

def get_user_by_email(self, email):
user = api.user.get(username=email)
if user is not None:
return user
email_lower = email.lower()
for u in api.user.get_users():
if email_lower == u.getProperty('billing_email', '').lower():
return u
return None # user does not exists
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<object name="portal_memberdata">
<property name="billing_email" type="string"></property>
</object>
26 changes: 26 additions & 0 deletions src/niteoweb/ipn/jvzoo/tests/test_jvzoo.py
Expand Up @@ -163,6 +163,32 @@ def test_call_with_valid_POST(self, parse_post, verify_post):
"Calling 'enable_member' in niteoweb.ipn.core.",
)

def test_user_by_email_billing_address(self):
"""Test get_user_by_email method with existing user and billing email.""" # noqa
# create new user and set it some billing_email
user = api.user.create(email='some.user@xyz.xyz')
user.setMemberProperties({'billing_email': 'billing.email@xyz.xyz'})

self.assertEqual(
self.view.get_user_by_email('some.user@xyz.xyz'),
self.view.get_user_by_email('billing.email@xyz.xyz')
)

def test_user_by_email_billing_none(self):
"""Test get_user_by_email method with existing user no billing email.
"""
self.assertEqual(
api.user.create(email='some.other.user@xyz.xyz'),
self.view.get_user_by_email('some.other.user@xyz.xyz')
)

def test_user_by_email_billing_non_existing(self):
"""Test get_user_by_email method with non-existing email.
"""
user = api.user.create(email='some.other.user@xyz.xyz')
user.setMemberProperties({'billing_email': 'billing.email@xyz.xyz'})
self.assertIsNone(self.view.get_user_by_email('not@xyz.xyz'))


class TestTransactionTypesToActionsMapping(TestJVZoo):
"""Test how Transaction Types map to niteoweb.ipn.core actions."""
Expand Down

0 comments on commit 895a038

Please sign in to comment.