@@ -4,6 +4,7 @@ const BILLING_SESSION_URL = API_BASE_URL + '/billing/session';
44const BILLING_CUSTOMER_URL = API_BASE_URL + '/billing/customers/by-hub-id';
55const CARD_CHECKOUT_URL = API_BASE_URL + '/billing/paddle-classic/checkout';
66const INVOICE_CHECKOUT_URL = API_BASE_URL + '/billing/espocrm/checkout';
7+ const INVOICE_PRICE_URL = API_BASE_URL + '/billing/espocrm/checkout/price';
78const MANAGE_SUBSCRIPTION_BASE_URL = API_BASE_URL + '/billing/manage/subscription';
89const CUSTOM_BILLING_URL = LEGACY_STORE_URL + '/hub/custom-billing';
910const GET_LICENSE_URL = API_BASE_URL + '/licenses/hub';
@@ -430,6 +431,35 @@ class HubSubscription {
430431 });
431432 }
432433
434+ invoiceProductId() {
435+ return this._subscriptionData.customBilling?.managed ? ESPOCRM_HUB_MANAGED_PRODUCT_ID : ESPOCRM_HUB_SELF_HOSTED_PRODUCT_ID;
436+ }
437+
438+ loadInvoicePrice() {
439+ if (this._subscriptionData.invoicePrice || !this.invoiceProductId()) {
440+ return;
441+ }
442+ $.ajax({
443+ url: INVOICE_PRICE_URL,
444+ type: 'GET',
445+ data: {
446+ product_id: this.invoiceProductId()
447+ }
448+ }).done(data => {
449+ this._subscriptionData.invoicePrice = data;
450+ });
451+ }
452+
453+ askForInvoiceConfirmation() {
454+ if (!$(this._form)[0].checkValidity()) {
455+ $(this._form).find(':input').addClass('show-invalid');
456+ this._subscriptionData.errorMessage = 'Please fill in all required fields.';
457+ return;
458+ }
459+ this._subscriptionData.errorMessage = '';
460+ this._subscriptionData.invoiceConfirmModal.open = true;
461+ }
462+
433463 invoiceCheckout() {
434464 if (!$(this._form)[0].checkValidity()) {
435465 $(this._form).find(':input').addClass('show-invalid');
@@ -446,7 +476,7 @@ class HubSubscription {
446476 data: {
447477 captcha: this._subscriptionData.invoiceCaptcha,
448478 hub_id: this._subscriptionData.hubId,
449- product_id: this.selectedPlanId (),
479+ product_id: this.invoiceProductId (),
450480 quantity: this._subscriptionData.quantity,
451481 session: this._subscriptionData.session,
452482 account_name: invoice.account_name,
@@ -468,6 +498,7 @@ class HubSubscription {
468498
469499 onCheckoutSucceeded() {
470500 this._subscriptionData.state = 'CHECKOUT_SUCCESS';
501+ this._subscriptionData.invoiceConfirmModal.open = false;
471502 this._subscriptionData.errorMessage = '';
472503 this._subscriptionData.inProgress = false;
473504 this._subscriptionData.shouldTransferToHub = !!this._subscriptionData.returnUrl;
@@ -542,6 +573,7 @@ class HubSubscription {
542573 openChangeSeatsModal() {
543574 this._subscriptionData.quantity = this._subscriptionData.details.seats;
544575 this._subscriptionData.changeSeatsModal.nextPayment = null;
576+ this._subscriptionData.changeSeatsModal.invoicePreview = null;
545577 this._subscriptionData.changeSeatsModal.confirmation = false;
546578 this._subscriptionData.changeSeatsModal.open = true;
547579 }
@@ -554,7 +586,7 @@ class HubSubscription {
554586 }
555587
556588 this._subscriptionData.changeSeatsModal.confirmation = true;
557- if (this._subscriptionData.details.processor == 'PADDLE_CLASSIC') {
589+ if (this._subscriptionData.details.processor == 'PADDLE_CLASSIC' || this._subscriptionData.details.processor == 'ESPOCRM' ) {
558590 this.previewChangeQuantity();
559591 }
560592 }
@@ -571,6 +603,7 @@ class HubSubscription {
571603 }
572604 }).done(data => {
573605 this._subscriptionData.changeSeatsModal.nextPayment = data.next_payment;
606+ this._subscriptionData.changeSeatsModal.invoicePreview = data.prorated_amount != null ? data : null;
574607 this._subscriptionData.errorMessage = '';
575608 this._subscriptionData.inProgress = false;
576609 }).fail(xhr => {
0 commit comments