Skip to content

Commit 72ccac4

Browse files
committed
Merge branch 'feature/api-migration' into develop
2 parents 52d714c + 087b063 commit 72ccac4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+397
-405
lines changed

.github/workflows/gh-pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969

7070
# DEPLOY STAGING
7171
deploy-staging:
72-
if: github.ref == 'refs/heads/feature/api-migration'
72+
if: github.ref == 'refs/heads/develop'
7373
name: Deploy Staging to GitHub Pages
7474
runs-on: ubuntu-latest
7575
needs: [build]

assets/js/androidkey.js

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,60 @@
11
"use strict";
22

3-
// requires newsletter.js
4-
53
class AndroidLicense {
64

75
constructor(form, checkoutData) {
86
this._form = form;
97
this._checkoutData = checkoutData;
108
this._paddle = $.ajax({
11-
url: 'https://cdn.paddle.com/paddle/paddle.js',
9+
url: 'https://cdn.paddle.com/paddle/v2/paddle.js',
1210
cache: true,
1311
dataType: 'script'
1412
}).then(() => {
1513
if (PADDLE_ENABLE_SANDBOX) {
1614
window.Paddle.Environment.set('sandbox');
1715
}
18-
window.Paddle.Setup({ vendor: PADDLE_VENDOR_ID });
16+
window.Paddle.Initialize({
17+
token: PADDLE_TOKEN,
18+
eventCallback: data => {
19+
if (data.name == "checkout.completed") {
20+
this.onCheckoutSucceeded();
21+
} else if (data.name == "checkout.closed") {
22+
this._checkoutData.inProgress = false;
23+
}
24+
}
25+
});
1926
return window.Paddle;
2027
});
2128
}
2229

2330
loadPrice() {
24-
$.ajax({
25-
url: PADDLE_PRICES_URL,
26-
dataType: 'jsonp',
27-
data: {
28-
product_ids: PADDLE_ANDROID_PRODUCT_ID
29-
},
30-
}).done(data => {
31-
this._checkoutData.price = {
32-
amount: data.response.products[0].price.gross,
33-
listAmount: data.response.products[0].list_price.gross,
34-
currency: data.response.products[0].currency
31+
this._paddle.then(paddle => {
32+
let request = {
33+
items: [{ priceId: PADDLE_ANDROID_PRICE_ID, quantity: 1}]
3534
};
35+
paddle.PricePreview(request).then(result => {
36+
this._checkoutData.price = {
37+
currencyCode: result.data.currencyCode,
38+
amount: result.data.details.lineItems[0].totals.total,
39+
formattedAmount: result.data.details.lineItems[0].formattedTotals.total
40+
};
41+
}).catch(() => {
42+
this._checkoutData.errorMessage = 'Retrieving price failed. Please try again later.';
43+
});
44+
// let discountedRequest = {
45+
// items: [{ priceId: PADDLE_ANDROID_PRICE_ID, quantity: 1}],
46+
// discountId: 'dsc_',
47+
// };
48+
// paddle.PricePreview(discountedRequest).then(discountedResult => {
49+
// if (Number(discountedResult.data.details.lineItems[0].totals.discount) > 0) {
50+
// this._checkoutData.discountedPrice = {
51+
// amount: discountedResult.data.details.lineItems[0].totals.total,
52+
// formattedAmount: discountedResult.data.details.lineItems[0].formattedTotals.total
53+
// };
54+
// }
55+
// }).catch(error => {
56+
// this._checkoutData.errorMessage = 'Retrieving discounted price failed. Please try again later.';
57+
// });
3658
});
3759
}
3860

@@ -48,33 +70,9 @@ class AndroidLicense {
4870
this._checkoutData.success = false;
4971
this._paddle.then(paddle => {
5072
paddle.Checkout.open({
51-
product: PADDLE_ANDROID_PRODUCT_ID,
52-
email: this._checkoutData.email,
53-
allowQuantity: false,
54-
locale: locale,
55-
successCallback: data => {
56-
this.onCheckoutSucceeded();
57-
this.getPaddleOrderDetails(data.checkout.id);
58-
if (this._checkoutData.acceptNewsletter) {
59-
subscribeToNewsletter(data.user.email, 6);
60-
}
61-
},
62-
closeCallback: () => {
63-
this._checkoutData.inProgress = false;
64-
}
65-
});
66-
});
67-
}
68-
69-
getPaddleOrderDetails(checkoutId) {
70-
this._paddle.then(paddle => {
71-
paddle.Order.details(checkoutId, data => {
72-
let licenseKey = data.lockers?.[0]?.license_code;
73-
if (licenseKey) {
74-
this._checkoutData.licenseKey = licenseKey;
75-
} else {
76-
this._checkoutData.errorMessage = 'Retrieving license key failed. Please check your emails instead.';
77-
}
73+
settings: { locale: locale },
74+
items: [{ priceId: PADDLE_ANDROID_PRICE_ID, quantity: 1 }],
75+
customer: { email: this._checkoutData.email }
7876
});
7977
});
8078
}

assets/js/base.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ function determineGlobalData(locale, globalData) {
3030
}
3131

3232
function determineGitHubStargazersCount(locale, globalData) {
33-
$.getJSON('https://api.cryptomator.org/desktop/repo.json', data => {
33+
$.getJSON(`${API_BASE_URL}/connect/social/github`, data => {
3434
globalData.githubStargazers = formatNumber(data.stargazers_count, locale);
3535
}).fail(() => {
3636
console.error('Error fetching repository data.');
3737
});
3838
}
3939

4040
function determineMastodonFollowersCount(locale, globalData) {
41-
$.getJSON('https://api.cryptomator.org/social/mastodon.json', data => {
41+
$.getJSON(`${API_BASE_URL}/connect/social/mastodon`, data => {
4242
globalData.mastodonFollowers = formatNumber(data.followers_count, locale);
4343
}).fail(() => {
4444
console.error('Error fetching Mastodon data.');

assets/js/cardpayments.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
const STRIPE_PHP_URL = LEGACY_API_URL + '/stripe/prepare_payment.php';
3+
const STRIPE_PREPARE_PAYMENT_URL = API_BASE_URL + '/donations/stripe/payments/prepare';
44

55
class OneTimePayment {
66

@@ -85,7 +85,7 @@ class OneTimePayment {
8585
this._status.success = false;
8686

8787
let preparedPayment = $.ajax({
88-
url: STRIPE_PHP_URL,
88+
url: STRIPE_PREPARE_PAYMENT_URL,
8989
type: 'POST',
9090
data: {
9191
currency: currency,

assets/js/const.template.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"use strict";
22

3-
const API_BASE_URL = '{{ .Site.Params.apiBaseURL }}';
3+
const API_BASE_URL = '{{ .Site.Params.apiBaseUrl }}';
44
const LEGACY_API_URL = '{{ .Site.Params.legacyApiUrl }}';
55
const PADDLE_ENABLE_SANDBOX = {{ .Site.Params.paddleEnableSandbox }};
6+
const PADDLE_TOKEN = '{{ .Site.Params.paddleToken }}';
67
const PADDLE_VENDOR_ID = {{ .Site.Params.paddleVendorId }};
7-
const PADDLE_DESKTOP_PRODUCT_IDS = {{ .Site.Params.paddleDesktopProductIds | jsonify }};
8-
const PADDLE_ANDROID_PRODUCT_ID = {{ .Site.Params.paddleAndroidProductId }};
8+
const PADDLE_DESKTOP_PRICE_IDS = {{ .Site.Params.paddleDesktopPriceIds | jsonify }};
9+
const PADDLE_ANDROID_PRICE_ID = '{{ .Site.Params.paddleAndroidPriceId }}';
910
const PADDLE_HUB_SELF_HOSTED_SUBSCRIPTION_PLAN_ID = {{ .Site.Params.paddleHubSelfHostedSubscriptionPlanId }};
1011
const PADDLE_HUB_MANAGED_SUBSCRIPTION_PLAN_ID = {{ .Site.Params.paddleHubManagedSubscriptionPlanId }};
1112
const PADDLE_PRICES_URL = '{{ .Site.Params.paddlePricesUrl }}';

assets/js/customerportal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
const REQUEST_CUSTOMER_PORTAL_URL = LEGACY_API_URL + '/stripe/request_customer_portal.php';
3+
const REQUEST_CUSTOMER_PORTAL_URL = API_BASE_URL + '/donations/stripe/portal/request-link';
44

55
class CustomerPortal {
66

assets/js/desktopkey.js

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,67 @@
11
"use strict";
22

3-
// requires newsletter.js
4-
53
class DesktopLicense {
64

75
constructor(form, checkoutData) {
86
this._form = form;
97
this._checkoutData = checkoutData;
108
this._paddle = $.ajax({
11-
url: 'https://cdn.paddle.com/paddle/paddle.js',
9+
url: 'https://cdn.paddle.com/paddle/v2/paddle.js',
1210
cache: true,
1311
dataType: 'script'
1412
}).then(() => {
1513
if (PADDLE_ENABLE_SANDBOX) {
1614
window.Paddle.Environment.set('sandbox');
1715
}
18-
window.Paddle.Setup({ vendor: PADDLE_VENDOR_ID });
16+
window.Paddle.Initialize({
17+
token: PADDLE_TOKEN,
18+
eventCallback: data => {
19+
if (data.name == "checkout.completed") {
20+
this.onCheckoutSucceeded();
21+
} else if (data.name == "checkout.closed") {
22+
this._checkoutData.inProgress = false;
23+
}
24+
}
25+
});
1926
return window.Paddle;
2027
});
2128
}
2229

2330
loadPrice() {
24-
$.ajax({
25-
url: PADDLE_PRICES_URL,
26-
dataType: 'jsonp',
27-
data: {
28-
product_ids: PADDLE_DESKTOP_PRODUCT_IDS.join(',')
29-
},
30-
}).done(data => {
31-
this._checkoutData.prices = data.response.products.map(product => {
32-
return {
33-
productId: product.product_id,
34-
amount: product.price.gross,
35-
listAmount: product.list_price.gross,
36-
currency: product.currency
37-
}
31+
this._paddle.then(paddle => {
32+
let request = {
33+
items: PADDLE_DESKTOP_PRICE_IDS.map(priceId => ({ priceId: priceId, quantity: 1 }))
34+
};
35+
paddle.PricePreview(request).then(result => {
36+
this._checkoutData.prices = result.data.details.lineItems.map(item => {
37+
return {
38+
priceId: item.price.id,
39+
currencyCode: result.data.currencyCode,
40+
amount: item.totals.total,
41+
formattedAmount: item.formattedTotals.total
42+
}
43+
});
44+
}).catch(() => {
45+
this._checkoutData.errorMessage = 'Retrieving prices failed. Please try again later.';
3846
});
47+
// let discountedRequest = {
48+
// items: [{ priceId: PADDLE_DESKTOP_PRICE_IDS[0], quantity: 1 }],
49+
// discountId: 'dsc_',
50+
// };
51+
// paddle.PricePreview(discountedRequest).then(discountedResult => {
52+
// if (Number(discountedResult.data.details.lineItems[0].totals.discount) > 0) {
53+
// this._checkoutData.discountedPrice = {
54+
// amount: discountedResult.data.details.lineItems[0].totals.total,
55+
// formattedAmount: discountedResult.data.details.lineItems[0].formattedTotals.total
56+
// };
57+
// }
58+
// }).catch(() => {
59+
// this._checkoutData.errorMessage = 'Retrieving discounted price failed. Please try again later.';
60+
// });
3961
});
4062
}
4163

42-
checkout(productId, locale) {
64+
checkout(priceId, locale) {
4365
if (!$(this._form)[0].checkValidity()) {
4466
$(this._form).find(':input').addClass('show-invalid');
4567
this._checkoutData.errorMessage = 'Please fill in all required fields.';
@@ -51,33 +73,9 @@ class DesktopLicense {
5173
this._checkoutData.success = false;
5274
this._paddle.then(paddle => {
5375
paddle.Checkout.open({
54-
product: productId,
55-
email: this._checkoutData.email,
56-
quantity: this._checkoutData.quantity,
57-
locale: locale,
58-
successCallback: data => {
59-
this.onCheckoutSucceeded();
60-
this.getPaddleOrderDetails(data.checkout.id);
61-
if (this._checkoutData.acceptNewsletter) {
62-
subscribeToNewsletter(data.user.email, 6);
63-
}
64-
},
65-
closeCallback: () => {
66-
this._checkoutData.inProgress = false;
67-
}
68-
});
69-
});
70-
}
71-
72-
getPaddleOrderDetails(checkoutId) {
73-
this._paddle.then(paddle => {
74-
paddle.Order.details(checkoutId, data => {
75-
let licenseKey = data.lockers?.[0]?.license_code;
76-
if (licenseKey) {
77-
this._checkoutData.licenseKey = licenseKey;
78-
} else {
79-
this._checkoutData.errorMessage = 'Retrieving supporter certificate failed. Please check your emails instead.';
80-
}
76+
settings: { locale: locale },
77+
items: [{ priceId: priceId, quantity: this._checkoutData.quantity }],
78+
customer: { email: this._checkoutData.email }
8179
});
8280
});
8381
}

assets/js/hubcontact.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
const REQUEST_HUB_CONTACT_URL = LEGACY_STORE_URL + '/hub/request-contact';
3+
const REQUEST_HUB_CONTACT_URL = API_BASE_URL + '/connect/contact/request-contact';
44

55
class HubContact {
66

@@ -24,12 +24,10 @@ class HubContact {
2424
$.ajax({
2525
url: REQUEST_HUB_CONTACT_URL,
2626
type: 'POST',
27-
data: this._submitData
27+
data: JSON.stringify(this._submitData),
28+
contentType: "application/json; charset=utf-8",
2829
}).done(_ => {
2930
this.onRequestSucceeded();
30-
if (this._submitData.acceptNewsletter) {
31-
subscribeToNewsletter(this._submitData.email, 7);
32-
}
3331
}).fail(xhr => {
3432
this.onRequestFailed(xhr.responseJSON?.message || 'Request failed.');
3533
});

assets/js/hubmanaged.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class HubManaged {
111111
}).done(_ => {
112112
this.onRequestSucceeded();
113113
if (this._submitData.acceptNewsletter) {
114-
subscribeToNewsletter(this._submitData.email, 7);
114+
subscribeToNewsletter(this._submitData.email, 7); // FIXME move to backend
115115
}
116116
}).fail(xhr => {
117117
this.onRequestFailed(xhr.responseJSON?.message || 'Requesting Hub Managed failed.');

assets/js/keyrecovery.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)