-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add recover failed callbacks command
fixes #6
- Loading branch information
Showing
8 changed files
with
294 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
paygate/management/commands/retry_baskets_payed_in_paygate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
""" | ||
Command that retries to receive the missing server callbacks from PayGate. | ||
""" | ||
|
||
import logging | ||
from datetime import datetime, timedelta | ||
|
||
from django.contrib.sites.models import Site | ||
from django.core.management.base import BaseCommand | ||
from paygate.processors import PayGate | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Command that retries to receive the missing server callbacks from PayGate. | ||
""" | ||
|
||
help = """retries to receive the missing server callbacks from PayGate.""" | ||
|
||
def add_arguments(self, parser): | ||
""" | ||
Arguments of this command. | ||
""" | ||
parser.add_argument( | ||
"--site", | ||
type=str, | ||
default=Site.objects.get_current().domain, | ||
help="The site domain to execute this recover", | ||
) | ||
parser.add_argument( | ||
"--start", | ||
type=str, | ||
help="The start date period to retry, incompatible with the --delta-in-minutes", | ||
) | ||
parser.add_argument( | ||
"--end", | ||
type=str, | ||
default=None, | ||
help="The end date period to retry, incompatible with the --delta-in-minutes", | ||
) | ||
parser.add_argument( | ||
"--delta-in-minutes", | ||
type=str, | ||
default=1440, # 1 day | ||
help="The number of seconds to retry, default to last day", | ||
) | ||
|
||
def handle(self, *args, **kwargs): | ||
""" | ||
Synchronize courses to the Richie marketing site, print to console its sync progress. | ||
""" | ||
start_str = kwargs["start"] | ||
end_str = kwargs["end"] | ||
if start_str or end_str: | ||
start = datetime.strptime(kwargs["start"], "%Y-%m-%d %H:%M:%S") | ||
end = datetime.strptime(kwargs["end"], "%Y-%m-%d %H:%M:%S") | ||
else: | ||
delta_in_minutes = kwargs["delta-in-minutes"] | ||
now = datetime.now() | ||
end = now | ||
start = now - timedelta(minutes=delta_in_minutes) | ||
|
||
site_domain = kwargs["site"] | ||
site = Site.objects.filter(domain=site_domain) | ||
paygate = PayGate(site) | ||
paygate.retry_baskets_payed_in_paygate(start, end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
|
||
class MockResponse: | ||
""" | ||
A mocked requests response. | ||
""" | ||
|
||
def __init__(self, json_data=None, status_code=200): | ||
self.json_data = json_data | ||
self.status_code = status_code | ||
|
||
def json(self): | ||
""" | ||
The Json output that will be mocked | ||
""" | ||
return self.json_data | ||
|
||
def content(self): | ||
""" | ||
The Json data | ||
""" | ||
return self.json_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
from oscar.core.loading import get_model | ||
from django.core.exceptions import ObjectDoesNotExist | ||
from oscar.core.loading import get_class, get_model | ||
|
||
Order = get_model('order', 'Order') | ||
from ecommerce.extensions.partner import strategy | ||
|
||
Order = get_model("order", "Order") | ||
Basket = get_model("basket", "Basket") | ||
Applicator = get_class("offer.applicator", "Applicator") | ||
|
||
|
||
def order_exist(basket: Basket) -> bool: | ||
""" | ||
Utility method that check if there is an Order for the Basket | ||
""" | ||
return Order.objects.filter(number=basket.order_number).exists() | ||
|
||
|
||
def get_basket(basket_id, request=None): | ||
""" | ||
Get the Django Oscar Basket class from its id. | ||
""" | ||
if not basket_id: | ||
return None | ||
try: | ||
basket_id = int(basket_id) | ||
basket = Basket.objects.get(id=basket_id) | ||
basket.strategy = strategy.Selector().strategy() | ||
Applicator().apply(basket, basket.owner, request=request) | ||
return basket | ||
except (ValueError, ObjectDoesNotExist): | ||
return None |
Oops, something went wrong.