Skip to content

Commit

Permalink
Merge pull request #9 from cashfree/version_bump-2.1.0
Browse files Browse the repository at this point in the history
Resolve issue of resource id aready exist
  • Loading branch information
prem-cashfree authored Aug 18, 2021
2 parents ac2b5f3 + 42eab9d commit 192db66
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Controller/Standard/Notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ public function execute() {
$status = $paymentMethod->validateResponse($params);
$referenceId = $params['referenceId'];
if ($status == "SUCCESS") {
$quoteId = $params['orderId'];
$quoteId = strip_tags($params["orderId"]);
list($quoteId) = explode('_', $quoteId);
if (empty($this->cache->load("quote_Front_processing_".$quoteId)) === false)
{
$this->logger->info("Cashfree Webhook: Order processing is active for quoteID: $quoteId");
Expand Down
35 changes: 26 additions & 9 deletions Controller/Standard/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function __construct(
\Magento\Customer\Model\CustomerFactory $customerFactory,
\Magento\Store\Model\StoreManagerInterface $storeManagement,
\Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepo,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
) {
Expand All @@ -49,6 +50,7 @@ public function __construct(
$this->storeManagement = $storeManagement;
$this->customerRepo = $customerRepo;
$this->customerFactory = $customerFactory;
$this->orderRepository = $orderRepository;
$this->objectManagement = \Magento\Framework\App\ObjectManager::getInstance();

parent::__construct(
Expand All @@ -74,7 +76,8 @@ public function __construct(
public function execute() {
$returnUrl = $this->getCheckoutHelper()->getUrl('checkout');
$params = $this->getRequest()->getParams();
$quoteId = $params['orderId'];
$quoteId = strip_tags($params["orderId"]);
list($quoteId) = explode('_', $quoteId);
$quote = $this->getQuoteObject($params, $quoteId);
if (!$this->getCustomerSession()->isLoggedIn()) {
$customerId = $quote->getCustomer()->getId();
Expand All @@ -88,19 +91,33 @@ public function execute() {
$status = $paymentMethod->validateResponse($params);
$debugLog = "";
if ($status == "SUCCESS") {
$order = $this->quoteManagement->submit($quote);

$payment = $order->getPayment();
# fetch the related sales order
# To avoid duplicate order entry for same quote
$collection = $this->objectManagement->get('Magento\Sales\Model\Order')
->getCollection()
->addFieldToSelect('entity_id')
->addFilter('quote_id', $quoteId)
->getFirstItem();
$salesOrder = $collection->getData();

if (empty($salesOrder['entity_id']) === true) {
$order = $this->quoteManagement->submit($quote);
$payment = $order->getPayment();

$paymentMethod->postProcessing($order, $payment, $params);
$paymentMethod->postProcessing($order, $payment, $params);
} else {
$order = $this->orderRepository->get($salesOrder['entity_id']);
}
$this->_checkoutSession
->setLastQuoteId($quote->getId())
->setLastSuccessQuoteId($quote->getId())
->clearHelperData();

$this->_checkoutSession->setLastOrderId($order->getId())
->setLastRealOrderId($order->getIncrementId())
->setLastOrderStatus($order->getStatus());

if ($order) {
$this->_checkoutSession->setLastOrderId($order->getId())
->setLastRealOrderId($order->getIncrementId())
->setLastOrderStatus($order->getStatus());
}

$returnUrl = $this->getCheckoutHelper()->getUrl('checkout/onepage/success');
$this->messageManager->addSuccess(__('Your payment was successful'));
Expand Down
8 changes: 6 additions & 2 deletions Model/Cfcheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function __construct(
\Magento\Sales\Model\Service\InvoiceService $invoiceService,
\Magento\Framework\HTTP\ZendClientFactory $httpClientFactory,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Sales\Model\Order\Email\Sender\OrderSender $orderSender,
\Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
\Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
) {
Expand All @@ -57,6 +58,7 @@ public function __construct(
$this->checkoutSession = $checkoutSession;
$this->invoiceService = $invoiceService;
$this->transaction = $transaction;
$this->orderSender = $orderSender;

parent::__construct(
$context,
Expand Down Expand Up @@ -120,7 +122,7 @@ public function buildCheckoutRequest() {

$params = array();
$params["appId"] = $this->getConfigData("app_id");
$params["orderId"] = $quote->getEntityId();
$params["orderId"] = $quote->getEntityId()."_".time();
$params["orderAmount"] = round($quote->getGrandTotal(), 2);
$params["orderCurrency"] = $quote->getQuoteCurrencyCode();
$params["customerName"] = $billing_address->getFirstName(). " ". $billing_address->getLastName();
Expand All @@ -129,6 +131,7 @@ public function buildCheckoutRequest() {
$params["customerPhone"] = $billing_address->getTelephone();

$params["notifyUrl"] = $this->getNotifyUrl();
// $params["paymentModes"] = "upi";

$params["returnUrl"] = $this->getReturnUrl();
$params["source"] = "magento";
Expand Down Expand Up @@ -191,7 +194,7 @@ public function validateResponse($returnParams) {
*/
public function postProcessing(\Magento\Sales\Model\Order $order,
\Magento\Framework\DataObject $payment, $response) {

$payment->setTransactionId($response['referenceId']);
$payment->setTransactionAdditionalInfo('Transaction Message', $response['txMsg']);
$payment->setAdditionalInformation('cashfree_payment_status', 'approved');
Expand All @@ -201,6 +204,7 @@ public function postProcessing(\Magento\Sales\Model\Order $order,
$order->setStatus('processing');
$order->setState('processing');
$order->save();
$this->orderSender->send($order, true);
$this->generateInvoice($order);
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"docs": "https://docs.cashfree.com/docs/"
},
"type": "magento2-module",
"version": "2.0.1",
"version": "2.1.0",
"license": [
"MIT"
],
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Cashfree_Cfcheckout" setup_version="2.0.1">
<module name="Cashfree_Cfcheckout" setup_version="2.1.0">
<sequence>
<module name="Magento_Sales" />
<module name="Magento_Payment" />
Expand Down

0 comments on commit 192db66

Please sign in to comment.