Skip to content

Commit

Permalink
added a bunch of logging to get more info around pending orders issue
Browse files Browse the repository at this point in the history
  • Loading branch information
David Froneberger committed Sep 16, 2019
1 parent 96413ed commit 8985ef1
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 22 deletions.
7 changes: 7 additions & 0 deletions Controller/Checkout/ValidateTotals.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}

Expand Down
16 changes: 15 additions & 1 deletion Helper/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class Checkout extends Quote
{
const BREAD_AMOUNT = "bread_transaction_amount";

/**
* @var \Bread\BreadCheckout\Helper\Log
*/
public $logger;

public function __construct(
\Magento\Framework\App\Helper\Context $helperContext,
\Magento\Framework\Model\Context $context,
Expand All @@ -23,8 +28,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,
Expand Down Expand Up @@ -76,10 +83,17 @@ 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']);
}

$this->logger->info([
'MESSAGE' => 'checking bread and quote tx amounts are same',
'BREAD' => $breadAmount,
'QUOTE' => $quoteTotal
]);

return (bool) ($breadAmount == $quoteTotal);
}
}
13 changes: 13 additions & 0 deletions Helper/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
48 changes: 42 additions & 6 deletions Model/Payment/Method/Bread.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -194,6 +197,7 @@ public function validate()
)
);
}
$this->breadLogger->info('can use billing country');

$token = $this->getToken();
if (empty($token)) {
Expand All @@ -205,6 +209,7 @@ public function validate()
)
);
}
$this->breadLogger->info('validate succeeded');

return $this;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 14 additions & 12 deletions view/base/web/js/sentry/sentry-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {};
}
};

Expand Down
15 changes: 12 additions & 3 deletions view/frontend/web/js/view/payment/method-renderer/breadcheckout.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ define(
alert(response.error);
} else {
$.when(
this.updateAddress(response),
this.updateAddress(response, errorInfo),
this.validateTotals()
).done(
$.proxy(
Expand Down Expand Up @@ -237,26 +237,35 @@ 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
*/
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;
},

/**
Expand Down

0 comments on commit 8985ef1

Please sign in to comment.