payment-kit 1.13.149 → 1.13.150
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.
|
@@ -3,6 +3,7 @@ import merge from 'lodash/merge';
|
|
|
3
3
|
|
|
4
4
|
import logger from '../../libs/logger';
|
|
5
5
|
import { getPriceUintAmountByCurrency } from '../../libs/session';
|
|
6
|
+
import { getSubscriptionItemPrice } from '../../libs/subscription';
|
|
6
7
|
import {
|
|
7
8
|
Customer,
|
|
8
9
|
PaymentCurrency,
|
|
@@ -244,7 +245,7 @@ export async function ensureStripeSubscription(
|
|
|
244
245
|
await Promise.all(
|
|
245
246
|
stripeSubscription.items.data.map(async (x: any) => {
|
|
246
247
|
const item = prices.find((y) => y.stripePrice.id === x.price.id);
|
|
247
|
-
const price = item
|
|
248
|
+
const price = getSubscriptionItemPrice(item); // local
|
|
248
249
|
let exist = await SubscriptionItem.findOne({
|
|
249
250
|
where: { price_id: price.id, subscription_id: internal.id },
|
|
250
251
|
});
|
|
@@ -97,14 +97,14 @@ export function getSubscriptionCreateSetup(items: TLineItemExpanded[], currencyI
|
|
|
97
97
|
let setup = new BN(0);
|
|
98
98
|
|
|
99
99
|
items.forEach((x) => {
|
|
100
|
-
const price = x
|
|
100
|
+
const price = getSubscriptionItemPrice(x);
|
|
101
101
|
const unit = getPriceUintAmountByCurrency(price, currencyId);
|
|
102
102
|
if (price.type === 'one_time' || (price.type === 'recurring' && price.recurring?.usage_type === 'licensed')) {
|
|
103
103
|
setup = setup.add(new BN(unit).mul(new BN(x.quantity)));
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
-
const item = items.find((x) => x.
|
|
107
|
+
const item = items.find((x) => getSubscriptionItemPrice(x).type === 'recurring');
|
|
108
108
|
const recurring = (item?.upsell_price || item?.price)?.recurring as PriceRecurring;
|
|
109
109
|
const cycle = getRecurringPeriod(recurring);
|
|
110
110
|
const trial = trialInDays ? trialInDays * 24 * 60 * 60 * 1000 : 0;
|
|
@@ -148,7 +148,9 @@ export function getSubscriptionCycleAmount(items: TLineItemExpanded[], currencyI
|
|
|
148
148
|
let amount = new BN(0);
|
|
149
149
|
|
|
150
150
|
items.forEach((x) => {
|
|
151
|
-
amount = amount.add(
|
|
151
|
+
amount = amount.add(
|
|
152
|
+
new BN(getPriceUintAmountByCurrency(getSubscriptionItemPrice(x), currencyId)).mul(new BN(x.quantity))
|
|
153
|
+
);
|
|
152
154
|
});
|
|
153
155
|
|
|
154
156
|
return {
|
|
@@ -156,6 +158,10 @@ export function getSubscriptionCycleAmount(items: TLineItemExpanded[], currencyI
|
|
|
156
158
|
};
|
|
157
159
|
}
|
|
158
160
|
|
|
161
|
+
export function getSubscriptionItemPrice(item: TLineItemExpanded) {
|
|
162
|
+
return item.upsell_price || item.price;
|
|
163
|
+
}
|
|
164
|
+
|
|
159
165
|
export async function createProration(
|
|
160
166
|
subscription: Subscription,
|
|
161
167
|
setup: ReturnType<typeof getSubscriptionCreateSetup>,
|
|
@@ -175,9 +181,10 @@ export async function createProration(
|
|
|
175
181
|
// 1. get last invoice, and invoice items, filter invoice items that are in licensed recurring mode
|
|
176
182
|
const invoiceItems = await InvoiceItem.findAll({ where: { invoice_id: lastInvoice.id, proration: false } });
|
|
177
183
|
const invoiceItemsExpanded = await Price.expand(invoiceItems.map((x) => x.toJSON()));
|
|
178
|
-
const prorationItems = invoiceItemsExpanded.filter(
|
|
179
|
-
|
|
180
|
-
|
|
184
|
+
const prorationItems = invoiceItemsExpanded.filter((x) => {
|
|
185
|
+
const price = getSubscriptionItemPrice(x);
|
|
186
|
+
return price.type === 'recurring' && price.recurring?.usage_type === 'licensed';
|
|
187
|
+
});
|
|
181
188
|
|
|
182
189
|
// 2. calculate proration args based on the filtered invoice items
|
|
183
190
|
const precision = 10000;
|
|
@@ -191,7 +198,8 @@ export async function createProration(
|
|
|
191
198
|
let unused = new BN(0);
|
|
192
199
|
const prorations = await Promise.all(
|
|
193
200
|
prorationItems.map((x: TLineItemExpanded & { [key: string]: any }) => {
|
|
194
|
-
const
|
|
201
|
+
const price = getSubscriptionItemPrice(x);
|
|
202
|
+
const unitAmount = getPriceUintAmountByCurrency(price, subscription.currency_id);
|
|
195
203
|
const amount = new BN(unitAmount)
|
|
196
204
|
.mul(new BN(x.quantity))
|
|
197
205
|
.mul(new BN(prorationRate))
|
|
@@ -206,11 +214,11 @@ export async function createProration(
|
|
|
206
214
|
unused = unused.add(new BN(amount));
|
|
207
215
|
|
|
208
216
|
return {
|
|
209
|
-
price_id:
|
|
217
|
+
price_id: price.id,
|
|
210
218
|
amount: `-${amount}`,
|
|
211
219
|
quantity: x.quantity,
|
|
212
220
|
// @ts-ignore
|
|
213
|
-
description: `Unused time on ${
|
|
221
|
+
description: `Unused time on ${price.product.name} after ${dayjs().format('lll')}`,
|
|
214
222
|
period: {
|
|
215
223
|
start: lastInvoice.period_start,
|
|
216
224
|
end: lastInvoice.period_end,
|
|
@@ -25,6 +25,7 @@ import { Product } from '../../store/models/product';
|
|
|
25
25
|
import { SetupIntent } from '../../store/models/setup-intent';
|
|
26
26
|
import { Subscription } from '../../store/models/subscription';
|
|
27
27
|
import { SubscriptionItem } from '../../store/models/subscription-item';
|
|
28
|
+
import { getSubscriptionItemPrice } from '../../libs/subscription';
|
|
28
29
|
|
|
29
30
|
type Result = {
|
|
30
31
|
checkoutSession: CheckoutSession;
|
|
@@ -446,9 +447,10 @@ export async function ensureInvoiceAndItems({
|
|
|
446
447
|
: [];
|
|
447
448
|
|
|
448
449
|
const getLineSetup = (x: TLineItemExpanded) => {
|
|
449
|
-
const price = x
|
|
450
|
+
const price = getSubscriptionItemPrice(x);
|
|
450
451
|
if (price.type === 'recurring' && trailing) {
|
|
451
452
|
return {
|
|
453
|
+
price,
|
|
452
454
|
amount: '0',
|
|
453
455
|
// @ts-ignore
|
|
454
456
|
description: trailing ? `${price.product.name} (trailing)` : price.product.name,
|
|
@@ -460,6 +462,7 @@ export async function ensureInvoiceAndItems({
|
|
|
460
462
|
}
|
|
461
463
|
|
|
462
464
|
return {
|
|
465
|
+
price,
|
|
463
466
|
amount: new BN(getPriceUintAmountByCurrency(price, props.currency_id)).mul(new BN(x.quantity)).toString(),
|
|
464
467
|
// @ts-ignore
|
|
465
468
|
description: price.product.name,
|
|
@@ -470,7 +473,7 @@ export async function ensureInvoiceAndItems({
|
|
|
470
473
|
const items = await Promise.all(
|
|
471
474
|
lineItems.map((x: TLineItemExpanded) => {
|
|
472
475
|
const setup = getLineSetup(x);
|
|
473
|
-
const price =
|
|
476
|
+
const { price } = setup;
|
|
474
477
|
let { quantity } = x;
|
|
475
478
|
if (price.type === 'recurring') {
|
|
476
479
|
if (price.recurring?.usage_type === 'metered' && !metered) {
|
|
@@ -489,10 +492,10 @@ export async function ensureInvoiceAndItems({
|
|
|
489
492
|
period: setup.period,
|
|
490
493
|
currency_id: props.currency_id,
|
|
491
494
|
customer_id: customer.id,
|
|
492
|
-
price_id:
|
|
495
|
+
price_id: price.id,
|
|
493
496
|
invoice_id: invoice.id,
|
|
494
497
|
subscription_id: subscription?.id,
|
|
495
|
-
subscription_item_id: subscriptionItems.find((si) => si.price_id ===
|
|
498
|
+
subscription_item_id: subscriptionItems.find((si) => si.price_id === price.id)?.id,
|
|
496
499
|
discountable: false,
|
|
497
500
|
discounts: [],
|
|
498
501
|
discount_amounts: [],
|
package/blocklet.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.150",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "cross-env COMPONENT_STORE_URL=https://test.store.blocklet.dev blocklet dev --open",
|
|
6
6
|
"eject": "vite eject",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@arcblock/jwt": "^1.18.110",
|
|
51
51
|
"@arcblock/ux": "^2.9.29",
|
|
52
52
|
"@blocklet/logger": "1.16.23",
|
|
53
|
-
"@blocklet/payment-react": "1.13.
|
|
53
|
+
"@blocklet/payment-react": "1.13.150",
|
|
54
54
|
"@blocklet/sdk": "1.16.23",
|
|
55
55
|
"@blocklet/ui-react": "^2.9.29",
|
|
56
56
|
"@blocklet/uploader": "^0.0.73",
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"devDependencies": {
|
|
111
111
|
"@abtnode/types": "1.16.23",
|
|
112
112
|
"@arcblock/eslint-config-ts": "^0.2.4",
|
|
113
|
-
"@blocklet/payment-types": "1.13.
|
|
113
|
+
"@blocklet/payment-types": "1.13.150",
|
|
114
114
|
"@types/cookie-parser": "^1.4.6",
|
|
115
115
|
"@types/cors": "^2.8.17",
|
|
116
116
|
"@types/dotenv-flow": "^3.3.3",
|
|
@@ -149,5 +149,5 @@
|
|
|
149
149
|
"parser": "typescript"
|
|
150
150
|
}
|
|
151
151
|
},
|
|
152
|
-
"gitHead": "
|
|
152
|
+
"gitHead": "b65548baa2ab6bd40aec35b2a6594bfe6dbb7ee9"
|
|
153
153
|
}
|