Skip to content

Simulations Synchronous Endpoints

This Simulations endpoint provides methods to interact with the simulations of the authenticated user.

Example usage of the Simulations endpoint object:

from pyrevolut.client import Client
from pyrevolut.api import EnumTransactionState

CREDS_JSON_LOC = "path/to/creds.json"

client = Client(
    creds_loc=CREDS_JSON_LOC,
    sandbox=True,
)

with client:
    response = client.Simulations.simulate_account_topup(
        account_id="SOME_ACCOUNT_ID",
        amount=100.0,
        currency="USD",
        reference="Sugar Daddy :heart:",
        state=EnumTransactionState.COMPLETED,
    )
    print(response)

EndpointSimulationsSync

Bases: BaseEndpointSync

The Simulations API

The Simulations API is only available in the Sandbox environment. It lets you simulate certain events that are otherwise only possible in the production environment, such as your account's top-up and transfer state changes.

Source code in pyrevolut/api/simulations/endpoint/synchronous.py
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
class EndpointSimulationsSync(BaseEndpointSync):
    """The Simulations API

    The Simulations API is only available in the Sandbox environment.
    It lets you simulate certain events that are otherwise only possible in the production environment,
    such as your account's top-up and transfer state changes.
    """

    def simulate_account_topup(
        self,
        account_id: UUID,
        amount: float,
        currency: str,
        reference: str | None = None,
        state: EnumTransactionState | None = None,
        **kwargs,
    ) -> dict | SimulateAccountTopup.Response:
        """
        Simulate a top-up of your account in the Sandbox environment.

        This is useful during testing, when you run out of money in your test account
        and need to add more.

        Parameters
        ----------
        account_id : UUID
            The ID of the account that you want to top up.
        amount : float
            The amount with which you want to top up the account. Must be <= 10000
        currency : str
            The currency of the top-up amount. Must be a valid ISO 4217 currency code.
        reference : str, optional
            A short description for your top up.
            Default value: 'Test Top-up' if not provided.
        state : EnumTransactionState, optional
            The state to which you want to set the top-up transaction.

            If not provided, the default value is 'completed'.

            Possible values:

                pending:
                    The transaction is pending until it's being processed.
                    If the transfer is made between Revolut accounts,
                    this state is skipped and the transaction is executed instantly.
                completed:
                    The transaction was successful.
                failed:
                    The transaction was unsuccessful. This can happen for a variety of reasons,
                    for example, invalid API calls, blocked payments, etc.
                reverted:
                    The transaction was reverted. This can happen for a variety of reasons,
                    for example, the receiver being inaccessible.

        Returns
        -------
        dict | SimulateAccountTopup.Response
            The top-up transaction information.
        """
        self.__check_sandbox()
        endpoint = SimulateAccountTopup
        path = endpoint.ROUTE
        body = endpoint.Body(
            account_id=account_id,
            amount=amount,
            currency=currency,
            reference=reference,
            state=state,
        )

        return self.client.post(
            path=path,
            response_model=endpoint.Response,
            body=body,
            **kwargs,
        )

    def simulate_transfer_state_update(
        self,
        transfer_id: UUID,
        action: Literal["complete", "revert", "decline", "fail"],
        **kwargs,
    ) -> dict | SimulateTransferStateUpdate.Response:
        """
        Simulate a transfer state change in the Sandbox environment.

        For example, after you make a transfer in Sandbox, you can change its
        state to completed.

        The resulting state is final and cannot be changed.

        Parameters
        ----------
        transfer_id : UUID
            The ID of the transfer whose state you want to update.
        action : Literal["complete", "revert", "decline", "fail"]
            The action you want to perform on the transfer. Possible values:

                complete:
                    Simulate a completed transfer.
                revert:
                    Simulate a reverted transfer.
                decline:
                    Simulate a declined transfer.
                fail:
                    Simulate a failed transfer.

        Returns
        -------
        dict | SimulateTransferStateUpdate.Response
            The updated transfer information.
        """
        self.__check_sandbox()
        assert action in ["complete", "revert", "decline", "fail"], "Invalid action"
        endpoint = SimulateTransferStateUpdate
        path = endpoint.ROUTE.format(transfer_id=transfer_id, action=action)
        body = endpoint.Body()

        return self.client.post(
            path=path,
            response_model=endpoint.Response,
            body=body,
            **kwargs,
        )

    def __check_sandbox(self):
        """
        Check if the sandbox is enabled.

        Raises
        ------
        PyRevolutInvalidEnvironment
            If the sandbox is enabled.
        """
        if not self.client.sandbox:
            raise PyRevolutInvalidEnvironment(
                "This feature is only available in the Sandbox."
            )

__check_sandbox()

Check if the sandbox is enabled.

Raises:

Type Description
PyRevolutInvalidEnvironment

If the sandbox is enabled.

Source code in pyrevolut/api/simulations/endpoint/synchronous.py
140
141
142
143
144
145
146
147
148
149
150
151
152
def __check_sandbox(self):
    """
    Check if the sandbox is enabled.

    Raises
    ------
    PyRevolutInvalidEnvironment
        If the sandbox is enabled.
    """
    if not self.client.sandbox:
        raise PyRevolutInvalidEnvironment(
            "This feature is only available in the Sandbox."
        )

