Skip to content

Schemas

Application

Bases: BaseModel

Application info.

Attributes:

Name Type Description
app_id int

Application unique ID.

name str

Application name.

payment_processing_bot_username str

Username of Crypto bot.

Source code in src/CryptoPayAPI/schemas.py
153
154
155
156
157
158
159
160
161
162
163
class Application(BaseModel):
    '''Application info.

    Attributes:
        app_id (int): Application unique ID.
        name (str): Application name.
        payment_processing_bot_username (str): Username of Crypto bot.
    '''
    app_id: int
    name: str
    payment_processing_bot_username: str

Assets

Bases: Enum

Currency code.

Attributes:

Name Type Description
BTC str

Bitcoin

TON str

Toncoin

ETH str

Ethereum

USDT str

Tether

USDC str

USD Coin

BUSD str

Binance USD

Source code in src/CryptoPayAPI/schemas.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Assets(Enum):
    '''Currency code.

    Attributes:
        BTC (str): Bitcoin
        TON (str): Toncoin
        ETH (str): Ethereum
        USDT (str): Tether
        USDC (str): USD Coin
        BUSD (str): Binance USD
    '''
    BTC = 'BTC'
    TON = 'TON'
    ETH = 'ETH'
    USDT = 'USDT'
    USDC = 'USDC'
    BUSD = 'BUSD'

    def __str__(self) -> str:
        return self.value

Balance

Bases: BaseModel

Balance info.

Attributes:

Name Type Description
currency_code str

Currency code.

available Decimal

Available for using.

Source code in src/CryptoPayAPI/schemas.py
166
167
168
169
170
171
172
173
174
class Balance(BaseModel):
    '''Balance info.

    Attributes:
        currency_code (str): Currency code.
        available (Decimal): Available for using.
    '''
    currency_code: str
    available: Decimal

Currency

Bases: BaseModel

Currency info.

Attributes:

Name Type Description
is_blockchain bool

Is blockchain asset?

is_stablecoin bool

Is stable coin?

is_fiat bool

Is fiat asset?

name str

Name of currency.

code str

Code of currency.

url Optional[str]

Optional. URL of currency site.

decimals int

?

Source code in src/CryptoPayAPI/schemas.py
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
class Currency(BaseModel):
    '''Currency info.

    Attributes:
        is_blockchain (bool): Is blockchain asset?
        is_stablecoin (bool): Is stable coin?
        is_fiat (bool): Is fiat asset?
        name (str): Name of currency.
        code (str): Code of currency.
        url (Optional[str]): *Optional*. URL of currency site.
        decimals (int): ?
    '''
    is_blockchain: bool
    is_stablecoin: bool
    is_fiat: bool
    name: str
    code: str
    url: Optional[str]
    decimals: int

ExchangeRate

Bases: BaseModel

Exchange rate info.

Attributes:

Name Type Description
is_valid bool

Is valid?

source str

Source asset.

target str

Target asset.

rate Decimal

Exchange rate.

Source code in src/CryptoPayAPI/schemas.py
177
178
179
180
181
182
183
184
185
186
187
188
189
class ExchangeRate(BaseModel):
    '''Exchange rate info.

    Attributes:
        is_valid (bool): Is valid?
        source (str): Source asset.
        target (str): Target asset.
        rate (Decimal): Exchange rate.
    '''
    is_valid: bool
    source: str
    target: str
    rate: Decimal

Invoice

Bases: BaseModel

Invoice info.

Attributes:

Name Type Description
invoice_id int

Unique ID for this invoice.

status InvoiceStatus

Status of the invoice.

hash str

Hash of the invoice.

asset Assets

Currency code.

amount Decimal

Amount of the invoice.

pay_url str

URL should be presented to the user to pay the invoice.

description Optional[str]

Optional. Description for this invoice.

created_at datetime

Date the invoice was created in ISO 8601 format.

allow_comments bool

True, if the user can add comment to the payment.

allow_anonymous bool

True, if the user can pay the invoice anonymously.

expiration_date Optional[datetime]

Optional. Date the invoice expires in Unix time.

paid_at Optional[datetime]

Optional. Date the invoice was paid in Unix time.

paid_anonymously Optional[bool]

