Skip to content

Commit

Permalink
Order notes addition (#465)
Browse files Browse the repository at this point in the history
* Added order notes with amount captured.

* Added notes for graphql orders

* Removed two blocks for notes addition
  • Loading branch information
yashgit891 authored Nov 30, 2023
1 parent 05592ea commit 58ffb50
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Controller/Payment/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class Callback extends \Razorpay\Magento\Controller\BaseController

const STATUS_APPROVED = 'APPROVED';
const STATUS_PROCESSING = 'processing';
const AUTHORIZED = 'authorized';
const CAPTURED = 'captured';

/**
* @var \Razorpay\Magento\Model\Config
*/
Expand Down Expand Up @@ -173,6 +176,8 @@ public function execute()
$payment = $order->getPayment();
$paymentId = $params['razorpay_payment_id'];

$rzpPayment = $this->rzp->request->request('GET', 'payments/'.$paymentId);

$payment->setLastTransId($paymentId)->setTransactionId($paymentId)->setIsTransactionClosed(true)
->setShouldCloseParentTransaction(true);

Expand Down Expand Up @@ -204,6 +209,16 @@ public function execute()
->load($order->getQuoteId());
$quote->setIsActive(false)
->save();

$amountPaid = number_format($rzpPayment['amount'] / 100, 2, ".", "");

$order->addStatusHistoryComment(
__(
'Amount %1 of %2, with Razorpay Offer/Fee applied.',
$rzpPayment['status'],
$order->getBaseCurrency()->formatTxt($amountPaid)
)
);

$orderLink->setRzpPaymentId($paymentId);

Expand Down
16 changes: 15 additions & 1 deletion Controller/Payment/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Validate extends \Razorpay\Magento\Controller\BaseController implements Cs

const STATUS_APPROVED = 'APPROVED';
const STATUS_PROCESSING = 'processing';
const AUTHORIZED = 'authorized';
const CAPTURED = 'captured';

/**
* @var \Magento\Sales\Model\Service\InvoiceService
Expand Down Expand Up @@ -198,7 +200,9 @@ public function execute()
$payment = $order->getPayment();

$paymentId = $post['razorpay_payment_id'];


$rzpPayment = $this->rzp->request->request('GET', 'payments/'.$paymentId);

$payment->setLastTransId($paymentId)
->setTransactionId($paymentId)
->setIsTransactionClosed(true)
Expand Down Expand Up @@ -243,6 +247,16 @@ public function execute()
$quote = $this->_objectManager->get('Magento\Quote\Model\Quote')->load($order->getQuoteId());
$quote->setIsActive(false)->save();

$amountPaid = number_format($rzpPayment['amount'] / 100, 2, ".", "");

$order->addStatusHistoryComment(
__(
'Actual Amount %1 of %2, with Razorpay Offer/Fee applied.',
$rzpPayment['status'],
$order->getBaseCurrency()->formatTxt($amountPaid)
)
);

$orderLink = $this->_objectManager->get('Razorpay\Magento\Model\OrderLink')
->getCollection()
->addFilter('order_id', $order->getEntityId())
Expand Down
15 changes: 15 additions & 0 deletions Model/Resolver/SetRzpPaymentDetailsForOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class SetRzpPaymentDetailsForOrder implements ResolverInterface

protected const STATUS_PROCESSING = 'processing';

const AUTHORIZED = 'authorized';
const CAPTURED = 'captured';

protected $rzp;

/**
Expand Down Expand Up @@ -297,6 +300,18 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value

$transaction->save();

$rzpPayment = $this->rzp->request->request('GET', 'payments/'.$rzp_payment_id);

$rzpAmountPaid = number_format($rzpPayment['amount'] / 100, 2, ".", "");

$order->addStatusHistoryComment(
__(
'Amount %1 of %2, with Razorpay Offer/Fee applied.',
$rzpPayment['status'],
$order->getBaseCurrency()->formatTxt($rzpAmountPaid)
)
);

$orderLink->setRzpUpdateOrderCronStatus(OrderCronStatus::PAYMENT_AUTHORIZED_COMPLETED);
$this->logger->info('Payment authorized completed for id : '. $order->getIncrementId());

Expand Down

0 comments on commit 58ffb50

Please sign in to comment.