agora.webhook package¶
Submodules¶
agora.webhook.create_account module¶
-
class
agora.webhook.create_account.CreateAccountRequest(creation, transaction)[source]¶ Bases:
objectA create account request received from Agora.
- Parameters:
creation (
Creation) – TheCreationan app client is requesting the server to verify.transaction (
Transaction) – TheTransactionobject.
agora.webhook.events module¶
-
class
agora.webhook.events.Event(transaction_event=None)[source]¶ Bases:
objectAn event container for a specific type of event triggered by a blockchain operation.
- Parameters:
transaction_event (
Optional[TransactionEvent]) – (optional) ATransactionEvent.
-
class
agora.webhook.events.SolanaEvent(transaction, tx_error=None, tx_error_raw=None)[source]¶ Bases:
objectSolana event data related to a transaction.
- Parameters:
transaction (
Transaction) – TheTransactionobject.tx_error (
Optional[Error]) – (optional) TheError <agora.error.Errorindicating why the transaction failed.tx_error_raw (
Optional[str]) – (optional) The raw transaction error.
-
class
agora.webhook.events.TransactionEvent(tx_id, solana_event, invoice_list=None)[source]¶ Bases:
objectAn event indicating a transaction has completed (either successfully or unsuccessfully).
- Parameters:
tx_id (
bytes) – the id of the transaction. Either a 32-byte Stellar transaction hash or a 64-byte Solana transaction signature.solana_event (
SolanaEvent) – any Solana data related to the transaction.invoice_list (
Optional[InvoiceList]) – (optional) the InvoiceList related to the transaction.
agora.webhook.handler module¶
-
class
agora.webhook.handler.WebhookHandler(environment, secret=None)[source]¶ Bases:
objectThe
WebhookHelpercontains hooks and methods that can be used to add support for Agora webhooks.- Parameters:
secret (
Optional[str]) – The secret used to verify request signatures.
-
handle_create_account(f, signature, req_body)[source]¶ A hook for handling a create account request from Agora.
- Parameters:
f (
Callable[[CreateAccountRequest,CreateAccountResponse],None]) – A function to call with the recieved request. Implementations can raiseWebhookRequestErrorto return a specific HTTP status code and body.signature (
str) – The Agora HMAC signature included in the request headers.req_body (
str) – The request body.
- Return type:
Tuple[int,str]- Returns:
A Tuple of the status code (int) and the request body (str)
-
handle_events(f, signature, req_body)[source]¶ A hook for handling an event request from Agora.
- Parameters:
f (
Callable[[List[Event]],None]) – A function to call with the received event. Implementations can raise
WebhookRequestErrorto return a specific HTTP status code and body. :type signature:str:param signature: The Agora HMAC signature included in the request headers. :type req_body:str:param req_body: The request body. :rtype:Tuple[int,str] :return: A Tuple of the status code (int) and the request body (str)
-
handle_sign_transaction(f, signature, req_body)[source]¶ A hook for handling a sign transaction request from Agora.
- Parameters:
f (
Callable[[SignTransactionRequest,SignTransactionResponse],None]) – A function to call with the received request. Implementations can raiseWebhookRequestErrorto return a specific HTTP status code and body.signature (
str) – The Agora HMAC signature included in the request headers.req_body (
str) – The request body.
- Return type:
Tuple[int,str]- Returns:
A Tuple of the status code (int) and the request body (str).
-
is_valid_signature(req_body, signature)[source]¶ Verifies that the provided signature is valid for the provided data.
- Parameters:
req_body (
str) – The request body that the provided signature is supposedly for.signature (
str) – The base64-encoded signature to verify for the corresponding req_body.
- Return type:
bool- Returns:
A bool indicating whether or not the signature is valid.
agora.webhook.sign_transaction module¶
-
class
agora.webhook.sign_transaction.SignTransactionRequest(creations, payments, transaction)[source]¶ Bases:
objectA sign transaction request received from Agora.
- Parameters:
payments (
List[ReadOnlyPayment]) – A list ofReadOnlyPaymentthat an app client is requesting the server to sign.transaction (
Transaction) – TheTransactionobject.
-
get_tx_id()[source]¶ Returns the transaction id of the transaction in the sign transaction request, if available. The id is a 32-byte hash for Stellar transactions and a 64-byte hash for Solana transactions.
- Return type:
Optional[bytes]- Returns:
The transaction id, in bytes, or None if the transaction id is not available.
-
class
agora.webhook.sign_transaction.SignTransactionResponse(transaction)[source]¶ Bases:
objectA response to a sign transaction request received from Agora.
-
mark_invoice_error(idx, reason)[source]¶ Marks that the payment at the provided index was rejected for the provided reason.
- Parameters:
idx (
int) – The index of the payment.reason (
InvoiceErrorReason) – TheInvoiceErrorReasonthe payment was rejected.
- Returns:
-
sign(private_key)[source]¶ Signs the transaction envelope with the provided account private key. No-op on Kin 4 transactions.
- Parameters:
private_key (
PrivateKey) – The accountPrivateKey
-
Module contents¶
-
class
agora.webhook.WebhookHandler(environment, secret=None)[source]¶ Bases:
objectThe
WebhookHelpercontains hooks and methods that can be used to add support for Agora webhooks.- Parameters:
secret (
Optional[str]) – The secret used to verify request signatures.
-
handle_create_account(f, signature, req_body)[source]¶ A hook for handling a create account request from Agora.
- Parameters:
f (
Callable[[CreateAccountRequest,CreateAccountResponse],None]) – A function to call with the recieved request. Implementations can raiseWebhookRequestErrorto return a specific HTTP status code and body.signature (
str) – The Agora HMAC signature included in the request headers.req_body (
str) – The request body.
- Return type:
Tuple[int,str]- Returns:
A Tuple of the status code (int) and the request body (str)
-
handle_events(f, signature, req_body)[source]¶ A hook for handling an event request from Agora.
- Parameters:
f (
Callable[[List[Event]],None]) – A function to call with the received event. Implementations can raise
WebhookRequestErrorto return a specific HTTP status code and body. :type signature:str:param signature: The Agora HMAC signature included in the request headers. :type req_body:str:param req_body: The request body. :rtype:Tuple[int,str] :return: A Tuple of the status code (int) and the request body (str)
-
handle_sign_transaction(f, signature, req_body)[source]¶ A hook for handling a sign transaction request from Agora.
- Parameters:
f (
Callable[[SignTransactionRequest,SignTransactionResponse],None]) – A function to call with the received request. Implementations can raiseWebhookRequestErrorto return a specific HTTP status code and body.signature (
str) – The Agora HMAC signature included in the request headers.req_body (
str) – The request body.
- Return type:
Tuple[int,str]- Returns:
A Tuple of the status code (int) and the request body (str).
-
is_valid_signature(req_body, signature)[source]¶ Verifies that the provided signature is valid for the provided data.
- Parameters:
req_body (
str) – The request body that the provided signature is supposedly for.signature (
str) – The base64-encoded signature to verify for the corresponding req_body.
- Return type:
bool- Returns:
A bool indicating whether or not the signature is valid.