Esempio n. 1
0
def test_create_payment_record_rollback_on_paybc_connection_error(
        session, public_user_mock):
    """Assert that the payment records are not created."""
    # Create a payment account
    factory_payment_account()

    # Mock here that the invoice update fails here to test the rollback scenario
    with patch('pay_api.services.oauth_service.requests.post',
               side_effect=ConnectionError('mocked error')):
        with pytest.raises(ServiceUnavailableException) as excinfo:
            PaymentService.create_invoice(get_payment_request(),
                                          get_auth_basic_user())
        assert excinfo.type == ServiceUnavailableException

    with patch('pay_api.services.oauth_service.requests.post',
               side_effect=ConnectTimeout('mocked error')):
        with pytest.raises(ServiceUnavailableException) as excinfo:
            PaymentService.create_invoice(get_payment_request(),
                                          get_auth_basic_user())
        assert excinfo.type == ServiceUnavailableException

    with patch('pay_api.services.oauth_service.requests.post',
               side_effect=HTTPError('mocked error')) as post_mock:
        post_mock.status_Code = 503
        with pytest.raises(HTTPError) as excinfo:
            PaymentService.create_invoice(get_payment_request(),
                                          get_auth_basic_user())
        assert excinfo.type == HTTPError
Esempio n. 2
0
def test_create_payment_record_rollback_on_paybc_connection_error(session):
    """Assert that the payment records are not created."""
    from unittest.mock import Mock
    # Mock here that the invoice update fails here to test the rollback scenario
    with patch('pay_api.services.oauth_service.requests.post',
               side_effect=ConnectionError('mocked error')):
        with pytest.raises(ServiceUnavailableException) as excinfo:
            PaymentService.create_payment(get_payment_request(), 'test')
        assert excinfo.type == ServiceUnavailableException
    with patch('pay_api.services.oauth_service.requests.post',
               side_effect=ConnectTimeout('mocked error')):
        with pytest.raises(ServiceUnavailableException) as excinfo:
            PaymentService.create_payment(get_payment_request(), 'test')
        assert excinfo.type == ServiceUnavailableException

    mock_create_site = patch('pay_api.services.oauth_service.requests.post')

    mock_post = mock_create_site.start()
    mock_post.return_value = Mock(status_code=503)

    with patch('pay_api.services.oauth_service.requests.post',
               side_effect=HTTPError('mocked error')) as post_mock:
        post_mock.status_Code = 503
        with pytest.raises(HTTPError) as excinfo:
            PaymentService.create_payment(get_payment_request(), 'test')
        assert excinfo.type == HTTPError
Esempio n. 3
0
def test_create_payment_record(session):
    """Assert that the payment records are created."""
    payment_response = PaymentService.create_payment(get_payment_request(), 'test')
    account_model = PaymentAccount.find_by_corp_number_and_corp_type_and_system('CP1234', 'CP', 'PAYBC')
    account_id = account_model.id
    assert account_id is not None
    assert payment_response.get('id') is not None
    # Create another payment with same request, the account should be the same
    PaymentService.create_payment(get_payment_request(), 'test')
    account_model = PaymentAccount.find_by_corp_number_and_corp_type_and_system('CP1234', 'CP', 'PAYBC')
    assert account_id == account_model.id