simulate_account_topup(account_id, amount, currency, reference=None, state=None, **kwargs)

Simulate a top-up of your account in the Sandbox environment.

This is useful during testing, when you run out of money in your test account and need to add more.

Parameters:

Name Type Description Default
account_id UUID

The ID of the account that you want to top up.

required
amount float

The amount with which you want to top up the account. Must be <= 10000

required
currency str

The currency of the top-up amount. Must be a valid ISO 4217 currency code.

required
reference str

A short description for your top up. Default value: 'Test Top-up' if not provided.

None
state EnumTransactionState

The state to which you want to set the top-up transaction.

If not provided, the default value is 'completed'.

Possible values:

pending:
    The transaction is pending until it's being processed.
    If the transfer is made between Revolut accounts,
    this state is skipped and the transaction is executed instantly.
completed:
    The transaction was successful.
failed:
    The transaction was unsuccessful. This can happen for a variety of reasons,
    for example, invalid API calls, blocked payments, etc.
reverted:
    The transaction was reverted. This can happen for a variety of reasons,
    for example, the receiver being inaccessible.
None

Returns:

Type Description
dict | Response

The top-up transaction information.

Source code in pyrevolut/api/simulations/endpoint/synchronous.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def simulate_account_topup(
    self,
    account_id: UUID,
    amount: float,
    currency: str,
    reference: str | None = None,
    state: EnumTransactionState | None = None,
    **kwargs,
) -> dict | SimulateAccountTopup.Response:
    """
    Simulate a top-up of your account in the Sandbox environment.

    This is useful during testing, when you run out of money in your test account
    and need to add more.

    Parameters
    ----------
    account_id : UUID
        The ID of the account that you want to top up.
    amount : float
        The amount with which you want to top up the account. Must be <= 10000
    currency : str
        The currency of the top-up amount. Must be a valid ISO 4217 currency code.
    reference : str, optional
        A short description for your top up.
        Default value: 'Test Top-up' if not provided.
    state : EnumTransactionState, optional
        The state to which you want to set the top-up transaction.

        If not provided, the default value is 'completed'.

        Possible values:

            pending:
                The transaction is pending until it's being processed.
                If the transfer is made between Revolut accounts,
                this state is skipped and the transaction is executed instantly.
            completed:
                The transaction was successful.
            failed:
                The transaction was unsuccessful. This can happen for a variety of reasons,
                for example, invalid API calls, blocked payments, etc.
            reverted:
                The transaction was reverted. This can happen for a variety of reasons,
                for example, the receiver being inaccessible.

    Returns
    -------
    dict | SimulateAccountTopup.Response
        The top-up transaction information.
    """
    self.__check_sandbox()
    endpoint = SimulateAccountTopup
    path = endpoint.ROUTE
    body = endpoint.Body(
        account_id=account_id,
        amount=amount,
        currency=currency,
        reference=reference,
        state=state,
    )

    return self.client.post(
        path=path,
        response_model=endpoint.Response,
        body=body,
        **kwargs,
    )

simulate_transfer_state_update(transfer_id, action, **kwargs)

Simulate a transfer state change in the Sandbox environment.

For example, after you make a transfer in Sandbox, you can change its state to completed.

The resulting state is final and cannot be changed.

Parameters:

Name Type Description Default
transfer_id UUID

The ID of the transfer whose state you want to update.

required
action Literal['complete', 'revert', 'decline', 'fail']

The action you want to perform on the transfer. Possible values:

complete:
    Simulate a completed transfer.
revert:
    Simulate a reverted transfer.
decline:
    Simulate a declined transfer.
fail:
    Simulate a failed transfer.
required

Returns:

Type Description
dict | Response

The updated transfer information.

Source code in pyrevolut/api/simulations/endpoint/synchronous.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
def simulate_transfer_state_update(
    self,
    transfer_id: UUID,
    action: Literal["complete", "revert", "decline", "fail"],
    **kwargs,
) -> dict | SimulateTransferStateUpdate.Response:
    """
    Simulate a transfer state change in the Sandbox environment.

    For example, after you make a transfer in Sandbox, you can change its
    state to completed.

    The resulting state is final and cannot be changed.

    Parameters
    ----------
    transfer_id : UUID
        The ID of the transfer whose state you want to update.
    action : Literal["complete", "revert", "decline", "fail"]
        The action you want to perform on the transfer. Possible values:

            complete:
                Simulate a completed transfer.
            revert:
                Simulate a reverted transfer.
            decline:
                Simulate a declined transfer.
            fail:
                Simulate a failed transfer.

    Returns
    -------
    dict | SimulateTransferStateUpdate.Response
        The updated transfer information.
    """
    self.__check_sandbox()
    assert action in ["complete", "revert", "decline", "fail"], "Invalid action"
    endpoint = SimulateTransferStateUpdate
    path = endpoint.ROUTE.format(transfer_id=transfer_id, action=action)
    body = endpoint.Body()

    return self.client.post(
        path=path,
        response_model=endpoint.Response,
        body=body,
        **kwargs,
    )