Esempio n. 1
0
    def _process_cfs_refund(cls, invoice: InvoiceModel):
        """Process refund in CFS."""
        if invoice.payment_method_code in ([
                PaymentMethod.DIRECT_PAY.value, PaymentMethod.DRAWDOWN.value
        ]):
            cls._publish_to_mailer(invoice)
            payment: PaymentModel = PaymentModel.find_payment_for_invoice(
                invoice.id)
            payment.payment_status_code = PaymentStatus.REFUNDED.value
            payment.flush()
        else:
            # Create credit memo in CFS if the invoice status is PAID.
            # Don't do anything is the status is APPROVED.
            if invoice.invoice_status_code == InvoiceStatus.APPROVED.value:
                return
            cfs_account: CfsAccountModel = CfsAccountModel.find_effective_by_account_id(
                invoice.payment_account_id)
            line_items: List[PaymentLineItemModel] = []
            for line_item in invoice.payment_line_items:
                line_items.append(PaymentLineItemModel.find_by_id(
                    line_item.id))

            cms_response = CFSService.create_cms(line_items=line_items,
                                                 cfs_account=cfs_account)
            # TODO Create a payment record for this to show up on transactions, when the ticket comes.
            # Create a credit with CM identifier as CMs are not reported in payment interface file
            # until invoice is applied.
            CreditModel(cfs_identifier=cms_response.get('credit_memo_number'),
                        is_credit_memo=True,
                        amount=invoice.total,
                        remaining_amount=invoice.total,
                        account_id=invoice.payment_account_id).save()
Esempio n. 2
0
 def process_cfs_refund(self, invoice: InvoiceModel):
     """Process refund in CFS."""
     self._publish_refund_to_mailer(invoice)
     payment: PaymentModel = PaymentModel.find_payment_for_invoice(
         invoice.id)
     payment.payment_status_code = PaymentStatus.REFUNDED.value
     payment.flush()
Esempio n. 3
0
    def _process_cfs_refund(cls, invoice: InvoiceModel):
        """Process refund in CFS."""
        if invoice.payment_method_code == PaymentMethod.DIRECT_PAY.value:
            cls._publish_to_mailer(invoice)
            payment: PaymentModel = PaymentModel.find_payment_for_invoice(
                invoice.id)
            payment.payment_status_code = PaymentStatus.REFUNDED.value
            payment.flush()
        else:
            # Create credit memo in CFS.
            # TODO Refactor this when actual task is done. This is just a quick fix for CFS UAT - Dec 2020
            cfs_account: CfsAccountModel = CfsAccountModel.find_effective_by_account_id(
                invoice.payment_account_id)
            line_items: List[PaymentLineItemModel] = []
            for line_item in invoice.payment_line_items:
                line_items.append(PaymentLineItemModel.find_by_id(
                    line_item.id))

            cms_response = CFSService.create_cms(line_items=line_items,
                                                 cfs_account=cfs_account)
            # TODO Create a payment record for this to show up on transactions, when the ticket comes.
            # Create a credit with CM identifier as CMs are not reported in payment interface file
            # until invoice is applied.
            CreditModel(cfs_identifier=cms_response.get('credit_memo_number'),
                        is_credit_memo=True,
                        amount=invoice.total,
                        remaining_amount=invoice.total,
                        account_id=invoice.payment_account_id).save()
Esempio n. 4
0
 def process_cfs_refund(self, invoice: InvoiceModel):
     """Process refund in CFS."""
     current_app.logger.debug(f'Processing refund for {invoice.id}')
     super()._publish_refund_to_mailer(invoice)
     payment: PaymentModel = PaymentModel.find_payment_for_invoice(
         invoice.id)
     payment.payment_status_code = PaymentStatus.REFUNDED.value
     payment.flush()
Esempio n. 5
0
    def find_payment_for_invoice(invoice_id: int):
        """Find payment for by invoice."""
        payment_dao = PaymentModel.find_payment_for_invoice(invoice_id)
        payment: Payment = None
        if payment_dao:
            payment = Payment._populate(payment_dao)

        current_app.logger.debug('>find_payment_for_invoice')
        return payment
Esempio n. 6
0
        # find if its a routing slip refund
        # if yes -> check existing one or legacy
        # if yes , add money back to rs after refunding

        if (routing_slip_number := invoice.routing_slip) is None:
            raise BusinessException(Error.INVALID_REQUEST)
        if invoice.total == 0:
            raise BusinessException(Error.NO_FEE_REFUND)
        if not (routing_slip :=
                RoutingSlipModel.find_by_number(routing_slip_number)):
            raise BusinessException(Error.ROUTING_SLIP_REFUND)
        current_app.logger.info(
            f'Processing refund for {invoice.id}, on routing slip {routing_slip.number}'
        )
        payment: PaymentModel = PaymentModel.find_payment_for_invoice(
            invoice.id)
        if payment:
            payment.payment_status_code = PaymentStatus.REFUNDED.value
            payment.flush()
        routing_slip.remaining_amount += get_quantized(invoice.total)
        # Move routing slip back to active on refund.
        if routing_slip.status == RoutingSlipStatus.COMPLETE.value:
            routing_slip.status = RoutingSlipStatus.ACTIVE.value
        routing_slip.flush()
        invoice.invoice_status_code = InvoiceStatus.REFUND_REQUESTED.value
        invoice.flush()

    @staticmethod
    def _validate_routing_slip(routing_slip: RoutingSlipModel,
                               invoice: Invoice):
        """Validate different conditions of a routing slip payment."""