예제 #1
0
def test_internal_rs_back_active(session, public_user_mock):
    """12033 - Scenario 2.

    Routing slip is complete and a transaction is cancelled
    the balance is restored - Should move back to Active
    """
    payment_response = PaymentService.create_invoice(
        get_routing_slip_payment_request(), get_auth_staff())
    account_model = PaymentAccount.find_by_auth_account_id(get_auth_staff().get('account').get('id'))
    account_id = account_model.id
    assert account_id is not None
    assert payment_response.get('id') is not None

    rs_number = '123456789'
    rs = factory_routing_slip(number=rs_number, payment_account_id=account_id, remaining_amount=50.00)
    rs.save()

    # Create another invoice with a routing slip.
    invoice = PaymentService.create_invoice(get_routing_slip_payment_request(), get_auth_staff())
    account_model = PaymentAccount.find_by_auth_account_id(get_auth_staff().get('account').get('id'))

    assert account_id == account_model.id

    rs = RoutingSlipModel.find_by_number(rs_number)
    assert rs.remaining_amount == 0.0
    assert rs.status == RoutingSlipStatus.COMPLETE.name

    invoice = Invoice.find_by_id(invoice['id'])
    InternalPayService().process_cfs_refund(invoice)

    assert rs.status == RoutingSlipStatus.ACTIVE.name
예제 #2
0
def test_create_payment_record_with_internal_pay(session, public_user_mock):
    """Assert that the payment records are created."""
    # Create invoice without routing slip.
    payment_response = PaymentService.create_invoice(
        get_routing_slip_payment_request(), get_auth_staff())
    account_model = PaymentAccount.find_by_auth_account_id(get_auth_staff().get('account').get('id'))
    account_id = account_model.id
    assert account_id is not None
    assert payment_response.get('id') is not None

    rs_number = '123456789'
    rs = factory_routing_slip(number=rs_number, payment_account_id=account_id, remaining_amount=50.00)
    rs.save()

    # Create another invoice with a routing slip.
    PaymentService.create_invoice(get_routing_slip_payment_request(), get_auth_staff())
    account_model = PaymentAccount.find_by_auth_account_id(get_auth_staff().get('account').get('id'))

    assert account_id == account_model.id

    rs = RoutingSlipModel.find_by_number(rs_number)
    assert rs.remaining_amount == 0.0
    """12033 - Scenario 1.

    Manual transaction reduces RS to 0.00
    Routing slip status becomes Completed
    """
    assert rs.status == RoutingSlipStatus.COMPLETE.name
예제 #3
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
예제 #4
0
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
예제 #5
0
def test_create_bcol_payment(session, public_user_mock):
    """Assert that the payment records are created."""
    payment_response = PaymentService.create_invoice(
        get_payment_request_with_payment_method(payment_method='DRAWDOWN', business_identifier='CP0002000'),
        get_auth_premium_user())
    assert payment_response is not None
    assert payment_response.get('payment_method') == 'DRAWDOWN'
    assert payment_response.get('status_code') == 'COMPLETED'
예제 #6
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'
예제 #7
0
def test_create_payment_record_rollback(session, public_user_mock):
    """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.flush', side_effect=Exception('mocked error')):
        with pytest.raises(Exception) as excinfo:
            PaymentService.create_invoice(get_payment_request(), get_auth_basic_user())
        assert excinfo.type == Exception

    # with patch('pay_api.services.invoice.InvoiceReference.create', side_effect=Exception('mocked error')):
    #     with pytest.raises(Exception) as excinfo:
    #         PaymentService.create_invoice(get_payment_request(), get_auth_basic_user())
    #     assert excinfo.type == Exception
    with patch('pay_api.services.direct_pay_service.DirectPayService.create_invoice',
               side_effect=Exception('mocked error')):
        with pytest.raises(Exception) as excinfo:
            PaymentService.create_invoice(
                get_payment_request_with_payment_method(payment_method=PaymentMethod.DIRECT_PAY.value),
                get_auth_basic_user())
        assert excinfo.type == Exception
예제 #8
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
예제 #9
0
def test_create_payment_record_with_rs(session, public_user_mock):
    """Assert that the payment records are created and completed."""
    payment_account = factory_payment_account()
    payment_account.save()
    rs = factory_routing_slip(payment_account_id=payment_account.id, total=1000, remaining_amount=1000)
    rs.save()
    cfs_response = Mock(spec=Response)
    cfs_response.json.return_value = {'invoice_number': 'abcde', }
    cfs_response.status_code = 200

    request = get_payment_request()
    request['accountInfo'] = {'routingSlip': rs.number}
    with patch.object(CFSService, 'create_account_invoice', return_value=cfs_response) as mock_post:
        PaymentService.create_invoice(request, get_auth_basic_user())
        mock_post.assert_called()

    request = get_zero_dollar_payment_request()
    request['accountInfo'] = {'routingSlip': rs.number}
    with patch.object(CFSService, 'create_account_invoice', return_value=cfs_response) as mock_post:
        PaymentService.create_invoice(request, get_auth_basic_user())
        mock_post.assert_not_called()
예제 #10
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
예제 #11
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
예제 #12
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