Skip to content

Commit

Permalink
Added Refund through credit memo (#272)
Browse files Browse the repository at this point in the history
* added Refund through credit memo
  • Loading branch information
ramth05 authored Sep 17, 2021
1 parent 0e5d079 commit 0bd8db1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Model/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,50 @@ protected function getPostData()
*/
public function refund(InfoInterface $payment, $amount)
{
$order = $payment->getOrder();

$creditmemo = $this->request->getPost('creditmemo');

$reason = (!empty($creditmemo['comment_text'])) ? $creditmemo['comment_text'] : 'Refunded by site admin';

$refundId = $payment->getTransactionId();

$paymentId = substr($refundId, 0, -7);

try
{
$data = array(
'amount' => (int) round($amount * 100),
'receipt' => $order->getIncrementId(),
'notes' => array(
'reason' => $reason,
'order_id' => $order->getIncrementId(),
'refund_from_website' => true,
'source' => 'Magento',
)
);

$refund = $this->rzp->payment
->fetch( $paymentId )
->refund( $data );

$payment->setAmountPaid($amount)
->setLastTransId($refund->id)
->setTransactionId($refund->id)
->setIsTransactionClosed(true)
->setShouldCloseParentTransaction(true);
}
catch(\Razorpay\Api\Errors\Error $e)
{
$this->_logger->critical($e);
throw new LocalizedException(__('Razorpay Error: %1.', $e->getMessage()));
}
catch(\Exception $e)
{
$this->_logger->critical($e);
throw new LocalizedException(__('Razorpay Error: %1.', $e->getMessage()));
}

return $this;
}

Expand Down

0 comments on commit 0bd8db1

Please sign in to comment.