11from __future__ import annotations
22
3- from typing import TYPE_CHECKING , List , Optional
3+ from typing import TYPE_CHECKING , List , Optional , Union
44
55from django .core .exceptions import ValidationError
66from django .http import HttpRequest
@@ -74,12 +74,14 @@ def validate_order(self, order: BaseOrder, request: HttpRequest) -> None:
7474 msg = _ ("Payment for order with status '{status}' is not allowed." )
7575 raise ValidationError (msg .format (status = order .status_display ))
7676
77- def basket_payment (self , basket : BaseBasket , request : HttpRequest ) -> str :
77+ def basket_payment (
78+ self ,
79+ basket : BaseBasket ,
80+ request : HttpRequest ,
81+ ) -> Union [str , dict ]:
7882 """
7983 This method gets called when new checkout is submitted and
8084 is responsible for creating a new order from given basket.
81- Should return the redirect url to either the next payment step or
82- the order success page. Raise ``PaymentError`` in case an issue appears.
8385
8486 Args:
8587 basket (Basket): Basket instance
@@ -89,15 +91,17 @@ def basket_payment(self, basket: BaseBasket, request: HttpRequest) -> str:
8991 PaymentError: If error with payment occurs
9092
9193 Returns:
92- str: Redirect url to the next step
94+ Union[ str, dict] : Redirect URL string or JSON serializable data dictionary
9395 """
9496 raise NotImplementedError ("Method `basket_payment()` is not implemented." )
9597
96- def order_payment (self , order : BaseOrder , request : HttpRequest ) -> str :
98+ def order_payment (
99+ self ,
100+ order : BaseOrder ,
101+ request : HttpRequest ,
102+ ) -> Union [str , dict ]:
97103 """
98104 This method gets called when payment for an existing order is requested.
99- Should return the redirect url to either the next payment step or the
100- order success page. Raise ``PaymentError`` in case an issue appears.
101105
102106 Args:
103107 order (Order): Order instance
@@ -107,7 +111,7 @@ def order_payment(self, order: BaseOrder, request: HttpRequest) -> str:
107111 PaymentError: If error with payment occurs
108112
109113 Returns:
110- str: Redirect url to the next step
114+ Union[ str, dict] : Redirect URL string or JSON serializable data dictionary
111115 """
112116 raise NotImplementedError ("Method `order_payment()` is not implemented." )
113117
0 commit comments