Skip to content

# Utilities

terminusgps.authorizenet.utils.calculate_amount_plus_tax(amount: Decimal, tax_rate: Decimal | None = None) → Decimal

  Returns the amount + tax. Uses `DEFAULT_TAX_RATE` if `tax_rate` wasn’t provided.

  Parameters:

    - amount (`Decimal`) – Amount to add tax to.

    - tax_rate (`Decimal` | `None`) – A tax rate to use in the calculation.

  Returns:

    The amount + tax.

  Return type:

    `Decimal`

terminusgps.authorizenet.utils.generate_customer_address(form: Form) → customerAddressType

  Takes a form and returns a `customerAddressType`.

  Required form fields:

  name | type
  --- | ---
  `address` | `customerAddressType`
  `first_name` | `str`
  `last_name` | `str`

  Parameters:

    form (`Form`) – A Django form.

  Raises:

    - ValueError – If `address` wasn’t in the form.

    - ValueError – If `first_name` wasn’t in the form.

    - ValueError – If `last_name` wasn’t in the form.

  Returns:

    A customer address object.

  Return type:

    `customerAddressType`

terminusgps.authorizenet.utils.generate_customer_payment(form: Form) → paymentType

  Takes a form and returns a `paymentType`.

  Required form fields:

  name | type
  --- | ---
  `credit_card` | `creditCardType`

  Parameters:

    form (`Form`) – A Django form.

  Raises:

    ValueError – If `credit_card` wasn’t in the form.

  Returns:

    A payment object.

  Return type:

    `paymentType`

terminusgps.authorizenet.utils.get_customer_profile_ids() → list[int]

  Returns a list of all customer profile ids in Authorizenet.

  Raises:

    AuthorizenetControllerExecutionError – If the API call fails.

  Returns:

    A list of all customer profile ids in Authorizenet.

  Return type:

    `list`

terminusgps.authorizenet.utils.get_merchant_details() → dict | None

  Returns Authorizenet merchant details.

  getMerchantDetailsRequest

  Raises:

    AuthorizenetControllerExecutionError – If the API call fails.

  Returns:

    A merchant details object, if found.

  Return type:

    `dict` | `None`

terminusgps.authorizenet.utils.get_transaction(id: int | str) → dict | None

  Returns Authorizenet transaction details by id.

  getTransactionDetailsRequest

  Parameters:

    id (`int` | `str`) – An Authorizenet transaction id.

  Raises:

    - ValueError – If `id` was provided as a string containing non-digits.

    - AuthorizenetControllerExecutionError – If the API call fails.

  Returns:

    A transaction object, if found.

  Return type:

    `dict` | `None`