Skip to content

Commit 58ffb50

Browse files
authored
Order notes addition (#465)
* Added order notes with amount captured. * Added notes for graphql orders * Removed two blocks for notes addition
1 parent 05592ea commit 58ffb50

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

Controller/Payment/Callback.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class Callback extends \Razorpay\Magento\Controller\BaseController
2929

3030
const STATUS_APPROVED = 'APPROVED';
3131
const STATUS_PROCESSING = 'processing';
32+
const AUTHORIZED = 'authorized';
33+
const CAPTURED = 'captured';
34+
3235
/**
3336
* @var \Razorpay\Magento\Model\Config
3437
*/
@@ -173,6 +176,8 @@ public function execute()
173176
$payment = $order->getPayment();
174177
$paymentId = $params['razorpay_payment_id'];
175178

179+
$rzpPayment = $this->rzp->request->request('GET', 'payments/'.$paymentId);
180+
176181
$payment->setLastTransId($paymentId)->setTransactionId($paymentId)->setIsTransactionClosed(true)
177182
->setShouldCloseParentTransaction(true);
178183

@@ -204,6 +209,16 @@ public function execute()
204209
->load($order->getQuoteId());
205210
$quote->setIsActive(false)
206211
->save();
212+
213+
$amountPaid = number_format($rzpPayment['amount'] / 100, 2, ".", "");
214+
215+
$order->addStatusHistoryComment(
216+
__(
217+
'Amount %1 of %2, with Razorpay Offer/Fee applied.',
218+
$rzpPayment['status'],
219+
$order->getBaseCurrency()->formatTxt($amountPaid)
220+
)
221+
);
207222

208223
$orderLink->setRzpPaymentId($paymentId);
209224

Controller/Payment/Validate.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class Validate extends \Razorpay\Magento\Controller\BaseController implements Cs
4242

4343
const STATUS_APPROVED = 'APPROVED';
4444
const STATUS_PROCESSING = 'processing';
45+
const AUTHORIZED = 'authorized';
46+
const CAPTURED = 'captured';
4547

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

200202
$paymentId = $post['razorpay_payment_id'];
201-
203+
204+
$rzpPayment = $this->rzp->request->request('GET', 'payments/'.$paymentId);
205+
202206
$payment->setLastTransId($paymentId)
203207
->setTransactionId($paymentId)
204208
->setIsTransactionClosed(true)
@@ -243,6 +247,16 @@ public function execute()
243247
$quote = $this->_objectManager->get('Magento\Quote\Model\Quote')->load($order->getQuoteId());
244248
$quote->setIsActive(false)->save();
245249

250+
$amountPaid = number_format($rzpPayment['amount'] / 100, 2, ".", "");
251+
252+
$order->addStatusHistoryComment(
253+
__(
254+
'Actual Amount %1 of %2, with Razorpay Offer/Fee applied.',
255+
$rzpPayment['status'],
256+
$order->getBaseCurrency()->formatTxt($amountPaid)
257+
)
258+
);
259+
246260
$orderLink = $this->_objectManager->get('Razorpay\Magento\Model\OrderLink')
247261
->getCollection()
248262
->addFilter('order_id', $order->getEntityId())

Model/Resolver/SetRzpPaymentDetailsForOrder.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class SetRzpPaymentDetailsForOrder implements ResolverInterface
7474

7575
protected const STATUS_PROCESSING = 'processing';
7676

77+
const AUTHORIZED = 'authorized';
78+
const CAPTURED = 'captured';
79+
7780
protected $rzp;
7881

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

298301
$transaction->save();
299302

303+
$rzpPayment = $this->rzp->request->request('GET', 'payments/'.$rzp_payment_id);
304+
305+
$rzpAmountPaid = number_format($rzpPayment['amount'] / 100, 2, ".", "");
306+
307+
$order->addStatusHistoryComment(
308+
__(
309+
'Amount %1 of %2, with Razorpay Offer/Fee applied.',
310+
$rzpPayment['status'],
311+
$order->getBaseCurrency()->formatTxt($rzpAmountPaid)
312+
)
313+
);
314+
300315
$orderLink->setRzpUpdateOrderCronStatus(OrderCronStatus::PAYMENT_AUTHORIZED_COMPLETED);
301316
$this->logger->info('Payment authorized completed for id : '. $order->getIncrementId());
302317

0 commit comments

Comments
 (0)