diff --git a/Controller/Payment/Order.php b/Controller/Payment/Order.php index e9f690d8..d89e076f 100644 --- a/Controller/Payment/Order.php +++ b/Controller/Payment/Order.php @@ -42,17 +42,17 @@ public function execute() { $amount = (int) (round($this->getQuote()->getBaseGrandTotal(), 2) * 100); - $receipt_id = $this->getQuote()->getId(); + $receiptId = $this->getQuote()->getId(); $code = 400; try { $order = $this->rzp->order->create([ - 'amount' => $amount, - 'receipt' => $receipt_id, - 'currency' => $this->_currency, - 'payment_capture' => 1 // auto-capture + 'amount' => $amount, + 'receipt' => $receiptId, + 'currency' => $this->_currency, + 'payment_capture' => 1 ]); $responseContent = [ @@ -65,7 +65,7 @@ public function execute() $responseContent = [ 'success' => true, 'rzp_order' => $order->id, - 'order_id' => $receipt_id, + 'order_id' => $receiptId, 'amount' => $order->amount, 'quote_currency' => $this->getQuote()->getQuoteCurrencyCode(), 'quote_amount' => round($this->getQuote()->getGrandTotal(), 2) diff --git a/Model/PaymentMethod.php b/Model/PaymentMethod.php index 95a3118f..b0db50db 100644 --- a/Model/PaymentMethod.php +++ b/Model/PaymentMethod.php @@ -213,18 +213,23 @@ public function capture(InfoInterface $payment, $amount) $order = $payment->getOrder(); $orderId = $order->getIncrementId(); + // + // Remote IP is set only for orders that are placed through the frontend + // + if (empty($order->getRemoteIp()) === true) + { + $this->handleApprovedPayment($amount, $payment); + + return; + } + $request = $this->getPostData(); $payment_id = $request['paymentMethod']['additional_data']['rzp_payment_id']; $this->validateSignature($request); - $payment->setStatus(self::STATUS_APPROVED) - ->setAmountPaid($amount) - ->setLastTransId($payment_id) - ->setTransactionId($payment_id) - ->setIsTransactionClosed(true) - ->setShouldCloseParentTransaction(true); + $this->handleApprovedPayment($amount, $payment, $payment_id); } catch (\Exception $e) { @@ -235,6 +240,16 @@ public function capture(InfoInterface $payment, $amount) return $this; } + protected function handleApprovedPayment($amount, InfoInterface $payment, $paymentId = null) + { + $payment->setStatus(self::STATUS_APPROVED) + ->setAmountPaid($amount) + ->setLastTransId($paymentId) + ->setTransactionId($paymentId) + ->setIsTransactionClosed(true) + ->setShouldCloseParentTransaction(true); + } + protected function validateSignature($request) { $attributes = array(