@rdlabo/workers-hono-kit 0.6.8 → 0.6.9
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.d.ts +1 -1
- package/dist/payment/failure.d.ts +8 -7
- package/dist/payment/failure.js +9 -9
- package/dist/stripe/failure.d.ts +18 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ export type { KVNamespace, KVCacheOptions } from './cache/kv-cache.js';
|
|
|
48
48
|
export { createStripeClient, verifyStripeWebhook } from './stripe/client.js';
|
|
49
49
|
export type { CreateStripeClientOptions } from './stripe/client.js';
|
|
50
50
|
export { extractStripeFailureReason, stripeFailureMessageJa, serializePaymentFailure, parsePaymentFailure, PaymentDeclinedError, toPaymentDeclinedError, } from './stripe/failure.js';
|
|
51
|
-
export type { StripeFailureReason, PaymentFailureSource, PaymentFailureRecord, PaymentDeclinedBody, } from './stripe/failure.js';
|
|
51
|
+
export type { StripeFailureReason, PaymentFailureSource, PaymentFailureRecord, PaymentFailureReason, IapFailureReason, PaymentDeclinedBody, } from './stripe/failure.js';
|
|
52
52
|
export { classifyStripeReconcile } from './stripe/reconcile.js';
|
|
53
53
|
export type { StripeReconcileAction } from './stripe/reconcile.js';
|
|
54
54
|
export { paymentFailureMessageJa, iapFailureKey, UNRESOLVED_PAYMENT_STATUSES } from './payment/failure.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PaymentFailureReason } from '../stripe/failure.js';
|
|
2
2
|
/**
|
|
3
3
|
* Provider-agnostic status of a row in the `payment_failed` table.
|
|
4
4
|
*
|
|
@@ -35,22 +35,23 @@ export declare function paymentFailureMessageJa(input: {
|
|
|
35
35
|
status: PaymentFailureStatus;
|
|
36
36
|
/** The row `type` (stripe/ios/android). Typed as `string` since it comes from the DB column. */
|
|
37
37
|
type?: string | null;
|
|
38
|
-
reason?:
|
|
38
|
+
reason?: PaymentFailureReason | null;
|
|
39
39
|
}): string;
|
|
40
40
|
/**
|
|
41
|
-
* Build the `payment_failed.recursions_id
|
|
41
|
+
* Build the provider-native `payment_failed.recursions_id`.
|
|
42
42
|
*
|
|
43
43
|
* @remarks
|
|
44
|
-
* - iOS:
|
|
44
|
+
* - iOS: `${original_transaction_id}:${expires_date_ms}`. `original_transaction_id` is stable
|
|
45
45
|
* across re-subscribes, so keying on it alone would let the resolved-reopen guard permanently mask
|
|
46
46
|
* every event after the first. Including `expires_date_ms` makes each billing cycle a distinct row,
|
|
47
47
|
* while the same cycle's daily reconcile (billing-retry) still converges to one row.
|
|
48
|
-
* - Android:
|
|
49
|
-
* cycle-specific; the `android:` prefix only guards against cross-type PK collisions.
|
|
48
|
+
* - Android: `${orderId}` — Google issues a new orderId per subscription, so it is already cycle-specific.
|
|
50
49
|
*
|
|
51
50
|
* Stripe rows use the invoice / subscription id directly (globally unique) and need no helper.
|
|
52
51
|
*
|
|
53
|
-
*
|
|
52
|
+
* The provider is stored separately in the `type` column. Provider-native ID formats are disjoint in practice
|
|
53
|
+
* (Apple numeric pair / Google `GPA.*` / Stripe `in_*` or `sub_*`), so duplicating `type` in the primary-key value
|
|
54
|
+
* is unnecessary.
|
|
54
55
|
*/
|
|
55
56
|
export declare function iapFailureKey(input: {
|
|
56
57
|
platform: 'ios';
|
package/dist/payment/failure.js
CHANGED
|
@@ -32,25 +32,25 @@ export function paymentFailureMessageJa(input) {
|
|
|
32
32
|
if (input.status === 'failed' && (input.type === 'ios' || input.type === 'android')) {
|
|
33
33
|
return IAP_FAILED_MESSAGE_JA[input.type];
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
const stripeReason = input.reason && !('provider' in input.reason) ? input.reason : null;
|
|
36
|
+
return stripeFailureMessageJa(stripeReason);
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
|
-
* Build the `payment_failed.recursions_id
|
|
39
|
+
* Build the provider-native `payment_failed.recursions_id`.
|
|
39
40
|
*
|
|
40
41
|
* @remarks
|
|
41
|
-
* - iOS:
|
|
42
|
+
* - iOS: `${original_transaction_id}:${expires_date_ms}`. `original_transaction_id` is stable
|
|
42
43
|
* across re-subscribes, so keying on it alone would let the resolved-reopen guard permanently mask
|
|
43
44
|
* every event after the first. Including `expires_date_ms` makes each billing cycle a distinct row,
|
|
44
45
|
* while the same cycle's daily reconcile (billing-retry) still converges to one row.
|
|
45
|
-
* - Android:
|
|
46
|
-
* cycle-specific; the `android:` prefix only guards against cross-type PK collisions.
|
|
46
|
+
* - Android: `${orderId}` — Google issues a new orderId per subscription, so it is already cycle-specific.
|
|
47
47
|
*
|
|
48
48
|
* Stripe rows use the invoice / subscription id directly (globally unique) and need no helper.
|
|
49
49
|
*
|
|
50
|
-
*
|
|
50
|
+
* The provider is stored separately in the `type` column. Provider-native ID formats are disjoint in practice
|
|
51
|
+
* (Apple numeric pair / Google `GPA.*` / Stripe `in_*` or `sub_*`), so duplicating `type` in the primary-key value
|
|
52
|
+
* is unnecessary.
|
|
51
53
|
*/
|
|
52
54
|
export function iapFailureKey(input) {
|
|
53
|
-
return input.platform === 'ios'
|
|
54
|
-
? `ios:${input.originalTransactionId}:${input.expiresDateMs}`
|
|
55
|
-
: `android:${input.orderId}`;
|
|
55
|
+
return input.platform === 'ios' ? `${input.originalTransactionId}:${input.expiresDateMs}` : input.orderId;
|
|
56
56
|
}
|
package/dist/stripe/failure.d.ts
CHANGED
|
@@ -22,6 +22,23 @@ export interface StripeFailureReason {
|
|
|
22
22
|
/** Id of the Subscription the failing invoice belongs to, when resolvable. */
|
|
23
23
|
subscriptionId?: string;
|
|
24
24
|
}
|
|
25
|
+
/** Normalized reason persisted for an App Store / Google Play subscription failure. */
|
|
26
|
+
export interface IapFailureReason {
|
|
27
|
+
/** Provider discriminator. */
|
|
28
|
+
provider: 'ios' | 'android';
|
|
29
|
+
/** Stable machine-readable classification. */
|
|
30
|
+
code: 'billing_retry' | 'auto_renew_off' | 'subscription_canceled' | 'subscription_gone';
|
|
31
|
+
/** Provider response status code when present (Apple verifyReceipt status / Google error code). */
|
|
32
|
+
statusCode?: number;
|
|
33
|
+
/** Apple auto-renew status (`'0'` means disabled). */
|
|
34
|
+
autoRenewStatus?: string;
|
|
35
|
+
/** Apple billing-retry status (`'1'` means retrying a failed renewal). */
|
|
36
|
+
billingRetryStatus?: string;
|
|
37
|
+
/** Google cancellation reason code (0=user, 1=system, 2=replaced, 3=developer). */
|
|
38
|
+
cancelReason?: number;
|
|
39
|
+
}
|
|
40
|
+
/** Provider-specific diagnostic reason stored in `payment_failed.receipt`. */
|
|
41
|
+
export type PaymentFailureReason = StripeFailureReason | IapFailureReason;
|
|
25
42
|
/** Where a {@link PaymentFailureRecord} was captured. */
|
|
26
43
|
export type PaymentFailureSource = 'webhook.invoice.payment_failed' | 'webhook.invoice.payment_action_required' | 'reconcile' | 'checkout' | 'iap';
|
|
27
44
|
/**
|
|
@@ -32,7 +49,7 @@ export type PaymentFailureSource = 'webhook.invoice.payment_failed' | 'webhook.i
|
|
|
32
49
|
* on read via {@link stripeFailureMessageJa} so that wording changes never require a data migration.
|
|
33
50
|
*/
|
|
34
51
|
export interface PaymentFailureRecord {
|
|
35
|
-
reason:
|
|
52
|
+
reason: PaymentFailureReason;
|
|
36
53
|
source: PaymentFailureSource;
|
|
37
54
|
/** ISO 8601 timestamp of when the failure was captured. */
|
|
38
55
|
occurredAt: string;
|