Skip to content

Commit

Permalink
refactor: remove console logging, return early
Browse files Browse the repository at this point in the history
  • Loading branch information
bashunaimiroy committed Mar 8, 2024
1 parent 9c4d1af commit afaf19c
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions theme/assets/js/templates/store/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ document.addEventListener('alpine:init', () => {
});

const createAfterpayBadgeData = () => ({
isLoading: true,
payments: null,
paymentAmount: null,
selector: '.afterpay-placement',
Expand All @@ -507,11 +506,11 @@ document.addEventListener('alpine:init', () => {
*
* @param {String} applicationId the application id
* @param {String} locationId the location id
* @return {Object}
* @return {Object|null}
*/
initWebPaymentsSDK(applicationId, locationId) {
if (!this.webPaymentsSDKLoaded()) {
console.error('Web Payments SDK not loaded');
return null;
}

const Square = window.Square;
Expand All @@ -531,6 +530,9 @@ document.addEventListener('alpine:init', () => {
const locationId = Alpine.store('product').locationId;
const storeLocale = Alpine.store('global').locale;
const payments = this.initWebPaymentsSDK(applicationId, locationId);
if (!payments) {
return;
}
payments.setLocale(storeLocale);
this.payments = payments;

Expand All @@ -546,18 +548,10 @@ document.addEventListener('alpine:init', () => {
this.attachAfterpayMessaging();
},
async attachAfterpayMessaging() {
this.isLoading = true;
this.error = null;

try {
const paymentRequest = this.buildPaymentRequest(this.paymentAmount);
const afterpay = await this.payments.afterpayClearpay(paymentRequest);
this.cleanupAfterpayMessaging();
await afterpay.attachMessaging(this.selector, Constants.AFTERPAY_MESSAGING_OPTIONS);
this.isLoading = false;
} catch (err) {
console.error(err);
}
const paymentRequest = this.buildPaymentRequest(this.paymentAmount);
const afterpay = await this.payments.afterpayClearpay(paymentRequest);
this.cleanupAfterpayMessaging();
await afterpay.attachMessaging(this.selector, Constants.AFTERPAY_MESSAGING_OPTIONS);
},

/**
Expand Down

0 comments on commit afaf19c

Please sign in to comment.