True, if the invoice was paid anonymously.

comment Optional[str]

Optional. Comment to the payment from the user.

hidden_message Optional[str]

Optional. Text of the hidden message for this invoice.

payload Optional[str]

Optional. Previously provided data for this invoice.

paid_btn_name Optional[PaidButtonNames]

Optional. Name of the button.

paid_btn_url Optional[str]

Optional. URL of the button.

fee Optional[Decimal]

Optional. Amount of charged service fees. Returned only if the invoice has paid status.

usd_rate Optional[Decimal]

Optional. Price of the asset in USD. Returned only if the invoice has paid status.

Source code in src/CryptoPayAPI/schemas.py
 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
class Invoice(BaseModel):
    '''Invoice info.

    Attributes:
        invoice_id (int): Unique ID for this invoice.
        status (InvoiceStatus): Status of the invoice.
        hash (str): Hash of the invoice.
        asset (Assets): Currency code.
        amount (Decimal): Amount of the invoice.
        pay_url (str): URL should be presented to the user to pay the invoice.
        description (Optional[str]): *Optional*. Description for this invoice.
        created_at (datetime): Date the invoice was created in ISO 8601 format.
        allow_comments (bool): `True`, if the user can add comment to the payment.
        allow_anonymous (bool): `True`, if the user can pay the invoice anonymously.
        expiration_date (Optional[datetime]): *Optional*. Date the invoice expires in Unix time.
        paid_at (Optional[datetime]): *Optional*. Date the invoice was paid in Unix time.
        paid_anonymously (Optional[bool]): `True`, if the invoice was paid anonymously.
        comment (Optional[str]): *Optional*. Comment to the payment from the user.
        hidden_message (Optional[str]): *Optional*. Text of the hidden message for this invoice.
        payload (Optional[str]): *Optional*. Previously provided data for this invoice.
        paid_btn_name (Optional[PaidButtonNames]): *Optional*. Name of the button.
        paid_btn_url (Optional[str]): *Optional*. URL of the button.
        fee (Optional[Decimal]): *Optional*. Amount of charged service fees. Returned only if the invoice has paid status.
        usd_rate (Optional[Decimal]): *Optional*. Price of the asset in USD. Returned only if the invoice has paid status.
    '''
    invoice_id: int
    status: InvoiceStatus
    hash: str
    asset: Assets
    amount: Decimal
    pay_url: str
    description: Optional[str]
    created_at: datetime
    allow_comments: bool
    allow_anonymous: bool
    expiration_date: Optional[datetime]
    paid_at: Optional[datetime]
    paid_anonymously: Optional[bool]
    comment: Optional[str]
    hidden_message: Optional[str]
    payload: Optional[str]
    paid_btn_name: Optional[PaidButtonNames]
    paid_btn_url: Optional[str]
    fee: Optional[Decimal]
    usd_rate: Optional[Decimal]

InvoiceStatus

Bases: Enum

Status of invoice.

Attributes:

Name Type Description
ACTIVE str

'active'

PAID str

'paid'

EXPIRED str

'expired'

Source code in src/CryptoPayAPI/schemas.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class InvoiceStatus(Enum):
    '''Status of invoice.

    Attributes:
        ACTIVE (str): 'active'
        PAID (str): 'paid'
        EXPIRED (str): 'expired'
    '''
    ACTIVE = 'active'
    PAID = 'paid'
    EXPIRED = 'expired'

    def __str__(self) -> str:
        return self.value

PaidButtonNames

Bases: Enum

Name of the button.

Attributes:

Name Type Description
VIEW_ITEM str

'viewItem'

OPEN_CHANNEL str

'openChannel'

OPEN_BOT str

'openBot'

CALLBACK str

'callback'

Source code in src/CryptoPayAPI/schemas.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class PaidButtonNames(Enum):
    '''Name of the button.

    Attributes:
        VIEW_ITEM (str): 'viewItem'
        OPEN_CHANNEL (str): 'openChannel'
        OPEN_BOT (str): 'openBot'
        CALLBACK (str): 'callback'
    '''
    VIEW_ITEM = 'viewItem'
    OPEN_CHANNEL = 'openChannel'
    OPEN_BOT = 'openBot'
    CALLBACK = 'callback'

    def __str__(self) -> str:
        return self.value