Esempio n. 4
0
def test_create_payment_record(session, public_user_mock):
    """Assert that the payment records are created."""
    payment_response = PaymentService.create_invoice(get_payment_request(), 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
    # Create another payment with same request, the account should be the same
    PaymentService.create_invoice(get_payment_request(), get_auth_basic_user())
    account_model = PaymentAccount.find_by_auth_account_id(get_auth_basic_user().get('account').get('id'))

    assert account_id == account_model.id
def test_create_payment_record_with_direct_pay(session, public_user_mock):
    """Assert that the payment records are created."""
    current_app.config['DIRECT_PAY_ENABLED'] = True
    payment_response = PaymentService.create_invoice(
        get_payment_request(), get_auth_basic_user(PaymentMethod.DIRECT_PAY.value))
    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
    # Create another payment with same request, the account should be the same
    PaymentService.create_invoice(get_payment_request(), get_auth_basic_user())
    account_model = PaymentAccount.find_by_auth_account_id(get_auth_basic_user().get('account').get('id'))

    assert account_id == account_model.id
Esempio n. 6
0
def test_create_payment_record(session, public_user_mock):
    """Assert that the payment records are created."""
    payment_response = PaymentService.create_payment(get_payment_request(), get_auth_basic_user())
    account_model = CreditPaymentAccount. \
        find_by_corp_number_and_corp_type_and_auth_account_id('CP0001234', 'CP',
                                                              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
    # Create another payment with same request, the account should be the same
    PaymentService.create_payment(get_payment_request(), get_auth_basic_user())
    account_model = CreditPaymentAccount. \
        find_by_corp_number_and_corp_type_and_auth_account_id('CP0001234', 'CP',
                                                              get_auth_basic_user().get('account').get('id'))
    assert account_id == account_model.id
Esempio n. 7
0
def test_transaction_put(session, client, jwt, app):
    """Assert that the endpoint returns 200."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    # Create a payment first
    rv = client.post(f'/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)
    payment_id = rv.json.get('id')
    data = {
        'clientSystemUrl':
        'http://localhost:8080/coops-web/transactions/transaction_id=abcd',
        'payReturnUrl': 'http://localhost:8080/pay-web'
    }
    receipt_number = '123451'
    rv = client.post(f'/api/v1/payment-requests/{payment_id}/transactions',
                     data=json.dumps(data),
                     headers={'content-type': 'application/json'})
    txn_id = rv.json.get('id')
    rv = client.patch(
        f'/api/v1/payment-requests/{payment_id}/transactions/{txn_id}',
        data=json.dumps({'receipt_number': receipt_number}),
        headers={'content-type': 'application/json'})
    assert rv.status_code == 200
Esempio n. 8
0
def test_create_refund_with_legacy_routing_slip(session, client, jwt, app,
                                                stan_server):
    """Assert that the endpoint  returns 202."""
    claims = get_claims(roles=[
        Role.FAS_CREATE.value, Role.FAS_SEARCH.value, Role.FAS_REFUND.value,
        Role.STAFF.value, 'make_payment'
    ])
    token = jwt.create_jwt(claims, token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    data = get_payment_request()
    data['accountInfo'] = {'routingSlip': 'legacy_number'}

    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(data),
                     headers=headers)
    inv_id = rv.json.get('id')

    rv = client.post(f'/api/v1/payment-requests/{inv_id}/refunds',
                     data=json.dumps({'reason': 'Test'}),
                     headers=headers)
    assert rv.status_code == 400
    assert rv.json.get('type') == 'ROUTING_SLIP_REFUND'
Esempio n. 9
0
def test_transaction_get_invalid_payment_and_transaction(
        session, client, jwt, app):
    """Assert that the endpoint returns 200."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    # Create a payment first
    rv = client.post(f'/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)
    payment_id = rv.json.get('id')
    data = {
        'clientSystemUrl':
        'http://localhost:8080/coops-web/transactions/transaction_id=abcd',
        'payReturnUrl': 'http://localhost:8080/pay-web'
    }
    rv = client.post(f'/api/v1/payment-requests/{payment_id}/transactions',
                     data=json.dumps(data),
                     headers={'content-type': 'application/json'})
    txn_id = rv.json.get('id')
    invalid_payment_id = 999
    rv = client.get(
        f'/api/v1/payment-requests/{invalid_payment_id}/transactions/{txn_id}',
        headers=headers)
    assert rv.status_code == 400
    assert rv.json.get('code') == 'PAY008'
    invalid_txn_id = uuid.uuid4()
    rv = client.get(
        f'/api/v1/payment-requests/{payment_id}/transactions/{invalid_txn_id}',
        headers=headers)
    assert rv.status_code == 400
    assert rv.json.get('code') == 'PAY008'
Esempio n. 10
0
def test_payment_creation_with_folio_number(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'
    }
    folio_number = '1234567890'

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

    assert schema_utils.validate(rv.json, 'invoice')[0]
    assert rv.json.get('folioNumber') == folio_number

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

    assert schema_utils.validate(rv.json, 'invoice')[0]
    assert rv.json.get('folioNumber') == 'MOCK1234'
Esempio n. 11
0
def test_transaction_get(session, client, jwt, app):
    """Assert that the endpoint returns 200."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    # Create a payment first
    rv = client.post(f'/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)
    payment_id = rv.json.get('id')
    redirect_uri = 'http%3A//localhost%3A8080/coops-web/transactions%3Ftransaction_id%3Dabcd'
    rv = client.post(
        f'/api/v1/payment-requests/{payment_id}/transactions?redirect_uri={redirect_uri}',
        data=None,
        headers=headers)
    txn_id = rv.json.get('id')
    rv = client.get(
        f'/api/v1/payment-requests/{payment_id}/transactions/{txn_id}',
        headers=headers)
    assert rv.status_code == 200
    assert rv.json.get('paymentId') == payment_id
    assert rv.json.get('id') == txn_id
    assert schema_utils.validate(rv.json, 'transaction')[0]
Esempio n. 12
0
def test_transaction_patch_completed_payment_and_transaction_status(
        session, client, jwt, app, stan_server):
    """Assert that payment tokens can be retrieved and decoded from the Queue."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    # Create a payment first
    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)
    invoice_id = rv.json.get('id')
    data = {
        'clientSystemUrl':
        'http://localhost:8080/coops-web/transactions/transaction_id=abcd',
        'payReturnUrl': 'http://localhost:8080/pay-web'
    }
    rv = client.post(f'/api/v1/payment-requests/{invoice_id}/transactions',
                     data=json.dumps(data),
                     headers={'content-type': 'application/json'})

    txn_id = rv.json.get('id')
    rv = client.patch(
        f'/api/v1/payment-requests/{invoice_id}/transactions/{txn_id}',
        data=json.dumps({}),
        headers={'content-type': 'application/json'})

    assert rv.status_code == 200
    assert rv.json.get('statusCode') == 'COMPLETED'
Esempio n. 13
0
def test_account_purchase_history_export_as_csv(session, client, jwt, app):
    """Assert that the endpoint returns 200."""
    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()),
                     headers=headers)

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

    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json',
        'Accept': 'text/csv'
    }

    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/payments/reports',
        data=json.dumps({}),
        headers=headers)

    assert rv.status_code == 201
