work-license-server 1.0.3 → 1.0.5

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/src/yookassa.js CHANGED
@@ -38,9 +38,11 @@ export class YooKassaService {
38
38
  */
39
39
  buildYooKassaPaymentPayload(order) {
40
40
  const valueStr = Number(order.amountRub || 0).toFixed(2);
41
- const description = order.includeBasePak
42
- ? `Заказ ${order.orderId}: ПАК ODANT-WORK (10 вечных лицензий + 1 год Enterprise) + доп. места (${order.addonSeats} мест, ${order.tierName})`
43
- : `Заказ ${order.orderId}: Годовая лицензия WORK (${order.addonSeats} польз., уровень ${order.tierName}, ${order.years} г.)`;
41
+ const description = order.kind === 'franchise_reservation'
42
+ ? `Заказ ${order.orderId}: Невозвратный залог за резервирование региональной франшизы ODANT-WORK (${order.regionName})`
43
+ : order.includeBasePak
44
+ ? `Заказ ${order.orderId}: ПАК ODANT-WORK (10 вечных лицензий + 1 год Enterprise) + доп. места (${order.addonSeats} мест, ${order.tierName})`
45
+ : `Заказ ${order.orderId}: Годовая лицензия WORK (${order.addonSeats} польз., уровень ${order.tierName}, ${order.years} г.)`;
44
46
 
45
47
  return {
46
48
  amount: {
@@ -160,22 +162,34 @@ export class YooKassaService {
160
162
 
161
163
  if (event === 'payment.succeeded' || obj.status === 'succeeded') {
162
164
  const result = this.store.completePaidOrder(order.orderId, { paymentId });
163
- if (!result.alreadyProcessed && typeof this.onOrderPaid === 'function') {
165
+ if (result.reservation) {
166
+ return {
167
+ ok: true,
168
+ status: 'paid',
169
+ kind: 'franchise_reservation',
170
+ orderId: result.order.orderId,
171
+ reservationId: result.reservation.reservationId,
172
+ regionCode: result.reservation.regionCode,
173
+ regionName: result.reservation.regionName,
174
+ alreadyProcessed: result.alreadyProcessed,
175
+ };
176
+ }
177
+ if (!result.alreadyProcessed && result.license && typeof this.onOrderPaid === 'function') {
164
178
  await Promise.resolve(this.onOrderPaid(result.order, result.license)).catch(() => {});
165
179
  }
166
180
  return {
167
181
  ok: true,
168
182
  status: 'paid',
169
183
  orderId: result.order.orderId,
170
- licenseId: result.license.licenseId,
171
- totalSeats: result.license.totalSeats,
172
- tier: result.license.support.tierName,
184
+ licenseId: result.license?.licenseId || result.order.licenseId,
185
+ totalSeats: result.license?.totalSeats ?? 0,
186
+ tier: result.license?.support?.tierName || result.order.tierName || '',
173
187
  alreadyProcessed: result.alreadyProcessed,
174
188
  };
175
189
  }
176
190
 
177
191
  if (event === 'payment.canceled' || obj.status === 'canceled') {
178
- this.store.updateOrder(order.orderId, { status: 'canceled' });
192
+ this.store.cancelOrder(order.orderId);
179
193
  return { ok: true, status: 'canceled', orderId: order.orderId };
180
194
  }
181
195