Transfer

Bases: BaseModel

Transfer info.

Attributes:

Name Type Description
transfer_id int

Unique ID for this transfer.

user_id int

Telegram user ID the transfer was sent to.

asset Assets

Currency code.

amount Decimal

Amount of the transfer.

status Literal['completed']

Status of the transfer, can be “completed”.

completed_at datetime

Date the transfer was completed in ISO 8601 format.

comment Optional[str]

Optional. Comment for this transfer.

Source code in src/CryptoPayAPI/schemas.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
class Transfer(BaseModel):
    '''Transfer info.

    Attributes:
        transfer_id (int): Unique ID for this transfer.
        user_id (int): Telegram user ID the transfer was sent to.
        asset (Assets): Currency code.
        amount (Decimal): Amount of the transfer.
        status (Literal['completed']): Status of the transfer, can be “completed”.
        completed_at (datetime): Date the transfer was completed in ISO 8601 format.
        comment (Optional[str]): *Optional*. Comment for this transfer.
    '''
    transfer_id: int
    user_id: int
    asset: Assets
    amount: Decimal
    status: Literal['completed']
    completed_at: datetime
    comment: Optional[str]

Update

Bases: BaseModel

Webhook update object.

Attributes:

Name Type Description
update_id int

Non-unique update ID.

update_type UpdateType

Webhook update type.

request_date datetime

Date the request was sent in ISO 8601 format.

payload Invoice

Payload contains Invoice object.

raw_body Optional[bytes]

Optional. Raw body of update, for check sign purpose.

Source code in src/CryptoPayAPI/schemas.py
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
class Update(BaseModel):
    '''Webhook update object.

    Attributes:
        update_id (int): Non-unique update ID.
        update_type (UpdateType): Webhook update type.
        request_date (datetime): Date the request was sent in ISO 8601 format.
        payload (Invoice): Payload contains `Invoice` object.
        raw_body (Optional[bytes]): *Optional*. Raw body of update, for check sign purpose.
    '''
    update_id: int
    update_type: UpdateType
    request_date: datetime
    payload: Invoice
    raw_body: Optional[bytes] = None

    def check_signature(self, api_key: str, sign: str) -> bool:
        '''Check update signature.

        Args:
            api_key (str): CryptoPay app API key.
            sign (str): Update signature. In request headers `crypto-pay-api-signature`.

        Returns:
            bool: Is signature verified?
        '''
        log.debug(f'Called with args: ({api_key}, {sign})')
        secret = sha256(api_key.encode()).digest()
        hmac = HMAC(secret, self.raw_body, digestmod=sha256)
        body_sign = hmac.hexdigest()
        log.debug(f'Calculated hash: {body_sign}')
        return body_sign == sign

check_signature(api_key, sign)

Check update signature.

Parameters:

Name Type Description Default
api_key str

CryptoPay app API key.

required
sign str

Update signature. In request headers crypto-pay-api-signature.

required

Returns:

Name Type Description
bool bool

Is signature verified?

Source code in src/CryptoPayAPI/schemas.py
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
def check_signature(self, api_key: str, sign: str) -> bool:
    '''Check update signature.

    Args:
        api_key (str): CryptoPay app API key.
        sign (str): Update signature. In request headers `crypto-pay-api-signature`.

    Returns:
        bool: Is signature verified?
    '''
    log.debug(f'Called with args: ({api_key}, {sign})')
    secret = sha256(api_key.encode()).digest()
    hmac = HMAC(secret, self.raw_body, digestmod=sha256)
    body_sign = hmac.hexdigest()
    log.debug(f'Calculated hash: {body_sign}')
    return body_sign == sign

UpdateType

Bases: Enum

Webhook update type.

Attributes:

Name Type Description
INVOICE_PAID str

'invoice_paid

Source code in src/CryptoPayAPI/schemas.py
76
77
78
79
80
81
82
class UpdateType(Enum):
    '''Webhook update type.

    Attributes:
        INVOICE_PAID (str): 'invoice_paid
    '''
    INVOICE_PAID = 'invoice_paid'

Last update: January 11, 2023
Created: January 11, 2023