Skip to content

Commit b37ca3e

Browse files
authored
[ECP-9940] Observe countyId before mounting the checkout component (#3282)
1 parent 8b9c2ec commit b37ca3e

5 files changed

Lines changed: 65 additions & 35 deletions

File tree

view/frontend/web/js/view/payment/method-renderer/adyen-cc-method.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,28 @@ define(
149149
},
150150
// Build AdyenCheckout library and creates the payment method component
151151
createCheckoutComponent: async function () {
152-
if (!this.checkoutComponent) {
153-
const paymentMethodsResponse = adyenPaymentService.getPaymentMethods();
154-
const countryCode = quote.billingAddress().countryId;
155-
156-
this.checkoutComponent = await adyenCheckout.buildCheckoutComponent(
157-
paymentMethodsResponse(),
158-
countryCode,
159-
this.handleOnAdditionalDetails.bind(this)
160-
)
161-
}
152+
const billingAddressObservable = quote.billingAddress;
153+
let self = this;
154+
155+
if (billingAddressObservable() && billingAddressObservable().countryId) {
156+
if (!this.checkoutComponent) {
157+
const paymentMethodsResponse = adyenPaymentService.getPaymentMethods();
158+
159+
this.checkoutComponent = await adyenCheckout.buildCheckoutComponent(
160+
paymentMethodsResponse(),
161+
billingAddressObservable().countryId,
162+
this.handleOnAdditionalDetails.bind(this)
163+
)
164+
}
162165

163-
this.renderCCPaymentMethod();
166+
this.renderCCPaymentMethod();
167+
} else {
168+
billingAddressObservable.subscribe(function (updatedBillingAddress) {
169+
if (updatedBillingAddress && updatedBillingAddress.countryId) {
170+
self.createCheckoutComponent();
171+
}
172+
});
173+
}
164174
},
165175
/**
166176
* Returns true if card details can be stored

view/frontend/web/js/view/payment/method-renderer/adyen-cc-vault-method.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,28 @@ define([
130130

131131
// Build AdyenCheckout library and creates the payment method component
132132
createCheckoutComponent: async function() {
133-
if (!this.checkoutComponent) {
134-
const paymentMethodsResponse = adyenPaymentService.getPaymentMethods();
135-
const countryCode = quote.billingAddress().countryId;
136-
137-
this.checkoutComponent = await adyenCheckout.buildCheckoutComponent(
138-
paymentMethodsResponse(),
139-
countryCode,
140-
this.handleOnAdditionalDetails.bind(this)
141-
);
142-
}
133+
const billingAddressObservable = quote.billingAddress;
134+
let self = this;
143135

144-
this.renderCheckoutComponent();
136+
if (billingAddressObservable() && billingAddressObservable().countryId) {
137+
if (!this.checkoutComponent) {
138+
const paymentMethodsResponse = adyenPaymentService.getPaymentMethods();
139+
140+
this.checkoutComponent = await adyenCheckout.buildCheckoutComponent(
141+
paymentMethodsResponse(),
142+
billingAddressObservable().countryId,
143+
this.handleOnAdditionalDetails.bind(this)
144+
);
145+
}
146+
147+
this.renderCheckoutComponent();
148+
} else {
149+
billingAddressObservable.subscribe(function (updatedBillingAddress) {
150+
if (updatedBillingAddress && updatedBillingAddress.countryId) {
151+
self.createCheckoutComponent();
152+
}
153+
});
154+
}
145155
},
146156

147157
handleOnAdditionalDetails: function (result) {

view/frontend/web/js/view/payment/method-renderer/adyen-giftcard-method.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ define(
5555
selectedGiftcardPaymentMethod: ko.observable(null),
5656
giftcardTitle: ko.observable(null),
5757
icon: ko.observable(window.checkoutConfig.payment.adyen.giftcard.icon),
58+
billingAddressAvailable: ko.observable(false),
5859

5960
initialize: async function () {
6061
this._super();
@@ -74,6 +75,8 @@ define(
7475
this.fetchGiftcardPaymentMethods(paymentMethodsObserver());
7576
this.fetchRedeemedGiftcards();
7677
}
78+
79+
this.billingAddressAvailable(quote.billingAddress() !== null);
7780
},
7881

7982
addNewGiftcard: function () {

view/frontend/web/js/view/payment/method-renderer/adyen-pm-method.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ define(
8080

8181
this._lastGrandTotal = undefined;
8282

83+
// This event is triggered when the total changes or billing address is added (virtual products)
8384
quote.totals.subscribe(function (totals) {
8485
if (!totals) {
8586
return;
@@ -177,20 +178,24 @@ define(
177178

178179
// Build AdyenCheckout library and creates the payment method component
179180
createCheckoutComponent: async function(forceCreate = false) {
180-
if (!this.checkoutComponent || forceCreate) {
181-
const paymentMethodsResponse = adyenPaymentService.getPaymentMethods();
182-
const countryCode = quote.billingAddress().countryId;
183-
184-
this.checkoutComponent = await adyenCheckout.buildCheckoutComponent(
185-
paymentMethodsResponse(),
186-
countryCode,
187-
this.handleOnAdditionalDetails.bind(this),
188-
this.handleOnCancel.bind(this),
189-
this.handleOnSubmit.bind(this),
190-
this.handleOnError.bind(this)
191-
);
181+
const billingAddressObservable = quote.billingAddress;
182+
let self = this;
192183

193-
this.renderCheckoutComponent();
184+
if (billingAddressObservable() && billingAddressObservable().countryId) {
185+
if (!this.checkoutComponent || forceCreate) {
186+
const paymentMethodsResponse = adyenPaymentService.getPaymentMethods();
187+
188+
this.checkoutComponent = await adyenCheckout.buildCheckoutComponent(
189+
paymentMethodsResponse(),
190+
billingAddressObservable().countryId,
191+
this.handleOnAdditionalDetails.bind(this),
192+
this.handleOnCancel.bind(this),
193+
this.handleOnSubmit.bind(this),
194+
this.handleOnError.bind(this)
195+
);
196+
197+
this.renderCheckoutComponent();
198+
}
194199
}
195200
},
196201

view/frontend/web/template/payment/giftcard-form.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<!--/ko-->
4444
</div>
4545

46+
<!-- ko if: billingAddressAvailable -->
4647
<div data-bind="attr: {'id': getCode() + '_new_giftcard_wrapper'}">
4748
<div class="field" data-bind="attr: {'id': getCode() + '_giftcard_button_wrapper'}, visible: canAddNewGiftCard">
4849
<button data-bind="click: addNewGiftcard, attr: {'class': 'adyen-checkout__button'}">
@@ -59,6 +60,7 @@
5960
</select>
6061
</div>
6162
</div>
63+
<!-- /ko -->
6264

6365
<h2 data-bind="attr: {'class': 'adyen-giftcard-header'}, visible: giftcardTitle, text: giftcardTitle"></h2>
6466
<div class="field" data-bind="attr: {'id': 'giftcard-component-wrapper'}"></div>

0 commit comments

Comments
 (0)