@@ -40,49 +40,6 @@ def prefilter_paddle_webhook(event_type: str, event_data: dict) -> bool:
4040 return True
4141
4242
43- @login_required
44- @inject_paddle
45- def subscription_complete (request : HttpRequest , paddle : Client ):
46- """User is redirected by Paddle via the successUrl."""
47- user = request .user
48- transaction_id = request .session .pop (SESSION_PADDLE_TRANSACTION_ID )
49- payment_type = request .session .pop (SESSION_PADDLE_PAYMENT_TYPE )
50-
51- # Hmm this shouldn't happen...send them home. They'll be redirected to subscribe if they're not subscribed anyways.
52- if not transaction_id or not payment_type :
53- return HttpResponseRedirect ('/' )
54-
55- transaction = paddle .transactions .get (transaction_id = transaction_id )
56- status = transaction .status .value
57-
58- if transaction and status in [Transaction .StatusValues .COMPLETED .value , Transaction .StatusValues .PAID .value ]:
59- user .is_awaiting_payment_verification = True
60- user .save ()
61-
62- if settings .IS_DEV :
63- tasks .dev_only_paddle_fake_webhook .delay (transaction_id = transaction_id , user_uuid = user .uuid .hex )
64-
65- """
66- Paddle folks mentioned these are the types that open pop-up windows:
67- """
68- if payment_type in [
69- PaymentMethodType .Paypal .value ,
70- # We don't use these, but for completeness' sake.
71- PaymentMethodType .Alipay .value ,
72- PaymentMethodType .Bancontact .value ,
73- PaymentMethodType .Ideal .value ,
74- PaymentMethodType .KoreaLocal .value ,
75- ]:
76- # Tell their window to close
77- return TemplateResponse (
78- request ,
79- 'close_window.html' ,
80- status = 200 ,
81- )
82-
83- return HttpResponseRedirect ('/subscribe' )
84-
85-
8643@login_required
8744@require_http_methods (['POST' ])
8845def get_paddle_information (request : Request ):
@@ -118,8 +75,7 @@ def set_paddle_transaction_id(request: Request):
11875
11976@login_required
12077@require_http_methods (['POST' ])
121- @inject_paddle
122- def is_paddle_transaction_done (request : Request , paddle : Client ):
78+ def is_paddle_transaction_done (request : Request ):
12379 """Checks if the Paddle transaction has finished and returns True or False.
12480 Also cleans up transaction id once the transaction is completed."""
12581 transaction_id = request .session .get (SESSION_PADDLE_TRANSACTION_ID , default = None )
@@ -132,18 +88,79 @@ def is_paddle_transaction_done(request: Request, paddle: Client):
13288
13389 status = Transaction .StatusValues .DRAFT .value
13490
135- # For dev machines we have to inquire directly, otherwise we rely on information given to us by the Paddle webhooks
136- if settings .IS_DEV :
137- transaction = paddle .transactions .get (transaction_id = transaction_id )
138- status = transaction .status .value
139- else :
140- transaction = Transaction .objects .filter (paddle_id = transaction_id ).first ()
141- if transaction :
142- status = transaction .status
91+ transaction = Transaction .objects .filter (paddle_id = transaction_id ).first ()
92+ if transaction :
93+ status = transaction .status
14394
14495 return JsonResponse ({'status' : status })
14596
14697
98+ @login_required
99+ @inject_paddle
100+ def paddle_transaction_complete (request : HttpRequest , paddle : Client ):
101+ """User is redirected by Paddle via the successUrl. This means we have a transaction that's paid or
102+ completed (noted as doneish.)
103+
104+ There's some special logic for certain payment processors that open a pop-up window instead of
105+ redirecting to another page or completeing on page. Those processors are defined in code, and
106+ will redirect the pop-up window to a django template that _should_ immediately close the window.
107+ For those processors the doneish/redirect logic is handled in
108+ :any:`thunderbird_accounts.subscription.views.is_paddle_transaction_done`
109+
110+ For regular payment processors like the default ``card`` we will simply redirect to the subscribe page.
111+ The front-end will handle if the check to see if the user's transaction and subscription has been pulled
112+ in our db via webhooks.
113+ """
114+ user = request .user
115+ transaction_id = request .session .pop (SESSION_PADDLE_TRANSACTION_ID )
116+ payment_type = request .session .pop (SESSION_PADDLE_PAYMENT_TYPE )
117+ redirect_response = HttpResponseRedirect ('/subscribe' )
118+
119+ # Hmm this shouldn't happen...
120+ if not transaction_id or not payment_type :
121+ return redirect_response
122+
123+ transaction = paddle .transactions .get (transaction_id = transaction_id )
124+ status = transaction .status .value
125+
126+ if transaction and status in [Transaction .StatusValues .COMPLETED .value , Transaction .StatusValues .PAID .value ]:
127+ user .is_awaiting_payment_verification = True
128+ user .save ()
129+
130+ if settings .IS_DEV :
131+ tasks .dev_only_paddle_fake_webhook .delay (transaction_id = transaction_id , user_uuid = user .uuid .hex )
132+
133+ """
134+ Paddle folks mentioned these are the types that open pop-up windows:
135+ * PayPal
136+ * Alipay
137+ * Bancontact
138+ * BLIK
139+ * iDEAL
140+ * MB WAY
141+ * South Korea local cards
142+ * Naver Pay, Kakao Pay, Samsung Pay, Payco
143+ * Pix
144+ * UPI
145+ """
146+ if payment_type in [
147+ PaymentMethodType .Paypal .value ,
148+ # We don't use these, but for completeness' sake.
149+ PaymentMethodType .Alipay .value ,
150+ PaymentMethodType .Bancontact .value ,
151+ PaymentMethodType .Ideal .value ,
152+ PaymentMethodType .KoreaLocal .value ,
153+ ]:
154+ # Tell their window to close
155+ return TemplateResponse (
156+ request ,
157+ 'close_window.html' ,
158+ status = 200 ,
159+ )
160+
161+ return redirect_response
162+
163+
147164@login_required
148165@require_http_methods (['POST' ])
149166@inject_paddle
0 commit comments