diff --git a/Controller/Checkout/EstimateShipping.php b/Controller/Checkout/EstimateShipping.php index 9242f98c..c4faa16a 100644 --- a/Controller/Checkout/EstimateShipping.php +++ b/Controller/Checkout/EstimateShipping.php @@ -97,9 +97,19 @@ public function execute() 'typeId' => $rate->getCode(), 'cost' => round($rate->getPrice() * 100), ]; + + $this->logger->log([ + 'SHIPPING METHOD' => $rate->getCode(), + 'SHIPPING AMOUNT' => $rate->getPrice() + ]); } } $response = ['result' => $methods]; + + $this->logger->log([ + 'ESTIMATE SHIPPING METHODS' => $methods + ]); + } catch (\Throwable $e) { $this->logger->log(['ERROR' => $e->getMessage(),'PARAMS'=> $this->getRequest()->getParams()]); $this->messageManager->addErrorMessage( diff --git a/Controller/Checkout/EstimateTax.php b/Controller/Checkout/EstimateTax.php index 77fa9cfc..e502eebf 100644 --- a/Controller/Checkout/EstimateTax.php +++ b/Controller/Checkout/EstimateTax.php @@ -76,6 +76,12 @@ public function execute() } $result = round($shippingAddress->getTaxAmount() * 100); + + $this->logger->log([ + 'SHIPPING ADDRESS TAX AMOUNT' => $shippingAddress->getTaxAmount(), + 'ESTIMATE TAX RETURNED' => $result + ]); + $response = ['result' => $result]; } catch (\Throwable $e) { $this->logger->log(['EXCEPTION IN TAX ESTIMATE ACTION' => $e->getMessage()]); 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 e29e1f44..aedc35f9 100644 --- a/Helper/Checkout.php +++ b/Helper/Checkout.php @@ -10,6 +10,12 @@ class Checkout extends Quote { + + /** + * @var \Psr\Log\LoggerInterface + */ + public $logger; + const BREAD_AMOUNT = "bread_transaction_amount"; public function __construct( @@ -23,8 +29,10 @@ public function __construct( \Magento\Sales\Model\AdminOrder\Create $orderCreateModel, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, \Bread\BreadCheckout\Model\Payment\Api\Client $paymentApiClient, - \Magento\Catalog\Api\ProductRepositoryInterface $productRepository + \Magento\Catalog\Api\ProductRepositoryInterface $productRepository, + \Bread\BreadCheckout\Helper\Log $logger ) { + $this->logger = $logger; parent::__construct( $helperContext, $context, @@ -76,10 +84,33 @@ 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']); } - return (bool) ($breadAmount == $quoteTotal || (abs((int)$breadAmount - (int)$quoteTotal) <= 2)); + $areAmountsEqual = (bool) (abs((int)$breadAmount - $quoteTotal) <= 2); + + if (!$areAmountsEqual) { + $quote = $this->getSessionQuote(); + + $itemPrices = array_map(function($item) { + return $item->getPrice() * 100; + }, $quote->getItems()); + + $this->logger->log([ + 'LOCATION' => __CLASS__, + 'SESSION QUOTE GRAND TOTAL' => ($quote->getGrandTotal() * 100), + 'SESSION QUOTE AFTER ROUND METHOD' => ($quoteTotal), + 'SESSION QUOTE SUB TOTAL' => ($quote->getSubtotal() * 100), + 'SESSION QUOTE SUB TOTAL W/ DISCOUNT' => ($quote->getSubtotalWithDiscount() * 100), + 'SESSION QUOTE SHIPPING ADDRESS TAX AMOUNT' => ($quote->getShippingAddress()->getBaseTaxAmount() * 100), + 'SESSION QUOTE SHIPPING COST' => ($quote->getShippingAddress()->getShippingAmount() * 100), + 'SESSION QUOTE ITEM PRICES' => $itemPrices + ]); + + } + + return $areAmountsEqual; } } 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/Api/Client.php b/Model/Payment/Api/Client.php index ee2d13c9..3a0fe1b7 100644 --- a/Model/Payment/Api/Client.php +++ b/Model/Payment/Api/Client.php @@ -44,6 +44,11 @@ class Client extends \Magento\Framework\Model\AbstractModel public $logger; + /** + * @var \Magento\Checkout\Model\Session + */ + private $checkoutSession; + public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, @@ -51,6 +56,7 @@ public function __construct( \Magento\Framework\Json\Helper\Data $jsonHelper, \Magento\Store\Model\StoreResolver $storeResolver, \Bread\BreadCheckout\Helper\Log $log, + \Magento\Checkout\Model\Session $checkoutSession, \Magento\Framework\App\CacheInterface $cache ) { $this->context = $context; @@ -58,6 +64,7 @@ public function __construct( $this->jsonHelper = $jsonHelper; $this->storeResolver = $storeResolver; $this->logger = $log; + $this->checkoutSession = $checkoutSession; $this->cache = $cache; parent::__construct($context, $registry); } @@ -130,6 +137,26 @@ public function authorize($breadTransactionId, $amount, $merchantOrderId = null) $amount = trim($amount); if (((int) $breadAmount != (int) $amount) && (abs((int)$breadAmount - (int)$amount) >= 2)) { + $quote = $this->checkoutSession->getQuote(); + + $items = $quote->getItems(); + $itemPrices = "No Item Prices"; + if (is_array($items)) { + $itemPrices = array_map(function ($item) { + return $item->getPrice() * 100; + }, $items); + } + + $this->logger->log([ + 'LOCATION' => __CLASS__, + 'SESSION QUOTE GRAND TOTAL' => ($quote->getGrandTotal() * 100), + 'SESSION QUOTE SUB TOTAL' => ($quote->getSubtotal() * 100), + 'SESSION QUOTE SUB TOTAL W/ DISCOUNT' => ($quote->getSubtotalWithDiscount() * 100), + 'SESSION QUOTE SHIPPING ADDRESS TAX AMOUNT' => ($quote->getShippingAddress()->getBaseTaxAmount() * 100), + 'SESSION QUOTE SHIPPING COST' => ($quote->getShippingAddress()->getShippingAmount() * 100), + 'SESSION QUOTE ITEM PRICES' => $itemPrices + ]); + $this->logger->log( [ 'ERROR' =>'BREAD AMOUNT AND QUOTE AMOUNT MIS-MATCH', 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/composer.json b/composer.json index a9ebc9b4..977012d8 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Offers the Bread financing and checkout tools for your Magento store", "license": "MIT", "minimum-stability": "stable", - "version": "1.1.12", + "version": "1.1.12.1", "require": { "php": "~7.0.13||~7.1.0||~7.1.3||~7.2.0||~7.3.0" }, diff --git a/view/base/web/js/sentry/sentry-config.js b/view/base/web/js/sentry/sentry-config.js index fddab37f..214b9748 100644 --- a/view/base/web/js/sentry/sentry-config.js +++ b/view/base/web/js/sentry/sentry-config.js @@ -4,22 +4,24 @@ define( return function (config) { var TRACKED_TAG_KEYS = [ - 'plugin_version', - 'merchant_api_key', + 'plugin_version', + 'merchant_api_key', + 'tx_id', ]; var getConsoleFunc = function (level) { + //don't print to console for info and debug level switch (level) { - case 'fatal': - return console.error; - case 'error': - return console.error; - case 'warning': - return console.warn; - case 'info': - return console.info; - case 'debug': - return console.log; + case 'fatal': + return console.error; + case 'error': + return console.error; + case 'warning': + return console.warn; + case 'info': + return function (issue) {}; + case 'debug': + return function (issue) {}; } }; 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 0d84f29a..1bb62c31 100644 --- a/view/frontend/web/js/view/payment/method-renderer/breadcheckout.js +++ b/view/frontend/web/js/view/payment/method-renderer/breadcheckout.js @@ -33,7 +33,7 @@ define( additionalValidators, quote ) { - 'use strict'; + 'use strict'; //todo fix all the breadConfigs here to be config provider one as well as button one return Component.extend( { defaults: { @@ -145,7 +145,8 @@ define( buttonCallback: function (token) { this.setBreadTransactionId(token); var paymentUrl = window.checkoutConfig.payment[this.getCode()].breadConfig.paymentUrl; - var breadConfig = window.checkoutConfig.payment[this.getCode()].breadConfig; + var configProviderOpts = window.checkoutConfig.payment[this.getCode()].breadConfig; + var actualButtonOpts = button.breadConfig; $.ajax( { @@ -162,7 +163,9 @@ define( var errorInfo; try { errorInfo = { - bread_config: breadConfig, + config_provider_opts: configProviderOpts, + button_opts: actualButtonOpts, + totals: quote.getTotals()._latestValue, response: response, tx_id: token, }; @@ -172,7 +175,7 @@ define( alert(response.error); } else { $.when( - this.updateAddress(response), + this.updateAddress(response, errorInfo), this.validateTotals() ).done( $.proxy( @@ -191,7 +194,9 @@ define( errorProcessor.process(error, this.messageContainer); errorInfo = { - bread_config: breadConfig, + config_provider_opts: configProviderOpts, + button_opts: actualButtonOpts, + totals: quote.getTotals()._latestValue, error: error, tx_id: token, }; @@ -210,7 +215,9 @@ define( errorInfo = { response: response, tx_id: token, - bread_config: breadConfig, + config_provider_opts: configProviderOpts, + button_opts: actualButtonOpts, + totals: quote.getTotals()._latestValue, }; document.logBreadIssue('error', errorInfo, e); } @@ -218,7 +225,9 @@ define( ).fail( function (error) { var errorInfo = { - bread_config: breadConfig, + config_provider_opts: configProviderOpts, + button_opts: actualButtonOpts, + totals: quote.getTotals()._latestValue, tx_id: token, }; document.logBreadIssue( @@ -237,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 @@ -256,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; }, /**