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 Jan 29, 2020
1 parent 6bd4f3b commit adcea70
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 9 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
1 change: 1 addition & 0 deletions Helper/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down
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
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 @@ -175,7 +175,7 @@ define(
alert(response.error);
} else {
$.when(
this.updateAddress(response),
this.updateAddress(response, errorInfo),
this.validateTotals()
).done(
$.proxy(
Expand Down Expand Up @@ -246,26 +246,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 adcea70

Please sign in to comment.