Commit 9dddb882 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_subscription_request: Stop Payments for Free Reservations automatically

parent 0b8e17fc
Pipeline #11270 failed with stage
in 0 seconds
......@@ -24,6 +24,7 @@ if current_invoice is None:
)
if context.SubscriptionRequest_testSkippedReservationFree(contract):
# Reservation is Free
amount = 0
for line in current_payment.contentValues():
......@@ -35,7 +36,11 @@ if current_invoice is None:
comment = "Validation payment for subscription request %s" % context.getRelativeUrl()
current_payment.confirm(comment=comment)
current_payment.start(comment=comment)
current_payment.PaymentTransaction_updateStatus()
if not amount:
current_payment.stop(comment="%s (Free)" % comment)
elif target_language != "zh":
# Payzen don't require update like this.
current_payment.PaymentTransaction_updateStatus()
current_payment.reindexObject(activate_kw={'tag': tag})
context.reindexObject(activate_kw={'tag': tag})
......
......@@ -320,6 +320,18 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
}
payment.PaymentTransaction_createPayzenEvent().PayzenEvent_processUpdate(data_kw, True)
def _checkFreeReservationPayment(self, subscription_request):
quantity = subscription_request.getQuantity()
# Check Payment
payment = self._getRelatedPaymentValue(subscription_request)
self.assertEqual(self.expected_price_currency, payment.getPriceCurrency())
self.assertEqual(-self.expected_reservation_fee*quantity,
payment.PaymentTransaction_getTotalPayablePrice())
self.assertEqual(payment.getSimulationState(), "stopped")
return payment
def _payPayment(self, subscription_request):
quantity = subscription_request.getQuantity()
# Check Payment
......@@ -353,8 +365,13 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
self.assertEqual(invoice.getSource(), self.expected_source)
self.assertEqual(invoice.getSourceSection(), self.expected_source_section)
# Pay Invoice if it is not Free
if not self.expected_free_reservation:
payment = self._payPayment(subscription_request)
else:
payment = self._checkFreeReservationPayment(subscription_request)
# Check Payment
payment = self._payPayment(subscription_request)
self.assertEqual(payment.getSourceSection(), self.expected_source_section)
self.assertEqual(payment.getSourcePayment(), "%s/bank_account" % self.expected_source_section)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment