Django SagePayPI

Model reference

Transaction

class sagepaypi.models.Transaction(id, created_at, updated_at, type, card_identifier, vendor_tx_code, amount, currency, description, status_code, status, status_detail, transaction_id, retrieval_reference, bank_authorisation_code, acs_url, pareq, pares, secure_status, instruction, instruction_created_at, reference_transaction)
exception DoesNotExist
exception MultipleObjectsReturned
abort()

Abort a deferred transaction.

This has to be completed within 30 days of the creation date. You can only either request a release or abort of a deferred payment once. After 30 days Sage Pay will auto abort the transaction if no instruction has been made.

Raises:InvalidTransactionStatus – if the transaction is not in a valid state to process.
clean()

Includes additional validation to ensure:

  • currency is a valid currency code
  • reference_transaction is present when the type is either a “Repeat” or “Refund”.
get_3d_secure_status(pares)

Get’s the result of the 3d secure login to Sage Pay.

User must have already been redirected to Sage Pay to login and redirected back to the site. If the cardholder was able to successfully authenticate, the status will be ‘Authenticated’.

Parameters:pares – A Base64 encoded, encrypted message sent back by the issuing bank to your TermUrl at the end of the 3-D Secure authentication process. See Sage Pay docs.
Raises:InvalidTransactionStatus – if the transaction is not in a valid state to process.
get_tokens()

Get transaction tokens.

Can be used in urls to get the transaction. It will be valid for the number of days defined in SAGEPAYPI_TOKEN_URL_DAYS_VALID and is only valid until the transaction has been updated.

Primarily used to generate a TermURL that Sage Pay will redirect to after 3d secure login.

Returns:Returns a tuple of base64 encoded string of the transaction id and a token that will be valid for limited period for this transaction, similar to django’s password reset token.
get_transaction_outcome()

Get’s the outcome of a transaction from Sage Pay.

Must have a valid transaction_id to process.

Raises:InvalidTransactionStatus – if the transaction is not in a valid state to process.
refund(**kwargs)

Refund a transaction

You can perform multiple refunds on a single transaction as long as the sum of the amounts does not exceed the original transaction.

Parameters:kwargs – Pass any defaults for the refund transaction, ie {‘amount’: 1, ‘description’: ‘Refund of payment’}
Raises:InvalidTransactionStatus – if the transaction is not in a valid state to process.
Returns:the new transaction instance.
release(amount=None)

Release a deferred transaction.

This has to be completed within 30 days of the creation date. You can only either request a release or abort of a deferred payment once. After 30 days Sage Pay will auto abort the transaction and you will be required to make another transaction with the card holder if you still require the funds.

Parameters:amount – Specify the amount if you do not want to release the full amount.
Raises:InvalidTransactionStatus – if the transaction is not in a valid state to process.
repeat(**kwargs)

Repeat a transaction

To repeat a transaction it must have been a successful Payment, Repeat or a released Deferred transaction and not void.

Parameters:kwargs – Pass any defaults for the repeat transaction, ie {‘amount’: 1, ‘description’: ‘Repeat of payment’}
Raises:InvalidTransactionStatus – if the transaction is not in a valid state to process.
Returns:the new transaction instance.
submit_transaction()

Submit’s the transaction to Sage Pay and saves the response.

void()

Void a transaction.

This has to be completed on the same calendar day as the original transaction. You can only void a “Payment” or “Refund” transaction that has an Ok status.

Raises:InvalidTransactionStatus – if the transaction is not in a valid state to process.

Card Identifier

class sagepaypi.models.CardIdentifier(id, created_at, first_name, last_name, billing_address_1, billing_address_2, billing_city, billing_country, billing_postal_code, billing_state, merchant_session_key, card_type, last_four_digits, expiry_date, card_identifier, card_identifier_expiry)
exception DoesNotExist
exception MultipleObjectsReturned
clean()

Includes additional validation to ensure:

  • billing_postal_code is present when billing_country is IE.
  • billing_state is present when billing_country is US.