gembapay 1.5.0 → 1.6.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog — `gembapay` (npm)
2
2
 
3
+ ## 1.6.1 — 2026-12-06
4
+
5
+ Types and README only — no runtime change.
6
+
7
+ **Changed**
8
+ - `SubscriptionEvent`: `interval` and `intervalCount` (sent on every `subscription.plan_changed` /
9
+ `subscription.plan_change_scheduled` variant), `testMode` (dashboard "Send test" samples carry it next to
10
+ `test: true`), documented `proratedRef` (null when nothing was charged).
11
+ - `reason` on `subscription.payment` (`cycle` | `plan_change`) is sent on Stripe and PayPal; it is absent only on
12
+ older deliveries (Stripe before 2026-10-29, PayPal before 2026-12-06). README shows how to branch on it.
13
+ - There is no `webhook.test` event: "Send test" sends a sample of a real event marked `"test": true`
14
+ (the SDK never listed `webhook.test`; nothing to change in code).
15
+
16
+ ## 1.6.0 — 2026-12-04
17
+
18
+ **Added**
19
+ - `createPayment({ expiresInMinutes })` — how long the payment request can be paid (whole minutes, 5 … 1440;
20
+ default 24 hours, as before).
21
+
3
22
  ## 1.5.0 — 2026-11-30
4
23
 
5
24
  Aligned with the GembaPay API as it runs today.
