better-auth-paystack 3.5.0 → 3.5.2
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/README.md +11 -2
- package/dist/client.d.mts +1 -1
- package/dist/client.mjs +1 -1
- package/dist/{index-Bt1AmLyW.d.mts → index-XVUaLDh_.d.mts} +2 -2
- package/dist/{index-Bt1AmLyW.d.mts.map → index-XVUaLDh_.d.mts.map} +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +309 -86
- package/dist/index.mjs.map +1 -1
- package/dist/{version-BEzR5d9x.mjs → version-CBSJ3ZWy.mjs} +2 -2
- package/dist/{version-BEzR5d9x.mjs.map → version-CBSJ3ZWy.mjs.map} +1 -1
- package/package.json +1 -1
- package/skills/better-auth-paystack-setup/SKILL.md +2 -2
- package/skills/paystack-billing-flows/SKILL.md +2 -2
- package/skills/paystack-catalog-limits/SKILL.md +2 -2
- package/skills/paystack-client-api/SKILL.md +2 -2
- package/skills/paystack-local-subscriptions/SKILL.md +2 -2
- package/skills/paystack-organization-billing/SKILL.md +2 -2
- package/skills/paystack-schema-migrations/SKILL.md +2 -2
- package/skills/paystack-tanstack-start/SKILL.md +2 -2
- package/skills/paystack-testing-fixtures/SKILL.md +2 -2
- package/skills/paystack-webhooks-events/SKILL.md +2 -2
package/README.md
CHANGED
|
@@ -468,8 +468,17 @@ with your own policy and [Paystack's refund API](https://paystack.com/docs/payme
|
|
|
468
468
|
promise one. See the provider guidance for [charging cards](https://paystack.com/docs/payments/charge-card/)
|
|
469
469
|
and [webhook events](https://paystack.com/docs/payments/webhooks/).
|
|
470
470
|
|
|
471
|
-
|
|
472
|
-
|
|
471
|
+
Callback failures leave webhook deliveries retryable (HTTP 503). Trusted transaction
|
|
472
|
+
reconciliation also persists a lifecycle delivery journal before subscription activation,
|
|
473
|
+
so a failed completion/update hook can resume from another verification transport without
|
|
474
|
+
resetting the billing period or repeating an already checkpointed hook. Application hooks
|
|
475
|
+
must remain idempotent by payment reference: a process can stop after an external side effect
|
|
476
|
+
and before its delivery checkpoint. Claims expire after five minutes for crash recovery.
|
|
477
|
+
Trial-start hooks use the same recovery mechanism after signed tokenization-charge webhooks.
|
|
478
|
+
Remote trial subscription creation is reserved before dispatch. If the provider response is
|
|
479
|
+
lost, the plugin keeps the reservation unresolved instead of creating a duplicate subscription;
|
|
480
|
+
reconcile the existing provider subscription (including its signed `subscription.create` event)
|
|
481
|
+
before retrying. A stored successful provider response can resume local activation normally.
|
|
473
482
|
|
|
474
483
|
#### Global Hook
|
|
475
484
|
|
package/dist/client.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as PaystackClientLike, E as parsePaystackMetadata, F as PaystackPlan, I as PaystackProduct, K as Subscription, M as PaystackInitializeResult, O as AnyPaystackOptions, U as PaystackTransaction, W as PaystackTransactionResponse, n as paystack$1, v as PaystackMetadata } from "./index-
|
|
1
|
+
import { A as PaystackClientLike, E as parsePaystackMetadata, F as PaystackPlan, I as PaystackProduct, K as Subscription, M as PaystackInitializeResult, O as AnyPaystackOptions, U as PaystackTransaction, W as PaystackTransactionResponse, n as paystack$1, v as PaystackMetadata } from "./index-XVUaLDh_.mjs";
|
|
2
2
|
import { BetterFetch, BetterFetchOption, BetterFetchResponse } from "@better-fetch/fetch";
|
|
3
3
|
import { BetterAuthClientPlugin } from "better-auth/client";
|
|
4
4
|
//#region src/client.d.ts
|
package/dist/client.mjs
CHANGED
|
@@ -694,7 +694,7 @@ declare const getConfig: <P extends string = "/get-config">(options: AnyPaystack
|
|
|
694
694
|
}>;
|
|
695
695
|
//#endregion
|
|
696
696
|
//#region src/version.d.ts
|
|
697
|
-
declare const PACKAGE_VERSION = "3.5.
|
|
697
|
+
declare const PACKAGE_VERSION = "3.5.2";
|
|
698
698
|
//#endregion
|
|
699
699
|
//#region src/metadata.d.ts
|
|
700
700
|
type PaystackMetadata = Record<string, unknown>;
|
|
@@ -903,4 +903,4 @@ declare const paystack: typeof createPaystackPlugin;
|
|
|
903
903
|
type PaystackPlugin<TPaystackClient extends PaystackClientLike = PaystackClientLike, O extends PaystackOptions<TPaystackClient> = PaystackOptions<TPaystackClient>> = ReturnType<typeof paystack<TPaystackClient, O>>;
|
|
904
904
|
//#endregion
|
|
905
905
|
export { PaystackClientLike as A, PaystackSubscriptionOperationHooks as B, getMetadataNumber as C, stringifyPaystackMetadata as D, parsePaystackMetadata as E, PaystackPlan as F, PaystackWebhookEventRecord as G, PaystackSyncResult as H, PaystackProduct as I, Subscription as K, PaystackSubscription as L, PaystackInitializeResult as M, PaystackOptions as N, AnyPaystackOptions as O, PaystackPaymentCredential as P, PaystackSubscriptionOperation as R, getMetadataBoolean as S, hasPaystackMetadata as T, PaystackTransaction as U, PaystackSubscriptionOperationPhase as V, PaystackTransactionResponse as W, syncPaystackProducts as _, migratePaystackSubscriptionSchema as a, createProrationMetadata as b, PaystackReconciliationSummary as c, ReconcilePaystackTransactionResult as d, ReconcilePaystackTransactionSuccess as f, syncPaystackPlans as g, chargeSubscriptionRenewal as h, PaystackSchemaMigrationReport as i, PaystackCustomer as j, ChargeRecurringSubscriptionResult as k, ReconcilePaystackTransactionFailure as l, getOrganizationEntitlements as m, paystack as n, PaystackReconciliationError as o, reconcilePaystackTransaction as p, SubscriptionOptions as q, PaystackSchemaMigrationFailure as r, PaystackReconciliationSource as s, PaystackPlugin as t, ReconcilePaystackTransactionInput as u, PaystackMetadata as v, getMetadataString as w, createRenewalMetadata as x, createCheckoutMetadata as y, PaystackSubscriptionOperationDecision as z };
|
|
906
|
-
//# sourceMappingURL=index-
|
|
906
|
+
//# sourceMappingURL=index-XVUaLDh_.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-XVUaLDh_.d.mts","names":[],"sources":["../src/schema.ts","../src/types.d.ts","../src/billing-store.ts","../src/routes.ts","../src/version.ts","../src/metadata.ts","../src/operations.ts","../src/limits.ts","../src/reconciliation.ts","../src/migrations.ts","../src/index.ts"],"mappings":";;;;;;;KAIK,kBAAkB,0BAA0B,4BAA4B,OAC3E;EAEE,QAAQ,OAAO,WAAW;EAC1B;EACA;;KAIC,qBAAqB;KAgBrB,sBAAsB;KAYtB,sBAAsB;KA0BtB,iBAAiB;KAWjB,2BAA2B;KAS3B,aAAa;KAEb,qBAAqB;KAErB,iBAAiB;KAejB,cAAc;KAeP,uBAAuB,sBACjC,qBACA,iBACA,2BACA,aACA,qBACA,iBACA,cACA;cAwYW,YAAa,SAAS,oBAAkB;;;KCjgBzC;;;;;UAWK;EACb;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,WAAW;EACX,WAAW;;UAEE;EACb;EACA;EACA;EACA;EACA;EACA;EACA,cAAc;EACd,WAAW;EACX,WAAW;;UAEE;EACb;EACA;EACA;;EAEA;EACA;EACA;EACA,WAAW;EACX,WAAW;;;UAGE;EACb;EACA;EACA,WAAW;EACX,WAAW;;UAEE;EACb;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,YAAY;EACZ,YAAY;;UAaC;EACb;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;EAKA;EACA;EACA;;;;;EAKA;EACA;IACI;;IAEA;IACA,gBAAgB,cAAc,iBAAiB;IAC/C,cAAc,cAAc,iBAAiB;IAC7C,kBAAkB,cAAc,iBAAiB;;EAErD,SAAS;EACT;EACA;EACA,YAAY;EACZ,YAAY;;;;;KAKJ,yBAAyB;;;;KAIzB,8BAA8B;KAC9B,sCAAsC;KAKtC;EACR;EACA;EACA;EACA;EACA;EACA;IACI;IACA;MACI;MACA;;;;EAIR;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;;;UAGa;EACb;IACI;;EAEJ;EACA;EACA,cAAc;EACd;IACI;IACA;IACA;IACA;IACA;IACA;IACA;IACA,aAAa;IACb,WAAW;IACX;IACA;;;KAGI;EACR;EACA;EACA;;EAEA;EACA,QAAQ;;EAER;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,kBAAkB;EAC1B,MAAM;EACN,qBAAqB;EACrB,SAAS,QAAQ;;cAGb,uBACJ,wBAAwB,qBAAqB,oBAC7C,UAAU,gBAAgB,mBAAmB,gBAAgB,kBAE7D,SAAS,MACR,uBAAuB;cAwbb,iBAAiB;KAElB,eACV,wBAAwB,qBAAqB,oBAC7C,UAAU,gBAAgB,mBAAmB,gBAAgB,oBAC3D,kBAAkB,SAAS,iBAAiB"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as PaystackClientLike, B as PaystackSubscriptionOperationHooks, C as getMetadataNumber, D as stringifyPaystackMetadata, E as parsePaystackMetadata, F as PaystackPlan, G as PaystackWebhookEventRecord, H as PaystackSyncResult, I as PaystackProduct, K as Subscription, L as PaystackSubscription, M as PaystackInitializeResult, N as PaystackOptions, P as PaystackPaymentCredential, R as PaystackSubscriptionOperation, S as getMetadataBoolean, T as hasPaystackMetadata, U as PaystackTransaction, V as PaystackSubscriptionOperationPhase, W as PaystackTransactionResponse, _ as syncPaystackProducts, a as migratePaystackSubscriptionSchema, b as createProrationMetadata, c as PaystackReconciliationSummary, d as ReconcilePaystackTransactionResult, f as ReconcilePaystackTransactionSuccess, g as syncPaystackPlans, h as chargeSubscriptionRenewal, i as PaystackSchemaMigrationReport, j as PaystackCustomer, k as ChargeRecurringSubscriptionResult, l as ReconcilePaystackTransactionFailure, m as getOrganizationEntitlements, n as paystack, o as PaystackReconciliationError, p as reconcilePaystackTransaction, q as SubscriptionOptions, r as PaystackSchemaMigrationFailure, s as PaystackReconciliationSource, t as PaystackPlugin, u as ReconcilePaystackTransactionInput, v as PaystackMetadata, w as getMetadataString, x as createRenewalMetadata, y as createCheckoutMetadata, z as PaystackSubscriptionOperationDecision } from "./index-
|
|
1
|
+
import { A as PaystackClientLike, B as PaystackSubscriptionOperationHooks, C as getMetadataNumber, D as stringifyPaystackMetadata, E as parsePaystackMetadata, F as PaystackPlan, G as PaystackWebhookEventRecord, H as PaystackSyncResult, I as PaystackProduct, K as Subscription, L as PaystackSubscription, M as PaystackInitializeResult, N as PaystackOptions, P as PaystackPaymentCredential, R as PaystackSubscriptionOperation, S as getMetadataBoolean, T as hasPaystackMetadata, U as PaystackTransaction, V as PaystackSubscriptionOperationPhase, W as PaystackTransactionResponse, _ as syncPaystackProducts, a as migratePaystackSubscriptionSchema, b as createProrationMetadata, c as PaystackReconciliationSummary, d as ReconcilePaystackTransactionResult, f as ReconcilePaystackTransactionSuccess, g as syncPaystackPlans, h as chargeSubscriptionRenewal, i as PaystackSchemaMigrationReport, j as PaystackCustomer, k as ChargeRecurringSubscriptionResult, l as ReconcilePaystackTransactionFailure, m as getOrganizationEntitlements, n as paystack, o as PaystackReconciliationError, p as reconcilePaystackTransaction, q as SubscriptionOptions, r as PaystackSchemaMigrationFailure, s as PaystackReconciliationSource, t as PaystackPlugin, u as ReconcilePaystackTransactionInput, v as PaystackMetadata, w as getMetadataString, x as createRenewalMetadata, y as createCheckoutMetadata, z as PaystackSubscriptionOperationDecision } from "./index-XVUaLDh_.mjs";
|
|
2
2
|
export { type ChargeRecurringSubscriptionResult, type PaystackClientLike, type PaystackCustomer, type PaystackInitializeResult, type PaystackMetadata, type PaystackOptions, type PaystackPaymentCredential, type PaystackPlan, PaystackPlugin, type PaystackProduct, type PaystackReconciliationError, type PaystackReconciliationSource, type PaystackReconciliationSummary, type PaystackSchemaMigrationFailure, type PaystackSchemaMigrationReport, type PaystackSubscription, type PaystackSubscriptionOperation, type PaystackSubscriptionOperationDecision, type PaystackSubscriptionOperationHooks, type PaystackSubscriptionOperationPhase, type PaystackSyncResult, type PaystackTransaction, type PaystackTransactionResponse, type PaystackWebhookEventRecord, type ReconcilePaystackTransactionFailure, type ReconcilePaystackTransactionInput, type ReconcilePaystackTransactionResult, type ReconcilePaystackTransactionSuccess, type Subscription, type SubscriptionOptions, chargeSubscriptionRenewal, createCheckoutMetadata, createProrationMetadata, createRenewalMetadata, getMetadataBoolean, getMetadataNumber, getMetadataString, getOrganizationEntitlements, hasPaystackMetadata, migratePaystackSubscriptionSchema, parsePaystackMetadata, paystack, reconcilePaystackTransaction, stringifyPaystackMetadata, syncPaystackPlans, syncPaystackProducts };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as getMetadataBoolean, c as hasPaystackMetadata, i as createRenewalMetadata, l as parsePaystackMetadata, n as createCheckoutMetadata, o as getMetadataNumber, r as createProrationMetadata, s as getMetadataString, t as PACKAGE_VERSION, u as stringifyPaystackMetadata } from "./version-
|
|
1
|
+
import { a as getMetadataBoolean, c as hasPaystackMetadata, i as createRenewalMetadata, l as parsePaystackMetadata, n as createCheckoutMetadata, o as getMetadataNumber, r as createProrationMetadata, s as getMetadataString, t as PACKAGE_VERSION, u as stringifyPaystackMetadata } from "./version-CBSJ3ZWy.mjs";
|
|
2
2
|
import { HIDE_METADATA, defineErrorCodes } from "better-auth";
|
|
3
3
|
import { APIError, createAuthEndpoint, createAuthMiddleware, getSessionFromCtx, originCheckMiddleware, sessionMiddleware } from "better-auth/api";
|
|
4
4
|
import { defu } from "defu";
|
|
@@ -6,6 +6,7 @@ import { PaystackError, PaystackResponse } from "@alexasomba/paystack-node";
|
|
|
6
6
|
import { createCipheriv, createDecipheriv, createHash, randomBytes, randomUUID } from "node:crypto";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import { Buffer } from "node:buffer";
|
|
9
|
+
import * as z$1 from "zod/v4";
|
|
9
10
|
import { mergeSchema } from "better-auth/db";
|
|
10
11
|
//#region src/models.ts
|
|
11
12
|
/** Provider-owned Better Auth model names. Keep these centralized so a provider
|
|
@@ -813,6 +814,158 @@ async function authorizeBillingReference(ctx, options, data) {
|
|
|
813
814
|
throw new APIError("UNAUTHORIZED");
|
|
814
815
|
}
|
|
815
816
|
//#endregion
|
|
817
|
+
//#region src/subscription-fulfillment.ts
|
|
818
|
+
const progressSchema = z$1.object({
|
|
819
|
+
version: z$1.literal(1),
|
|
820
|
+
completed: z$1.array(z$1.enum([
|
|
821
|
+
"complete",
|
|
822
|
+
"update",
|
|
823
|
+
"trialStart"
|
|
824
|
+
])),
|
|
825
|
+
remoteCreationSubmitted: z$1.boolean().optional(),
|
|
826
|
+
remoteSubscriptionCode: z$1.string().optional()
|
|
827
|
+
});
|
|
828
|
+
const unavailable = () => new APIError("SERVICE_UNAVAILABLE", { message: "Subscription fulfillment is pending. Retry verification." });
|
|
829
|
+
/** Persist delivery intent before activation, sharing one lease across verification transports. */
|
|
830
|
+
async function claimSubscriptionFulfillment(ctx, reference, subscription, phase = "subscription-fulfillment") {
|
|
831
|
+
const store = createBillingStore(ctx);
|
|
832
|
+
const eventId = `${phase}:${createHash("sha256").update(JSON.stringify([reference, subscription.id])).digest("hex")}`;
|
|
833
|
+
const findRecord = () => ctx.context.adapter.findOne({
|
|
834
|
+
model: PAYSTACK_MODELS.webhookEvent,
|
|
835
|
+
where: [{
|
|
836
|
+
field: "eventId",
|
|
837
|
+
value: eventId
|
|
838
|
+
}]
|
|
839
|
+
});
|
|
840
|
+
let record = await findRecord();
|
|
841
|
+
if (record === null) {
|
|
842
|
+
if (subscription.status !== "incomplete") return null;
|
|
843
|
+
try {
|
|
844
|
+
record = await store.createWebhookEvent({
|
|
845
|
+
eventId,
|
|
846
|
+
event: "subscription.fulfillment",
|
|
847
|
+
reference,
|
|
848
|
+
status: "pending",
|
|
849
|
+
payload: JSON.stringify({
|
|
850
|
+
version: 1,
|
|
851
|
+
completed: []
|
|
852
|
+
}),
|
|
853
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
854
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
855
|
+
});
|
|
856
|
+
} catch (error) {
|
|
857
|
+
record = await findRecord();
|
|
858
|
+
if (record === null) throw error;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
if (record.status === "processed") return null;
|
|
862
|
+
if (record.status.startsWith("processing:") && Date.now() - new Date(record.updatedAt).getTime() < 3e5) throw unavailable();
|
|
863
|
+
const progress = progressSchema.parse(JSON.parse(record.payload));
|
|
864
|
+
const status = `processing:${randomUUID()}`;
|
|
865
|
+
if (await ctx.context.adapter.update({
|
|
866
|
+
model: PAYSTACK_MODELS.webhookEvent,
|
|
867
|
+
where: [
|
|
868
|
+
{
|
|
869
|
+
field: "eventId",
|
|
870
|
+
value: eventId
|
|
871
|
+
},
|
|
872
|
+
{
|
|
873
|
+
field: "status",
|
|
874
|
+
value: record.status
|
|
875
|
+
},
|
|
876
|
+
{
|
|
877
|
+
field: "updatedAt",
|
|
878
|
+
value: record.updatedAt
|
|
879
|
+
}
|
|
880
|
+
],
|
|
881
|
+
update: {
|
|
882
|
+
status,
|
|
883
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
884
|
+
}
|
|
885
|
+
}) === null) throw unavailable();
|
|
886
|
+
return {
|
|
887
|
+
eventId,
|
|
888
|
+
status,
|
|
889
|
+
progress
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
async function deliverTrialStart(ctx, claim, subscription, plan) {
|
|
893
|
+
if (!claim.progress.completed.includes("trialStart")) {
|
|
894
|
+
await checkpoint(ctx, claim);
|
|
895
|
+
await plan?.freeTrial?.onTrialStart?.(subscription);
|
|
896
|
+
claim.progress.completed.push("trialStart");
|
|
897
|
+
await checkpoint(ctx, claim);
|
|
898
|
+
}
|
|
899
|
+
await checkpoint(ctx, claim, true);
|
|
900
|
+
}
|
|
901
|
+
async function reserveRemoteTrialSubscription(ctx, claim, create) {
|
|
902
|
+
if (claim.progress.remoteSubscriptionCode !== void 0) return claim.progress.remoteSubscriptionCode;
|
|
903
|
+
if (claim.progress.remoteCreationSubmitted === true) throw new APIError("SERVICE_UNAVAILABLE", { message: "Remote trial subscription creation is unresolved. Reconcile the existing provider subscription before retrying." });
|
|
904
|
+
claim.progress.remoteCreationSubmitted = true;
|
|
905
|
+
await checkpoint(ctx, claim);
|
|
906
|
+
const code = await create();
|
|
907
|
+
if (code === void 0 || code === "") throw unavailable();
|
|
908
|
+
claim.progress.remoteSubscriptionCode = code;
|
|
909
|
+
await checkpoint(ctx, claim);
|
|
910
|
+
return code;
|
|
911
|
+
}
|
|
912
|
+
async function checkpoint(ctx, claim, processed = false) {
|
|
913
|
+
if (await ctx.context.adapter.update({
|
|
914
|
+
model: PAYSTACK_MODELS.webhookEvent,
|
|
915
|
+
where: [{
|
|
916
|
+
field: "eventId",
|
|
917
|
+
value: claim.eventId
|
|
918
|
+
}, {
|
|
919
|
+
field: "status",
|
|
920
|
+
value: claim.status
|
|
921
|
+
}],
|
|
922
|
+
update: {
|
|
923
|
+
payload: JSON.stringify(claim.progress),
|
|
924
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
925
|
+
...processed ? {
|
|
926
|
+
status: "processed",
|
|
927
|
+
processedAt: /* @__PURE__ */ new Date()
|
|
928
|
+
} : {}
|
|
929
|
+
}
|
|
930
|
+
}) === null) throw unavailable();
|
|
931
|
+
}
|
|
932
|
+
async function deliverSubscriptionFulfillment(ctx, options, claim, subscription, plan, event) {
|
|
933
|
+
if (plan !== void 0) {
|
|
934
|
+
const callbacks = {
|
|
935
|
+
complete: options.subscription?.onSubscriptionComplete,
|
|
936
|
+
update: options.subscription?.onSubscriptionUpdate
|
|
937
|
+
};
|
|
938
|
+
for (const name of ["complete", "update"]) {
|
|
939
|
+
if (claim.progress.completed.includes(name)) continue;
|
|
940
|
+
await checkpoint(ctx, claim);
|
|
941
|
+
await callbacks[name]?.({
|
|
942
|
+
event,
|
|
943
|
+
subscription,
|
|
944
|
+
plan
|
|
945
|
+
}, ctx);
|
|
946
|
+
claim.progress.completed.push(name);
|
|
947
|
+
await checkpoint(ctx, claim);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
await checkpoint(ctx, claim, true);
|
|
951
|
+
}
|
|
952
|
+
async function releaseSubscriptionFulfillment(ctx, claim) {
|
|
953
|
+
await ctx.context.adapter.update({
|
|
954
|
+
model: PAYSTACK_MODELS.webhookEvent,
|
|
955
|
+
where: [{
|
|
956
|
+
field: "eventId",
|
|
957
|
+
value: claim.eventId
|
|
958
|
+
}, {
|
|
959
|
+
field: "status",
|
|
960
|
+
value: claim.status
|
|
961
|
+
}],
|
|
962
|
+
update: {
|
|
963
|
+
status: "pending",
|
|
964
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
//#endregion
|
|
816
969
|
//#region src/reconciliation.ts
|
|
817
970
|
function getAllowedSubscriptionChannels$1(options) {
|
|
818
971
|
const channels = options.subscription?.allowedPaymentChannels;
|
|
@@ -905,7 +1058,7 @@ async function reconcilePaystackTransaction(ctx, options, input) {
|
|
|
905
1058
|
}
|
|
906
1059
|
});
|
|
907
1060
|
const status = data.status ?? "failed";
|
|
908
|
-
const reference =
|
|
1061
|
+
const reference = input.reference;
|
|
909
1062
|
const paystackIdRaw = data.id;
|
|
910
1063
|
const paystackId = paystackIdRaw !== void 0 && paystackIdRaw !== null ? String(paystackIdRaw) : void 0;
|
|
911
1064
|
const authorizationCode = data.authorization?.authorization_code;
|
|
@@ -955,6 +1108,20 @@ async function reconcilePaystackTransaction(ctx, options, input) {
|
|
|
955
1108
|
}
|
|
956
1109
|
});
|
|
957
1110
|
}
|
|
1111
|
+
if (data.reference !== reference || txRecord !== null && typeof txRecord.amount === "number" && txRecord.amount !== data.amount || txRecord !== null && typeof txRecord.currency === "string" && txRecord.currency !== data.currency) return throwOrReturnFailure({
|
|
1112
|
+
throwOnError,
|
|
1113
|
+
apiStatus: "BAD_REQUEST",
|
|
1114
|
+
source,
|
|
1115
|
+
status,
|
|
1116
|
+
reference,
|
|
1117
|
+
data,
|
|
1118
|
+
summary,
|
|
1119
|
+
error: {
|
|
1120
|
+
code: "PAYMENT_INTENT_MISMATCH",
|
|
1121
|
+
message: "Verified payment does not match the stored reference, amount, and currency.",
|
|
1122
|
+
status: 400
|
|
1123
|
+
}
|
|
1124
|
+
});
|
|
958
1125
|
const transactionUpdate = {
|
|
959
1126
|
status,
|
|
960
1127
|
paystackId,
|
|
@@ -1065,7 +1232,11 @@ async function reconcilePaystackTransaction(ctx, options, input) {
|
|
|
1065
1232
|
summary.subscription.found = targetSub !== void 0;
|
|
1066
1233
|
summary.subscription.id = targetSub?.id;
|
|
1067
1234
|
summary.subscription.status = targetSub?.status;
|
|
1068
|
-
if (targetSub
|
|
1235
|
+
if (!targetSub || ![
|
|
1236
|
+
"incomplete",
|
|
1237
|
+
"active",
|
|
1238
|
+
"trialing"
|
|
1239
|
+
].includes(targetSub.status)) return {
|
|
1069
1240
|
ok: true,
|
|
1070
1241
|
source,
|
|
1071
1242
|
status,
|
|
@@ -1073,64 +1244,8 @@ async function reconcilePaystackTransaction(ctx, options, input) {
|
|
|
1073
1244
|
data,
|
|
1074
1245
|
...summary
|
|
1075
1246
|
};
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
const planConfig = (await getPlans(options.subscription)).find((plan) => plan.name.toLowerCase() === targetPlan.toLowerCase());
|
|
1079
|
-
if (planConfig !== void 0 && planConfig !== null && (planConfig.planCode === void 0 || planConfig.planCode === null || planConfig.planCode === "")) subscriptionCode = `LOC_${reference}`;
|
|
1080
|
-
else if (targetSub?.subscriptionCode !== void 0 && targetSub.subscriptionCode !== null && targetSub.subscriptionCode !== "") subscriptionCode = targetSub.subscriptionCode;
|
|
1081
|
-
else if (authorizationCode !== void 0 && authorizationCode !== null && email !== void 0 && email !== null && email !== "" && planConfig?.planCode !== void 0 && planConfig.planCode !== null && planConfig.planCode !== "") subscriptionCode = unwrapSdkResult(await paystack?.subscription?.create({ body: {
|
|
1082
|
-
customer: email,
|
|
1083
|
-
plan: planConfig.planCode,
|
|
1084
|
-
authorization: authorizationCode,
|
|
1085
|
-
start_date: trialEnd
|
|
1086
|
-
} }))?.subscription_code;
|
|
1087
|
-
} else if (isTrial === false) {
|
|
1088
|
-
const planCodeFromPaystack = data.plan?.plan_code;
|
|
1089
|
-
if (planCodeFromPaystack === void 0 || planCodeFromPaystack === null || planCodeFromPaystack === "") subscriptionCode = `LOC_${reference}`;
|
|
1090
|
-
else subscriptionCode = data.subscription?.subscription_code ?? void 0;
|
|
1091
|
-
}
|
|
1092
|
-
let updatedSubscription = null;
|
|
1093
|
-
if (targetSub !== void 0 && targetSub !== null) {
|
|
1094
|
-
const resolvedPlan = (await getPlans(options.subscription)).find((candidate) => candidate.name.toLowerCase() === targetSub.plan.toLowerCase());
|
|
1095
|
-
updatedSubscription = await store.updateSubscription(targetSub.id, {
|
|
1096
|
-
status: isTrial ? "trialing" : "active",
|
|
1097
|
-
billingInterval: resolvedPlan?.interval ?? targetSub.billingInterval ?? null,
|
|
1098
|
-
periodStart: /* @__PURE__ */ new Date(),
|
|
1099
|
-
updatedAt: /* @__PURE__ */ new Date(),
|
|
1100
|
-
...isTrial && trialEnd !== void 0 ? {
|
|
1101
|
-
trialStart: /* @__PURE__ */ new Date(),
|
|
1102
|
-
trialEnd: new Date(trialEnd),
|
|
1103
|
-
periodEnd: new Date(trialEnd)
|
|
1104
|
-
} : {},
|
|
1105
|
-
...subscriptionCode !== void 0 ? { subscriptionCode } : {}
|
|
1106
|
-
});
|
|
1107
|
-
summary.subscription.updated = updatedSubscription !== null;
|
|
1108
|
-
summary.subscription.id = updatedSubscription?.id ?? targetSub.id;
|
|
1109
|
-
summary.subscription.status = updatedSubscription?.status ?? targetSub.status;
|
|
1110
|
-
if (authorizationCode !== void 0 && authorizationCode !== null && authorizationCode !== "" && updatedSubscription !== null) await savePaystackPaymentCredentials(ctx.context.adapter, options, updatedSubscription.id, { authorizationCode });
|
|
1111
|
-
if (updatedSubscription !== null && (updatedSubscription.status === "active" || updatedSubscription.status === "trialing")) await store.retireCompetingSubscriptions(updatedSubscription.referenceId, updatedSubscription.groupId ?? null, updatedSubscription.id);
|
|
1112
|
-
}
|
|
1113
|
-
if (updatedSubscription !== void 0 && updatedSubscription !== null) {
|
|
1114
|
-
const plan = (await getPlans(options.subscription)).find((candidate) => candidate.name.toLowerCase() === updatedSubscription.plan.toLowerCase());
|
|
1115
|
-
if (plan !== void 0) {
|
|
1116
|
-
const callbackData = {
|
|
1117
|
-
event: data,
|
|
1118
|
-
subscription: updatedSubscription,
|
|
1119
|
-
plan
|
|
1120
|
-
};
|
|
1121
|
-
for (const callback of [options.subscription?.onSubscriptionComplete, options.subscription?.onSubscriptionUpdate]) try {
|
|
1122
|
-
await callback?.(callbackData, ctx);
|
|
1123
|
-
} catch (error) {
|
|
1124
|
-
ctx.context.logger.error("Paystack subscription callback failed", error);
|
|
1125
|
-
}
|
|
1126
|
-
if (targetSub?.status === "trialing" && updatedSubscription.status === "active") try {
|
|
1127
|
-
await plan.freeTrial?.onTrialEnd?.(updatedSubscription);
|
|
1128
|
-
} catch (error) {
|
|
1129
|
-
ctx.context.logger.error("Paystack trial end callback failed", error);
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
return {
|
|
1247
|
+
const claim = await claimSubscriptionFulfillment(ctx, reference, targetSub);
|
|
1248
|
+
if (claim === null) return {
|
|
1134
1249
|
ok: true,
|
|
1135
1250
|
source,
|
|
1136
1251
|
status,
|
|
@@ -1138,6 +1253,95 @@ async function reconcilePaystackTransaction(ctx, options, input) {
|
|
|
1138
1253
|
data,
|
|
1139
1254
|
...summary
|
|
1140
1255
|
};
|
|
1256
|
+
try {
|
|
1257
|
+
if (targetSub.status !== "incomplete") {
|
|
1258
|
+
if (authorizationCode !== void 0 && authorizationCode !== null && authorizationCode !== "") await savePaystackPaymentCredentials(ctx.context.adapter, options, targetSub.id, { authorizationCode });
|
|
1259
|
+
await store.retireCompetingSubscriptions(targetSub.referenceId, targetSub.groupId ?? null, targetSub.id);
|
|
1260
|
+
await deliverSubscriptionFulfillment(ctx, options, claim, targetSub, (await getPlans(options.subscription)).find((candidate) => candidate.name.toLowerCase() === targetSub.plan.toLowerCase()), data);
|
|
1261
|
+
return {
|
|
1262
|
+
ok: true,
|
|
1263
|
+
source,
|
|
1264
|
+
status,
|
|
1265
|
+
reference,
|
|
1266
|
+
data,
|
|
1267
|
+
...summary
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1270
|
+
if (isTrial && targetPlan !== void 0 && trialEnd !== void 0) {
|
|
1271
|
+
const email = data.customer?.email;
|
|
1272
|
+
const planConfig = (await getPlans(options.subscription)).find((plan) => plan.name.toLowerCase() === targetPlan.toLowerCase());
|
|
1273
|
+
if (planConfig !== void 0 && planConfig !== null && (planConfig.planCode === void 0 || planConfig.planCode === null || planConfig.planCode === "")) subscriptionCode = `LOC_${reference}`;
|
|
1274
|
+
else if (targetSub?.subscriptionCode !== void 0 && targetSub.subscriptionCode !== null && targetSub.subscriptionCode !== "") subscriptionCode = targetSub.subscriptionCode;
|
|
1275
|
+
else if (authorizationCode !== void 0 && authorizationCode !== null && email !== void 0 && email !== null && email !== "" && planConfig?.planCode !== void 0 && planConfig.planCode !== null && planConfig.planCode !== "") {
|
|
1276
|
+
const planCode = planConfig.planCode;
|
|
1277
|
+
subscriptionCode = await reserveRemoteTrialSubscription(ctx, claim, async () => {
|
|
1278
|
+
return unwrapSdkResult(await paystack?.subscription?.create({ body: {
|
|
1279
|
+
customer: email,
|
|
1280
|
+
plan: planCode,
|
|
1281
|
+
authorization: authorizationCode,
|
|
1282
|
+
start_date: trialEnd
|
|
1283
|
+
} }))?.subscription_code;
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
} else if (isTrial === false) {
|
|
1287
|
+
const planCodeFromPaystack = data.plan?.plan_code;
|
|
1288
|
+
if (planCodeFromPaystack === void 0 || planCodeFromPaystack === null || planCodeFromPaystack === "") subscriptionCode = `LOC_${reference}`;
|
|
1289
|
+
else subscriptionCode = data.subscription?.subscription_code ?? void 0;
|
|
1290
|
+
}
|
|
1291
|
+
let updatedSubscription = null;
|
|
1292
|
+
if (targetSub !== void 0 && targetSub !== null) {
|
|
1293
|
+
const resolvedPlan = (await getPlans(options.subscription)).find((candidate) => candidate.name.toLowerCase() === targetSub.plan.toLowerCase());
|
|
1294
|
+
updatedSubscription = await ctx.context.adapter.update({
|
|
1295
|
+
model: PAYSTACK_MODELS.subscription,
|
|
1296
|
+
where: [
|
|
1297
|
+
{
|
|
1298
|
+
field: "id",
|
|
1299
|
+
value: targetSub.id
|
|
1300
|
+
},
|
|
1301
|
+
{
|
|
1302
|
+
field: "status",
|
|
1303
|
+
value: "incomplete"
|
|
1304
|
+
},
|
|
1305
|
+
{
|
|
1306
|
+
field: "transactionReference",
|
|
1307
|
+
value: reference
|
|
1308
|
+
}
|
|
1309
|
+
],
|
|
1310
|
+
update: {
|
|
1311
|
+
status: isTrial ? "trialing" : "active",
|
|
1312
|
+
billingInterval: resolvedPlan?.interval ?? targetSub.billingInterval ?? null,
|
|
1313
|
+
periodStart: /* @__PURE__ */ new Date(),
|
|
1314
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
1315
|
+
...isTrial && trialEnd !== void 0 ? {
|
|
1316
|
+
trialStart: /* @__PURE__ */ new Date(),
|
|
1317
|
+
trialEnd: new Date(trialEnd),
|
|
1318
|
+
periodEnd: new Date(trialEnd)
|
|
1319
|
+
} : {},
|
|
1320
|
+
...subscriptionCode !== void 0 ? { subscriptionCode } : {}
|
|
1321
|
+
}
|
|
1322
|
+
});
|
|
1323
|
+
summary.subscription.updated = updatedSubscription !== null;
|
|
1324
|
+
summary.subscription.id = updatedSubscription?.id ?? targetSub.id;
|
|
1325
|
+
summary.subscription.status = updatedSubscription?.status ?? targetSub.status;
|
|
1326
|
+
if (authorizationCode !== void 0 && authorizationCode !== null && authorizationCode !== "" && updatedSubscription !== null) await savePaystackPaymentCredentials(ctx.context.adapter, options, updatedSubscription.id, { authorizationCode });
|
|
1327
|
+
if (updatedSubscription !== null && (updatedSubscription.status === "active" || updatedSubscription.status === "trialing")) await store.retireCompetingSubscriptions(updatedSubscription.referenceId, updatedSubscription.groupId ?? null, updatedSubscription.id);
|
|
1328
|
+
}
|
|
1329
|
+
if (updatedSubscription !== void 0 && updatedSubscription !== null) {
|
|
1330
|
+
const plan = (await getPlans(options.subscription)).find((candidate) => candidate.name.toLowerCase() === updatedSubscription.plan.toLowerCase());
|
|
1331
|
+
await deliverSubscriptionFulfillment(ctx, options, claim, updatedSubscription, plan, data);
|
|
1332
|
+
} else throw new APIError("SERVICE_UNAVAILABLE", { message: "Subscription activation is pending. Retry verification." });
|
|
1333
|
+
return {
|
|
1334
|
+
ok: true,
|
|
1335
|
+
source,
|
|
1336
|
+
status,
|
|
1337
|
+
reference,
|
|
1338
|
+
data,
|
|
1339
|
+
...summary
|
|
1340
|
+
};
|
|
1341
|
+
} catch (error) {
|
|
1342
|
+
await releaseSubscriptionFulfillment(ctx, claim);
|
|
1343
|
+
throw error;
|
|
1344
|
+
}
|
|
1141
1345
|
}
|
|
1142
1346
|
//#endregion
|
|
1143
1347
|
//#region src/reference-middleware.ts
|
|
@@ -1671,13 +1875,20 @@ const paystackWebhook = (options, path = "/webhook") => {
|
|
|
1671
1875
|
claimStatus = `processing:${randomUUID()}`;
|
|
1672
1876
|
if (await ctx.context.adapter.update({
|
|
1673
1877
|
model: PAYSTACK_MODELS.webhookEvent,
|
|
1674
|
-
where: [
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1878
|
+
where: [
|
|
1879
|
+
{
|
|
1880
|
+
field: "eventId",
|
|
1881
|
+
value: eventId
|
|
1882
|
+
},
|
|
1883
|
+
{
|
|
1884
|
+
field: "status",
|
|
1885
|
+
value: existingEvent.status
|
|
1886
|
+
},
|
|
1887
|
+
{
|
|
1888
|
+
field: "updatedAt",
|
|
1889
|
+
value: existingEvent.updatedAt
|
|
1890
|
+
}
|
|
1891
|
+
],
|
|
1681
1892
|
update: {
|
|
1682
1893
|
status: claimStatus,
|
|
1683
1894
|
updatedAt: /* @__PURE__ */ new Date()
|
|
@@ -1713,24 +1924,36 @@ const paystackWebhook = (options, path = "/webhook") => {
|
|
|
1713
1924
|
value: reference
|
|
1714
1925
|
}]
|
|
1715
1926
|
});
|
|
1716
|
-
if (pendingTrial
|
|
1717
|
-
const
|
|
1718
|
-
|
|
1719
|
-
status
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1927
|
+
if (pendingTrial !== null && ["incomplete", "trialing"].includes(pendingTrial.status) && pendingTrial.trialStart !== void 0 && pendingTrial.trialStart !== null) {
|
|
1928
|
+
const trialClaim = await claimSubscriptionFulfillment(ctx, reference, pendingTrial, "trial-start");
|
|
1929
|
+
if (trialClaim !== null) try {
|
|
1930
|
+
const startedTrial = pendingTrial.status === "trialing" ? pendingTrial : await ctx.context.adapter.update({
|
|
1931
|
+
model: PAYSTACK_MODELS.subscription,
|
|
1932
|
+
where: [
|
|
1933
|
+
{
|
|
1934
|
+
field: "id",
|
|
1935
|
+
value: pendingTrial.id
|
|
1936
|
+
},
|
|
1937
|
+
{
|
|
1938
|
+
field: "status",
|
|
1939
|
+
value: "incomplete"
|
|
1940
|
+
},
|
|
1941
|
+
{
|
|
1942
|
+
field: "transactionReference",
|
|
1943
|
+
value: reference
|
|
1944
|
+
}
|
|
1945
|
+
],
|
|
1946
|
+
update: {
|
|
1947
|
+
status: "trialing",
|
|
1948
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1949
|
+
}
|
|
1950
|
+
});
|
|
1951
|
+
if (startedTrial === null) throw new Error("Trial activation changed concurrently; retry later.");
|
|
1952
|
+
await deliverTrialStart(ctx, trialClaim, startedTrial, await getPlanByName(options, pendingTrial.plan) ?? void 0);
|
|
1953
|
+
} catch (error) {
|
|
1954
|
+
await releaseSubscriptionFulfillment(ctx, trialClaim);
|
|
1955
|
+
throw error;
|
|
1956
|
+
}
|
|
1734
1957
|
}
|
|
1735
1958
|
}
|
|
1736
1959
|
try {
|