Skip to content

Commit adcea70

Browse files
author
David Froneberger
committed
added a bunch of logging to get more info around pending orders issue
1 parent 6bd4f3b commit adcea70

File tree

5 files changed

+75
-9
lines changed

5 files changed

+75
-9
lines changed

Controller/Checkout/ValidateTotals.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,22 @@ public function execute()
6060
$result = ['valid' => false];
6161

6262
if (isset($params['bread_transaction_id'])) {
63+
$this->logger->info([
64+
'MESSAGE' => 'tx_id is set',
65+
'TX_ID' => $params['bread_transaction_id']
66+
]);
6367
if ($this->helper->validateTransactionAmount($params['bread_transaction_id'])) {
68+
$this->logger->info(['MESSAGE' => 'tx amount is valid']);
6469
$result['valid'] = true;
6570
} else {
6671
$errorMsg = __(
6772
'Your order total does not match the amount authorized by Bread.
6873
Please complete checkout again before placing the order.'
6974
);
75+
$this->logger->info(['MESSAGE' => 'order total doesnt match amount authorized']);
7076
}
7177
} else {
78+
$this->logger->info(['ERROR' => 'tx_id not set']);
7279
$errorMsg = __('Please complete the Bread checkout form before placing the order.');
7380
}
7481

Helper/Checkout.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function validateTransactionAmount($transactionId)
8484
$quoteTotal = (int)($this->priceCurrency->round($this->getSessionQuote()->getGrandTotal() * 100));
8585

8686
if ($breadAmount === 0) {
87+
$this->logger->info('bread amount is 0');
8788
$info = $this->paymentApiClient->getInfo($transactionId);
8889
$this->setBreadTransactionAmount($info['adjustedTotal']);
8990
}

Helper/Log.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,17 @@ public function log($data)
5252
$this->breadLogger->debug($data);
5353
}
5454
}
55+
56+
/**
57+
* @param $data
58+
*/
59+
public function info($data)
60+
{
61+
if ($this->logEnabled()) {
62+
if (!is_string($data)) {
63+
$data = print_r($data, true);
64+
}
65+
$this->breadLogger->info($data);
66+
}
67+
}
5568
}

Model/Payment/Method/Bread.php

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,13 @@ public function fetchTransactionInfo(\Magento\Payment\Model\InfoInterface $payme
179179
public function validate()
180180
{
181181
$paymentInfo = $this->getInfoInstance();
182+
$this->breadLogger->info('got payment info');
182183
if ($paymentInfo instanceof \Magento\Sales\Model\Order\Payment) {
183-
$billingCountry = $paymentInfo->getOrder()->getBillingAddress()->getCountryId();
184+
$this->breadLogger->info('payment info instance of payment');
185+
$billingCountry = $paymentInfo->getOrder()->getBillingAddress()->getCountryId();
184186
} else {
185-
$billingCountry = $paymentInfo->getQuote()->getBillingAddress()->getCountryId();
187+
$this->breadLogger->info('payment info NOT instance of payment');
188+
$billingCountry = $paymentInfo->getQuote()->getBillingAddress()->getCountryId();
186189
}
187190

188191
if (!$this->canUseForCountry($billingCountry)) {
@@ -194,6 +197,7 @@ public function validate()
194197
)
195198
);
196199
}
200+
$this->breadLogger->info('can use billing country');
197201

198202
$token = $this->getToken();
199203
if (empty($token)) {
@@ -205,6 +209,7 @@ public function validate()
205209
)
206210
);
207211
}
212+
$this->breadLogger->info('validate succeeded');
208213

