def test_update_pad_account_when_cfs_up(session, client, jwt, app): """Assert that the payment records are created with 202.""" token = jwt.create_jwt(get_claims(role=Role.SYSTEM.value), token_header) headers = {'Authorization': f'Bearer {token}', 'content-type': 'application/json'} rv = client.post('/api/v1/accounts', data=json.dumps(get_unlinked_pad_account_payload()), headers=headers) auth_account_id = rv.json.get('authAccountId') rv = client.put(f'/api/v1/accounts/{auth_account_id}', data=json.dumps(get_unlinked_pad_account_payload(bank_account='11111111')), headers=headers) assert rv.status_code == 200
def test_create_pad_account(session): """Assert that pad account details are created.""" pad_account = PaymentAccountService.create(get_unlinked_pad_account_payload()) assert pad_account.bank_number == get_unlinked_pad_account_payload().get('paymentInfo'). \ get('bankInstitutionNumber') assert pad_account.bank_account_number == get_unlinked_pad_account_payload(). \ get('paymentInfo').get('bankAccountNumber') assert pad_account.bank_branch_number == get_unlinked_pad_account_payload(). \ get('paymentInfo').get('bankTransitNumber') assert pad_account.payment_method == PaymentMethod.PAD.value assert pad_account.cfs_account_id assert pad_account.cfs_account is None assert pad_account.cfs_party is None assert pad_account.cfs_site is None
def test_create_pad_payment_request(session, client, jwt, app): """Assert payment request works for PAD 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_unlinked_pad_account_payload(account_id=1234)), headers=headers) auth_account_id = rv.json.get('authAccountId') # Update the payment account as ACTIVE activate_pad_account(auth_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_with_no_contact_info( corp_type='BEN', filing_type_code='BCINC', payment_method=PaymentMethod.PAD.value)), headers=headers) assert rv.json.get('paymentMethod') == PaymentMethod.PAD.value assert not rv.json.get('isOnlineBankingAllowed')
def test_create_pad_payment_request_when_account_is_pending( session, client, jwt, app): """Assert payment request works for PAD 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_unlinked_pad_account_payload(account_id=1234)), headers=headers) auth_account_id = rv.json.get('authAccountId') 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_no_contact_info( corp_type='BEN', filing_type_code='BCINC', payment_method=PaymentMethod.PAD.value)), headers=headers) assert rv.status_code == 400 assert rv.json.get('type') == 'ACCOUNT_IN_PAD_CONFIRMATION_PERIOD'
def test_payment_request_creation_for_wills(session, client, jwt, app): """Assert that the endpoint returns 201.""" 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_unlinked_pad_account_payload(account_id=1234)), headers=headers) auth_account_id = rv.json.get('authAccountId') # Update the payment account as ACTIVE activate_pad_account(auth_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_for_wills(will_alias_quantity=2)), headers=headers) assert rv.json.get('serviceFees') == 1.5 assert rv.json.get( 'total' ) == 28.5 # Wills Noticee : 17, Alias : 5 each for 2, service fee 1.5 assert rv.json.get('lineItems')[0]['serviceFees'] == 1.5 assert rv.json.get('lineItems')[1]['serviceFees'] == 0
def test_account_get_by_user(session, client, jwt, app): """Assert that the endpoint returns 200.""" token = jwt.create_jwt(get_claims(roles=[Role.SYSTEM.value]), token_header) headers = { 'Authorization': f'Bearer {token}', 'content-type': 'application/json' } account = get_unlinked_pad_account_payload() rv = client.post('/api/v1/accounts', data=json.dumps(account), headers=headers) auth_account_id = rv.json.get('accountId') token = jwt.create_jwt(get_claims(), token_header) headers = { 'Authorization': f'Bearer {token}', 'content-type': 'application/json' } rv = client.get(f'/api/v1/accounts/{auth_account_id}', headers=headers) assert rv.json.get('cfsAccount').get('bankTransitNumber') expected_bank_number = len( account.get('paymentInfo').get('bankAccountNumber')) * 'X' assert rv.json.get('cfsAccount').get( 'bankAccountNumber') == expected_bank_number assert rv.json.get('cfsAccount').get('bankInstitutionNumber')
def test_create_pad_update_when_cfs_down(session, client, jwt, app): """Assert that the payment records are created with 202.""" 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_unlinked_pad_account_payload()), headers=headers) auth_account_id = rv.json.get('authAccountId') # Mock ServiceUnavailableException with patch('pay_api.services.oauth_service.OAuthService.post', side_effect=ServiceUnavailableException(ConnectionError('mocked error'))): rv = client.put(f'/api/v1/accounts/{auth_account_id}', data=json.dumps(get_unlinked_pad_account_payload(bank_account='11111111')), headers=headers) assert rv.status_code == 503
def test_create_pad_account_to_drawdown(session): """Assert updating PAD to DRAWDOWN works.""" # Create a PAD Account first pad_account = PaymentAccountService.create(get_unlinked_pad_account_payload()) # Update this payment account with drawdown and assert payment method bcol_account = PaymentAccountService.update(pad_account.auth_account_id, get_premium_account_payload()) assert bcol_account.auth_account_id == bcol_account.auth_account_id assert bcol_account.payment_method == PaymentMethod.DRAWDOWN.value
def test_create_pad_to_bcol_to_pad(session): """Assert that update from BCOL to PAD works.""" # Create a PAD Account first pad_account_1 = PaymentAccountService.create(get_unlinked_pad_account_payload(bank_number='009')) assert pad_account_1.bank_number == '009' # Update this payment account with drawdown and assert payment method bcol_account = PaymentAccountService.update(pad_account_1.auth_account_id, get_premium_account_payload()) assert bcol_account.auth_account_id == bcol_account.auth_account_id assert bcol_account.payment_method == PaymentMethod.DRAWDOWN.value # Update to PAD again pad_account_2 = PaymentAccountService.update(pad_account_1.auth_account_id, get_unlinked_pad_account_payload(bank_number='010')) assert pad_account_2.bank_number == '010' assert pad_account_2.payment_method == PaymentMethod.PAD.value assert pad_account_2.cfs_account_id != pad_account_1.cfs_account_id
def test_create_bcol_account_to_pad(session): """Assert that update from BCOL to PAD works.""" # Create a DRAWDOWN Account first bcol_account = PaymentAccountService.create(get_premium_account_payload()) # Update to PAD pad_account = PaymentAccountService.update(bcol_account.auth_account_id, get_unlinked_pad_account_payload()) assert bcol_account.auth_account_id == bcol_account.auth_account_id assert pad_account.payment_method == PaymentMethod.PAD.value assert pad_account.cfs_account_id assert pad_account.cfs_account is None assert pad_account.cfs_party is None assert pad_account.cfs_site is None
def test_create_pad_payment_receipt(session, client, jwt, app): """Assert payment request works for PAD 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_unlinked_pad_account_payload(account_id=1234)), headers=headers) auth_account_id = rv.json.get('accountId') # Update the payment account as ACTIVE payment_account: PaymentAccountModel = PaymentAccountModel.find_by_auth_account_id( auth_account_id) payment_account.pad_activation_date = datetime.now() payment_account.save() cfs_account: CfsAccountModel = CfsAccountModel.find_effective_by_account_id( payment_account.id) cfs_account.status = 'ACTIVE' cfs_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_no_contact_info( corp_type='BEN', filing_type_code='BCINC', payment_method=PaymentMethod.PAD.value)), headers=headers) assert rv.json.get('paymentMethod') == PaymentMethod.PAD.value inv_id = rv.json.get('id') filing_data = { 'corpName': 'CP0001234', 'filingDateTime': 'June 27, 2019', 'fileName': 'director-change' } rv = client.post(f'/api/v1/payment-requests/{inv_id}/receipts', data=json.dumps(filing_data), headers=headers) assert rv.status_code == 201
def test_pad_factory_for_system_fails(session, system_user_mock): """Test payment system creation for PAD payment instances.""" from pay_api.factory.payment_system_factory import PaymentSystemFactory # noqa I001; errors out the test case from pay_api.exceptions import BusinessException pad_account = PaymentAccountService.create(get_unlinked_pad_account_payload()) # Try a DRAWDOWN for system user with pytest.raises(BusinessException) as excinfo: PaymentSystemFactory.create(payment_method='PAD', payment_account=pad_account) assert excinfo.value.code == Error.ACCOUNT_IN_PAD_CONFIRMATION_PERIOD.name time_delay = current_app.config['PAD_CONFIRMATION_PERIOD_IN_DAYS'] with freeze_time(datetime.today() + timedelta(days=time_delay + 1, minutes=1)): instance = PaymentSystemFactory.create(payment_method='PAD', payment_account=pad_account) assert isinstance(instance, PadService)
"""Assert that update from online banking to credit card works.""" online_banking_account = PaymentAccountService.create( get_basic_account_payload( payment_method=PaymentMethod.ONLINE_BANKING.value)) credit_account = PaymentAccountService.update( online_banking_account.auth_account_id, get_basic_account_payload()) assert credit_account.payment_method == PaymentMethod.DIRECT_PAY.value @pytest.mark.parametrize('payload', [ get_basic_account_payload( payment_method=PaymentMethod.ONLINE_BANKING.value), get_basic_account_payload(), get_premium_account_payload(), get_pad_account_payload(), get_unlinked_pad_account_payload() ]) def test_delete_account(session, payload): """Assert that delete payment account works.""" pay_account: PaymentAccountService = PaymentAccountService.create(payload) PaymentAccountService.delete_account(payload.get('accountId')) # Try to find the account by id. pay_account = PaymentAccountService.find_by_id(pay_account.id) for cfs_account in CfsAccountModel.find_by_account_id(pay_account.id): assert cfs_account.status == CfsAccountStatus.INACTIVE.value if cfs_account else True def test_delete_account_failures(session): """Assert that delete payment account works.""" # Create a PAD Account.
'content-type': 'application/json' } rv = client.post('/api/v1/accounts', data=json.dumps(get_premium_account_payload()), headers=headers) auth_account_id = rv.json.get('accountId') rv = client.delete(f'/api/v1/accounts/{auth_account_id}', headers=headers) assert rv.status_code == 204 @pytest.mark.parametrize( 'pay_load, is_cfs_account_expected, expected_response_status, roles', [(get_unlinked_pad_account_payload(), True, 201, [Role.SYSTEM.value, Role.CREATE_SANDBOX_ACCOUNT.value]), (get_premium_account_payload(), False, 201, [Role.SYSTEM.value, Role.CREATE_SANDBOX_ACCOUNT.value]), (get_premium_account_payload(), False, 403, [Role.SYSTEM.value])]) def test_create_sandbox_accounts(session, client, jwt, app, pay_load, is_cfs_account_expected, expected_response_status, roles): """Assert that the payment records are created with 202.""" token = jwt.create_jwt(get_claims(roles=roles), token_header) headers = { 'Authorization': f'Bearer {token}', 'content-type': 'application/json' } rv = client.post('/api/v1/accounts?sandbox=true', data=json.dumps(pay_load),
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