1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
8 from django.conf import settings
10 DESC = 'Wolne Lektury subscription'
13 def paypal_request(data):
15 'USER': settings.PAYPAL['user'],
16 'PWD': settings.PAYPAL['password'],
17 'SIGNATURE': settings.PAYPAL['signature'],
18 'SUBJECT': settings.PAYPAL['email'],
21 request_data.update(data)
23 response = requests.post(settings.PAYPAL['api-url'], data=request_data)
24 return dict(urlparse.parse_qsl(response.text))
27 def set_express_checkout(amount):
28 response = paypal_request({
29 'METHOD': 'SetExpressCheckout',
30 'PAYMENTREQUEST_0_PAYMENTACTION': 'SALE',
31 'PAYMENTREQUEST_0_AMT': amount,
32 'PAYMENTREQUEST_0_CURRENCYCODE': 'PLN',
33 'L_BILLINGTYPE0': 'RecurringPayments',
34 'L_BILLINGAGREEMENTDESCRIPTION0': DESC,
35 'RETURNURL': settings.PAYPAL['return-url'],
36 'CANCELURL': settings.PAYPAL['cancel-url'],
38 return response.get('TOKEN')
41 def create_profile(token, amount):
42 response = paypal_request({
43 'METHOD': 'CreateRecurringPaymentsProfile',
45 'PROFILESTARTDATE': '2011-03-11T00:00:00Z',
47 'MAXFAILEDPAYMENTS': 3,
48 'AUTOBILLAMT': 'AddToNextBilling',
49 'BILLINGPERIOD': 'Month', # or 30 Days?
50 'BILLINGFREQUENCY': 1,
52 'CURRENCYCODE': 'PLN',
53 'L_PAYMENTREQUEST_0_ITEMCATEGORY0': 'Digital',
54 'L_PAYMENTREQUEST_0_NAME0': 'Subskrypcja Wolnych Lektur',
55 'L_PAYMENTREQUEST_0_AMT0': amount,
56 'L_PAYMENTREQUEST_0_QTY0': 1,
58 return response.get('PROFILEID')
61 # min amount: 10, max amount: 30000