-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error on refund #114
Comments
Did you solve this problem? Is it an erroneous validation check that should perhaps be removed? |
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 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. |
getTransactionDetails works for AIM |
@Nks Two quick questions:
|
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. 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()
]));
} |
Using:
omnipay/authorizenet:2.6.0
omnipay/common:2.5.2
laravel/framework:5.4.36
I am attempting to issue a refund and I am getting error
The card parameter is required
I understand I need the card details when issuing refunds.
How can I get the card details?
I do not store credit card information to DB.
The text was updated successfully, but these errors were encountered: