private function addTransactionReference(array &$gatewayData, $isAuthorize = false)
    {
        /** @var Payment $payment */
        $payment = $this->owner->getPayment();

        // Only apply the changes if the gateway is SagePay Server
        if ($payment->Gateway == 'SagePay_Server') {
            $type = ($isAuthorize) ? Message\AuthorizeRedirectResponse::class : Message\PurchaseRedirectResponse::class;

            /** @var PurchaseRedirectResponse $message */
            $message = $payment->getLatestMessageOfType($type);
            $gatewayData['transactionReference'] = $message->Reference;
        }
    }