@wipperoz/wipperoz-core 1.0.2 → 1.0.4
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/billing/index.d.ts +1 -0
- package/dist/billing/index.d.ts.map +1 -1
- package/dist/billing/index.js +1 -0
- package/dist/billing/index.js.map +1 -1
- package/dist/billing/services/stripePaymentMapper.d.ts +84 -0
- package/dist/billing/services/stripePaymentMapper.d.ts.map +1 -0
- package/dist/billing/services/stripePaymentMapper.js +83 -0
- package/dist/billing/services/stripePaymentMapper.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/billing/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/billing/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yCAAyC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/billing/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yCAAyC,CAAC;AACxD,cAAc,gCAAgC,CAAC"}
|
package/dist/billing/index.js
CHANGED
|
@@ -3,4 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./services/tokenFormatter"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./services/accountCreditManager.service"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./services/stripePaymentMapper"), exports);
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/billing/index.ts"],"names":[],"mappings":";;;AAAA,oEAA0C;AAC1C,kFAAwD"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/billing/index.ts"],"names":[],"mappings":";;;AAAA,oEAA0C;AAC1C,kFAAwD;AACxD,yEAA+C"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { CurrencyEnum } from '@wipperoz/common-entities-account/dist/src';
|
|
2
|
+
import { StripePaymentStatusEnum } from '../enums';
|
|
3
|
+
import { StripePaymentDetails } from '../interfaces/stripePayment.interface';
|
|
4
|
+
/**
|
|
5
|
+
* Minimal "Stripe-like" types so wipperoz-core does not depend directly on the Stripe SDK.
|
|
6
|
+
*/
|
|
7
|
+
export interface StripeCustomerLike {
|
|
8
|
+
id: string;
|
|
9
|
+
invoice_settings?: {
|
|
10
|
+
default_payment_method?: string | null;
|
|
11
|
+
} | null;
|
|
12
|
+
}
|
|
13
|
+
export interface StripePaymentIntentLike {
|
|
14
|
+
id: string;
|
|
15
|
+
status: string;
|
|
16
|
+
amount: number;
|
|
17
|
+
currency: string;
|
|
18
|
+
last_payment_error?: {
|
|
19
|
+
message?: string | null;
|
|
20
|
+
} | null;
|
|
21
|
+
}
|
|
22
|
+
export interface StripeBalanceTransactionLike {
|
|
23
|
+
fee?: number | null;
|
|
24
|
+
}
|
|
25
|
+
export interface StripePaymentMeta {
|
|
26
|
+
/**
|
|
27
|
+
* Number of tokens that were added for this payment.
|
|
28
|
+
*/
|
|
29
|
+
tokensAdded: number;
|
|
30
|
+
/**
|
|
31
|
+
* Whether this payment was triggered automatically by auto top-up.
|
|
32
|
+
*/
|
|
33
|
+
isAutoTopUp: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* ISO timestamp when the payment record was created in our system.
|
|
36
|
+
* If omitted, the caller should set this separately on the persistence layer.
|
|
37
|
+
*/
|
|
38
|
+
createdAt?: string;
|
|
39
|
+
/**
|
|
40
|
+
* ISO timestamp when the payment completed. If omitted, this will be derived
|
|
41
|
+
* from the mapped status (null for non-succeeded payments).
|
|
42
|
+
*/
|
|
43
|
+
completedAt?: string | null;
|
|
44
|
+
}
|
|
45
|
+
export interface StripePaymentMappingInput {
|
|
46
|
+
customer: StripeCustomerLike;
|
|
47
|
+
paymentIntent: StripePaymentIntentLike;
|
|
48
|
+
/**
|
|
49
|
+
* Optional balance transaction used to derive stripeFeeCents.
|
|
50
|
+
*/
|
|
51
|
+
balanceTransaction?: StripeBalanceTransactionLike | null;
|
|
52
|
+
/**
|
|
53
|
+
* Business metadata required by our model.
|
|
54
|
+
*/
|
|
55
|
+
meta: StripePaymentMeta;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Map Stripe currency codes (lowercase) to our CurrencyEnum.
|
|
59
|
+
* Currently supports AUD and USD.
|
|
60
|
+
*/
|
|
61
|
+
export declare const mapStripeCurrencyToCurrencyEnum: (currency: string) => CurrencyEnum;
|
|
62
|
+
/**
|
|
63
|
+
* Map Stripe payment_intent.status to our StripePaymentStatusEnum.
|
|
64
|
+
*
|
|
65
|
+
* - 'succeeded' -> SUCCEEDED
|
|
66
|
+
* - clearly failed states -> FAILED
|
|
67
|
+
* - everything else (processing, requires_payment_method, etc.) -> PENDING
|
|
68
|
+
*/
|
|
69
|
+
export declare const mapStripeStatusToStripePaymentStatus: (status: string) => StripePaymentStatusEnum;
|
|
70
|
+
/**
|
|
71
|
+
* Create a StripePaymentDetails object from Stripe customer/payment intent
|
|
72
|
+
* plus optional balance transaction and our own business metadata.
|
|
73
|
+
*
|
|
74
|
+
* This encodes the canonical mapping between Stripe fields and our platform model:
|
|
75
|
+
* - stripe.customerId <- customer.id
|
|
76
|
+
* - paymentIntentId <- payment_intent.id
|
|
77
|
+
* - status <- payment_intent.status (mapped to enum)
|
|
78
|
+
* - amountCents <- payment_intent.amount
|
|
79
|
+
* - currency <- payment_intent.currency
|
|
80
|
+
* - stripeFeeCents <- balance_transaction.fee
|
|
81
|
+
* - failureReason <- payment_intent.last_payment_error.message
|
|
82
|
+
*/
|
|
83
|
+
export declare const mapStripeToStripePaymentDetails: (input: StripePaymentMappingInput) => StripePaymentDetails;
|
|
84
|
+
//# sourceMappingURL=stripePaymentMapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripePaymentMapper.d.ts","sourceRoot":"","sources":["../../../src/billing/services/stripePaymentMapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,4CAA4C,CAAC;AAExE,OAAO,EAAC,uBAAuB,EAAC,MAAM,UAAU,CAAC;AACjD,OAAO,EAAC,oBAAoB,EAAC,MAAM,uCAAuC,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB,CAAC,EAAE;QACjB,sBAAsB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KACxC,GAAG,IAAI,CAAC;CACV;AAED,MAAM,WAAW,uBAAuB;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,CAAC,EAAE;QACnB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KACzB,GAAG,IAAI,CAAC;CACV;AAED,MAAM,WAAW,4BAA4B;IAC3C,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,aAAa,EAAE,uBAAuB,CAAC;IACvC;;OAEG;IACH,kBAAkB,CAAC,EAAE,4BAA4B,GAAG,IAAI,CAAC;IACzD;;OAEG;IACH,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED;;;GAGG;AACH,eAAO,MAAM,+BAA+B,GAAI,UAAU,MAAM,KAAG,YAWlE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oCAAoC,GAAI,QAAQ,MAAM,KAAG,uBAgBrE,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,+BAA+B,GAAI,OAAO,yBAAyB,KAAG,oBA8BlF,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapStripeToStripePaymentDetails = exports.mapStripeStatusToStripePaymentStatus = exports.mapStripeCurrencyToCurrencyEnum = void 0;
|
|
4
|
+
const src_1 = require("@wipperoz/common-entities-account/dist/src");
|
|
5
|
+
const enums_1 = require("../enums");
|
|
6
|
+
/**
|
|
7
|
+
* Map Stripe currency codes (lowercase) to our CurrencyEnum.
|
|
8
|
+
* Currently supports AUD and USD.
|
|
9
|
+
*/
|
|
10
|
+
const mapStripeCurrencyToCurrencyEnum = (currency) => {
|
|
11
|
+
const normalized = currency.toLowerCase();
|
|
12
|
+
switch (normalized) {
|
|
13
|
+
case 'aud':
|
|
14
|
+
return src_1.CurrencyEnum.AUD;
|
|
15
|
+
case 'usd':
|
|
16
|
+
return src_1.CurrencyEnum.USD;
|
|
17
|
+
default:
|
|
18
|
+
throw new Error(`Unsupported Stripe currency: ${currency}`);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.mapStripeCurrencyToCurrencyEnum = mapStripeCurrencyToCurrencyEnum;
|
|
22
|
+
/**
|
|
23
|
+
* Map Stripe payment_intent.status to our StripePaymentStatusEnum.
|
|
24
|
+
*
|
|
25
|
+
* - 'succeeded' -> SUCCEEDED
|
|
26
|
+
* - clearly failed states -> FAILED
|
|
27
|
+
* - everything else (processing, requires_payment_method, etc.) -> PENDING
|
|
28
|
+
*/
|
|
29
|
+
const mapStripeStatusToStripePaymentStatus = (status) => {
|
|
30
|
+
const normalized = status.toLowerCase();
|
|
31
|
+
if (normalized === 'succeeded') {
|
|
32
|
+
return enums_1.StripePaymentStatusEnum.SUCCEEDED;
|
|
33
|
+
}
|
|
34
|
+
// Common failure-like states from Stripe
|
|
35
|
+
const failedLikeStatuses = new Set(['canceled', 'requires_payment_method', 'requires_action', 'requires_capture']);
|
|
36
|
+
if (failedLikeStatuses.has(normalized)) {
|
|
37
|
+
return enums_1.StripePaymentStatusEnum.FAILED;
|
|
38
|
+
}
|
|
39
|
+
// Fallback: treat everything else as pending (e.g. 'processing', 'requires_confirmation')
|
|
40
|
+
return enums_1.StripePaymentStatusEnum.PENDING;
|
|
41
|
+
};
|
|
42
|
+
exports.mapStripeStatusToStripePaymentStatus = mapStripeStatusToStripePaymentStatus;
|
|
43
|
+
/**
|
|
44
|
+
* Create a StripePaymentDetails object from Stripe customer/payment intent
|
|
45
|
+
* plus optional balance transaction and our own business metadata.
|
|
46
|
+
*
|
|
47
|
+
* This encodes the canonical mapping between Stripe fields and our platform model:
|
|
48
|
+
* - stripe.customerId <- customer.id
|
|
49
|
+
* - paymentIntentId <- payment_intent.id
|
|
50
|
+
* - status <- payment_intent.status (mapped to enum)
|
|
51
|
+
* - amountCents <- payment_intent.amount
|
|
52
|
+
* - currency <- payment_intent.currency
|
|
53
|
+
* - stripeFeeCents <- balance_transaction.fee
|
|
54
|
+
* - failureReason <- payment_intent.last_payment_error.message
|
|
55
|
+
*/
|
|
56
|
+
const mapStripeToStripePaymentDetails = (input) => {
|
|
57
|
+
const { customer, paymentIntent, balanceTransaction, meta } = input;
|
|
58
|
+
const statusEnum = (0, exports.mapStripeStatusToStripePaymentStatus)(paymentIntent.status);
|
|
59
|
+
const currencyEnum = (0, exports.mapStripeCurrencyToCurrencyEnum)(paymentIntent.currency);
|
|
60
|
+
const stripeFeeCents = balanceTransaction?.fee ?? 0;
|
|
61
|
+
const createdAt = meta.createdAt ?? new Date().toISOString();
|
|
62
|
+
const completedAt = meta.completedAt !== undefined
|
|
63
|
+
? meta.completedAt
|
|
64
|
+
: statusEnum === enums_1.StripePaymentStatusEnum.SUCCEEDED
|
|
65
|
+
? new Date().toISOString()
|
|
66
|
+
: null;
|
|
67
|
+
const failureReason = paymentIntent.last_payment_error?.message ?? undefined;
|
|
68
|
+
return {
|
|
69
|
+
paymentIntentId: paymentIntent.id,
|
|
70
|
+
stripeCustomerId: customer.id,
|
|
71
|
+
status: statusEnum,
|
|
72
|
+
amountCents: paymentIntent.amount,
|
|
73
|
+
currency: currencyEnum,
|
|
74
|
+
tokensAdded: meta.tokensAdded,
|
|
75
|
+
stripeFeeCents,
|
|
76
|
+
isAutoTopUp: meta.isAutoTopUp,
|
|
77
|
+
createdAt,
|
|
78
|
+
completedAt,
|
|
79
|
+
failureReason,
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
exports.mapStripeToStripePaymentDetails = mapStripeToStripePaymentDetails;
|
|
83
|
+
//# sourceMappingURL=stripePaymentMapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripePaymentMapper.js","sourceRoot":"","sources":["../../../src/billing/services/stripePaymentMapper.ts"],"names":[],"mappings":";;;AAAA,oEAAwE;AAExE,oCAAiD;AA6DjD;;;GAGG;AACI,MAAM,+BAA+B,GAAG,CAAC,QAAgB,EAAgB,EAAE;IAChF,MAAM,UAAU,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IAE1C,QAAQ,UAAU,EAAE,CAAC;QACnB,KAAK,KAAK;YACR,OAAO,kBAAY,CAAC,GAAG,CAAC;QAC1B,KAAK,KAAK;YACR,OAAO,kBAAY,CAAC,GAAG,CAAC;QAC1B;YACE,MAAM,IAAI,KAAK,CAAC,gCAAgC,QAAQ,EAAE,CAAC,CAAC;IAChE,CAAC;AACH,CAAC,CAAC;AAXW,QAAA,+BAA+B,mCAW1C;AAEF;;;;;;GAMG;AACI,MAAM,oCAAoC,GAAG,CAAC,MAAc,EAA2B,EAAE;IAC9F,MAAM,UAAU,G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