Ejemplo n.º 1
0
def test_create_payment_record_with_service_charge(session, public_user_mock):
    """Assert that the payment records are created."""
    # Create a payment request for corp type BC
    payment_response = PaymentService.create_invoice(get_payment_request_with_service_fees(),
                                                     get_auth_basic_user())
    account_model = PaymentAccount.find_by_auth_account_id(get_auth_basic_user().get('account').get('id'))
    account_id = account_model.id
    assert account_id is not None
    assert payment_response.get('id') is not None
    assert payment_response.get('service_fees') == 1.50
Ejemplo n.º 2
0
def test_create_eft_payment(session, public_user_mock):
    """Assert that the payment records are created."""
    factory_payment_account(payment_method_code=PaymentMethod.EFT.value).save()

    payment_response = PaymentService.create_invoice(
        get_payment_request_with_service_fees(business_identifier='CP0002000'),
        get_auth_premium_user())
    assert payment_response is not None
    assert payment_response.get('payment_method') == PaymentMethod.EFT.value
    assert payment_response.get('status_code') == 'CREATED'
Ejemplo n.º 3
0
def test_payment_creation_with_service_fees(session, client, jwt, app):
    """Assert that the endpoint returns 201."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(get_payment_request_with_service_fees()),
                     headers=headers)
    assert rv.status_code == 201
    assert rv.json.get('_links') is not None
    assert rv.json.get('serviceFees') > 0

    assert schema_utils.validate(rv.json, 'invoice')[0]
Ejemplo n.º 4
0
def test_patch_online_banking_payment_to_cc(session, public_user_mock):
    """Assert that the payment records are created."""
    payment_account = factory_payment_account(
        payment_method_code=PaymentMethod.ONLINE_BANKING.value).save()
    payment_account.save()
    # payment.save()
    payment_response = PaymentService.create_invoice(
        get_payment_request_with_service_fees(business_identifier='CP0002000'),
        get_auth_premium_user())
    invoice_id = payment_response.get('id')

    factory_invoice_reference(invoice_id).save()

    request = {'paymentInfo': {'methodOfPayment': PaymentMethod.CC.value}}

    invoice_response = PaymentService.update_invoice(invoice_id, request)
    assert invoice_response.get('payment_method') == PaymentMethod.CC.value
Ejemplo n.º 5
0
def test_patch_online_banking_payment_to_direct_pay(session, public_user_mock):
    """Assert that the payment records are created."""
    factory_payment_account(
        payment_method_code=PaymentMethod.ONLINE_BANKING.value).save()

    payment_response = PaymentService.create_invoice(
        get_payment_request_with_service_fees(business_identifier='CP0002000'),
        get_auth_premium_user())
    assert payment_response is not None
    assert payment_response.get('payment_method') == 'ONLINE_BANKING'
    assert payment_response.get('status_code') == 'CREATED'

    invoice_id = payment_response.get('id')

    request = {'paymentInfo': {'methodOfPayment': PaymentMethod.CC.value}}

    invoice_response = PaymentService.update_invoice(invoice_id, request)
    assert invoice_response.get(
        'payment_method') == PaymentMethod.DIRECT_PAY.value
Ejemplo n.º 6
0
def test_payment_creation_with_service_fees_for_zero_fees(
        session, client, jwt, app):
    """Assert that the service fee is zero if it's a free filing."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    rv = client.post(
        '/api/v1/payment-requests',
        data=json.dumps(
            get_payment_request_with_service_fees(filing_type='OTFDR')),
        headers=headers)
    assert rv.status_code == 201
    assert rv.json.get('_links') is not None
    assert rv.json.get('invoices')[0].get('serviceFees') == 0

    assert schema_utils.validate(rv.json, 'payment_response')[0]
