nodebb-plugin-calendar-onekite 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/helloasso.js ADDED
@@ -0,0 +1,81 @@
1
+ 'use strict';
2
+
3
+ const fetch = require('node-fetch');
4
+
5
+ const HELLOASSO_CLIENT_ID = process.env.HELLOASSO_CLIENT_ID;
6
+ const HELLOASSO_CLIENT_SECRET = process.env.HELLOASSO_CLIENT_SECRET;
7
+ const HELLOASSO_ORG_SLUG = process.env.HELLOASSO_ORG_SLUG;
8
+ const HELLOASSO_FORM_SLUG = process.env.HELLOASSO_FORM_SLUG;
9
+ const HELLOASSO_API_BASE = 'https://api.helloasso.com';
10
+
11
+ async function getHelloAssoAccessToken() {
12
+ if (!HELLOASSO_CLIENT_ID || !HELLOASSO_CLIENT_SECRET) {
13
+ throw new Error('[HelloAsso] HELLOASSO_CLIENT_ID/SECRET non définis');
14
+ }
15
+
16
+ const res = await fetch(`${HELLOASSO_API_BASE}/oauth2/token`, {
17
+ method: 'POST',
18
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
19
+ body: new URLSearchParams({
20
+ grant_type: 'client_credentials',
21
+ client_id: HELLOASSO_CLIENT_ID,
22
+ client_secret: HELLOASSO_CLIENT_SECRET
23
+ })
24
+ });
25
+
26
+ if (!res.ok) {
27
+ const txt = await res.text();
28
+ throw new Error('[HelloAsso] échec OAuth2: ' + txt);
29
+ }
30
+ const data = await res.json();
31
+ return data.access_token;
32
+ }
33
+
34
+ async function createHelloAssoCheckoutIntent({ eid, rid, uid, itemId, quantity, amount }) {
35
+ if (!HELLOASSO_ORG_SLUG || !HELLOASSO_FORM_SLUG) {
36
+ console.warn('[calendar-lite] HelloAsso non configuré, retournera une URL générique.');
37
+ return 'https://www.helloasso.com/';
38
+ }
39
+
40
+ const token = await getHelloAssoAccessToken();
41
+
42
+ const body = {
43
+ items: [{
44
+ name: `Réservation ${itemId} (événement ${eid})`,
45
+ quantity,
46
+ amount: Math.round(amount * 100)
47
+ }],
48
+ customFields: {
49
+ eid,
50
+ rid,
51
+ uid,
52
+ itemId,
53
+ quantity
54
+ },
55
+ returnUrl: 'https://tonforum.fr/calendar/payment/ok',
56
+ cancelUrl: 'https://tonforum.fr/calendar/payment/cancel'
57
+ };
58
+
59
+ const url = `${HELLOASSO_API_BASE}/v5/organizations/${HELLOASSO_ORG_SLUG}/forms/${HELLOASSO_FORM_SLUG}/checkout-intents`;
60
+
61
+ const res = await fetch(url, {
62
+ method: 'POST',
63
+ headers: {
64
+ Authorization: 'Bearer ' + token,
65
+ 'Content-Type': 'application/json'
66
+ },
67
+ body: JSON.stringify(body)
68
+ });
69
+
70
+ if (!res.ok) {
71
+ const txt = await res.text();
72
+ throw new Error('[HelloAsso] erreur CheckoutIntent: ' + txt);
73
+ }
74
+
75
+ const data = await res.json();
76
+ return data.redirectUrl || data.paymentUrl || 'https://www.helloasso.com/';
77
+ }
78
+
79
+ module.exports = {
80
+ createHelloAssoCheckoutIntent,
81
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-calendar-onekite",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,6 +16,7 @@
16
16
  "files": [
17
17
  "plugin.json",
18
18
  "library.js",
19
+ "helloasso.js",
19
20
  "templates/",
20
21
  "static/"
21
22
  ]
package/plugin.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "Calendar Onekite",
4
4
  "description": "Calendrier + réservation de matériel + validation admin + paiement HelloAsso pour NodeBB v4",
5
5
  "url": "",
6
- "version": "1.0.2",
6
+ "version": "1.0.3",
7
7
  "library": "./library.js",
8
8
  "staticDirs": {
9
9
  "static": "static"