package/README.md CHANGED
@@ -67,7 +67,7 @@ const payment = await gembapay.createPayment({
67
67
 
68
68
  // payment → { success, orderId, paymentUrl, amountUsd: '49.99', amountOriginal: 49.99,
69
69
  // currencyOriginal: 'USD', exchangeRate: 1, allowedMethods, expiresAt }
70
- // exchangeRate = units of currencyOriginal per 1 USD (EUR ≈ 0.91); the request expires after 24 h.
70
+ // exchangeRate = units of currencyOriginal per 1 USD (EUR ≈ 0.91); the request expires at expiresAt (24 h by default).
71
71
 
72
72
  // Send the customer to payment.paymentUrl as-is (unguessable token, not your orderId) —
73
73
  // a redirect or a new tab; the checkout cannot be shown in an iframe.
@@ -76,6 +76,23 @@ const payment = await gembapay.createPayment({
76
76
  res.redirect(payment.paymentUrl);
77
77
  ```
78
78
 
79
+ #### Payment with a shorter expiry
80
+
81
+ By default a payment request can be paid for 24 hours. `expiresInMinutes` (whole number, 5 … 1440) makes it
82
+ shorter — for tickets, seats or stock that you hold for the customer:
83
+
84
+ ```javascript
85
+ const payment = await gembapay.createPayment({
86
+ orderId: 'TICKET-1001',
87
+ amount: 25.00,
88
+ currency: 'EUR',
89
+ description: '2 tickets',
90
+ expiresInMinutes: 30
91
+ });
92
+
93
+ console.log(payment.expiresAt); // 30 minutes from now — after that it cannot be paid
94
+ ```
95
+
79
96
  After paying, the customer stays on GembaPay's confirmation page — there is no return URL. Mark the
80
97
  order paid from the `payment.completed` webhook (below) or by polling `getPaymentStatus()`.
81
98
 
@@ -104,7 +121,9 @@ V2 header do they fall back to the legacy `X-GembaPay-Signature` (bare hex over
104
121
  with `express.raw({ type: 'application/json' })` so the SDK sees the exact bytes that were signed
105
122
  (a parsed `express.json()` body is re-serialized as a fallback, which is less reliable).
106
123
  Subscription cycles arrive as `subscription.payment` (flat payload, no `orderId`), not
107
- `payment.completed`. Each `payment.completed` also carries `payment.paymentMethod`
124
+ `payment.completed`. Its `reason` is `cycle` (a renewal — extend access by one period) or `plan_change`
125
+ (the prorated difference of an upgrade — money, not a period); it is absent only on older deliveries
126
+ (Stripe before 2026-10-29, PayPal before 2026-12-06), treat those as `cycle`. Each `payment.completed` also carries `payment.paymentMethod`
108
127
  (`card`, `apple_pay`, `google_pay`, `link`, or `null` for PayPal).
109
128
 
110
129
  ```javascript
@@ -148,9 +167,11 @@ each event: [docs/webhooks.md](https://github.com/ivanovslavy/gembapay/blob/main
148
167
  ```javascript
149
168
  app.post('/webhooks/gembapay', express.raw({ type: 'application/json' }),
150
169
  gembapay.webhookHandler(async (event) => {
151
- if (event.test) return; // dashboard "Send test"
170
+ if (event.test) return; // dashboard "Send test" (a sample of a real event)
152
171
  switch (event.event) {
153
172
  case 'payment.completed': return markPaid(event.payment.orderId);
173
+ case 'subscription.payment':
174
+ return event.reason === 'plan_change' ? recordUpgradeCharge(event) : extendSubscription(event.subscriptionId);
154
175
  case 'payment.refunded': return recordRefund(event.refund, event.payment.fullyRefunded);
155
176
  case 'payment.expired': return cancelIfUnpaid(event.payment.orderId);
156
177
  case 'dispute.created': return holdOrder(event.dispute.orderId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gembapay",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "description": "GembaPay — unified payment gateway for Stripe card payments and PayPal. Funds settle directly to the merchant.",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
package/src/index.d.ts CHANGED
@@ -19,6 +19,8 @@ declare module 'gembapay' {
19
19
  currency?: string;
20
20
  /** Shown on the checkout */
21
21
  description?: string;
22
+ /** How long the request can be paid: whole minutes, 5 … 1440 (default 1440 = 24 h) */
23
+ expiresInMinutes?: number;
22
24
  }
23
25
 
24
26
  export type PaymentRequestStatus = 'pending' | 'completed' | 'expired' | 'refunded' | (string & {});
@@ -35,7 +37,7 @@ declare module 'gembapay' {
35
37
  /** Units of currencyOriginal per 1 USD (amountUsd = amountOriginal / exchangeRate) */
36
38
  exchangeRate: number;
37
39
  allowedMethods: ('stripe' | 'paypal' | (string & {}))[];
38
- /** 24 h after creation */
40
+ /** Creation + expiresInMinutes (24 h by default) */
39
41
  expiresAt: string;
40
42
  }
41
43
 
@@ -212,18 +214,31 @@ declare module 'gembapay' {
212
214
  amount?: number;
213
215
  currency?: string;
214
216
  paymentMethod?: PaymentMethod | null;
215
- /** subscription.payment: 'cycle' (renewal) or 'plan_change' (prorated upgrade difference) */
217
+ /**
218
+ * subscription.payment: 'cycle' (renewal) or 'plan_change' (prorated upgrade difference - money, not a
219
+ * period). Sent on Stripe and PayPal; absent only on older deliveries (Stripe before 2026-10-29,
220
+ * PayPal before 2026-12-06) - treat absent as 'cycle'.
221
+ */
216
222
  reason?: 'cycle' | 'plan_change' | (string & {});
217
223
  /** plan-change events */
218
224
  fromPlanToken?: string | null;
219
225
  toPlanToken?: string | null;
220
226
  fromAmount?: number | null;
221
227
  toAmount?: number | null;
228
+ /** plan-change events: billing interval of the plan (every variant) */
229
+ interval?: 'day' | 'week' | 'month' | 'year' | (string & {});
230
+ /** plan-change events: number of intervals per cycle (every variant) */
231
+ intervalCount?: number;
232
+ /** subscription.plan_changed: prorated difference charged (0 when applied at a period end) */
222
233
  prorated?: number | null;
234
+ /** subscription.plan_changed: provider reference of the prorated charge, null when nothing was charged */
223
235
  proratedRef?: string | null;
224
236
  scheduled?: boolean;
225
237
  effectiveAt?: string | null;
238
+ /** true only for dashboard "Send test" samples (eventId 'evt_test_…') - never act on them */
226
239
  test?: boolean;
240
+ /** Send-test samples also carry testMode: true; real subscription events use isTestMode */
241
+ testMode?: boolean;
227
242
  timestamp: string;
228
243
  }
229
244
 
package/src/index.js CHANGED
@@ -4,7 +4,7 @@ const https = require('https');
4
4
  const crypto = require('crypto');
5
5
 
6
6
  const BASE_URL = 'https://api.gembapay.com';
7
- const VERSION = '1.5.0';
7
+ const VERSION = '1.6.0';
8
8
  const SIGNATURE_TOLERANCE_SEC = 300;
9
9
 
10
10
  class GembaPayError extends Error {
@@ -48,17 +48,24 @@ class GembaPay {
48
48
  * @param {number} params.amount - Payment amount
49
49
  * @param {string} [params.currency='USD'] - ISO 4217 code (70 supported)
50
50
  * @param {string} [params.description] - Shown on the checkout
51
+ * @param {number} [params.expiresInMinutes=1440] - How long it can be paid: whole minutes, 5 … 1440
51
52
  * @returns {Promise<Object>} { success, orderId, paymentUrl, amountUsd, amountOriginal, currencyOriginal,
52
53
  * exchangeRate (units of currencyOriginal per 1 USD), allowedMethods, expiresAt }.
53
- * The request expires after 24 h. Only these four fields are sent: the API has no return URL,
54
+ * The request expires at expiresAt (24 h by default). Only these fields are sent: the API has no return URL,
54
55
  * customer email or metadata parameter.
55
56
  */
56
- async createPayment({ orderId, amount, currency = 'USD', description } = {}) {
57
+ async createPayment({ orderId, amount, currency = 'USD', description, expiresInMinutes } = {}) {
57
58
  if (!orderId) throw new GembaPayError('orderId is required', null, 'missing_param');
58
59
  if (!amount || amount <= 0) throw new GembaPayError('amount must be greater than 0', null, 'invalid_param');
59
60
 
60
61
  const body = { orderId, amount, currency };
61
62
  if (description) body.description = description;
63
+ if (expiresInMinutes !== undefined && expiresInMinutes !== null) {
64
+ if (!Number.isInteger(expiresInMinutes) || expiresInMinutes < 5 || expiresInMinutes > 1440) {
65
+ throw new GembaPayError('expiresInMinutes must be a whole number between 5 and 1440', null, 'invalid_param');
66
+ }
67
+ body.expiresInMinutes = expiresInMinutes;
68
+ }
62
69
 
63
70
  return this._request('POST', '/api/merchant/payment-request', body);
64
71
  }