-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π§βπ»(debug) update payment debug view with
OrderFactory
The `OrderGeneratorFactory` used for the debug payment view was not appropriate because it creates a transaction when the state of the order in in pending payment. When we create a payment with the debug view, and we want to refund it, the method `get_transaction_references_to_refund` would find 2 different transactions with the same amount to refund. Only one out of two is known to the payment provider, and thus, it would raise an error while attempting to refund the order from the backoffice of Joanie.
- Loading branch information
1 parent
8f76999
commit d5547b7
Showing
1 changed file
with
33 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
from django.conf import settings | ||
from django.contrib.auth.mixins import LoginRequiredMixin | ||
from django.urls import reverse | ||
from django.utils import translation | ||
from django.utils import timezone, translation | ||
from django.utils.decorators import method_decorator | ||
from django.views.decorators.csrf import csrf_exempt | ||
from django.views.generic.base import TemplateView | ||
|
@@ -29,16 +29,25 @@ | |
PAYMENT_STATE_REFUSED, | ||
) | ||
from joanie.core.factories import ( | ||
ContractDefinitionFactory, | ||
ContractFactory, | ||
CourseRunFactory, | ||
OrderFactory, | ||
OrderGeneratorFactory, | ||
ProductFactory, | ||
ProductTargetCourseRelationFactory, | ||
UserFactory, | ||
) | ||
from joanie.core.models import Certificate, Contract | ||
from joanie.core.models import Certificate, Contract, CourseState | ||
from joanie.core.utils import contract_definition, issuers | ||
from joanie.core.utils.sentry import decrypt_data | ||
from joanie.payment import get_payment_backend | ||
from joanie.payment.enums import INVOICE_TYPE_INVOICE | ||
from joanie.payment.models import CreditCard, Invoice | ||
from joanie.payment.factories import ( | ||
BillingAddressDictFactory, | ||
CreditCardFactory, | ||
) | ||
from joanie.payment.models import Invoice | ||
|
||
logger = getLogger(__name__) | ||
LOGO_FALLBACK = ( | ||
|
@@ -507,17 +516,34 @@ def get_context_data(self, **kwargs): | |
last_name="Card", | ||
email="[email protected]", | ||
) | ||
product = ProductFactory(price=Decimal("123.45")) | ||
product = ProductFactory(price=Decimal("123.46")) | ||
product.set_current_language("en-us") | ||
product.title = "Test product" | ||
product.set_current_language("fr-fr") | ||
product.title = "Test produit" | ||
product.save() | ||
order = OrderGeneratorFactory( | ||
owner=owner, product=product, state=ORDER_STATE_PENDING_PAYMENT | ||
order = OrderFactory(owner=owner, product=product) | ||
ContractFactory( | ||
order=order, | ||
definition=ContractDefinitionFactory(), | ||
organization_signed_on=timezone.now(), | ||
student_signed_on=timezone.now(), | ||
signature_backend_reference="wfl_demo_dev_experience", | ||
) | ||
CourseRunFactory( | ||
course=order.course, | ||
is_gradable=True, | ||
state=CourseState.ONGOING_OPEN, | ||
end=timezone.now() + datetime.timedelta(days=200), | ||
) | ||
ProductTargetCourseRelationFactory( | ||
product=order.product, | ||
course=order.course, | ||
is_graded=True, | ||
) | ||
credit_card = CreditCardFactory(owner=owner) | ||
order.init_flow(billing_address=BillingAddressDictFactory()) | ||
billing_address = order.main_invoice.recipient_address | ||
credit_card = CreditCard.objects.filter(owner=owner, is_main=True).first() | ||
one_click = "one-click" in self.request.GET | ||
tokenize_card = "tokenize-card" in self.request.GET | ||
zero_click = "zero-click" in self.request.GET | ||
|