Ejemplo n.º 7
0
def test_account_purchase_history_with_service_account(session, client, jwt,
                                                       app):
    """Assert that purchase history returns only invoices for that product."""
    # Create one invoice for CSO and one fpr BUSINESS.
    # Then query without any filter and make sure only CSO invoice is returned for service account with CSO product_code
    for corp_filing_type in (['CSO', 'CSBVFEE'], ['PPR', 'FSDIS']):
        token = jwt.create_jwt(
            get_claims(roles=[Role.SYSTEM.value],
                       product_code=corp_filing_type[0]), token_header)
        headers = {
            'Authorization': f'Bearer {token}',
            'content-type': 'application/json'
        }
        rv = client.post('/api/v1/payment-requests',
                         data=json.dumps(
                             get_payment_request_with_service_fees(
                                 corp_type=corp_filing_type[0],
                                 filing_type=corp_filing_type[1])),
                         headers=headers)

    invoice: Invoice = Invoice.find_by_id(rv.json.get('id'))
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        invoice.payment_account_id)

    token = jwt.create_jwt(
        get_claims(roles=[Role.SYSTEM.value], product_code='CSO'),
        token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }
    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/payments/queries?page=1&limit=5',
        data=json.dumps({}),
        headers=headers)

    assert rv.status_code == 200
    assert rv.json.get('total') == 1
    assert len(rv.json.get('items')) == 1
    assert rv.json.get('items')[0]['corpTypeCode'] == 'CSO'
Ejemplo n.º 8
0
def test_create_pad_refund(session, client, jwt, app, stan_server):
    """Assert that the endpoint returns 202 and creates a credit on the account."""
    # 1. Create a PAD payment_account and cfs_account.
    # 2. Create a PAD invoice and mark as PAID.
    # 3. Issue a refund and assert credit is reflected on payment_account.
    # 4. Create an invoice again and assert that credit is updated.
    auth_account_id = 1234

    token = jwt.create_jwt(get_claims(role=Role.SYSTEM.value), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }
    client.post(
        '/api/v1/accounts',
        data=json.dumps(
            get_unlinked_pad_account_payload(account_id=auth_account_id)),
        headers=headers)
    pay_account: PaymentAccountModel = PaymentAccountModel.find_by_auth_account_id(
        auth_account_id)
    cfs_account: CfsAccountModel = CfsAccountModel.find_by_account_id(
        pay_account.id)[0]
    cfs_account.cfs_party = '1111'
    cfs_account.cfs_account = '1111'
    cfs_account.cfs_site = '1111'
    cfs_account.status = CfsAccountStatus.ACTIVE.value
    cfs_account.save()

    pay_account.pad_activation_date = datetime.now()
    pay_account.save()

    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json',
        'Account-Id': auth_account_id
    }

    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(
                         get_payment_request_with_payment_method(
                             payment_method=PaymentMethod.PAD.value)),
                     headers=headers)

    inv_id = rv.json.get('id')
    inv_total = rv.json.get('total')

    inv: InvoiceModel = InvoiceModel.find_by_id(inv_id)
    inv.invoice_status_code = InvoiceStatus.PAID.value
    inv.save()

    token = jwt.create_jwt(get_claims(app_request=app, role=Role.SYSTEM.value),
                           token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }
    rv = client.post(f'/api/v1/payment-requests/{inv_id}/refunds',
                     data=json.dumps({'reason': 'Test'}),
                     headers=headers)
    assert rv.status_code == 202
    assert rv.json.get('message') == REFUND_SUCCESS_MESSAGES['PAD.PAID']

    # Assert credit is updated.
    pay_account: PaymentAccountModel = PaymentAccountModel.find_by_auth_account_id(
        auth_account_id)
    credit = pay_account.credit
    assert pay_account.credit == inv_total

    # Create an invoice again and assert that credit is updated.
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json',
        'Account-Id': auth_account_id
    }

    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(
                         get_payment_request_with_service_fees(
                             corp_type='CP', filing_type='OTADD')),
                     headers=headers)
    inv_total = rv.json.get('total')

    pay_account: PaymentAccountModel = PaymentAccountModel.find_by_auth_account_id(
        auth_account_id)
    credit -= inv_total
    assert pay_account.credit == credit

    # Create an invoice again and assert that credit is updated.
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json',
        'Account-Id': auth_account_id
    }

    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(
                         get_payment_request_with_payment_method(
                             payment_method=PaymentMethod.PAD.value)),
                     headers=headers)
    inv_total = rv.json.get('total')
    # Credit must be zero now as the new invoice amount exceeds remaining credit.
    assert pay_account.credit == 0