@drawbridge/drawbridge-stripe 0.1.3 → 0.1.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/dist/index.js +44 -40
- package/dist/index.mjs +44 -40
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -74,11 +74,8 @@ var require_billing = __commonJS({
|
|
|
74
74
|
currency,
|
|
75
75
|
cadence_data: {
|
|
76
76
|
billing_cycle: {
|
|
77
|
-
type:
|
|
78
|
-
interval_count: 1
|
|
79
|
-
month: {
|
|
80
|
-
day_of_month: 1
|
|
81
|
-
}
|
|
77
|
+
type: process.env.STRIPE_SUBSCRIPTION_INTERVAL,
|
|
78
|
+
interval_count: 1
|
|
82
79
|
},
|
|
83
80
|
payer
|
|
84
81
|
},
|
|
@@ -162,6 +159,12 @@ var require_billing = __commonJS({
|
|
|
162
159
|
throw new Error("Stripe billing intent did not return a pricing plan subscription ID for customer: " + customer);
|
|
163
160
|
}
|
|
164
161
|
;
|
|
162
|
+
let stripePricingPlanSubscriptionNextBillingDate;
|
|
163
|
+
if (!default_payment_method) {
|
|
164
|
+
const { billing_cadence: billingCadenceId } = await stripe2.v2.billing.pricingPlanSubscriptions.retrieve(stripePricingPlanSubscriptionId);
|
|
165
|
+
({ next_billing_date: stripePricingPlanSubscriptionNextBillingDate } = await stripe2.v2.billing.cadences.retrieve(billingCadenceId));
|
|
166
|
+
}
|
|
167
|
+
;
|
|
165
168
|
return {
|
|
166
169
|
stripeAlerts: {
|
|
167
170
|
ai: {
|
|
@@ -169,7 +172,8 @@ var require_billing = __commonJS({
|
|
|
169
172
|
replenish: replenish == null ? void 0 : replenish.id
|
|
170
173
|
}
|
|
171
174
|
},
|
|
172
|
-
stripePricingPlanSubscriptionId
|
|
175
|
+
stripePricingPlanSubscriptionId,
|
|
176
|
+
stripePricingPlanSubscriptionNextBillingDate
|
|
173
177
|
};
|
|
174
178
|
} catch (error) {
|
|
175
179
|
throw error;
|
|
@@ -384,24 +388,24 @@ var require_subscription = __commonJS({
|
|
|
384
388
|
proration_behavior: "create_prorations"
|
|
385
389
|
}
|
|
386
390
|
);
|
|
387
|
-
let
|
|
388
|
-
if ((
|
|
389
|
-
({ id:
|
|
390
|
-
|
|
391
|
+
let actions = (items == null ? void 0 : items.actions) || {};
|
|
392
|
+
if ((actions == null ? void 0 : actions.id) && (actions == null ? void 0 : actions.price)) {
|
|
393
|
+
({ id: actions["id"] } = await stripe2.subscriptionItems.update(
|
|
394
|
+
actions.id,
|
|
391
395
|
{
|
|
392
396
|
...props,
|
|
393
|
-
price:
|
|
397
|
+
price: actions.price,
|
|
394
398
|
proration_behavior: "none"
|
|
395
399
|
}
|
|
396
400
|
));
|
|
397
401
|
} else {
|
|
398
|
-
|
|
402
|
+
actions = await createItem({
|
|
399
403
|
currency: to.currency,
|
|
400
404
|
interval: to.interval,
|
|
401
|
-
limit: to.limits.organization.
|
|
405
|
+
limit: to.limits.organization.actions,
|
|
402
406
|
metadata,
|
|
403
|
-
name: "
|
|
404
|
-
overage: to.overages.
|
|
407
|
+
name: "actions",
|
|
408
|
+
overage: to.overages.actions,
|
|
405
409
|
proration_behavior: "none",
|
|
406
410
|
subscription: stripeSubscriptionId
|
|
407
411
|
});
|
|
@@ -419,7 +423,7 @@ var require_subscription = __commonJS({
|
|
|
419
423
|
price: (_c = plan == null ? void 0 : plan.price) == null ? void 0 : _c.id,
|
|
420
424
|
product: (_d = plan == null ? void 0 : plan.price) == null ? void 0 : _d.product
|
|
421
425
|
},
|
|
422
|
-
|
|
426
|
+
actions
|
|
423
427
|
}
|
|
424
428
|
};
|
|
425
429
|
} catch (error) {
|
|
@@ -435,13 +439,13 @@ var require_subscription = __commonJS({
|
|
|
435
439
|
}) => {
|
|
436
440
|
var _a, _b, _c;
|
|
437
441
|
try {
|
|
438
|
-
const
|
|
442
|
+
const actions = await createItem({
|
|
439
443
|
currency: to.currency,
|
|
440
444
|
interval: to.interval,
|
|
441
|
-
limit: to.limits.organization.
|
|
445
|
+
limit: to.limits.organization.actions,
|
|
442
446
|
metadata,
|
|
443
|
-
name: "
|
|
444
|
-
overage: to.overages.
|
|
447
|
+
name: "actions",
|
|
448
|
+
overage: to.overages.actions,
|
|
445
449
|
proration_behavior: "none"
|
|
446
450
|
});
|
|
447
451
|
const subscription = await stripe2.subscriptions.create({
|
|
@@ -454,7 +458,7 @@ var require_subscription = __commonJS({
|
|
|
454
458
|
discounts: (discounts == null ? void 0 : discounts.length) > 0 ? discounts : "",
|
|
455
459
|
items: [
|
|
456
460
|
{
|
|
457
|
-
price:
|
|
461
|
+
price: actions.price
|
|
458
462
|
}
|
|
459
463
|
],
|
|
460
464
|
metadata
|
|
@@ -474,9 +478,9 @@ var require_subscription = __commonJS({
|
|
|
474
478
|
price: to == null ? void 0 : to.stripePriceId,
|
|
475
479
|
product
|
|
476
480
|
},
|
|
477
|
-
|
|
481
|
+
actions: {
|
|
478
482
|
id: (_c = (_b = (_a = subscription == null ? void 0 : subscription.items) == null ? void 0 : _a.data) == null ? void 0 : _b[0]) == null ? void 0 : _c.id,
|
|
479
|
-
...
|
|
483
|
+
...actions
|
|
480
484
|
}
|
|
481
485
|
},
|
|
482
486
|
stripeCustomerId: customer,
|
|
@@ -505,33 +509,33 @@ var require_subscription = __commonJS({
|
|
|
505
509
|
proration_behavior: "always_invoice"
|
|
506
510
|
}
|
|
507
511
|
);
|
|
508
|
-
let
|
|
509
|
-
if (((_d = (_c = current == null ? void 0 : current.items) == null ? void 0 : _c.
|
|
510
|
-
|
|
512
|
+
let actions;
|
|
513
|
+
if (((_d = (_c = current == null ? void 0 : current.items) == null ? void 0 : _c.actions) == null ? void 0 : _d.id) && ((_f = (_e = current == null ? void 0 : current.items) == null ? void 0 : _e.actions) == null ? void 0 : _f.meter)) {
|
|
514
|
+
actions = await createTier({
|
|
511
515
|
currency: to.currency,
|
|
512
516
|
interval: to.interval,
|
|
513
|
-
limit: to.limits.organization.
|
|
517
|
+
limit: to.limits.organization.actions,
|
|
514
518
|
metadata,
|
|
515
|
-
meter: current.items.
|
|
516
|
-
name: "
|
|
517
|
-
overage: to.overages.
|
|
519
|
+
meter: current.items.actions.meter,
|
|
520
|
+
name: "actions",
|
|
521
|
+
overage: to.overages.actions
|
|
518
522
|
});
|
|
519
|
-
({ id:
|
|
520
|
-
current.items.
|
|
523
|
+
({ id: actions["id"] } = await stripe2.subscriptionItems.update(
|
|
524
|
+
current.items.actions.id,
|
|
521
525
|
{
|
|
522
526
|
...props,
|
|
523
|
-
price:
|
|
527
|
+
price: actions == null ? void 0 : actions.price,
|
|
524
528
|
proration_behavior: "none"
|
|
525
529
|
}
|
|
526
530
|
));
|
|
527
531
|
} else {
|
|
528
|
-
|
|
532
|
+
actions = await createItem({
|
|
529
533
|
currency: to.currency,
|
|
530
534
|
interval: to.interval,
|
|
531
|
-
limit: to.limits.organization.
|
|
535
|
+
limit: to.limits.organization.actions,
|
|
532
536
|
metadata,
|
|
533
|
-
name: "
|
|
534
|
-
overage: to.overages.
|
|
537
|
+
name: "actions",
|
|
538
|
+
overage: to.overages.actions,
|
|
535
539
|
proration_behavior: "none",
|
|
536
540
|
subscription: stripeSubscriptionId
|
|
537
541
|
});
|
|
@@ -550,9 +554,9 @@ var require_subscription = __commonJS({
|
|
|
550
554
|
price: (_g = plan == null ? void 0 : plan.price) == null ? void 0 : _g.id,
|
|
551
555
|
product: (_h = plan == null ? void 0 : plan.price) == null ? void 0 : _h.product
|
|
552
556
|
},
|
|
553
|
-
|
|
554
|
-
...((_i = current == null ? void 0 : current.items) == null ? void 0 : _i.
|
|
555
|
-
...
|
|
557
|
+
actions: {
|
|
558
|
+
...((_i = current == null ? void 0 : current.items) == null ? void 0 : _i.actions) || {},
|
|
559
|
+
...actions
|
|
556
560
|
}
|
|
557
561
|
}
|
|
558
562
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -80,11 +80,8 @@ var require_billing = __commonJS({
|
|
|
80
80
|
currency,
|
|
81
81
|
cadence_data: {
|
|
82
82
|
billing_cycle: {
|
|
83
|
-
type:
|
|
84
|
-
interval_count: 1
|
|
85
|
-
month: {
|
|
86
|
-
day_of_month: 1
|
|
87
|
-
}
|
|
83
|
+
type: process.env.STRIPE_SUBSCRIPTION_INTERVAL,
|
|
84
|
+
interval_count: 1
|
|
88
85
|
},
|
|
89
86
|
payer
|
|
90
87
|
},
|
|
@@ -168,6 +165,12 @@ var require_billing = __commonJS({
|
|
|
168
165
|
throw new Error("Stripe billing intent did not return a pricing plan subscription ID for customer: " + customer);
|
|
169
166
|
}
|
|
170
167
|
;
|
|
168
|
+
let stripePricingPlanSubscriptionNextBillingDate;
|
|
169
|
+
if (!default_payment_method) {
|
|
170
|
+
const { billing_cadence: billingCadenceId } = await stripe.v2.billing.pricingPlanSubscriptions.retrieve(stripePricingPlanSubscriptionId);
|
|
171
|
+
({ next_billing_date: stripePricingPlanSubscriptionNextBillingDate } = await stripe.v2.billing.cadences.retrieve(billingCadenceId));
|
|
172
|
+
}
|
|
173
|
+
;
|
|
171
174
|
return {
|
|
172
175
|
stripeAlerts: {
|
|
173
176
|
ai: {
|
|
@@ -175,7 +178,8 @@ var require_billing = __commonJS({
|
|
|
175
178
|
replenish: replenish == null ? void 0 : replenish.id
|
|
176
179
|
}
|
|
177
180
|
},
|
|
178
|
-
stripePricingPlanSubscriptionId
|
|
181
|
+
stripePricingPlanSubscriptionId,
|
|
182
|
+
stripePricingPlanSubscriptionNextBillingDate
|
|
179
183
|
};
|
|
180
184
|
} catch (error) {
|
|
181
185
|
throw error;
|
|
@@ -390,24 +394,24 @@ var require_subscription = __commonJS({
|
|
|
390
394
|
proration_behavior: "create_prorations"
|
|
391
395
|
}
|
|
392
396
|
);
|
|
393
|
-
let
|
|
394
|
-
if ((
|
|
395
|
-
({ id:
|
|
396
|
-
|
|
397
|
+
let actions = (items == null ? void 0 : items.actions) || {};
|
|
398
|
+
if ((actions == null ? void 0 : actions.id) && (actions == null ? void 0 : actions.price)) {
|
|
399
|
+
({ id: actions["id"] } = await stripe.subscriptionItems.update(
|
|
400
|
+
actions.id,
|
|
397
401
|
{
|
|
398
402
|
...props,
|
|
399
|
-
price:
|
|
403
|
+
price: actions.price,
|
|
400
404
|
proration_behavior: "none"
|
|
401
405
|
}
|
|
402
406
|
));
|
|
403
407
|
} else {
|
|
404
|
-
|
|
408
|
+
actions = await createItem({
|
|
405
409
|
currency: to.currency,
|
|
406
410
|
interval: to.interval,
|
|
407
|
-
limit: to.limits.organization.
|
|
411
|
+
limit: to.limits.organization.actions,
|
|
408
412
|
metadata,
|
|
409
|
-
name: "
|
|
410
|
-
overage: to.overages.
|
|
413
|
+
name: "actions",
|
|
414
|
+
overage: to.overages.actions,
|
|
411
415
|
proration_behavior: "none",
|
|
412
416
|
subscription: stripeSubscriptionId
|
|
413
417
|
});
|
|
@@ -425,7 +429,7 @@ var require_subscription = __commonJS({
|
|
|
425
429
|
price: (_c = plan == null ? void 0 : plan.price) == null ? void 0 : _c.id,
|
|
426
430
|
product: (_d = plan == null ? void 0 : plan.price) == null ? void 0 : _d.product
|
|
427
431
|
},
|
|
428
|
-
|
|
432
|
+
actions
|
|
429
433
|
}
|
|
430
434
|
};
|
|
431
435
|
} catch (error) {
|
|
@@ -441,13 +445,13 @@ var require_subscription = __commonJS({
|
|
|
441
445
|
}) => {
|
|
442
446
|
var _a, _b, _c;
|
|
443
447
|
try {
|
|
444
|
-
const
|
|
448
|
+
const actions = await createItem({
|
|
445
449
|
currency: to.currency,
|
|
446
450
|
interval: to.interval,
|
|
447
|
-
limit: to.limits.organization.
|
|
451
|
+
limit: to.limits.organization.actions,
|
|
448
452
|
metadata,
|
|
449
|
-
name: "
|
|
450
|
-
overage: to.overages.
|
|
453
|
+
name: "actions",
|
|
454
|
+
overage: to.overages.actions,
|
|
451
455
|
proration_behavior: "none"
|
|
452
456
|
});
|
|
453
457
|
const subscription = await stripe.subscriptions.create({
|
|
@@ -460,7 +464,7 @@ var require_subscription = __commonJS({
|
|
|
460
464
|
discounts: (discounts == null ? void 0 : discounts.length) > 0 ? discounts : "",
|
|
461
465
|
items: [
|
|
462
466
|
{
|
|
463
|
-
price:
|
|
467
|
+
price: actions.price
|
|
464
468
|
}
|
|
465
469
|
],
|
|
466
470
|
metadata
|
|
@@ -480,9 +484,9 @@ var require_subscription = __commonJS({
|
|
|
480
484
|
price: to == null ? void 0 : to.stripePriceId,
|
|
481
485
|
product
|
|
482
486
|
},
|
|
483
|
-
|
|
487
|
+
actions: {
|
|
484
488
|
id: (_c = (_b = (_a = subscription == null ? void 0 : subscription.items) == null ? void 0 : _a.data) == null ? void 0 : _b[0]) == null ? void 0 : _c.id,
|
|
485
|
-
...
|
|
489
|
+
...actions
|
|
486
490
|
}
|
|
487
491
|
},
|
|
488
492
|
stripeCustomerId: customer,
|
|
@@ -511,33 +515,33 @@ var require_subscription = __commonJS({
|
|
|
511
515
|
proration_behavior: "always_invoice"
|
|
512
516
|
}
|
|
513
517
|
);
|
|
514
|
-
let
|
|
515
|
-
if (((_d = (_c = current == null ? void 0 : current.items) == null ? void 0 : _c.
|
|
516
|
-
|
|
518
|
+
let actions;
|
|
519
|
+
if (((_d = (_c = current == null ? void 0 : current.items) == null ? void 0 : _c.actions) == null ? void 0 : _d.id) && ((_f = (_e = current == null ? void 0 : current.items) == null ? void 0 : _e.actions) == null ? void 0 : _f.meter)) {
|
|
520
|
+
actions = await createTier({
|
|
517
521
|
currency: to.currency,
|
|
518
522
|
interval: to.interval,
|
|
519
|
-
limit: to.limits.organization.
|
|
523
|
+
limit: to.limits.organization.actions,
|
|
520
524
|
metadata,
|
|
521
|
-
meter: current.items.
|
|
522
|
-
name: "
|
|
523
|
-
overage: to.overages.
|
|
525
|
+
meter: current.items.actions.meter,
|
|
526
|
+
name: "actions",
|
|
527
|
+
overage: to.overages.actions
|
|
524
528
|
});
|
|
525
|
-
({ id:
|
|
526
|
-
current.items.
|
|
529
|
+
({ id: actions["id"] } = await stripe.subscriptionItems.update(
|
|
530
|
+
current.items.actions.id,
|
|
527
531
|
{
|
|
528
532
|
...props,
|
|
529
|
-
price:
|
|
533
|
+
price: actions == null ? void 0 : actions.price,
|
|
530
534
|
proration_behavior: "none"
|
|
531
535
|
}
|
|
532
536
|
));
|
|
533
537
|
} else {
|
|
534
|
-
|
|
538
|
+
actions = await createItem({
|
|
535
539
|
currency: to.currency,
|
|
536
540
|
interval: to.interval,
|
|
537
|
-
limit: to.limits.organization.
|
|
541
|
+
limit: to.limits.organization.actions,
|
|
538
542
|
metadata,
|
|
539
|
-
name: "
|
|
540
|
-
overage: to.overages.
|
|
543
|
+
name: "actions",
|
|
544
|
+
overage: to.overages.actions,
|
|
541
545
|
proration_behavior: "none",
|
|
542
546
|
subscription: stripeSubscriptionId
|
|
543
547
|
});
|
|
@@ -556,9 +560,9 @@ var require_subscription = __commonJS({
|
|
|
556
560
|
price: (_g = plan == null ? void 0 : plan.price) == null ? void 0 : _g.id,
|
|
557
561
|
product: (_h = plan == null ? void 0 : plan.price) == null ? void 0 : _h.product
|
|
558
562
|
},
|
|
559
|
-
|
|
560
|
-
...((_i = current == null ? void 0 : current.items) == null ? void 0 : _i.
|
|
561
|
-
...
|
|
563
|
+
actions: {
|
|
564
|
+
...((_i = current == null ? void 0 : current.items) == null ? void 0 : _i.actions) || {},
|
|
565
|
+
...actions
|
|
562
566
|
}
|
|
563
567
|
}
|
|
564
568
|
};
|
package/package.json
CHANGED