Esempio n. 14
0
def test_create_receipt_with_no_receipt(session, public_user_mock):
    """Try creating a receipt with invoice number."""
    payment_account = factory_payment_account()
    payment = factory_payment()
    payment_account.save()
    payment.save()
    invoice = factory_invoice(payment.id, payment_account.id)
    invoice.save()
    factory_invoice_reference(invoice.id).save()
    fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN')
    line = factory_payment_line_item(
        invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id)
    line.save()

    PaymentService.update_payment(payment.id, get_payment_request())
    input_data = {
        'corpName': 'Pennsular Coop ',
        'filingDateTime': '1999',
        'fileName': 'coopser'
    }

    with pytest.raises(BusinessException) as excinfo:
        ReceiptService.create_receipt(payment.id,
                                      '',
                                      input_data,
                                      skip_auth_check=True)
    assert excinfo.type == BusinessException
Esempio n. 15
0
def test_get_monthly_statement_report_as_csv(session, client, jwt, app):
    """Assert that the monthly statement report is returning response."""
    # Create a payment account and statement details, then get all statements for the account
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json',
        'Accept': ContentType.CSV.value
    }

    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(
                         get_payment_request(business_identifier='CP0002000')),
                     headers=headers)

    payment: Payment = Payment.find_by_id(rv.json.get('id'))
    bcol_account: BcolPaymentAccount = BcolPaymentAccount.find_by_id(
        payment.invoices[0].bcol_account_id)
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        bcol_account.account_id)

    settings_model = factory_statement_settings(
        payment_account_id=pay_account.id,
        frequency=StatementFrequency.DAILY.value)
    statement_model = factory_statement(
        payment_account_id=pay_account.id,
        frequency=StatementFrequency.DAILY.value,
        statement_settings_id=settings_model.id)
    factory_statement_invoices(statement_id=statement_model.id,
                               invoice_id=payment.invoices[0].id)

    rv = client.get(
        f'/api/v1/accounts/{pay_account.auth_account_id}/statements/{statement_model.id}',
        headers=headers)
    assert rv.status_code == 200
