agora.webhook package

Submodules

agora.webhook.create_account module

class agora.webhook.create_account.CreateAccountRequest(creation, transaction)[source]

Bases: object

A create account request received from Agora.

Parameters:
classmethod from_json(data)[source]
class agora.webhook.create_account.CreateAccountResponse(transaction)[source]

Bases: object

reject()[source]
sign(private_key)[source]

agora.webhook.events module

class agora.webhook.events.Event(transaction_event=None)[source]

Bases: object

An event container for a specific type of event triggered by a blockchain operation.

Parameters:

transaction_event (Optional[TransactionEvent]) – (optional) A TransactionEvent.

classmethod from_json(data)[source]
Return type:

Event

class agora.webhook.events.SolanaEvent(transaction, tx_error=None, tx_error_raw=None)[source]

Bases: object

Solana event data related to a transaction.

Parameters:
  • transaction (Transaction) – The Transaction object.

  • tx_error (Optional[Error]) – (optional) The Error <agora.error.Error indicating why the transaction failed.

  • tx_error_raw (Optional[str]) – (optional) The raw transaction error.

classmethod from_json(data)[source]
Return type:

SolanaEvent

class agora.webhook.events.TransactionEvent(tx_id, solana_event, invoice_list=None)[source]

Bases: object

An 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.

classmethod from_json(data)[source]
Return type:

TransactionEvent

agora.webhook.handler module

class agora.webhook.handler.WebhookHandler(environment, secret=None)[source]

Bases: object

The WebhookHelper contains 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 raise WebhookRequestError to 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

WebhookRequestError to 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 raise WebhookRequestError to 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: object

A sign transaction request received from Agora.

Parameters:
classmethod from_json(data)[source]
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: object

A 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:
Returns:

reject()[source]

Marks that the sign transaction request is rejected.

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 account PrivateKey

Module contents

class agora.webhook.WebhookHandler(environment, secret=None)[source]

Bases: object

The WebhookHelper contains 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 raise WebhookRequestError to 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

WebhookRequestError to 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 raise WebhookRequestError to 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.