Comments (6)
/**
* 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.
Did you solve this problem? Is it an erroneous validation check that should perhaps be removed?
from omnipay-authorizenet.
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.
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.
@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 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)
- Add support for retail data to AIMAuthorizeRequest HOT 3
- Add support for track data to AIMAuthorizeRequest HOT 1
- Array to string conversion in CIMAbstractResponse HOT 7
- Add Line Items HOT 2
- Omnipay 3.0 support? HOT 3
- Laravel 5.6 failed HOT 5
- AIMRequest simplexml_load_string chokes HOT 6
- Error on refund
- Add customer info to transaction. HOT 6
- SIM complete purchase response HOT 2
- InvalidArgumentException: Invalid header syntax HOT 1
- Support HMAC SHA-512 hash rather than md5 (urgent) HOT 19
- Invalid paths for AIM query messages HOT 10
- Deprecated API HOT 4
- Need of Full example with all options (optional options also) HOT 1
- Unable to make few partial refunds for transaction
- Show example of passing CreditCard with auth.net HOT 2
- Sale Tax HOT 1
- Declined transactions being passed as successful
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from omnipay-authorizenet.