Esempio n. 16
0
def test_payment_put_incomplete_input(session, client, jwt, app):
    """Assert that the endpoint returns 400."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    rv = client.post(f'/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)
    pay_id = rv.json.get('id')

    transaction = factory_payment_transaction(pay_id)
    transaction.save()

    data = {
        'businessInfo': {
            'businessIdentifier': 'CP0001234',
            'corpType': 'CP',
            'businessName': 'ABC Corp',
            'contactInfo': {
                'city': 'Victoria',
                'postalCode': 'V8P2P2',
                'province': 'BC',
                'addressLine1': '100 Douglas Street',
                'country': 'CA'
            }
        }
    }
    rv = client.put(f'/api/v1/payment-requests/{pay_id}',
                    data=json.dumps(data),
                    headers=headers)
    assert rv.status_code == 400
Esempio n. 17
0
def test_create_ejv_payment_request(session, client, jwt, app):
    """Assert payment request works for EJV accounts."""
    token = jwt.create_jwt(get_claims(role=Role.SYSTEM.value), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }
    # Create account first
    rv = client.post('/api/v1/accounts',
                     data=json.dumps(get_gov_account_payload(account_id=1234)),
                     headers=headers)
    auth_account_id = rv.json.get('authAccountId')

    payment_account: PaymentAccountModel = PaymentAccountModel.find_by_auth_account_id(
        auth_account_id)
    dist_code: DistributionCodeModel = DistributionCodeModel.find_by_active_for_account(
        payment_account.id)

    assert dist_code
    assert dist_code.account_id == payment_account.id

    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()),
                     headers=headers)
    assert rv.json.get('paymentMethod') == PaymentMethod.EJV.value
    assert rv.json.get('statusCode') == InvoiceStatus.APPROVED.value
Esempio n. 18
0
def test_receipt_creation(session, client, jwt, app):
    """Assert that the endpoint returns 201."""
    token = jwt.create_jwt(get_claims(app_request=app), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    rv = client.post(f'/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)
    pay_id = rv.json.get('id')

    payment_id = rv.json.get('id')
    redirect_uri = 'http%3A//localhost%3A8080/coops-web/transactions%3Ftransaction_id%3Dabcd'
    receipt_number = '123451'
    rv = client.post(
        f'/api/v1/payment-requests/{payment_id}/transactions?redirect_uri={redirect_uri}',
        data=None,
        headers=headers)
    txn_id = rv.json.get('id')
    rv = client.patch(
        f'/api/v1/payment-requests/{payment_id}/transactions/{txn_id}?receipt_number={receipt_number}',
        data=None,
        headers=headers)

    filing_data = {
        'corpName': 'CP1234',
        'filingDateTime': 'June 27, 2019',
        'fileName': 'director-change'
    }
    rv = client.post(f'/api/v1/payment-requests/{pay_id}/receipts',
                     data=json.dumps(filing_data),
                     headers=headers)
    assert rv.status_code == 201
Esempio n. 19
0
def test_create_payment_record_rollback(session):
    """Assert that the payment records are created."""
    # Mock here that the invoice update fails here to test the rollback scenario
    with patch('pay_api.services.invoice.Invoice.save', side_effect=Exception('mocked error')):
        with pytest.raises(Exception) as excinfo:
            PaymentService.create_payment(get_payment_request(), 'test')
        assert excinfo.type == Exception

    with patch('pay_api.services.payment.Payment.create', side_effect=Exception('mocked error')):
        with pytest.raises(Exception) as excinfo:
            PaymentService.create_payment(get_payment_request(), 'test')
        assert excinfo.type == Exception
    with patch('pay_api.services.paybc_service.PaybcService.create_invoice', side_effect=Exception('mocked error')):
        with pytest.raises(Exception) as excinfo:
            PaymentService.create_payment(get_payment_request(), 'test')
        assert excinfo.type == Exception
Esempio n. 20
0
def test_transaction_patch_when_paybc_down(session, client, jwt, app):
    """Assert that the endpoint returns 200."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    # Create a payment first
    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)
    invoice_id = rv.json.get('id')
    data = {
        'clientSystemUrl':
        'http://localhost:8080/coops-web/transactions/transaction_id=abcd',
        'payReturnUrl': 'http://localhost:8080/pay-web'
    }
    receipt_number = '123451'
    rv = client.post(f'/api/v1/payment-requests/{invoice_id}/transactions',
                     data=json.dumps(data),
                     headers={'content-type': 'application/json'})
    txn_id = rv.json.get('id')
    with patch('pay_api.services.oauth_service.requests.post',
               side_effect=ConnectionError('mocked error')):
        rv = client.patch(
            f'/api/v1/payment-requests/{invoice_id}/transactions/{txn_id}',
            data=json.dumps({'receipt_number': receipt_number}),
            headers={'content-type': 'application/json'})
        assert rv.status_code == 200
        assert rv.json.get('paySystemReasonCode') == 'SERVICE_UNAVAILABLE'
