Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions laterpay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class ItemDefinition(object):
For Single item purchases: http://docs.laterpay.net/platform/dialogs/buy/
"""

def __init__(self, item_id, pricing, url, title, expiry=None, sub_id=None, period=None, item_type=None):
def __init__(self, item_id, pricing, url, title, expiry=None, sub_id=None,
period=None, item_type=None, election_id=None):
for price in pricing.split(','):
if not _PRICING_RE.match(price):
raise InvalidItemDefinition('Pricing is not valid: %s' % pricing)
Expand All @@ -82,9 +83,16 @@ def __init__(self, item_id, pricing, url, title, expiry=None, sub_id=None, perio
'expiry': expiry,
}

if item_type in {constants.ITEM_TYPE_CONTRIBUTION, constants.ITEM_TYPE_DONATION}:
if item_type in {
constants.ITEM_TYPE_CONTRIBUTION,
constants.ITEM_TYPE_DONATION,
constants.ITEM_TYPE_POLITICAL_CONTRIBUTION,
}:
self.data['campaign_id'] = item_id
self.item_type = item_type

if item_type == constants.ITEM_TYPE_POLITICAL_CONTRIBUTION:
self.data['election_id'] = election_id
else:
self.data['article_id'] = item_id
self.item_type = None
Expand Down Expand Up @@ -320,6 +328,8 @@ def get_buy_url(self, item_definition, *args, **kwargs):
page_type = 'contribute/pay_now'
elif item_type == constants.ITEM_TYPE_DONATION:
page_type = 'donate/pay_now'
elif item_type == constants.ITEM_TYPE_POLITICAL_CONTRIBUTION:
page_type = 'political_contribution/pay_now'
else:
page_type = 'buy'

Expand All @@ -339,6 +349,8 @@ def get_add_url(self, item_definition, *args, **kwargs):
page_type = 'contribute/pay_later'
elif item_type == constants.ITEM_TYPE_DONATION:
page_type = 'donate/pay_later'
elif item_type == constants.ITEM_TYPE_POLITICAL_CONTRIBUTION:
page_type = 'political_contribution/pay_later'
else:
page_type = 'add'

Expand Down
1 change: 1 addition & 0 deletions laterpay/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@

ITEM_TYPE_CONTRIBUTION = 'contribution'
ITEM_TYPE_DONATION = 'donation'
ITEM_TYPE_POLITICAL_CONTRIBUTION = 'political'
Loading