@paykit-sdk/paystack 1.0.0

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/schema.js ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,14 @@
1
+ import { Customer, Payment, Checkout, Subscription, Refund, Invoice } from '@paykit-sdk/core';
2
+ import { PaystackCustomer, PaystackTransaction, PaystackInitializeResponse, PaystackSubscription, PaystackRefund } from '../schema.mjs';
3
+
4
+ declare const paykitCustomer$InboundSchema: (data: PaystackCustomer) => Customer;
5
+ declare const paykitPayment$InboundSchema: (data: PaystackTransaction, overridePaymentUrl?: string | null) => Payment;
6
+ declare const paykitCheckout$InboundSchema: (init: PaystackInitializeResponse, transaction: Partial<PaystackTransaction> & {
7
+ currency?: string;
8
+ amount?: number;
9
+ }) => Checkout;
10
+ declare const paykitSubscription$InboundSchema: (data: PaystackSubscription) => Subscription;
11
+ declare const paykitRefund$InboundSchema: (data: PaystackRefund, fallbackCurrency: string) => Refund;
12
+ declare const paykitInvoice$InboundSchema: (data: PaystackTransaction) => Invoice;
13
+
14
+ export { paykitCheckout$InboundSchema, paykitCustomer$InboundSchema, paykitInvoice$InboundSchema, paykitPayment$InboundSchema, paykitRefund$InboundSchema, paykitSubscription$InboundSchema };
@@ -0,0 +1,14 @@
1
+ import { Customer, Payment, Checkout, Subscription, Refund, Invoice } from '@paykit-sdk/core';
2
+ import { PaystackCustomer, PaystackTransaction, PaystackInitializeResponse, PaystackSubscription, PaystackRefund } from '../schema.js';
3
+
4
+ declare const paykitCustomer$InboundSchema: (data: PaystackCustomer) => Customer;
5
+ declare const paykitPayment$InboundSchema: (data: PaystackTransaction, overridePaymentUrl?: string | null) => Payment;
6
+ declare const paykitCheckout$InboundSchema: (init: PaystackInitializeResponse, transaction: Partial<PaystackTransaction> & {
7
+ currency?: string;
8
+ amount?: number;
9
+ }) => Checkout;
10
+ declare const paykitSubscription$InboundSchema: (data: PaystackSubscription) => Subscription;
11
+ declare const paykitRefund$InboundSchema: (data: PaystackRefund, fallbackCurrency: string) => Refund;
12
+ declare const paykitInvoice$InboundSchema: (data: PaystackTransaction) => Invoice;
13
+
14
+ export { paykitCheckout$InboundSchema, paykitCustomer$InboundSchema, paykitInvoice$InboundSchema, paykitPayment$InboundSchema, paykitRefund$InboundSchema, paykitSubscription$InboundSchema };
@@ -0,0 +1,171 @@
1
+ 'use strict';
2
+
3
+ var core = require('@paykit-sdk/core');
4
+
5
+ // src/utils/mapper.ts
6
+ var paykitCustomer$InboundSchema = (data) => {
7
+ const { fullName } = core.parseCustomerName({
8
+ name: [data.first_name, data.last_name].filter(Boolean).join(" ") || "",
9
+ email: data.email
10
+ });
11
+ return {
12
+ id: data.customer_code,
13
+ email: data.email,
14
+ name: fullName,
15
+ phone: data.phone ?? "",
16
+ metadata: data.metadata ?? void 0,
17
+ created_at: new Date(data.created_at),
18
+ updated_at: data.updated_at ? new Date(data.updated_at) : null
19
+ };
20
+ };
21
+ var paystackStatusMap = {
22
+ success: "succeeded",
23
+ failed: "failed",
24
+ pending: "pending",
25
+ abandoned: "canceled"
26
+ };
27
+ var paykitPayment$InboundSchema = (data, overridePaymentUrl) => {
28
+ const rawMetadata = core.parseJSON(
29
+ data.metadata,
30
+ core.Schema.record(core.Schema.string(), core.Schema.unknown())
31
+ ) ?? {};
32
+ const metadata = core.omitInternalMetadata(rawMetadata);
33
+ let itemId = null;
34
+ const paykitMeta = core.parseJSON(
35
+ rawMetadata[core.PAYKIT_METADATA_KEY],
36
+ core.Schema.object({
37
+ item_id: core.Schema.string().optional()
38
+ })
39
+ );
40
+ if (paykitMeta) {
41
+ itemId = paykitMeta.item_id ?? null;
42
+ }
43
+ const status = paystackStatusMap[data.status] ?? "pending";
44
+ return {
45
+ id: data.reference,
46
+ amount: data.amount,
47
+ currency: data.currency,
48
+ customer: data.customer?.email ?? "",
49
+ status,
50
+ metadata,
51
+ item_id: itemId,
52
+ requires_action: status === "pending",
53
+ payment_url: overridePaymentUrl ?? null
54
+ };
55
+ };
56
+ var paykitCheckout$InboundSchema = (init, transaction) => {
57
+ const rawMetadata = core.parseJSON(
58
+ transaction.metadata,
59
+ core.Schema.record(core.Schema.string(), core.Schema.unknown())
60
+ ) ?? {};
61
+ const metadata = core.omitInternalMetadata(rawMetadata);
62
+ let itemId = "";
63
+ let quantity = 1;
64
+ let type = null;
65
+ const paykitMeta = core.parseJSON(
66
+ rawMetadata[core.PAYKIT_METADATA_KEY],
67
+ core.Schema.object({
68
+ item_id: core.Schema.string().optional(),
69
+ quantity: core.Schema.number().optional(),
70
+ type: core.billingModeSchema.optional()
71
+ })
72
+ );
73
+ if (paykitMeta && typeof paykitMeta === "string") {
74
+ const parsed = core.parseJSON(
75
+ paykitMeta,
76
+ core.Schema.object({
77
+ item_id: core.Schema.string().optional(),
78
+ quantity: core.Schema.number().optional(),
79
+ type: core.billingModeSchema.optional()
80
+ })
81
+ );
82
+ if (parsed) {
83
+ itemId = parsed.item_id ?? "";
84
+ quantity = parsed.quantity ?? 1;
85
+ type = parsed.type ?? null;
86
+ }
87
+ }
88
+ return {
89
+ id: init.reference,
90
+ customer: { email: transaction.customer?.email ?? "" },
91
+ payment_url: init.authorization_url,
92
+ metadata: Object.keys(metadata).length > 0 ? metadata : null,
93
+ session_type: type ?? "one_time",
94
+ products: [{ id: itemId, quantity }],
95
+ currency: transaction.currency ?? "NGN",
96
+ amount: transaction.amount ?? 0
97
+ };
98
+ };
99
+ var paystackIntervalMap = {
100
+ daily: "day",
101
+ weekly: "week",
102
+ monthly: "month",
103
+ annually: "year",
104
+ quarterly: {
105
+ type: "custom",
106
+ durationMs: 3 * 30 * 24 * 60 * 60 * 1e3
107
+ },
108
+ biannually: {
109
+ type: "custom",
110
+ durationMs: 6 * 30 * 24 * 60 * 60 * 1e3
111
+ }
112
+ };
113
+ var paystackSubscriptionStatusMap = {
114
+ active: "active",
115
+ "non-renewing": "canceled",
116
+ cancelled: "canceled",
117
+ attention: "past_due",
118
+ completed: "expired"
119
+ };
120
+ var paykitSubscription$InboundSchema = (data) => {
121
+ const nextPaymentDate = data.next_payment_date ? new Date(data.next_payment_date) : /* @__PURE__ */ new Date();
122
+ return {
123
+ id: data.subscription_code,
124
+ customer: data.customer?.email ?? "",
125
+ amount: data.amount,
126
+ currency: data.currency || data.plan?.currency || "NGN",
127
+ status: paystackSubscriptionStatusMap[data.status] ?? "active",
128
+ current_period_start: new Date(data.createdAt),
129
+ current_period_end: nextPaymentDate,
130
+ item_id: data.plan?.plan_code ?? "",
131
+ billing_interval: paystackIntervalMap[data.plan?.interval] ?? "month",
132
+ metadata: null,
133
+ custom_fields: null,
134
+ requires_action: false,
135
+ payment_url: null
136
+ };
137
+ };
138
+ var paykitRefund$InboundSchema = (data, fallbackCurrency) => ({
139
+ id: String(data.id),
140
+ amount: data.amount,
141
+ currency: data.currency || fallbackCurrency,
142
+ reason: data.customer_note || data.merchant_note || null,
143
+ metadata: null
144
+ });
145
+ var paykitInvoice$InboundSchema = (data) => {
146
+ const rawMetadata = core.parseJSON(
147
+ data.metadata,
148
+ core.Schema.record(core.Schema.string(), core.Schema.unknown())
149
+ ) ?? {};
150
+ const metadata = core.omitInternalMetadata(rawMetadata);
151
+ return {
152
+ id: String(data.id),
153
+ customer: data.customer?.email ?? "",
154
+ subscription_id: null,
155
+ billing_mode: "one_time",
156
+ amount_paid: data.amount,
157
+ currency: data.currency,
158
+ status: "paid",
159
+ paid_at: data.paid_at ?? (/* @__PURE__ */ new Date()).toISOString(),
160
+ line_items: null,
161
+ metadata: Object.keys(metadata).length > 0 ? metadata : null,
162
+ custom_fields: null
163
+ };
164
+ };
165
+
166
+ exports.paykitCheckout$InboundSchema = paykitCheckout$InboundSchema;
167
+ exports.paykitCustomer$InboundSchema = paykitCustomer$InboundSchema;
168
+ exports.paykitInvoice$InboundSchema = paykitInvoice$InboundSchema;
169
+ exports.paykitPayment$InboundSchema = paykitPayment$InboundSchema;
170
+ exports.paykitRefund$InboundSchema = paykitRefund$InboundSchema;
171
+ exports.paykitSubscription$InboundSchema = paykitSubscription$InboundSchema;
@@ -0,0 +1,164 @@
1
+ import { parseCustomerName, parseJSON, Schema, omitInternalMetadata, PAYKIT_METADATA_KEY, billingModeSchema } from '@paykit-sdk/core';
2
+
3
+ // src/utils/mapper.ts
4
+ var paykitCustomer$InboundSchema = (data) => {
5
+ const { fullName } = parseCustomerName({
6
+ name: [data.first_name, data.last_name].filter(Boolean).join(" ") || "",
7
+ email: data.email
8
+ });
9
+ return {
10
+ id: data.customer_code,
11
+ email: data.email,
12
+ name: fullName,
13
+ phone: data.phone ?? "",
14
+ metadata: data.metadata ?? void 0,
15
+ created_at: new Date(data.created_at),
16
+ updated_at: data.updated_at ? new Date(data.updated_at) : null
17
+ };
18
+ };
19
+ var paystackStatusMap = {
20
+ success: "succeeded",
21
+ failed: "failed",
22
+ pending: "pending",
23
+ abandoned: "canceled"
24
+ };
25
+ var paykitPayment$InboundSchema = (data, overridePaymentUrl) => {
26
+ const rawMetadata = parseJSON(
27
+ data.metadata,
28
+ Schema.record(Schema.string(), Schema.unknown())
29
+ ) ?? {};
30
+ const metadata = omitInternalMetadata(rawMetadata);
31
+ let itemId = null;
32
+ const paykitMeta = parseJSON(
33
+ rawMetadata[PAYKIT_METADATA_KEY],
34
+ Schema.object({
35
+ item_id: Schema.string().optional()
36
+ })
37
+ );
38
+ if (paykitMeta) {
39
+ itemId = paykitMeta.item_id ?? null;
40
+ }
41
+ const status = paystackStatusMap[data.status] ?? "pending";
42
+ return {
43
+ id: data.reference,
44
+ amount: data.amount,
45
+ currency: data.currency,
46
+ customer: data.customer?.email ?? "",
47
+ status,
48
+ metadata,
49
+ item_id: itemId,
50
+ requires_action: status === "pending",
51
+ payment_url: overridePaymentUrl ?? null
52
+ };
53
+ };
54
+ var paykitCheckout$InboundSchema = (init, transaction) => {
55
+ const rawMetadata = parseJSON(
56
+ transaction.metadata,
57
+ Schema.record(Schema.string(), Schema.unknown())
58
+ ) ?? {};
59
+ const metadata = omitInternalMetadata(rawMetadata);
60
+ let itemId = "";
61
+ let quantity = 1;
62
+ let type = null;
63
+ const paykitMeta = parseJSON(
64
+ rawMetadata[PAYKIT_METADATA_KEY],
65
+ Schema.object({
66
+ item_id: Schema.string().optional(),
67
+ quantity: Schema.number().optional(),
68
+ type: billingModeSchema.optional()
69
+ })
70
+ );
71
+ if (paykitMeta && typeof paykitMeta === "string") {
72
+ const parsed = parseJSON(
73
+ paykitMeta,
74
+ Schema.object({
75
+ item_id: Schema.string().optional(),
76
+ quantity: Schema.number().optional(),
77
+ type: billingModeSchema.optional()
78
+ })
79
+ );
80
+ if (parsed) {
81
+ itemId = parsed.item_id ?? "";
82
+ quantity = parsed.quantity ?? 1;
83
+ type = parsed.type ?? null;
84
+ }
85
+ }
86
+ return {
87
+ id: init.reference,
88
+ customer: { email: transaction.customer?.email ?? "" },
89
+ payment_url: init.authorization_url,
90
+ metadata: Object.keys(metadata).length > 0 ? metadata : null,
91
+ session_type: type ?? "one_time",
92
+ products: [{ id: itemId, quantity }],
93
+ currency: transaction.currency ?? "NGN",
94
+ amount: transaction.amount ?? 0
95
+ };
96
+ };
97
+ var paystackIntervalMap = {
98
+ daily: "day",
99
+ weekly: "week",
100
+ monthly: "month",
101
+ annually: "year",
102
+ quarterly: {
103
+ type: "custom",
104
+ durationMs: 3 * 30 * 24 * 60 * 60 * 1e3
105
+ },
106
+ biannually: {
107
+ type: "custom",
108
+ durationMs: 6 * 30 * 24 * 60 * 60 * 1e3
109
+ }
110
+ };
111
+ var paystackSubscriptionStatusMap = {
112
+ active: "active",
113
+ "non-renewing": "canceled",
114
+ cancelled: "canceled",
115
+ attention: "past_due",
116
+ completed: "expired"
117
+ };
118
+ var paykitSubscription$InboundSchema = (data) => {
119
+ const nextPaymentDate = data.next_payment_date ? new Date(data.next_payment_date) : /* @__PURE__ */ new Date();
120
+ return {
121
+ id: data.subscription_code,
122
+ customer: data.customer?.email ?? "",
123
+ amount: data.amount,
124
+ currency: data.currency || data.plan?.currency || "NGN",
125
+ status: paystackSubscriptionStatusMap[data.status] ?? "active",
126
+ current_period_start: new Date(data.createdAt),
127
+ current_period_end: nextPaymentDate,
128
+ item_id: data.plan?.plan_code ?? "",
129
+ billing_interval: paystackIntervalMap[data.plan?.interval] ?? "month",
130
+ metadata: null,
131
+ custom_fields: null,
132
+ requires_action: false,
133
+ payment_url: null
134
+ };
135
+ };
136
+ var paykitRefund$InboundSchema = (data, fallbackCurrency) => ({
137
+ id: String(data.id),
138
+ amount: data.amount,
139
+ currency: data.currency || fallbackCurrency,
140
+ reason: data.customer_note || data.merchant_note || null,
141
+ metadata: null
142
+ });
143
+ var paykitInvoice$InboundSchema = (data) => {
144
+ const rawMetadata = parseJSON(
145
+ data.metadata,
146
+ Schema.record(Schema.string(), Schema.unknown())
147
+ ) ?? {};
148
+ const metadata = omitInternalMetadata(rawMetadata);
149
+ return {
150
+ id: String(data.id),
151
+ customer: data.customer?.email ?? "",
152
+ subscription_id: null,
153
+ billing_mode: "one_time",
154
+ amount_paid: data.amount,
155
+ currency: data.currency,
156
+ status: "paid",
157
+ paid_at: data.paid_at ?? (/* @__PURE__ */ new Date()).toISOString(),
158
+ line_items: null,
159
+ metadata: Object.keys(metadata).length > 0 ? metadata : null,
160
+ custom_fields: null
161
+ };
162
+ };
163
+
164
+ export { paykitCheckout$InboundSchema, paykitCustomer$InboundSchema, paykitInvoice$InboundSchema, paykitPayment$InboundSchema, paykitRefund$InboundSchema, paykitSubscription$InboundSchema };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@paykit-sdk/paystack",
3
+ "version": "1.0.0",
4
+ "description": "Paystack provider for PayKit",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.esm.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsup"
13
+ },
14
+ "keywords": [
15
+ "paystack",
16
+ "paykit",
17
+ "payment",
18
+ "typescript"
19
+ ],
20
+ "author": "Emmanuel Odii",
21
+ "license": "ISC",
22
+ "peerDependencies": {
23
+ "@paykit-sdk/core": ">=1.1.102"
24
+ },
25
+ "devDependencies": {
26
+ "@paykit-sdk/core": "workspace:*",
27
+ "tsup": "^8.5.0",
28
+ "typescript": "^5.9.2",
29
+ "zod": "^3.24.2"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/usepaykit/paykit-sdk.git"
37
+ },
38
+ "bugs": {
39
+ "url": "https://github.com/usepaykit/paykit-sdk/issues"
40
+ }
41
+ }