Esempio n. 21
0
def test_create_receipt_without_invoice(session, public_user_mock):
    """Try creating a receipt without invoice number."""
    payment_account = factory_payment_account()
    payment = factory_payment()
    payment_account.save()
    payment.save()
    invoice = factory_invoice(payment.id, payment_account.id)
    invoice.save()
    factory_invoice_reference(invoice.id).save()
    fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN')
    line = factory_payment_line_item(
        invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id)
    line.save()
    transaction = factory_payment_transaction(payment.id)
    transaction.save()

    PaymentService.update_payment(payment.id, get_payment_request())
    input_data = {
        'corpName': 'Pennsular Coop ',
        'filingDateTime': '1999',
        'fileName': 'coopser'
    }
    response = ReceiptService.create_receipt(payment.id,
                                             '',
                                             input_data,
                                             skip_auth_check=True)
    assert response is not None
Esempio n. 22
0
def test_receipt_creation_with_invoice(session, client, jwt, app):
    """Assert that the endpoint returns 201."""
    token = jwt.create_jwt(get_claims(app_request=app), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)
    inovice_id = rv.json.get('id')
    data = {
        'clientSystemUrl':
        'http://localhost:8080/coops-web/transactions/transaction_id=abcd',
        'payReturnUrl': 'http://localhost:8080/pay-web'
    }
    receipt_number = '123451'
    rv = client.post(f'/api/v1/payment-requests/{inovice_id}/transactions',
                     data=json.dumps(data),
                     headers=headers)
    txn_id = rv.json.get('id')
    client.patch(
        f'/api/v1/payment-requests/{inovice_id}/transactions/{txn_id}',
        data=json.dumps({'receipt_number': receipt_number}),
        headers=headers)
    filing_data = {
        'corpName': 'CP0001234',
        'filingDateTime': 'June 27, 2019',
        'fileName': 'director-change'
    }
    rv = client.post(f'/api/v1/payment-requests/{inovice_id}/receipts',
                     data=json.dumps(filing_data),
                     headers=headers)
    assert rv.status_code == 201
Esempio n. 23
0
def test_transaction_put_completed_payment(session, client, jwt, app,
                                           stan_server):
    """Assert that the endpoint returns 200."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    # Create a payment first
    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)
    invoice_id = rv.json.get('id')
    data = {
        'clientSystemUrl':
        'http://localhost:8080/coops-web/transactions/transaction_id=abcd',
        'payReturnUrl': 'http://localhost:8080/pay-web'
    }
    rv = client.post(f'/api/v1/payment-requests/{invoice_id}/transactions',
                     data=json.dumps(data),
                     headers={'content-type': 'application/json'})

    txn_id = rv.json.get('id')
    rv = client.patch(
        f'/api/v1/payment-requests/{invoice_id}/transactions/{txn_id}',
        data=json.dumps({}),
        headers={'content-type': 'application/json'})

    rv = client.patch(
        f'/api/v1/payment-requests/{invoice_id}/transactions/{txn_id}',
        data=json.dumps({}),
        headers={'content-type': 'application/json'})
    assert rv.status_code == 400
    assert rv.json.get('type') == 'INVALID_TRANSACTION'
Esempio n. 24
0
def test_account_purchase_history_export_invalid_request(
        session, client, jwt, app):
    """Assert that the endpoint returns 200."""
    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()),
                     headers=headers)

    payment: Payment = Payment.find_by_id(rv.json.get('id'))
    credit_account: CreditPaymentAccount = CreditPaymentAccount.find_by_id(
        payment.invoices[0].credit_account_id)
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        credit_account.account_id)

    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json',
        'Accept': 'application/pdf'
    }

    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/payments/reports',
        data=json.dumps({'businessIdentifier': 1111}),
        headers=headers)

    assert rv.status_code == 400
Esempio n. 25
0
def test_transaction_post(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'
    }

    # Create a payment first
    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)
    invoice_id = rv.json.get('id')
    data = {
        'clientSystemUrl':
        'http://localhost:8080/coops-web/transactions/transaction_id=abcd',
        'payReturnUrl': 'http://localhost:8080/pay-web'
    }
    rv = client.post(f'/api/v1/payment-requests/{invoice_id}/transactions',
                     data=json.dumps(data),
                     headers={'content-type': 'application/json'})
    assert rv.status_code == 201
    assert rv.json.get('paymentId')

    assert schema_utils.validate(rv.json, 'transaction')[0]
Esempio n. 26
0
def test_account_purchase_history_default_list(session, client, jwt, app):
    """Assert that the endpoint returns 200."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    # Create 11 payments
    for i in range(11):
        rv = client.post('/api/v1/payment-requests',
                         data=json.dumps(get_payment_request()),
                         headers=headers)

    payment: Payment = Payment.find_by_id(rv.json.get('id'))
    credit_account: CreditPaymentAccount = CreditPaymentAccount.find_by_id(
        payment.invoices[0].credit_account_id)
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        credit_account.account_id)

    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/payments/queries',
        data=json.dumps({}),
        headers=headers)

    assert rv.status_code == 200
    # Assert the total is coming as 10 which is the value of default TRANSACTION_REPORT_DEFAULT_TOTAL
    assert rv.json.get('total') == 10
