Esempio n. 1
0
    def create(business_info: Dict[str, Any], account_details: Dict[str, str],
               payment_system: str, authorization: Dict[str, Any]):
        """Create Payment account record."""
        current_app.logger.debug('<create')
        auth_account_id = get_str_by_path(authorization, 'account/id')
        payment_account: PaymentAccountModel = PaymentAccountModel.find_by_auth_account_id(auth_account_id)
        new_payment_account: bool = False
        is_premium_payment: bool = False
        if not payment_account:
            payment_account = PaymentAccountModel()
            payment_account.auth_account_id = auth_account_id
            payment_account = payment_account.save()
            new_payment_account = True

        dao = None
        if payment_system == PaymentSystem.BCOL.value:
            dao = BcolPaymentAccount()
            dao.account_id = payment_account.id
            dao.bcol_account_id = account_details.get('bcol_account_id', None)
            dao.bcol_user_id = account_details.get('bcol_user_id', None)
            is_premium_payment = True
        elif payment_system == PaymentSystem.INTERNAL.value:
            dao = InternalPaymentAccount()
            dao.corp_number = business_info.get('businessIdentifier', None)
            dao.corp_type_code = business_info.get('corpType', None)
            dao.account_id = payment_account.id
        elif payment_system == PaymentSystem.PAYBC.value:
            dao = CreditPaymentAccount()
            dao.corp_number = business_info.get('businessIdentifier', None)
            dao.corp_type_code = business_info.get('corpType', None)
            dao.paybc_account = account_details.get('account_number', None)
            dao.paybc_party = account_details.get('party_number', None)
            dao.paybc_site = account_details.get('site_number', None)
            dao.account_id = payment_account.id

        dao = dao.save()

        if new_payment_account and is_premium_payment:
            PaymentAccount._persist_default_statement_frequency(payment_account.id)

        p = PaymentAccount()
        p.populate(dao)  # pylint: disable=protected-access
        current_app.logger.debug('>create')
        return p
Esempio n. 2
0
    def create(cls, account_request: Dict[str, Any] = None) -> PaymentAccount:
        """Create new payment account record."""
        current_app.logger.debug('<create payment account')
        auth_account_id = account_request.get('accountId')
        # If an account already exists, throw error.
        if PaymentAccountModel.find_by_auth_account_id(str(auth_account_id)):
            raise BusinessException(Error.ACCOUNT_EXISTS)

        account = PaymentAccountModel()

        PaymentAccount._save_account(account_request, account)
        PaymentAccount._persist_default_statement_frequency(account.id)

        payment_account = PaymentAccount()
        payment_account._dao = account  # pylint: disable=protected-access

        payment_account.publish_account_mailer_event()

        current_app.logger.debug('>create payment account')
        return payment_account
Esempio n. 3
0
 def _dao(self):
     if not self.__dao:
         self.__dao = PaymentAccountModel()
     return self.__dao
Esempio n. 4
0
    def create(cls, request_json: Dict[str, any], **kwargs):
        """Search for routing slip."""
        # 1. Create customer profile in CFS and store it in payment_account and cfs_accounts
        # 2. Create receipt in CFS
        # 3. Create routing slip and payment records.

        rs_number = request_json.get('number')
        # Validate Routing slip digits and if slip number is unique.
        if cls.validate_and_find_by_number(rs_number):
            raise BusinessException(Error.FAS_INVALID_ROUTING_SLIP_NUMBER)

        payment_methods: [str] = [payment.get('paymentMethod') for payment in request_json.get('payments')]
        # all the payment should have the same payment method
        if len(set(payment_methods)) != 1:
            raise BusinessException(Error.FAS_INVALID_PAYMENT_METHOD)

        # If payment method is cheque and then there is no payment date then raise error
        if payment_methods[0] == PaymentMethod.CHEQUE.value:
            for payment in request_json.get('payments'):
                if payment.get('paymentDate') is None:
                    raise BusinessException(Error.INVALID_REQUEST)

        pay_account: PaymentAccountModel = PaymentAccountModel(
            name=request_json.get('paymentAccount').get('accountName'),
            payment_method=payment_methods[0],
        ).flush()

        CfsAccountModel(
            account_id=pay_account.id,
            status=CfsAccountStatus.PENDING.value
        ).flush()

        total = get_quantized(sum(float(payment.get('paidAmount')) for payment in request_json.get('payments')))

        # Calculate Total USD
        total_usd = get_quantized(sum(float(payment.get('paidUsdAmount', 0))
                                      for payment in request_json.get('payments')))

        # Create a routing slip record.
        routing_slip: RoutingSlipModel = RoutingSlipModel(
            number=rs_number,
            payment_account_id=pay_account.id,
            status=RoutingSlipStatus.ACTIVE.value,
            total=total,
            remaining_amount=total,
            routing_slip_date=string_to_date(request_json.get('routingSlipDate')),
            total_usd=total_usd
        ).flush()

        for payment in request_json.get('payments'):
            PaymentModel(
                payment_system_code=PaymentSystem.FAS.value,
                payment_account_id=pay_account.id,
                payment_method_code=payment.get('paymentMethod'),
                payment_status_code=PaymentStatus.COMPLETED.value,
                receipt_number=rs_number,
                cheque_receipt_number=payment.get('chequeReceiptNumber'),
                is_routing_slip=True,
                paid_amount=payment.get('paidAmount'),
                payment_date=string_to_date(payment.get('paymentDate')) if payment.get('paymentDate') else None,
                created_by=kwargs['user'].user_name,
                paid_usd_amount=payment.get('paidUsdAmount', None)
            ).flush()

        routing_slip.commit()
        return cls.find_by_number(rs_number)