Skip to content

Commit

Permalink
[ECP-9491] Handle single card payments for multishipping orders
Browse files Browse the repository at this point in the history
  • Loading branch information
Can Demiralp committed Oct 16, 2024
1 parent a99423c commit c33b305
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ define(
quote.billingAddress() != null),
comboCardOption: ko.observable('credit'),
checkoutComponent: null,
cardComponent: null,

defaults: {
template: 'Adyen_Payment/payment/cc-form',
Expand Down Expand Up @@ -545,6 +546,9 @@ define(
}
return quote.totals().grand_total;
},
getPaymentMethodComponent: function () {
return this.cardComponent;
}
});
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
define([
'jquery',
'ko',
'Adyen_Payment/js/view/payment/method-renderer/adyen-cc-method'
'Adyen_Payment/js/view/payment/method-renderer/adyen-cc-method',
'Magento_Checkout/js/model/full-screen-loader'
], function (
$,
ko,
Component
Component,
fullScreenLoader
) {
'use strict';
return Component.extend({
paymentMethodReady: ko.observable(false),
isTemplateRendered: ko.observable(false),
defaults: {
template: 'Adyen_Payment/payment/multishipping/cc-form'
},
Expand All @@ -29,6 +32,47 @@ define([
this.paymentMethodReady(paymentMethodsResponse);
},

selectPaymentMethod: function () {
fullScreenLoader.startLoader();
let self = this;

this.isTemplateRendered.subscribe(function (response) {
self.initializeMultishippingPaymentMethod();
})
if (this.isTemplateRendered()) {
this.initializeMultishippingPaymentMethod();
}

return true;
},

// This will return a promise once the payment component is created and mounted.
createMultishippingCheckoutComponent: async function () {
await this.createCheckoutComponent();
return true;
},

initializeMultishippingPaymentMethod: function () {
let self = this;

this.createMultishippingCheckoutComponent().then(function (status) {
if (status) {
let paymentComponent = self.getPaymentMethodComponent();

// Remove previously assigned event listeners
$("#payment-continue").off();
// Assign event listener for component validation
$("#payment-continue").on("click", function () {
paymentComponent.showValidation();
});
} else {
console.warn('Payment component could not be generated!');
}

fullScreenLoader.stopLoader();
});
},

buildComponentConfiguration: function () {
let self = this;
let baseComponentConfiguration = this._super();
Expand All @@ -39,7 +83,12 @@ define([
self.storeCc = !!state.data.storePaymentMethod;
};

return baseComponentConfiguration
return baseComponentConfiguration;
},

// Observable is set to true after div element in `cc-form.html` template is rendered
setIsTemplateRendered: function () {
this.isTemplateRendered(true);
}
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<div class="field number cardContainerField">
<div class="checkout-component-dock" data-bind="attr: { id: 'cardContainer'}">
<div class="checkout-component-dock"
data-bind="attr: { id: 'cardContainer'}"
afterRender="setIsTemplateRendered()">
</div>
</div>

0 comments on commit c33b305

Please sign in to comment.