Giter Club home page Giter Club logo

Comments (6)

Nks avatar Nks commented on June 26, 2024 1
/**
     * Get details by transaction id.
     *
     * @param $transactionId
     * @return \Omnipay\Common\Message\ResponseInterface
     */
    public function getTransactionDetails($transactionId)
    {
        $refId = 'ref' . time();

        $params = [
            'refId' => $refId,
            'transactionReference' => $transactionId,
        ];

        $request = $this->gateway_auth->queryDetail($params);


        return $request->send();
    }

getTransactionDetails works for AIM

from omnipay-authorizenet.

judgej avatar judgej commented on June 26, 2024

Did you solve this problem? Is it an erroneous validation check that should perhaps be removed?

from omnipay-authorizenet.

ammonkc avatar ammonkc commented on June 26, 2024

The Authorize.net api has a GetTransactionDetails method that takes a transId and returns all the details about the transaction including the last four digits of the cards. The transId and the last 4 of the card should be all you need. But I don't think this package supports GetTransactionDetails api call (unless i'm mistaken).

from omnipay-authorizenet.

judgej avatar judgej commented on June 26, 2024

From what I remember, the GetTransactionDetails API was a completely different API system that would need some major writing, additional credentials etc. Since then, the Authorize.Net REST API has changed substantially, so it may be something that can be revisited if it is now more closely integrated.

from omnipay-authorizenet.

judgej avatar judgej commented on June 26, 2024

@Nks Two quick questions:

  • What is $this->gateway_auth?
  • Is it always necessary to provide a unique refId even for transaction queries?

from omnipay-authorizenet.

Nks avatar Nks commented on June 26, 2024

@Nks Two quick questions:

  • What is $this->gateway_auth?
  • Is it always necessary to provide a unique refId even for transaction queries?

1 - This is just the instance to omnipay.

        $this->gateway_auth = Omnipay::create('AuthorizeNet_AIM');
        $this->gateway_auth->setDeveloperMode(config('app.env') !== 'production');
        $this->gateway_auth->setTestMode(config('services.authorize_net.test_mode', false));
        $this->gateway_auth->setApiLoginId(config('services.authorize_net.login_id'));
        $this->gateway_auth->setTransactionKey(config('services.authorize_net.transaction_key'));

2 - Feel free to check. I don't think so. https://developer.authorize.net/api/reference/#transaction-reporting-get-transaction-details

After this you can make partial refunds. Make sure that you are storing the refund transaction which can be voided in this case.
If you are going refund full amount just send the same amount on refund operation.

Here how I making the refund:

 /**
     * Making the refund for the payment.
     *
     * @param array $transactionReference
     * @param float $amount
     * @return \Omnipay\AuthorizeNet\Message\AIMResponse|\Omnipay\Common\Message\ResponseInterface
     */
    public function makeRefund(array $transactionReference, float $amount)
    {
        $amount = (floor($amount * 100) / 100);

        $params = [
            'amount' => $amount,
            'transactionReference' => json_encode($transactionReference),
        ];

        $request = $this->gateway_auth->refund($params);

        return $request->send();
    }

And here the full example of calling the refund method:

/**
     * @param int $paymentId
     * @param array $refundData
     * @return string
     * @throws \Exception
     */
    public function makeRefund(int $paymentId, array $refundData): string
    {
        /** @var Payment $payment */
        $payment = $this->repository->findEntity($paymentId);

        $amount = 0;

        switch ($refundData['refund_type']) {
            case Payment::REFUND_TYPE_FULL:
                $amount = $payment->total_amount;
                break;
            case Payment::REFUND_OTHER_AMOUNT:
                $amount = $refundData['refund_amount'];
                break;
        }

        if ($amount > $payment->total_amount || $amount <= 0) {
            throw new \Exception('Wrong refund amount');
        }

        //Resolving the transaction detail which requested by refund.
        $transactionResponse = $this->client->getTransactionDetails($payment->transaction_id);

        $transactionReference = [
            'transId' => $payment->transaction_id,
            'card' => [
                'number' => null,
                'expiry' => null,
            ]
        ];

        if ($transactionResponse->isSuccessful()) {
            $transaction = optional($transactionResponse->getData())->transaction;

            $cardNumber = (string)$transaction->payment->creditCard->cardNumber;

            $transactionReference['card'] = [
                'number' => substr($cardNumber, -4, 4) ?: null,
                'expiry' => 'XXXX',
            ];
        } else {
            Log::critical('Unable get transaction details', [
                'payment' => $payment,
                'error' => $transactionResponse->getMessage(),
            ]);

            throw new \Exception(__('Unable get transaction details from Authorize.net: :error', [
                'error' => $transactionResponse->getMessage(),
            ]));
        }

        $response = $this->client
            ->setGateway('AuthorizeNet_AIM')
            ->makeRefund($transactionReference, $amount);

        if ($response->isSuccessful()) {
            $transaction = json_decode($response->getTransactionReference(), true);
            $transId = Arr::get($transaction, 'transId');

            $paymentAttributes = [
                'order_id' => $payment->order_id,
                'customer_id' => $payment->customer_id,
                'total_amount' => $amount,
                'transaction_id' => $transId,
                'payment_method_preview' => __('Refund (:type) for transaction #:trans_id', [
                    'trans_id' => $payment->transaction_id,
                    'type' => Str::title(str_replace('_', ' ', $refundData['refund_type'])),
                ]),
                'payment_status' => $response->getResultCode() ?? Payment::STATUS_REFUNDED,
                'gateway_response' => $response->getMessage(),
            ];

            $this->repository->create($paymentAttributes);

            return $response->getMessage();
        } else {
            Log::critical(__('The payment was not refunded! Payment Gateway response: :error', [
                'error' => $response->getMessage(),
            ]), [
                'response' => $response
            ]);
        }

        throw new \Exception(__('Unable make refund with error: :error', [
            'error' => $response->getMessage()
        ]));
    }

from omnipay-authorizenet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.