Skip to content

Commit f722818

Browse files
committed
Add invoice order summary with exact EspoCRM pricing and prorated seat-change preview
1 parent 78b57b1 commit f722818

8 files changed

Lines changed: 187 additions & 8 deletions

File tree

‎assets/js/const.template.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const PADDLE_HUB_MANAGED_MONTHLY_PLAN_ID = {{ .Site.Params.paddleHubManagedMonth
1313
const PADDLE_PRICES_URL = '{{ .Site.Params.paddlePricesUrl }}';
1414
const PADDLE_DESKTOP_SALE_PRICE_ID = '{{ .Site.Params.paddleDesktopSalePriceId }}';
1515
const PADDLE_ANDROID_SALE_PRICE_ID = '{{ .Site.Params.paddleAndroidSalePriceId }}';
16+
const ESPOCRM_HUB_SELF_HOSTED_PRODUCT_ID = '{{ .Site.Params.espocrmHubSelfHostedProductId }}';
17+
const ESPOCRM_HUB_MANAGED_PRODUCT_ID = '{{ .Site.Params.espocrmHubManagedProductId }}';
1618
const LEGACY_STORE_URL = '{{ .Site.Params.legacyStoreUrl }}';
1719
const HUB_MANAGED_DOMAIN = '{{ .Site.Params.hubManagedDomain }}';
1820
const STRIPE_PK = '{{ .Site.Params.stripePk }}';

‎assets/js/hubsubscription.js‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const BILLING_SESSION_URL = API_BASE_URL + '/billing/session';
44
const BILLING_CUSTOMER_URL = API_BASE_URL + '/billing/customers/by-hub-id';
55
const CARD_CHECKOUT_URL = API_BASE_URL + '/billing/paddle-classic/checkout';
66
const INVOICE_CHECKOUT_URL = API_BASE_URL + '/billing/espocrm/checkout';
7+
const INVOICE_PRICE_URL = API_BASE_URL + '/billing/espocrm/checkout/price';
78
const MANAGE_SUBSCRIPTION_BASE_URL = API_BASE_URL + '/billing/manage/subscription';
89
const CUSTOM_BILLING_URL = LEGACY_STORE_URL + '/hub/custom-billing';
910
const 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 => {

‎config/development/params.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@ paddlePricesUrl: https://sandbox-checkout.paddle.com/api/2.0/prices
2323
paddleDesktopSalePriceId: pri_01kk1z8f8cb5f6fnf9x7bv4xg9
2424
paddleAndroidSalePriceId: pri_01kk243hedea8mbabs8q22ygdn
2525

26+
# ESPOCRM
27+
espocrmHubSelfHostedProductId: 69bd302d5c65eabaa
28+
espocrmHubManagedProductId: 69bd302d521a70103
29+
2630
# STRIPE
2731
stripePk: pk_test_51RCM24IBZmkR4F9UiLBiSmsAnJvWqmHcDLxXR8ABKK1MNsZk3zCk2VJW7ZfaBlD81zpQxCX243sS3LEp9dABwiG800kJnGykDF

‎config/production/params.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@ paddlePricesUrl: https://checkout.paddle.com/api/2.0/prices
2323
paddleDesktopSalePriceId: pri_01kk4gejs06jg0m0n9tghk0ktr
2424
paddleAndroidSalePriceId: pri_01kk4gg6c3pj0tq0vvpf4x4vw2
2525

26+
# ESPOCRM
27+
espocrmHubSelfHostedProductId: # TODO: set production EspoCRM Self-Hosted Standard product id
28+
espocrmHubManagedProductId: # TODO: set production EspoCRM Managed Standard product id
29+
2630
# STRIPE
2731
stripePk: pk_live_eSasX216vGvC26GdbVwA011V

‎config/staging/params.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@ paddlePricesUrl: https://sandbox-checkout.paddle.com/api/2.0/prices
2323
paddleDesktopSalePriceId: pri_01kk1z8f8cb5f6fnf9x7bv4xg9
2424
paddleAndroidSalePriceId: pri_01kk243hedea8mbabs8q22ygdn
2525

26+
# ESPOCRM
27+
espocrmHubSelfHostedProductId: 69bd302d5c65eabaa
28+
espocrmHubManagedProductId: 69bd302d521a70103
29+
2630
# STRIPE
2731
stripePk: pk_test_51RCM24IBZmkR4F9UiLBiSmsAnJvWqmHcDLxXR8ABKK1MNsZk3zCk2VJW7ZfaBlD81zpQxCX243sS3LEp9dABwiG800kJnGykDF

‎i18n/de.yaml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,12 @@
588588
translation: "Du bist dabei, das Sitzplatzlimit zu verringern. Wenn du dies bestätigst, wird deine nächste Zahlung um die Differenz reduziert."
589589
- id: hub_billing_manage_change_quantity_confirmation_decrease_warning_invoice
590590
translation: "Du bist dabei, das Sitzplatzlimit zu verringern. Wenn du dies bestätigst, wird die Reduzierung auf deiner nächsten Rechnung berücksichtigt."
591+
- id: hub_billing_manage_change_quantity_confirmation_prorated_invoice
592+
translation: "Anteiliger Betrag für den laufenden Zeitraum (wird jetzt in Rechnung gestellt)"
593+
- id: hub_billing_manage_change_quantity_confirmation_prorated_credit_invoice
594+
translation: "Anteilige Gutschrift für den laufenden Zeitraum"
595+
- id: hub_billing_manage_change_quantity_confirmation_new_recurring_invoice
596+
translation: "Neuer Jahresbetrag (netto)"
591597

592598
- id: hub_billing_checkout_description
593599
translation: "Schöpfe das volle Potenzial deiner Hub-Instanz aus und hol dein Team mit der clientseitigen Verschlüsselung für deinen Cloud-Speicher an Bord."
@@ -665,6 +671,22 @@
665671
translation: "Eine Rechnung wird ausgestellt und an deine E-Mail-Adresse gesendet."
666672
- id: hub_billing_checkout_invoice_submit
667673
translation: "Auf Rechnung kaufen"
674+
- id: hub_billing_checkout_invoice_total
675+
translation: "Gesamtbetrag"
676+
- id: hub_billing_checkout_invoice_total_suffix
677+
translation: "pro Jahr (netto)"
678+
- id: hub_billing_checkout_invoice_total_vat_hint
679+
translation: "zzgl. 19 % USt."
680+
- id: hub_billing_checkout_invoice_total_reverse_charge_hint
681+
translation: "Reverse-Charge-Verfahren – Steuerschuldnerschaft des Leistungsempfängers"
682+
- id: hub_billing_checkout_invoice_confirm_title
683+
translation: "Bestellübersicht"
684+
- id: hub_billing_checkout_invoice_confirm_product
685+
translation: "Produkt"
686+
- id: hub_billing_checkout_invoice_confirm_unit_price
687+
translation: "Preis pro Seat"
688+
- id: hub_billing_checkout_invoice_confirm_billing_address
689+
translation: "Rechnungsadresse"
668690

669691
- id: hub_billing_checkout_success_description
670692
translation: "Vielen Dank für deinen Kauf! Dein Abonnement ist jetzt aktiv."

‎i18n/en.yaml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,12 @@
588588
translation: "You are about to decrease the seats limit. By confirming, your next payment will be reduced by the difference."
589589
- id: hub_billing_manage_change_quantity_confirmation_decrease_warning_invoice
590590
translation: "You are about to decrease the seats limit. By confirming, the reduction will be reflected on your next invoice."
591+
- id: hub_billing_manage_change_quantity_confirmation_prorated_invoice
592+
translation: "Prorated amount for the current period (invoiced now)"
593+
- id: hub_billing_manage_change_quantity_confirmation_prorated_credit_invoice
594+
translation: "Prorated credit for the current period"
595+
- id: hub_billing_manage_change_quantity_confirmation_new_recurring_invoice
596+
translation: "New yearly total (net)"
591597

592598
- id: hub_billing_checkout_description
593599
translation: "Unlock the full potential of your Hub instance and get your team on board with client-side encryption for your cloud storage."
@@ -665,6 +671,22 @@
665671
translation: "An invoice will be issued and sent to your email address."
666672
- id: hub_billing_checkout_invoice_submit
667673
translation: "Buy on Invoice"
674+
- id: hub_billing_checkout_invoice_total
675+
translation: "Total"
676+
- id: hub_billing_checkout_invoice_total_suffix
677+
translation: "per year (net)"
678+
- id: hub_billing_checkout_invoice_total_vat_hint
679+
translation: "plus 19% German VAT"
680+
- id: hub_billing_checkout_invoice_total_reverse_charge_hint
681+
translation: "reverse charge – VAT to be accounted for by the recipient"
682+
- id: hub_billing_checkout_invoice_confirm_title
683+
translation: "Order Summary"
684+
- id: hub_billing_checkout_invoice_confirm_product
685+
translation: "Product"
686+
- id: hub_billing_checkout_invoice_confirm_unit_price
687+
translation: "Price per Seat"
688+
- id: hub_billing_checkout_invoice_confirm_billing_address
689+
translation: "Billing Address"
668690

669691
- id: hub_billing_checkout_success_description
670692
translation: "Thank you for your purchase! Your subscription is now active."

0 commit comments

Comments
 (0)