|
1 | 1 | "use strict"; |
2 | 2 |
|
| 3 | +const COMMUNITY_EDITION_REGISTER_URL = API_BASE_URL + '/licenses/hub/register'; |
| 4 | + |
3 | 5 | const BILLING_PORTAL_SESSION_URL = LEGACY_STORE_URL + '/hub/billing-portal-session'; |
4 | 6 | const CUSTOM_BILLING_URL = LEGACY_STORE_URL + '/hub/custom-billing'; |
5 | 7 | const GENERATE_PAY_LINK_URL = LEGACY_STORE_URL + '/hub/generate-pay-link'; |
6 | 8 | const MANAGE_SUBSCRIPTION_URL = LEGACY_STORE_URL + '/hub/manage-subscription'; |
7 | 9 | const UPDATE_PAYMENT_METHOD_URL = LEGACY_STORE_URL + '/hub/update-payment-method'; |
8 | 10 |
|
| 11 | +class CommunityEdition { |
| 12 | + |
| 13 | + constructor(form, registrationData, searchParams) { |
| 14 | + this._form = form; |
| 15 | + this._registrationData = registrationData; |
| 16 | + this._registrationData.hubId = searchParams.get('hub_id'); |
| 17 | + this._registrationData.returnUrl = searchParams.get('return_url'); |
| 18 | + } |
| 19 | + |
| 20 | + register() { |
| 21 | + if (!this._registrationData.captcha) { |
| 22 | + this._registrationData.errorMessage = 'Please complete the CAPTCHA challenge.'; |
| 23 | + return; |
| 24 | + } |
| 25 | + |
| 26 | + this._registrationData.inProgress = true; |
| 27 | + this._registrationData.errorMessage = ''; |
| 28 | + $.ajax({ |
| 29 | + url: COMMUNITY_EDITION_REGISTER_URL, |
| 30 | + type: 'POST', |
| 31 | + data: { |
| 32 | + captcha: this._registrationData.captcha, |
| 33 | + hubId: this._registrationData.hubId, |
| 34 | + email: this._registrationData.email |
| 35 | + } |
| 36 | + }).done(token => { |
| 37 | + this.onRegisterSucceeded(token); |
| 38 | + }).fail(xhr => { |
| 39 | + this.onRegisterFailed('Registering Hub failed.'); |
| 40 | + }); |
| 41 | + } |
| 42 | + |
| 43 | + onRegisterSucceeded(token) { |
| 44 | + this._registrationData.inProgress = false; |
| 45 | + this._registrationData.errorMessage = ''; |
| 46 | + if (this._registrationData.returnUrl && this._registrationData.returnUrl.length > 0) { |
| 47 | + const returnUrl = new URL(this._registrationData.returnUrl); |
| 48 | + returnUrl.searchParams.set('token', token); |
| 49 | + window.location.href = returnUrl; |
| 50 | + } else { |
| 51 | + console.warn('No return URL specified, cannot transfer token to Hub.', token); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + onRegisterFailed(error) { |
| 56 | + this._registrationData.inProgress = false; |
| 57 | + this._registrationData.errorMessage = error; |
| 58 | + } |
| 59 | + |
| 60 | +} |
| 61 | + |
9 | 62 | class HubSubscription { |
10 | 63 |
|
11 | 64 | constructor(form, subscriptionData, searchParams) { |
|
0 commit comments