@paykit-sdk/paystack 1.0.1 → 1.2.1

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 ADDED
@@ -0,0 +1,154 @@
1
+ # @paykit-sdk/paystack
2
+
3
+ Paystack provider for PayKit.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @paykit-sdk/paystack
9
+ # or
10
+ pnpm add @paykit-sdk/paystack
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { createEndpointHandlers, PayKit } from '@paykit-sdk/core';
17
+ import { paystack } from '@paykit-sdk/paystack';
18
+
19
+ export const paykit = new PayKit(paystack());
20
+ export const endpoints = createEndpointHandlers(paykit);
21
+ ```
22
+
23
+ Or with direct config:
24
+
25
+ ```typescript
26
+ import { PayKit } from '@paykit-sdk/core';
27
+ import { createPaystack } from '@paykit-sdk/paystack';
28
+
29
+ export const paykit = new PayKit(
30
+ createPaystack({
31
+ secretKey: 'sk_test_...',
32
+ isSandbox: true,
33
+ }),
34
+ );
35
+ ```
36
+
37
+ ## Environment Variables
38
+
39
+ ```bash
40
+ PAYSTACK_SECRET_KEY=sk_test_...
41
+ ```
42
+
43
+ `isSandbox` is inferred from `NODE_ENV` — set `NODE_ENV=production` for live mode.
44
+
45
+ ## Next.js API Route
46
+
47
+ ```typescript
48
+ // app/api/paykit/[...endpoint]/route.ts
49
+ import { endpoints } from '@/lib/paykit';
50
+ import { EndpointPath } from '@paykit-sdk/core';
51
+ import { NextRequest, NextResponse } from 'next/server';
52
+
53
+ export async function POST(
54
+ request: NextRequest,
55
+ { params }: { params: Promise<{ endpoint: string[] }> },
56
+ ) {
57
+ const { endpoint: endpointArray } = await params;
58
+ const endpoint = ('/' + endpointArray.join('/')) as EndpointPath;
59
+ const handler = endpoints[endpoint];
60
+
61
+ if (!handler) {
62
+ return NextResponse.json(
63
+ { message: 'Not found' },
64
+ { status: 404 },
65
+ );
66
+ }
67
+
68
+ const { args } = await request.json();
69
+ const result = await handler(...args);
70
+ return NextResponse.json({ result });
71
+ }
72
+ ```
73
+
74
+ ## Webhooks
75
+
76
+ Paystack sends signed POST requests. Pass your webhook secret to verify signatures.
77
+
78
+ ```typescript
79
+ // app/api/paykit/webhooks/route.ts
80
+ import { paykit } from '@/lib/paykit';
81
+ import { NextRequest, NextResponse } from 'next/server';
82
+
83
+ export async function POST(request: NextRequest) {
84
+ const body = await request.text();
85
+
86
+ const webhook = paykit.webhooks
87
+ .setup({ webhookSecret: process.env.PAYSTACK_SECRET_KEY! })
88
+ .on('payment.created', async event => {
89
+ /* charge.success — pending authorization */
90
+ })
91
+ .on('payment.updated', async event => {
92
+ /* charge.dispute.create — pre-auth hold updated */
93
+ })
94
+ .on('payment.failed', async event => {
95
+ /* charge.failed */
96
+ })
97
+ .on('invoice.generated', async event => {
98
+ /* invoice.payment_failed or invoice.update */
99
+ })
100
+ .on('customer.created', async event => {
101
+ /* customeridentification.success */
102
+ })
103
+ .on('customer.updated', async event => {
104
+ /* customeridentification.failed */
105
+ })
106
+ .on('subscription.created', async event => {
107
+ /* subscription.create */
108
+ })
109
+ .on('subscription.canceled', async event => {
110
+ /* subscription.disable */
111
+ });
112
+
113
+ await webhook.handle({
114
+ body,
115
+ headersAsObject: Object.fromEntries(request.headers),
116
+ fullUrl: request.url,
117
+ });
118
+
119
+ return NextResponse.json({ received: true });
120
+ }
121
+ ```
122
+
123
+ ## Checkout
124
+
125
+ Paystack requires an email customer and amount/currency in `provider_metadata`:
126
+
127
+ ```typescript
128
+ const checkout = await paykit.checkouts.create({
129
+ customer: { email: 'user@example.com' },
130
+ item_id: 'plan_pro',
131
+ session_type: 'one_time',
132
+ quantity: 1,
133
+ success_url: 'https://example.com/success',
134
+ provider_metadata: {
135
+ amount: 50000, // in kobo (NGN) or smallest currency unit
136
+ currency: 'NGN',
137
+ },
138
+ });
139
+
140
+ // Redirect user to checkout.payment_url
141
+ ```
142
+
143
+ ## Documentation
144
+
145
+ Full docs at [docs.usepaykit.com/providers/paystack](https://docs.usepaykit.com/providers/paystack).
146
+
147
+ ## Support
148
+
149
+ - [Paystack Documentation](https://paystack.com/docs)
150
+ - [PayKit Issues](https://github.com/usepaykit/paykit-sdk/issues)
151
+
152
+ ## License
153
+
154
+ ISC
package/dist/index.js CHANGED
@@ -4086,11 +4086,17 @@ var Payment$inboundSchema = (data, overridePaymentUrl) => {
4086
4086
  itemId = paykitMeta.item_id ?? null;
4087
4087
  }
4088
4088
  const status = paystackStatusMap[data.status] ?? "pending";
4089
+ let customer = null;
4090
+ if (data.customer?.email) {
4091
+ customer = { email: data.customer.email };
4092
+ } else if (data.customer?.id) {
4093
+ customer = { id: data.customer.id };
4094
+ }
4089
4095
  return {
4090
4096
  id: data.reference,
4091
4097
  amount: data.amount,
4092
4098
  currency: data.currency,
4093
- customer: data.customer?.email ? { email: data.customer.email } : null,
4099
+ customer,
4094
4100
  status,
4095
4101
  metadata,
4096
4102
  item_id: itemId,
@@ -4130,9 +4136,15 @@ var Checkout$inboundSchema = (init, transaction) => {
4130
4136
  type = parsed.type ?? null;
4131
4137
  }
4132
4138
  }
4139
+ let customer = null;
4140
+ if (transaction.customer?.email) {
4141
+ customer = { email: transaction.customer.email };
4142
+ } else if (transaction.customer?.id) {
4143
+ customer = { id: transaction.customer.id };
4144
+ }
4133
4145
  return {
4134
4146
  id: init.reference,
4135
- customer: transaction.customer?.email ? { email: transaction.customer.email } : null,
4147
+ customer,
4136
4148
  payment_url: init.authorization_url,
4137
4149
  metadata: Object.keys(metadata).length > 0 ? metadata : null,
4138
4150
  session_type: type ?? "one_time",
package/dist/index.mjs CHANGED
@@ -4084,11 +4084,17 @@ var Payment$inboundSchema = (data, overridePaymentUrl) => {
4084
4084
  itemId = paykitMeta.item_id ?? null;
4085
4085
  }
4086
4086
  const status = paystackStatusMap[data.status] ?? "pending";
4087
+ let customer = null;
4088
+ if (data.customer?.email) {
4089
+ customer = { email: data.customer.email };
4090
+ } else if (data.customer?.id) {
4091
+ customer = { id: data.customer.id };
4092
+ }
4087
4093
  return {
4088
4094
  id: data.reference,
4089
4095
  amount: data.amount,
4090
4096
  currency: data.currency,
4091
- customer: data.customer?.email ? { email: data.customer.email } : null,
4097
+ customer,
4092
4098
  status,
4093
4099
  metadata,
4094
4100
  item_id: itemId,
@@ -4128,9 +4134,15 @@ var Checkout$inboundSchema = (init, transaction) => {
4128
4134
  type = parsed.type ?? null;
4129
4135
  }
4130
4136
  }
4137
+ let customer = null;
4138
+ if (transaction.customer?.email) {
4139
+ customer = { email: transaction.customer.email };
4140
+ } else if (transaction.customer?.id) {
4141
+ customer = { id: transaction.customer.id };
4142
+ }
4131
4143
  return {
4132
4144
  id: init.reference,
4133
- customer: transaction.customer?.email ? { email: transaction.customer.email } : null,
4145
+ customer,
4134
4146
  payment_url: init.authorization_url,
4135
4147
  metadata: Object.keys(metadata).length > 0 ? metadata : null,
4136
4148
  session_type: type ?? "one_time",
@@ -4086,11 +4086,17 @@ var Payment$inboundSchema = (data, overridePaymentUrl) => {
4086
4086
  itemId = paykitMeta.item_id ?? null;
4087
4087
  }
4088
4088
  const status = paystackStatusMap[data.status] ?? "pending";
4089
+ let customer = null;
4090
+ if (data.customer?.email) {
4091
+ customer = { email: data.customer.email };
4092
+ } else if (data.customer?.id) {
4093
+ customer = { id: data.customer.id };
4094
+ }
4089
4095
  return {
4090
4096
  id: data.reference,
4091
4097
  amount: data.amount,
4092
4098
  currency: data.currency,
4093
- customer: data.customer?.email ? { email: data.customer.email } : null,
4099
+ customer,
4094
4100
  status,
4095
4101
  metadata,
4096
4102
  item_id: itemId,
@@ -4130,9 +4136,15 @@ var Checkout$inboundSchema = (init, transaction) => {
4130
4136
  type = parsed.type ?? null;
4131
4137
  }
4132
4138
  }
4139
+ let customer = null;
4140
+ if (transaction.customer?.email) {
4141
+ customer = { email: transaction.customer.email };
4142
+ } else if (transaction.customer?.id) {
4143
+ customer = { id: transaction.customer.id };
4144
+ }
4133
4145
  return {
4134
4146
  id: init.reference,
4135
- customer: transaction.customer?.email ? { email: transaction.customer.email } : null,
4147
+ customer,
4136
4148
  payment_url: init.authorization_url,
4137
4149
  metadata: Object.keys(metadata).length > 0 ? metadata : null,
4138
4150
  session_type: type ?? "one_time",
@@ -4084,11 +4084,17 @@ var Payment$inboundSchema = (data, overridePaymentUrl) => {
4084
4084
  itemId = paykitMeta.item_id ?? null;
4085
4085
  }
4086
4086
  const status = paystackStatusMap[data.status] ?? "pending";
4087
+ let customer = null;
4088
+ if (data.customer?.email) {
4089
+ customer = { email: data.customer.email };
4090
+ } else if (data.customer?.id) {
4091
+ customer = { id: data.customer.id };
4092
+ }
4087
4093
  return {
4088
4094
  id: data.reference,
4089
4095
  amount: data.amount,
4090
4096
  currency: data.currency,
4091
- customer: data.customer?.email ? { email: data.customer.email } : null,
4097
+ customer,
4092
4098
  status,
4093
4099
  metadata,
4094
4100
  item_id: itemId,
@@ -4128,9 +4134,15 @@ var Checkout$inboundSchema = (init, transaction) => {
4128
4134
  type = parsed.type ?? null;
4129
4135
  }
4130
4136
  }
4137
+ let customer = null;
4138
+ if (transaction.customer?.email) {
4139
+ customer = { email: transaction.customer.email };
4140
+ } else if (transaction.customer?.id) {
4141
+ customer = { id: transaction.customer.id };
4142
+ }
4131
4143
  return {
4132
4144
  id: init.reference,
4133
- customer: transaction.customer?.email ? { email: transaction.customer.email } : null,
4145
+ customer,
4134
4146
  payment_url: init.authorization_url,
4135
4147
  metadata: Object.keys(metadata).length > 0 ? metadata : null,
4136
4148
  session_type: type ?? "one_time",
@@ -41,11 +41,17 @@ var Payment$inboundSchema = (data, overridePaymentUrl) => {
41
41
  itemId = paykitMeta.item_id ?? null;
42
42
  }
43
43
  const status = paystackStatusMap[data.status] ?? "pending";
44
+ let customer = null;
45
+ if (data.customer?.email) {
46
+ customer = { email: data.customer.email };
47
+ } else if (data.customer?.id) {
48
+ customer = { id: data.customer.id };
49
+ }
44
50
  return {
45
51
  id: data.reference,
46
52
  amount: data.amount,
47
53
  currency: data.currency,
48
- customer: data.customer?.email ? { email: data.customer.email } : null,
54
+ customer,
49
55
  status,
50
56
  metadata,
51
57
  item_id: itemId,
@@ -85,9 +91,15 @@ var Checkout$inboundSchema = (init, transaction) => {
85
91
  type = parsed.type ?? null;
86
92
  }
87
93
  }
94
+ let customer = null;
95
+ if (transaction.customer?.email) {
96
+ customer = { email: transaction.customer.email };
97
+ } else if (transaction.customer?.id) {
98
+ customer = { id: transaction.customer.id };
99
+ }
88
100
  return {
89
101
  id: init.reference,
90
- customer: transaction.customer?.email ? { email: transaction.customer.email } : null,
102
+ customer,
91
103
  payment_url: init.authorization_url,
92
104
  metadata: Object.keys(metadata).length > 0 ? metadata : null,
93
105
  session_type: type ?? "one_time",
@@ -39,11 +39,17 @@ var Payment$inboundSchema = (data, overridePaymentUrl) => {
39
39
  itemId = paykitMeta.item_id ?? null;
40
40
  }
41
41
  const status = paystackStatusMap[data.status] ?? "pending";
42
+ let customer = null;
43
+ if (data.customer?.email) {
44
+ customer = { email: data.customer.email };
45
+ } else if (data.customer?.id) {
46
+ customer = { id: data.customer.id };
47
+ }
42
48
  return {
43
49
  id: data.reference,
44
50
  amount: data.amount,
45
51
  currency: data.currency,
46
- customer: data.customer?.email ? { email: data.customer.email } : null,
52
+ customer,
47
53
  status,
48
54
  metadata,
49
55
  item_id: itemId,
@@ -83,9 +89,15 @@ var Checkout$inboundSchema = (init, transaction) => {
83
89
  type = parsed.type ?? null;
84
90
  }
85
91
  }
92
+ let customer = null;
93
+ if (transaction.customer?.email) {
94
+ customer = { email: transaction.customer.email };
95
+ } else if (transaction.customer?.id) {
96
+ customer = { id: transaction.customer.id };
97
+ }
86
98
  return {
87
99
  id: init.reference,
88
- customer: transaction.customer?.email ? { email: transaction.customer.email } : null,
100
+ customer,
89
101
  payment_url: init.authorization_url,
90
102
  metadata: Object.keys(metadata).length > 0 ? metadata : null,
91
103
  session_type: type ?? "one_time",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paykit-sdk/paystack",
3
- "version": "1.0.1",
3
+ "version": "1.2.1",
4
4
  "description": "Paystack provider for PayKit",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -8,6 +8,9 @@
8
8
  "files": [
9
9
  "dist"
10
10
  ],
11
+ "paykit": {
12
+ "type": "provider"
13
+ },
11
14
  "scripts": {
12
15
  "build": "tsup"
13
16
  },
@@ -20,7 +23,7 @@
20
23
  "author": "Emmanuel Odii",
21
24
  "license": "ISC",
22
25
  "peerDependencies": {
23
- "@paykit-sdk/core": ">=1.1.103"
26
+ "@paykit-sdk/core": ">=1.2.2"
24
27
  },
25
28
  "devDependencies": {
26
29
  "@paykit-sdk/core": "workspace:*",