X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/1a12630094dd57a463a8a1d4f64744e3b3b245af..e17ba704033aba068a935c1beb42d1f306e6a114:/src/paypal/rest.py?ds=sidebyside diff --git a/src/paypal/rest.py b/src/paypal/rest.py index a2e22322f..9d9f45ab9 100644 --- a/src/paypal/rest.py +++ b/src/paypal/rest.py @@ -11,7 +11,7 @@ from django.core.urlresolvers import reverse from django.utils import timezone from paypalrestsdk import BillingPlan, BillingAgreement, ResourceNotFound from django.conf import settings -from .models import BillingPlan as BillingPlanModel +from .models import BillingPlan as BillingPlanModel, BillingAgreement as BillingAgreementModel paypalrestsdk.configure(settings.PAYPAL_CONFIG) @@ -65,7 +65,7 @@ def get_link(links, rel): return link.href -def create_agreement(amount): +def create_agreement(amount, app=False): try: plan = BillingPlanModel.objects.get(amount=amount) except BillingPlanModel.DoesNotExist: @@ -84,6 +84,10 @@ def create_agreement(amount): "payment_method": "paypal" }, }) + if app: + billing_agreement['override_merchant_preferences'] = { + 'return_url': absolute_url('paypal_app_return'), + } response = billing_agreement.create() if response: @@ -92,8 +96,8 @@ def create_agreement(amount): raise PaypalError(billing_agreement.error) -def agreement_approval_url(amount): - agreement = create_agreement(amount) +def agreement_approval_url(amount, app=False): + agreement = create_agreement(amount, app=app) return get_link(agreement.links, 'approval_url') @@ -110,5 +114,13 @@ def check_agreement(agreement_id): return a.state == 'Active' +def user_is_subscribed(user): + try: + agreement = BillingAgreementModel.objects.get(user=user) + except BillingAgreementModel.DoesNotExist: + return False + return agreement.check_agreement() + + def execute_agreement(token): return BillingAgreement.execute(token)