Esempio n. 27
0
def test_payment_creation_when_paybc_down(session, client, jwt, app):
    """Assert that the endpoint returns 400."""
    token = jwt.create_jwt(get_claims(role=Role.SYSTEM.value), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json',
        'Account-Id': '1234'
    }

    # Create an account first with CC as preffered payment, and it will create a DIRECT_PAY account
    client.post('/api/v1/accounts',
                data=json.dumps(
                    get_basic_account_payload(PaymentMethod.CC.value)),
                headers=headers)

    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()),
                     headers=headers)
    assert rv.status_code == 201
    assert rv.json.get('isPaymentActionRequired')
Esempio n. 28
0
def test_account_purchase_history_pagination(session, client, jwt, app):
    """Assert that the endpoint returns 200."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    for i in range(10):
        rv = client.post('/api/v1/payment-requests',
                         data=json.dumps(get_payment_request()),
                         headers=headers)

    payment: Payment = Payment.find_by_id(rv.json.get('id'))
    credit_account: CreditPaymentAccount = CreditPaymentAccount.find_by_id(
        payment.invoices[0].credit_account_id)
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        credit_account.account_id)

    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') == 10
    assert len(rv.json.get('items')) == 5
Esempio n. 29
0
def test_receipt_creation_with_invalid_request(session, client, jwt, app):
    """Assert that the endpoint returns 400."""
    token = jwt.create_jwt(get_claims(app_request=app), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)
    pay_id = rv.json.get('id')
    inovice_id = rv.json.get('invoices')[0].get('id')
    payment_id = rv.json.get('id')
    redirect_uri = 'http%3A//localhost%3A8080/coops-web/transactions%3Ftransaction_id%3Dabcd'
    receipt_number = '123451'
    rv = client.post(
        f'/api/v1/payment-requests/{payment_id}/transactions?redirect_uri={redirect_uri}',
        data=None,
        headers=headers)
    txn_id = rv.json.get('id')
    client.patch(
        f'/api/v1/payment-requests/{payment_id}/transactions/{txn_id}',
        data=json.dumps({'receipt_number': receipt_number}),
        headers=headers)
    filing_data = {'corpName': 'CP0001234'}
    rv = client.post(
        f'/api/v1/payment-requests/{pay_id}/invoices/{inovice_id}/receipts',
        data=json.dumps(filing_data),
        headers=headers)
    assert rv.status_code == 400
    assert rv.json.get('type') == 'INVALID_REQUEST'
Esempio n. 30
0
def test_account_purchase_history_invalid_request(session, client, jwt, app):
    """Assert that the endpoint returns 400."""
    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()),
                     headers=headers)

    payment: Payment = Payment.find_by_id(rv.json.get('id'))
    credit_account: CreditPaymentAccount = CreditPaymentAccount.find_by_id(
        payment.invoices[0].credit_account_id)
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        credit_account.account_id)

    search_filter = {'businessIdentifier': 1111}

    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/payments/queries?page=1&limit=5',
        data=json.dumps(search_filter),
        headers=headers)

    assert rv.status_code == 400
    assert schema_utils.validate(rv.json, 'problem')[0]