payment-kit 1.13.199 → 1.13.201
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.
|
@@ -10,7 +10,6 @@ import isEmpty from 'lodash/isEmpty';
|
|
|
10
10
|
import { estimateMaxGasForTx, hasStakedForGas } from '../../integrations/blockchain/stake';
|
|
11
11
|
import { blocklet, wallet } from '../../libs/auth';
|
|
12
12
|
import dayjs from '../../libs/dayjs';
|
|
13
|
-
import env from '../../libs/env';
|
|
14
13
|
import logger from '../../libs/logger';
|
|
15
14
|
import { getGasPayerExtra, getTokenLimitsForDelegation } from '../../libs/payment';
|
|
16
15
|
import { getFastCheckoutAmount, getPriceUintAmountByCurrency, getStatementDescriptor } from '../../libs/session';
|
|
@@ -667,7 +666,7 @@ export async function getStakeTxClaim({
|
|
|
667
666
|
|
|
668
667
|
return {
|
|
669
668
|
type: 'StakeTx',
|
|
670
|
-
description:
|
|
669
|
+
description: `Stake to complete subscription ${subscription.id}`,
|
|
671
670
|
partialTx: {
|
|
672
671
|
from: userDid,
|
|
673
672
|
pk: userPk,
|
|
@@ -676,7 +675,7 @@ export async function getStakeTxClaim({
|
|
|
676
675
|
receiver: wallet.address,
|
|
677
676
|
slashers: [wallet.address],
|
|
678
677
|
revokeWaitingPeriod: setup.cycle.duration / 1000, // wait for at least 1 billing cycle
|
|
679
|
-
message: `Stake for subscription
|
|
678
|
+
message: `Stake for subscription ${subscription.id}`,
|
|
680
679
|
inputs: [],
|
|
681
680
|
data,
|
|
682
681
|
},
|
|
@@ -118,7 +118,63 @@ router.get('/', authMine, async (req, res) => {
|
|
|
118
118
|
],
|
|
119
119
|
});
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
// push staking info as first invoice if we are on the last page
|
|
122
|
+
let subscription;
|
|
123
|
+
if (where.subscription_id) {
|
|
124
|
+
subscription = await Subscription.findByPk(where.subscription_id);
|
|
125
|
+
if (subscription?.payment_details?.arcblock?.staking?.tx_hash && page === Math.ceil((count || 1) / pageSize)) {
|
|
126
|
+
const method = await PaymentMethod.findOne({ where: { type: 'arcblock', livemode: subscription.livemode } });
|
|
127
|
+
if (method) {
|
|
128
|
+
const client = method.getOcapClient();
|
|
129
|
+
const { address } = subscription.payment_details.arcblock.staking;
|
|
130
|
+
const { state } = await client.getStakeState({ address });
|
|
131
|
+
const last =
|
|
132
|
+
list[list.length - 1] ||
|
|
133
|
+
(await Invoice.findOne({ where: { subscription_id: subscription.id }, order: [['created_at', 'ASC']] }));
|
|
134
|
+
|
|
135
|
+
if (state && last) {
|
|
136
|
+
const data = JSON.parse(state.data?.value || '{}');
|
|
137
|
+
list.push({
|
|
138
|
+
id: address as string,
|
|
139
|
+
status: 'paid',
|
|
140
|
+
description: 'Subscription staking',
|
|
141
|
+
billing_reason: 'subscription_create',
|
|
142
|
+
total: data[subscription.id],
|
|
143
|
+
amount_due: '0',
|
|
144
|
+
amount_paid: data[subscription.id],
|
|
145
|
+
amount_remaining: '0',
|
|
146
|
+
...pick(last, [
|
|
147
|
+
'number',
|
|
148
|
+
'paid',
|
|
149
|
+
'auto_advance',
|
|
150
|
+
'currency_id',
|
|
151
|
+
'customer_id',
|
|
152
|
+
'subscription_id',
|
|
153
|
+
'period_start',
|
|
154
|
+
'period_end',
|
|
155
|
+
'created_at',
|
|
156
|
+
'updated_at',
|
|
157
|
+
]),
|
|
158
|
+
// @ts-ignore
|
|
159
|
+
paymentCurrency: await PaymentCurrency.findByPk(last.currency_id),
|
|
160
|
+
paymentMethod: method,
|
|
161
|
+
// @ts-ignore
|
|
162
|
+
customer: await Customer.findByPk(last.customer_id),
|
|
163
|
+
metadata: {
|
|
164
|
+
payment_details: {
|
|
165
|
+
arcblock: {
|
|
166
|
+
tx_hash: subscription.payment_details.arcblock.staking.tx_hash,
|
|
167
|
+
payer: subscription.payment_details.arcblock.payer,
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
res.json({ count, list, subscription });
|
|
122
178
|
} catch (err) {
|
|
123
179
|
console.error(err);
|
|
124
180
|
res.json({ count: 0, list: [] });
|
|
@@ -681,18 +681,17 @@ router.put('/:id', authPortal, async (req, res) => {
|
|
|
681
681
|
}
|
|
682
682
|
|
|
683
683
|
// handle subscription item changes
|
|
684
|
-
let invoice: Invoice;
|
|
685
684
|
let connectAction = '';
|
|
686
|
-
if (subscription.isActive() === false) {
|
|
687
|
-
throw new Error('Subscription is not active');
|
|
688
|
-
}
|
|
689
|
-
if (subscription.isScheduledToCancel()) {
|
|
690
|
-
throw new Error('Subscription is scheduled to cancel');
|
|
691
|
-
}
|
|
692
|
-
|
|
693
685
|
if (Array.isArray(value.items) && value.items.length > 0) {
|
|
686
|
+
if (subscription.isActive() === false) {
|
|
687
|
+
throw new Error('Updating subscription item not allowed for inactive subscriptions');
|
|
688
|
+
}
|
|
689
|
+
if (subscription.isScheduledToCancel()) {
|
|
690
|
+
throw new Error('Updating subscription item not allowed for scheduled-to-cancel subscriptions');
|
|
691
|
+
}
|
|
692
|
+
|
|
694
693
|
if (paymentMethod.type === 'stripe') {
|
|
695
|
-
throw new Error('
|
|
694
|
+
throw new Error('Updating subscription item not allowed for subscriptions paid with stripe');
|
|
696
695
|
}
|
|
697
696
|
|
|
698
697
|
// validate the request
|
|
@@ -773,7 +772,7 @@ router.put('/:id', authPortal, async (req, res) => {
|
|
|
773
772
|
footer: lastInvoice.footer || '',
|
|
774
773
|
} as Invoice,
|
|
775
774
|
});
|
|
776
|
-
invoice = result
|
|
775
|
+
const { invoice } = result;
|
|
777
776
|
updates.latest_invoice_id = invoice.id;
|
|
778
777
|
logger.info('subscription update invoice created', { subscription: req.params.id, invoice: invoice.id });
|
|
779
778
|
|
|
@@ -869,6 +868,13 @@ router.put('/:id', authPortal, async (req, res) => {
|
|
|
869
868
|
}
|
|
870
869
|
}
|
|
871
870
|
} else if (req.body.billing_cycle_anchor === 'now') {
|
|
871
|
+
if (subscription.isActive() === false) {
|
|
872
|
+
throw new Error('Updating billing_cycle_anchor not allowed for inactive subscriptions');
|
|
873
|
+
}
|
|
874
|
+
if (subscription.isScheduledToCancel()) {
|
|
875
|
+
throw new Error('Updating billing_cycle_anchor not allowed for scheduled-to-cancel subscriptions');
|
|
876
|
+
}
|
|
877
|
+
|
|
872
878
|
// FIXME: handle billing cycle anchor change without any item change
|
|
873
879
|
await subscription.update(updates);
|
|
874
880
|
} else {
|
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.201",
|
|
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.113",
|
|
51
51
|
"@arcblock/ux": "^2.9.57",
|
|
52
52
|
"@blocklet/logger": "1.16.24",
|
|
53
|
-
"@blocklet/payment-react": "1.13.
|
|
53
|
+
"@blocklet/payment-react": "1.13.201",
|
|
54
54
|
"@blocklet/sdk": "1.16.24",
|
|
55
55
|
"@blocklet/ui-react": "^2.9.57",
|
|
56
56
|
"@blocklet/uploader": "^0.0.74",
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"devDependencies": {
|
|
111
111
|
"@abtnode/types": "1.16.24",
|
|
112
112
|
"@arcblock/eslint-config-ts": "^0.2.4",
|
|
113
|
-
"@blocklet/payment-types": "1.13.
|
|
113
|
+
"@blocklet/payment-types": "1.13.201",
|
|
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": "0f62c0c55a77845cece0656cc6801847b9dc9e24"
|
|
153
153
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable react/no-unstable-nested-components */
|
|
2
2
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
3
|
-
import { TxLink, api, formatTime } from '@blocklet/payment-react';
|
|
3
|
+
import { CustomerInvoiceList, TxLink, api, formatTime } from '@blocklet/payment-react';
|
|
4
4
|
import type { TSubscriptionExpanded } from '@blocklet/payment-types';
|
|
5
5
|
import { ArrowBackOutlined } from '@mui/icons-material';
|
|
6
6
|
import { Alert, Box, Button, CircularProgress, Stack, Typography } from '@mui/material';
|
|
@@ -10,7 +10,6 @@ import { Link, useNavigate, useParams } from 'react-router-dom';
|
|
|
10
10
|
import Currency from '../../../components/currency';
|
|
11
11
|
import CustomerLink from '../../../components/customer/link';
|
|
12
12
|
import InfoRow from '../../../components/info-row';
|
|
13
|
-
import InvoiceList from '../../../components/invoice/list';
|
|
14
13
|
import SectionHeader from '../../../components/section/header';
|
|
15
14
|
import SubscriptionDescription from '../../../components/subscription/description';
|
|
16
15
|
import SubscriptionItemList from '../../../components/subscription/items';
|
|
@@ -160,17 +159,7 @@ export default function CustomerSubscriptionDetail() {
|
|
|
160
159
|
<Box className="section">
|
|
161
160
|
<SectionHeader title={t('admin.invoices')} mb={0} />
|
|
162
161
|
<Box className="section-body">
|
|
163
|
-
<
|
|
164
|
-
features={{ customer: false, toolbar: false }}
|
|
165
|
-
subscription_id={data.id}
|
|
166
|
-
invoiceProps={{
|
|
167
|
-
onClick: (invoice) => {
|
|
168
|
-
navigate(`/customer/invoice/${invoice.id}`);
|
|
169
|
-
},
|
|
170
|
-
}}
|
|
171
|
-
ignoreZero
|
|
172
|
-
mode="customer"
|
|
173
|
-
/>
|
|
162
|
+
<CustomerInvoiceList subscription_id={data.id} />
|
|
174
163
|
</Box>
|
|
175
164
|
</Box>
|
|
176
165
|
</Stack>
|