subscribepro / subscribepro-magento2-ext

Subscribe Pro Magento 2 Integration Extension
MIT License
24 stars 22 forks source link

Admin reorder on a guest order does not work #89

Open friendscottn opened 4 years ago

friendscottn commented 4 years ago

The issue

I know most people don't use the subscribe pro payment method for guest orders. But if you do you'll get an error when trying to use the reorder functionality in the admin:

Transaction has been declined. Please try again later.

Which is masking:

Cannot create payment profile.

vendor/subscribepro/subscribepro-magento2-ext/Gateway/Command/AbstractProfileCreatorCommand.php

The solution

The payment form has the hidden field payment[is_active_payment_token_enabler] hard coded to 'true'. This should be false for guest orders.

friendscottn commented 2 years ago

Here's a patch that resolves the issue for us:

diff --git a/vendor/subscribepro/subscribepro-magento2-ext/Block/Adminhtml/Payment/Cc.php b/vendor/subscribepro/subscribepro-magento2-ext/Block/Adminhtml/Payment/Cc.php
index 98367f61a..cdca660d8 100644
--- a/vendor/subscribepro/subscribepro-magento2-ext/Block/Adminhtml/Payment/Cc.php
+++ b/vendor/subscribepro/subscribepro-magento2-ext/Block/Adminhtml/Payment/Cc.php
@@ -51,4 +51,15 @@ class Cc extends \Magento\Payment\Block\Form\Cc
     {
         return ConfigProvider::CODE;
     }
+
+    // BANYAN MOD: Fixing admin guest checkout
+    /**
+     *
+     * @return bool
+     */
+    public function getQuoteHasCustomer()
+    {
+        return $this->quoteSession->getQuote()->getCustomerId() !== null;
+    }
+    // END BANYAN MOD
 }
diff --git a/vendor/subscribepro/subscribepro-magento2-ext/view/adminhtml/templates/payment/cc.phtml b/vendor/subscribepro/subscribepro-magento2-ext/view/adminhtml/templates/payment/cc.phtml
index afa39615d..18f72135c 100644
--- a/vendor/subscribepro/subscribepro-magento2-ext/view/adminhtml/templates/payment/cc.phtml
+++ b/vendor/subscribepro/subscribepro-magento2-ext/view/adminhtml/templates/payment/cc.phtml
@@ -64,5 +64,7 @@ $code = $block->escapeHtml($block->getMethodCode());
     </div>

     <input type="hidden" id="<?php echo $code; ?>_payment_method_token" name="payment[payment_method_token]"/>
-    <input name="payment[is_active_payment_token_enabler]" type="hidden" value="true" />
+    <!-- BANYAN MOD: Fixing admin guest checkout -->
+    <input name="payment[is_active_payment_token_enabler]" type="hidden" value="<?= $block->getQuoteHasCustomer() ? 'true' : 'false'; ?>" />
+    <!-- END BANYAN MOD -->
 </fieldset>