209214
return $this;
210215
}
@@ -248,12 +253,25 @@ public function void(\Magento\Payment\Model\InfoInterface $payment)
248253
public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount)
249254
{
250255
if (!$this->canAuthorize()) {
256+
$this->breadLogger->info('authorize action is not available');
251257
throw new \Magento\Framework\Exception\LocalizedException(__('Authorize action is not available.'));
252258
}
253259

260+
$this->breadLogger->info([
261+
'MESSAGE' => 'about to set amount in authorize',
262+
'amount' => $amount
263+
]);
254264
$payment->setAmount($amount);
265+
$this->breadLogger->info('about to set isTxClosed in authorize');
255266
$payment->setIsTransactionClosed(false);
256-
$payment->setTransactionId($this->getToken());
267+
$tx_id = $this->getToken();
268+
$this->breadLogger->info([
269+
'MESSAGE' => 'about to set tx_id in authorize',
270+
'tx_id' => $tx_id
271+
]);
272+
$payment->setTransactionId($tx_id);
273+
274+
$this->breadLogger->info('all payment info set in authorize');
257275

258276
$this->_place($payment, $amount, self::ACTION_AUTHORIZE);
259277
return $this;
@@ -385,13 +403,31 @@ public function order(\Magento\Payment\Model\InfoInterface $payment, $amount)
385403
protected function _place(\Magento\Payment\Model\InfoInterface $payment, $amount, $requestType)
386404
{
387405
$this->apiClient->setOrder($payment->getOrder());
406+
$this->breadLogger->info('api client order was set');
407+
388408
switch ($requestType) {
389409
case self::ACTION_AUTHORIZE:
410+
$this->breadLogger->info('about to call api client authorize');
411+
$tx_id = $this->getValidatedTxId($payment);
412+
$this->breadLogger->info('got tx_id in place authorize');
413+
$amount = ($this->priceCurrency->round($amount) * 100);
414+
$this->breadLogger->info([
415+
'MESSAGE' => 'got amount in place authorize',
416+
'amount' => $amount
417+
]);
418+
$orderId = $payment->getOrder()->getIncrementId();
419+
$this->breadLogger->info([
420+
'MESSAGE' => 'got orderId in place authorize',
421+
'orderId' => $orderId
422+
]);
423+
390424
$result = $this->apiClient->authorize(
391-
$this->getValidatedTxId($payment),
392-
($this->priceCurrency->round($amount) * 100),
393-
$payment->getOrder()->getIncrementId()
425+
$tx_id,
426+
$amount,
427+
$orderId
394428
);
429+
$this->breadLogger->info('called api client authorize');
430+
395431
$payment->setTransactionId($result['breadTransactionId']);
396432
$this->addTransactionInfo(
397433
$payment,

view/frontend/web/js/view/payment/method-renderer/breadcheckout.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ define(
175175
alert(response.error);
176176
} else {
177177
$.when(
178-
this.updateAddress(response),
178+
this.updateAddress(response, errorInfo),
179179
this.validateTotals()
180180
).done(
181181
$.proxy(
@@ -246,26 +246,35 @@ define(
246246
*
247247
* @return {jQuery.Deferred}
248248
*/
249-
updateAddress: function (data) {
249+
updateAddress: function (data, errorInfo) {
250250
var self = this;
251251
/**
252252
* Billing address
253253
*/
254+
document.logBreadIssue('info', errorInfo, 'starting update address');
255+
254256
var billingAddressData = this.getAddressData(data.billingAddress);
257+
document.logBreadIssue('info', $.extend(true, {}, errorInfo, {billingAddressData: billingAddressData}), 'got billing address data');
255258
var newBillingAddress = createBillingAddress(billingAddressData);
259+
document.logBreadIssue('info', $.extend(true, {}, errorInfo, {newBillingAddress: newBillingAddress}), 'got new billing address');
256260

257261
// New address must be selected as a billing address
258262
selectBillingAddress(newBillingAddress);
263+
document.logBreadIssue('info', errorInfo, 'selected new billing address');
259264
checkoutData.setSelectedBillingAddress(newBillingAddress.getKey());
265+
document.logBreadIssue('info', errorInfo, 'set selected billing address');
260266
checkoutData.setNewCustomerBillingAddress(billingAddressData);
267+
document.logBreadIssue('info', errorInfo, 'set new customer billing address');
261268

262269
/**
263270
* Reload checkout section & add bread token
264271
*/
265272
if(quote.isVirtual()) {
266273
return defaultProcessor;
267274
}
268-
return defaultProcessor.saveShippingInformation();
275+
var defaultProcessorSavedShipping = defaultProcessor.saveShippingInformation();
276+
document.logBreadIssue('info', $.extend(true, {}, errorInfo, {defaultProcessorSavedShipping: defaultProcessorSavedShipping}), 'default processor saved shipping info');
277+
return defaultProcessorSavedShipping;
269278
},
270279

271280
/**

0 commit comments

Comments
 (0)