From adcea70f399bfafaf9dfe0cc183071840d59ddb3 Mon Sep 17 00:00:00 2001 From: David Froneberger Date: Mon, 16 Sep 2019 16:43:32 -0400 Subject: [PATCH] added a bunch of logging to get more info around pending orders issue --- Controller/Checkout/ValidateTotals.php | 7 +++ Helper/Checkout.php | 1 + Helper/Log.php | 13 +++++ Model/Payment/Method/Bread.php | 48 ++++++++++++++++--- .../payment/method-renderer/breadcheckout.js | 15 ++++-- 5 files changed, 75 insertions(+), 9 deletions(-) diff --git a/Controller/Checkout/ValidateTotals.php b/Controller/Checkout/ValidateTotals.php index bd62923a..184af75b 100644 --- a/Controller/Checkout/ValidateTotals.php +++ b/Controller/Checkout/ValidateTotals.php @@ -60,15 +60,22 @@ public function execute() $result = ['valid' => false]; if (isset($params['bread_transaction_id'])) { + $this->logger->info([ + 'MESSAGE' => 'tx_id is set', + 'TX_ID' => $params['bread_transaction_id'] + ]); if ($this->helper->validateTransactionAmount($params['bread_transaction_id'])) { + $this->logger->info(['MESSAGE' => 'tx amount is valid']); $result['valid'] = true; } else { $errorMsg = __( 'Your order total does not match the amount authorized by Bread. Please complete checkout again before placing the order.' ); + $this->logger->info(['MESSAGE' => 'order total doesnt match amount authorized']); } } else { + $this->logger->info(['ERROR' => 'tx_id not set']); $errorMsg = __('Please complete the Bread checkout form before placing the order.'); } diff --git a/Helper/Checkout.php b/Helper/Checkout.php index bc3ae48d..aedc35f9 100644 --- a/Helper/Checkout.php +++ b/Helper/Checkout.php @@ -84,6 +84,7 @@ public function validateTransactionAmount($transactionId) $quoteTotal = (int)($this->priceCurrency->round($this->getSessionQuote()->getGrandTotal() * 100)); if ($breadAmount === 0) { + $this->logger->info('bread amount is 0'); $info = $this->paymentApiClient->getInfo($transactionId); $this->setBreadTransactionAmount($info['adjustedTotal']); } diff --git a/Helper/Log.php b/Helper/Log.php index f9d2f55c..7188eb0b 100644 --- a/Helper/Log.php +++ b/Helper/Log.php @@ -52,4 +52,17 @@ public function log($data) $this->breadLogger->debug($data); } } + + /** + * @param $data + */ + public function info($data) + { + if ($this->logEnabled()) { + if (!is_string($data)) { + $data = print_r($data, true); + } + $this->breadLogger->info($data); + } + } } diff --git a/Model/Payment/Method/Bread.php b/Model/Payment/Method/Bread.php index 0573128c..2ddbe688 100644 --- a/Model/Payment/Method/Bread.php +++ b/Model/Payment/Method/Bread.php @@ -179,10 +179,13 @@ public function fetchTransactionInfo(\Magento\Payment\Model\InfoInterface $payme public function validate() { $paymentInfo = $this->getInfoInstance(); + $this->breadLogger->info('got payment info'); if ($paymentInfo instanceof \Magento\Sales\Model\Order\Payment) { - $billingCountry = $paymentInfo->getOrder()->getBillingAddress()->getCountryId(); + $this->breadLogger->info('payment info instance of payment'); + $billingCountry = $paymentInfo->getOrder()->getBillingAddress()->getCountryId(); } else { - $billingCountry = $paymentInfo->getQuote()->getBillingAddress()->getCountryId(); + $this->breadLogger->info('payment info NOT instance of payment'); + $billingCountry = $paymentInfo->getQuote()->getBillingAddress()->getCountryId(); } if (!$this->canUseForCountry($billingCountry)) { @@ -194,6 +197,7 @@ public function validate() ) ); } + $this->breadLogger->info('can use billing country'); $token = $this->getToken(); if (empty($token)) { @@ -205,6 +209,7 @@ public function validate() ) ); } + $this->breadLogger->info('validate succeeded'); return $this; } @@ -248,12 +253,25 @@ public function void(\Magento\Payment\Model\InfoInterface $payment) public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount) { if (!$this->canAuthorize()) { + $this->breadLogger->info('authorize action is not available'); throw new \Magento\Framework\Exception\LocalizedException(__('Authorize action is not available.')); } + $this->breadLogger->info([ + 'MESSAGE' => 'about to set amount in authorize', + 'amount' => $amount + ]); $payment->setAmount($amount); + $this->breadLogger->info('about to set isTxClosed in authorize'); $payment->setIsTransactionClosed(false); - $payment->setTransactionId($this->getToken()); + $tx_id = $this->getToken(); + $this->breadLogger->info([ + 'MESSAGE' => 'about to set tx_id in authorize', + 'tx_id' => $tx_id + ]); + $payment->setTransactionId($tx_id); + + $this->breadLogger->info('all payment info set in authorize'); $this->_place($payment, $amount, self::ACTION_AUTHORIZE); return $this; @@ -385,13 +403,31 @@ public function order(\Magento\Payment\Model\InfoInterface $payment, $amount) protected function _place(\Magento\Payment\Model\InfoInterface $payment, $amount, $requestType) { $this->apiClient->setOrder($payment->getOrder()); + $this->breadLogger->info('api client order was set'); + switch ($requestType) { case self::ACTION_AUTHORIZE: + $this->breadLogger->info('about to call api client authorize'); + $tx_id = $this->getValidatedTxId($payment); + $this->breadLogger->info('got tx_id in place authorize'); + $amount = ($this->priceCurrency->round($amount) * 100); + $this->breadLogger->info([ + 'MESSAGE' => 'got amount in place authorize', + 'amount' => $amount + ]); + $orderId = $payment->getOrder()->getIncrementId(); + $this->breadLogger->info([ + 'MESSAGE' => 'got orderId in place authorize', + 'orderId' => $orderId + ]); + $result = $this->apiClient->authorize( - $this->getValidatedTxId($payment), - ($this->priceCurrency->round($amount) * 100), - $payment->getOrder()->getIncrementId() + $tx_id, + $amount, + $orderId ); + $this->breadLogger->info('called api client authorize'); + $payment->setTransactionId($result['breadTransactionId']); $this->addTransactionInfo( $payment, diff --git a/view/frontend/web/js/view/payment/method-renderer/breadcheckout.js b/view/frontend/web/js/view/payment/method-renderer/breadcheckout.js index e73a11ba..1bb62c31 100644 --- a/view/frontend/web/js/view/payment/method-renderer/breadcheckout.js +++ b/view/frontend/web/js/view/payment/method-renderer/breadcheckout.js @@ -175,7 +175,7 @@ define( alert(response.error); } else { $.when( - this.updateAddress(response), + this.updateAddress(response, errorInfo), this.validateTotals() ).done( $.proxy( @@ -246,18 +246,25 @@ define( * * @return {jQuery.Deferred} */ - updateAddress: function (data) { + updateAddress: function (data, errorInfo) { var self = this; /** * Billing address */ + document.logBreadIssue('info', errorInfo, 'starting update address'); + var billingAddressData = this.getAddressData(data.billingAddress); + document.logBreadIssue('info', $.extend(true, {}, errorInfo, {billingAddressData: billingAddressData}), 'got billing address data'); var newBillingAddress = createBillingAddress(billingAddressData); + document.logBreadIssue('info', $.extend(true, {}, errorInfo, {newBillingAddress: newBillingAddress}), 'got new billing address'); // New address must be selected as a billing address selectBillingAddress(newBillingAddress); + document.logBreadIssue('info', errorInfo, 'selected new billing address'); checkoutData.setSelectedBillingAddress(newBillingAddress.getKey()); + document.logBreadIssue('info', errorInfo, 'set selected billing address'); checkoutData.setNewCustomerBillingAddress(billingAddressData); + document.logBreadIssue('info', errorInfo, 'set new customer billing address'); /** * Reload checkout section & add bread token @@ -265,7 +272,9 @@ define( if(quote.isVirtual()) { return defaultProcessor; } - return defaultProcessor.saveShippingInformation(); + var defaultProcessorSavedShipping = defaultProcessor.saveShippingInformation(); + document.logBreadIssue('info', $.extend(true, {}, errorInfo, {defaultProcessorSavedShipping: defaultProcessorSavedShipping}), 'default processor saved shipping info'); + return defaultProcessorSavedShipping; }, /**