Skip to content

Commit 3a80a00

Browse files
committed
Added support for merchant user IDs to manual ident URLs
1 parent 75aebcd commit 3a80a00

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
installation requirements as it's required for the added manual ident URLs
1313
feature.
1414

15+
* Added support for `muid` when creating manual ident URLs.
16+
1517
* Added support to check for access based on `muid` instead of `lptoken`.
1618

1719
## 5.2.0

laterpay/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,19 +407,21 @@ def get_access_data(self, article_ids, lptoken=None, muid=None):
407407

408408
return response.json()
409409

410-
def get_manual_ident_url(self, article_url, article_ids):
410+
def get_manual_ident_url(self, article_url, article_ids, muid=None):
411411
"""
412412
Return a URL to allow users to claim previous purchase content.
413413
"""
414-
token = self._get_manual_ident_token(article_url, article_ids)
414+
token = self._get_manual_ident_token(article_url, article_ids, muid=muid)
415415
return '%s/ident/%s/%s/' % (self.web_root, self.cp_key, token)
416416

417-
def _get_manual_ident_token(self, article_url, article_ids):
417+
def _get_manual_ident_token(self, article_url, article_ids, muid=None):
418418
"""
419419
Return the token data for ``get_manual_ident_url()``.
420420
"""
421421
data = {
422422
'back': compat.stringify(article_url),
423423
'ids': [compat.stringify(article_id) for article_id in article_ids],
424424
}
425+
if muid:
426+
data['muid'] = compat.stringify(muid)
425427
return jwt.encode(data, self.shared_secret).decode()

tests/test_client.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ def test_get_manual_ident_url(self):
526526
article_url = u'http://example.com/news?id=10&emoji=😄'
527527
article_ids = ['aid≠1', b'aid\xe2\x89\xa02']
528528

529-
url = self.lp.get_manual_ident_url(article_url, article_ids)
529+
url = self.lp.get_manual_ident_url(article_url, article_ids, muid='blụb')
530530

531531
url_info = urlparse(url)
532532

@@ -555,6 +555,7 @@ def test_get_manual_ident_url(self):
555555
self.assertEqual(data, {
556556
'back': u'http://example.com/news?id=10&emoji=\U0001f604',
557557
'ids': [u'aid\u22601', u'aid\u22602'],
558+
'muid': u'bl\u1ee5b'
558559
})
559560

560561
def test_get_manual_ident_token(self):
@@ -569,6 +570,20 @@ def test_get_manual_ident_token(self):
569570
'ids': [u'aid\u22601', u'aid\u22602'],
570571
})
571572

573+
def test_get_manual_ident_token_muid(self):
574+
article_url = 'http://example.com/news'
575+
article_ids = ['aid=1']
576+
muid = u'😄'
577+
578+
token = self.lp._get_manual_ident_token(article_url, article_ids, muid=muid)
579+
data = jwt.decode(token, self.lp.shared_secret)
580+
581+
self.assertEqual(data, {
582+
'back': 'http://example.com/news',
583+
'ids': ['aid=1'],
584+
'muid': u'\U0001f604',
585+
})
586+
572587

573588
if __name__ == '__main__':
574589
unittest.main()

0 commit comments

Comments
 (0)