@paykit-sdk/chapa 1.0.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 +157 -0
- package/dist/chapa-provider.d.mts +58 -0
- package/dist/chapa-provider.d.ts +58 -0
- package/dist/chapa-provider.js +4607 -0
- package/dist/chapa-provider.mjs +4605 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +4625 -0
- package/dist/index.mjs +4621 -0
- package/dist/schema.d.mts +194 -0
- package/dist/schema.d.ts +194 -0
- package/dist/schema.js +6 -0
- package/dist/schema.mjs +4 -0
- package/dist/utils/mapper.d.mts +41 -0
- package/dist/utils/mapper.d.ts +41 -0
- package/dist/utils/mapper.js +105 -0
- package/dist/utils/mapper.mjs +99 -0
- package/package.json +46 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chapa wraps every response in this envelope, e.g.
|
|
3
|
+
* `{ message: "Refund verified successfully", status: "success", data: {...} }`
|
|
4
|
+
*/
|
|
5
|
+
interface ChapaResponse<T = unknown> {
|
|
6
|
+
/**
|
|
7
|
+
* A human readable message describing the result
|
|
8
|
+
*/
|
|
9
|
+
message: string;
|
|
10
|
+
/**
|
|
11
|
+
* Whether the request was successful
|
|
12
|
+
*/
|
|
13
|
+
status: 'success' | 'failed';
|
|
14
|
+
/**
|
|
15
|
+
* The data of the response
|
|
16
|
+
*/
|
|
17
|
+
data: T;
|
|
18
|
+
}
|
|
19
|
+
interface ChapaCustomization {
|
|
20
|
+
/**
|
|
21
|
+
* The title shown on the Chapa checkout page
|
|
22
|
+
*/
|
|
23
|
+
title: string | null;
|
|
24
|
+
/**
|
|
25
|
+
* The description shown on the Chapa checkout page
|
|
26
|
+
*/
|
|
27
|
+
description: string | null;
|
|
28
|
+
/**
|
|
29
|
+
* A logo shown on the Chapa checkout page
|
|
30
|
+
*/
|
|
31
|
+
logo?: string | null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The shape returned by `GET /transaction/verify/:tx_ref`, and the shape
|
|
35
|
+
* of the `charge.*` webhook payload (minus the `event` key).
|
|
36
|
+
*/
|
|
37
|
+
interface ChapaTransaction {
|
|
38
|
+
/**
|
|
39
|
+
* The customer's first name
|
|
40
|
+
*/
|
|
41
|
+
first_name: string | null;
|
|
42
|
+
/**
|
|
43
|
+
* The customer's last name
|
|
44
|
+
*/
|
|
45
|
+
last_name: string | null;
|
|
46
|
+
/**
|
|
47
|
+
* The customer's email
|
|
48
|
+
*/
|
|
49
|
+
email: string | null;
|
|
50
|
+
/**
|
|
51
|
+
* The customer's mobile number
|
|
52
|
+
*/
|
|
53
|
+
mobile: string | null;
|
|
54
|
+
/**
|
|
55
|
+
* The currency of the transaction e.g `ETB`
|
|
56
|
+
*/
|
|
57
|
+
currency: string;
|
|
58
|
+
/**
|
|
59
|
+
* The amount of the transaction, as a decimal string e.g `"400.00"`
|
|
60
|
+
*/
|
|
61
|
+
amount: string;
|
|
62
|
+
/**
|
|
63
|
+
* The fee charged by Chapa, as a decimal string
|
|
64
|
+
*/
|
|
65
|
+
charge: string;
|
|
66
|
+
/**
|
|
67
|
+
* The status of the transaction
|
|
68
|
+
*/
|
|
69
|
+
status: 'success' | 'failed' | 'pending' | string;
|
|
70
|
+
/**
|
|
71
|
+
* Whether the transaction happened in `test` or `live` mode
|
|
72
|
+
*/
|
|
73
|
+
mode: 'test' | 'live';
|
|
74
|
+
/**
|
|
75
|
+
* Chapa's internal reference for the transaction
|
|
76
|
+
*/
|
|
77
|
+
reference: string;
|
|
78
|
+
/**
|
|
79
|
+
* The created at timestamp of the transaction
|
|
80
|
+
*/
|
|
81
|
+
created_at: string;
|
|
82
|
+
/**
|
|
83
|
+
* The updated at timestamp of the transaction
|
|
84
|
+
*/
|
|
85
|
+
updated_at: string;
|
|
86
|
+
/**
|
|
87
|
+
* The channel the transaction was initiated through e.g `API`
|
|
88
|
+
*/
|
|
89
|
+
type: string;
|
|
90
|
+
/**
|
|
91
|
+
* The merchant-supplied transaction reference
|
|
92
|
+
*/
|
|
93
|
+
tx_ref: string;
|
|
94
|
+
/**
|
|
95
|
+
* The payment channel used e.g `telebirr`, `mpesa`, `card`
|
|
96
|
+
*/
|
|
97
|
+
payment_method: string | null;
|
|
98
|
+
/**
|
|
99
|
+
* The checkout customization used for the transaction
|
|
100
|
+
*/
|
|
101
|
+
customization: ChapaCustomization | null;
|
|
102
|
+
/**
|
|
103
|
+
* Free-form metadata echoed back from what was sent at initialization
|
|
104
|
+
*/
|
|
105
|
+
meta: Record<string, unknown> | null;
|
|
106
|
+
}
|
|
107
|
+
interface ChapaInitializeResponse {
|
|
108
|
+
/**
|
|
109
|
+
* The URL to redirect the customer to in order to complete payment
|
|
110
|
+
*/
|
|
111
|
+
checkout_url: string;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The shape returned by `GET /refund/:ref_id/verify`. The create-refund
|
|
115
|
+
* response is assumed to follow the same envelope/shape; fields that
|
|
116
|
+
* aren't confirmed there are backfilled from request-time context in
|
|
117
|
+
* the mapper rather than assumed present.
|
|
118
|
+
*/
|
|
119
|
+
interface ChapaRefund {
|
|
120
|
+
/**
|
|
121
|
+
* The refunded amount
|
|
122
|
+
*/
|
|
123
|
+
amount: number;
|
|
124
|
+
/**
|
|
125
|
+
* The currency of the refund
|
|
126
|
+
*/
|
|
127
|
+
currency: string;
|
|
128
|
+
/**
|
|
129
|
+
* Chapa's internal reference for the refund
|
|
130
|
+
*/
|
|
131
|
+
ref_id: string;
|
|
132
|
+
/**
|
|
133
|
+
* The reference of the original payment being refunded
|
|
134
|
+
*/
|
|
135
|
+
payment_reference: string;
|
|
136
|
+
/**
|
|
137
|
+
* An optional merchant-supplied reference for the refund
|
|
138
|
+
*/
|
|
139
|
+
merchant_reference: string | null;
|
|
140
|
+
/**
|
|
141
|
+
* The status of the refund
|
|
142
|
+
*/
|
|
143
|
+
status: 'initiated' | 'processing' | 'refunded' | 'reversed' | string;
|
|
144
|
+
/**
|
|
145
|
+
* The created at timestamp of the refund
|
|
146
|
+
*/
|
|
147
|
+
created_at: string;
|
|
148
|
+
/**
|
|
149
|
+
* The updated at timestamp of the refund
|
|
150
|
+
*/
|
|
151
|
+
updated_at: string;
|
|
152
|
+
}
|
|
153
|
+
interface ChapaWebhookTransactionEvent extends ChapaTransaction {
|
|
154
|
+
/**
|
|
155
|
+
* e.g `charge.success`. Chapa's docs also show `charge.refunded`,
|
|
156
|
+
* `charge.reversed` and `charge.failed/cancelled`, but only
|
|
157
|
+
* `charge.success` is unambiguously documented as a literal value -
|
|
158
|
+
* the others are handled defensively off the `status` field instead
|
|
159
|
+
* of an exact string match.
|
|
160
|
+
*/
|
|
161
|
+
event: string;
|
|
162
|
+
}
|
|
163
|
+
interface ChapaWebhookPayoutEvent {
|
|
164
|
+
/**
|
|
165
|
+
* e.g `payout.success`
|
|
166
|
+
*/
|
|
167
|
+
event: string;
|
|
168
|
+
type: 'Payout';
|
|
169
|
+
account_name: string;
|
|
170
|
+
account_number: string;
|
|
171
|
+
bank_id: number;
|
|
172
|
+
bank_name: string;
|
|
173
|
+
amount: string;
|
|
174
|
+
charge: string;
|
|
175
|
+
currency: string;
|
|
176
|
+
status: string;
|
|
177
|
+
reference: string;
|
|
178
|
+
chapa_reference: string;
|
|
179
|
+
bank_reference: string;
|
|
180
|
+
created_at: string;
|
|
181
|
+
updated_at: string;
|
|
182
|
+
}
|
|
183
|
+
type ChapaWebhookEvent = ChapaWebhookTransactionEvent | ChapaWebhookPayoutEvent;
|
|
184
|
+
declare const isChapaTransactionEvent: (event: ChapaWebhookEvent) => event is ChapaWebhookTransactionEvent;
|
|
185
|
+
type ChapaRawEvents = {
|
|
186
|
+
'chapa.charge.success': ChapaWebhookTransactionEvent;
|
|
187
|
+
'chapa.charge.failure': ChapaWebhookTransactionEvent;
|
|
188
|
+
'chapa.charge.refunded': ChapaWebhookTransactionEvent;
|
|
189
|
+
'chapa.charge.reversed': ChapaWebhookTransactionEvent;
|
|
190
|
+
'chapa.payout.success': ChapaWebhookPayoutEvent;
|
|
191
|
+
'chapa.payout.failure': ChapaWebhookPayoutEvent;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export { type ChapaCustomization, type ChapaInitializeResponse, type ChapaRawEvents, type ChapaRefund, type ChapaResponse, type ChapaTransaction, type ChapaWebhookEvent, type ChapaWebhookPayoutEvent, type ChapaWebhookTransactionEvent, isChapaTransactionEvent };
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chapa wraps every response in this envelope, e.g.
|
|
3
|
+
* `{ message: "Refund verified successfully", status: "success", data: {...} }`
|
|
4
|
+
*/
|
|
5
|
+
interface ChapaResponse<T = unknown> {
|
|
6
|
+
/**
|
|
7
|
+
* A human readable message describing the result
|
|
8
|
+
*/
|
|
9
|
+
message: string;
|
|
10
|
+
/**
|
|
11
|
+
* Whether the request was successful
|
|
12
|
+
*/
|
|
13
|
+
status: 'success' | 'failed';
|
|
14
|
+
/**
|
|
15
|
+
* The data of the response
|
|
16
|
+
*/
|
|
17
|
+
data: T;
|
|
18
|
+
}
|
|
19
|
+
interface ChapaCustomization {
|
|
20
|
+
/**
|
|
21
|
+
* The title shown on the Chapa checkout page
|
|
22
|
+
*/
|
|
23
|
+
title: string | null;
|
|
24
|
+
/**
|
|
25
|
+
* The description shown on the Chapa checkout page
|
|
26
|
+
*/
|
|
27
|
+
description: string | null;
|
|
28
|
+
/**
|
|
29
|
+
* A logo shown on the Chapa checkout page
|
|
30
|
+
*/
|
|
31
|
+
logo?: string | null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The shape returned by `GET /transaction/verify/:tx_ref`, and the shape
|
|
35
|
+
* of the `charge.*` webhook payload (minus the `event` key).
|
|
36
|
+
*/
|
|
37
|
+
interface ChapaTransaction {
|
|
38
|
+
/**
|
|
39
|
+
* The customer's first name
|
|
40
|
+
*/
|
|
41
|
+
first_name: string | null;
|
|
42
|
+
/**
|
|
43
|
+
* The customer's last name
|
|
44
|
+
*/
|
|
45
|
+
last_name: string | null;
|
|
46
|
+
/**
|
|
47
|
+
* The customer's email
|
|
48
|
+
*/
|
|
49
|
+
email: string | null;
|
|
50
|
+
/**
|
|
51
|
+
* The customer's mobile number
|
|
52
|
+
*/
|
|
53
|
+
mobile: string | null;
|
|
54
|
+
/**
|
|
55
|
+
* The currency of the transaction e.g `ETB`
|
|
56
|
+
*/
|
|
57
|
+
currency: string;
|
|
58
|
+
/**
|
|
59
|
+
* The amount of the transaction, as a decimal string e.g `"400.00"`
|
|
60
|
+
*/
|
|
61
|
+
amount: string;
|
|
62
|
+
/**
|
|
63
|
+
* The fee charged by Chapa, as a decimal string
|
|
64
|
+
*/
|
|
65
|
+
charge: string;
|
|
66
|
+
/**
|
|
67
|
+
* The status of the transaction
|
|
68
|
+
*/
|
|
69
|
+
status: 'success' | 'failed' | 'pending' | string;
|
|
70
|
+
/**
|
|
71
|
+
* Whether the transaction happened in `test` or `live` mode
|
|
72
|
+
*/
|
|
73
|
+
mode: 'test' | 'live';
|
|
74
|
+
/**
|
|
75
|
+
* Chapa's internal reference for the transaction
|
|
76
|
+
*/
|
|
77
|
+
reference: string;
|
|
78
|
+
/**
|
|
79
|
+
* The created at timestamp of the transaction
|
|
80
|
+
*/
|
|
81
|
+
created_at: string;
|
|
82
|
+
/**
|
|
83
|
+
* The updated at timestamp of the transaction
|
|
84
|
+
*/
|
|
85
|
+
updated_at: string;
|
|
86
|
+
/**
|
|
87
|
+
* The channel the transaction was initiated through e.g `API`
|
|
88
|
+
*/
|
|
89
|
+
type: string;
|
|
90
|
+
/**
|
|
91
|
+
* The merchant-supplied transaction reference
|
|
92
|
+
*/
|
|
93
|
+
tx_ref: string;
|
|
94
|
+
/**
|
|
95
|
+
* The payment channel used e.g `telebirr`, `mpesa`, `card`
|
|
96
|
+
*/
|
|
97
|
+
payment_method: string | null;
|
|
98
|
+
/**
|
|
99
|
+
* The checkout customization used for the transaction
|
|
100
|
+
*/
|
|
101
|
+
customization: ChapaCustomization | null;
|
|
102
|
+
/**
|
|
103
|
+
* Free-form metadata echoed back from what was sent at initialization
|
|
104
|
+
*/
|
|
105
|
+
meta: Record<string, unknown> | null;
|
|
106
|
+
}
|
|
107
|
+
interface ChapaInitializeResponse {
|
|
108
|
+
/**
|
|
109
|
+
* The URL to redirect the customer to in order to complete payment
|
|
110
|
+
*/
|
|
111
|
+
checkout_url: string;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The shape returned by `GET /refund/:ref_id/verify`. The create-refund
|
|
115
|
+
* response is assumed to follow the same envelope/shape; fields that
|
|
116
|
+
* aren't confirmed there are backfilled from request-time context in
|
|
117
|
+
* the mapper rather than assumed present.
|
|
118
|
+
*/
|
|
119
|
+
interface ChapaRefund {
|
|
120
|
+
/**
|
|
121
|
+
* The refunded amount
|
|
122
|
+
*/
|
|
123
|
+
amount: number;
|
|
124
|
+
/**
|
|
125
|
+
* The currency of the refund
|
|
126
|
+
*/
|
|
127
|
+
currency: string;
|
|
128
|
+
/**
|
|
129
|
+
* Chapa's internal reference for the refund
|
|
130
|
+
*/
|
|
131
|
+
ref_id: string;
|
|
132
|
+
/**
|
|
133
|
+
* The reference of the original payment being refunded
|
|
134
|
+
*/
|
|
135
|
+
payment_reference: string;
|
|
136
|
+
/**
|
|
137
|
+
* An optional merchant-supplied reference for the refund
|
|
138
|
+
*/
|
|
139
|
+
merchant_reference: string | null;
|
|
140
|
+
/**
|
|
141
|
+
* The status of the refund
|
|
142
|
+
*/
|
|
143
|
+
status: 'initiated' | 'processing' | 'refunded' | 'reversed' | string;
|
|
144
|
+
/**
|
|
145
|
+
* The created at timestamp of the refund
|
|
146
|
+
*/
|
|
147
|
+
created_at: string;
|
|
148
|
+
/**
|
|
149
|
+
* The updated at timestamp of the refund
|
|
150
|
+
*/
|
|
151
|
+
updated_at: string;
|
|
152
|
+
}
|
|
153
|
+
interface ChapaWebhookTransactionEvent extends ChapaTransaction {
|
|
154
|
+
/**
|
|
155
|
+
* e.g `charge.success`. Chapa's docs also show `charge.refunded`,
|
|
156
|
+
* `charge.reversed` and `charge.failed/cancelled`, but only
|
|
157
|
+
* `charge.success` is unambiguously documented as a literal value -
|
|
158
|
+
* the others are handled defensively off the `status` field instead
|
|
159
|
+
* of an exact string match.
|
|
160
|
+
*/
|
|
161
|
+
event: string;
|
|
162
|
+
}
|
|
163
|
+
interface ChapaWebhookPayoutEvent {
|
|
164
|
+
/**
|
|
165
|
+
* e.g `payout.success`
|
|
166
|
+
*/
|
|
167
|
+
event: string;
|
|
168
|
+
type: 'Payout';
|
|
169
|
+
account_name: string;
|
|
170
|
+
account_number: string;
|
|
171
|
+
bank_id: number;
|
|
172
|
+
bank_name: string;
|
|
173
|
+
amount: string;
|
|
174
|
+
charge: string;
|
|
175
|
+
currency: string;
|
|
176
|
+
status: string;
|
|
177
|
+
reference: string;
|
|
178
|
+
chapa_reference: string;
|
|
179
|
+
bank_reference: string;
|
|
180
|
+
created_at: string;
|
|
181
|
+
updated_at: string;
|
|
182
|
+
}
|
|
183
|
+
type ChapaWebhookEvent = ChapaWebhookTransactionEvent | ChapaWebhookPayoutEvent;
|
|
184
|
+
declare const isChapaTransactionEvent: (event: ChapaWebhookEvent) => event is ChapaWebhookTransactionEvent;
|
|
185
|
+
type ChapaRawEvents = {
|
|
186
|
+
'chapa.charge.success': ChapaWebhookTransactionEvent;
|
|
187
|
+
'chapa.charge.failure': ChapaWebhookTransactionEvent;
|
|
188
|
+
'chapa.charge.refunded': ChapaWebhookTransactionEvent;
|
|
189
|
+
'chapa.charge.reversed': ChapaWebhookTransactionEvent;
|
|
190
|
+
'chapa.payout.success': ChapaWebhookPayoutEvent;
|
|
191
|
+
'chapa.payout.failure': ChapaWebhookPayoutEvent;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export { type ChapaCustomization, type ChapaInitializeResponse, type ChapaRawEvents, type ChapaRefund, type ChapaResponse, type ChapaTransaction, type ChapaWebhookEvent, type ChapaWebhookPayoutEvent, type ChapaWebhookTransactionEvent, isChapaTransactionEvent };
|
package/dist/schema.js
ADDED
package/dist/schema.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Payment, Checkout, Invoice, Refund } from '@paykit-sdk/core';
|
|
2
|
+
import { ChapaTransaction, ChapaRefund } from '../schema.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
declare const Payment$inboundSchema: (data: ChapaTransaction, overridePaymentUrl?: string | null) => Payment;
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
declare const Checkout$inboundSchema: (init: {
|
|
12
|
+
checkout_url: string | null;
|
|
13
|
+
tx_ref: string;
|
|
14
|
+
}, transaction: Omit<Partial<ChapaTransaction>, "amount" | "currency"> & {
|
|
15
|
+
amount?: number | string;
|
|
16
|
+
currency?: string;
|
|
17
|
+
}) => Checkout;
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
declare const Invoice$inboundSchema: (data: ChapaTransaction) => Invoice;
|
|
22
|
+
/**
|
|
23
|
+
* Builds a `Refund` from a `charge.refunded`/`charge.reversed` webhook
|
|
24
|
+
* payload, which is a transaction snapshot rather than a dedicated refund
|
|
25
|
+
* resource - Chapa doesn't send a refund id on these events, so `tx_ref`
|
|
26
|
+
* is used as the id.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
declare const RefundFromTransaction$inboundSchema: (data: ChapaTransaction) => Refund;
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
declare const Refund$inboundSchema: (data: Partial<ChapaRefund>, context: {
|
|
35
|
+
paymentId: string;
|
|
36
|
+
amount: number;
|
|
37
|
+
currency: string;
|
|
38
|
+
reason: string | null;
|
|
39
|
+
}) => Refund;
|
|
40
|
+
|
|
41
|
+
export { Checkout$inboundSchema, Invoice$inboundSchema, Payment$inboundSchema, Refund$inboundSchema, RefundFromTransaction$inboundSchema };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Payment, Checkout, Invoice, Refund } from '@paykit-sdk/core';
|
|
2
|
+
import { ChapaTransaction, ChapaRefund } from '../schema.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
declare const Payment$inboundSchema: (data: ChapaTransaction, overridePaymentUrl?: string | null) => Payment;
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
declare const Checkout$inboundSchema: (init: {
|
|
12
|
+
checkout_url: string | null;
|
|
13
|
+
tx_ref: string;
|
|
14
|
+
}, transaction: Omit<Partial<ChapaTransaction>, "amount" | "currency"> & {
|
|
15
|
+
amount?: number | string;
|
|
16
|
+
currency?: string;
|
|
17
|
+
}) => Checkout;
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
declare const Invoice$inboundSchema: (data: ChapaTransaction) => Invoice;
|
|
22
|
+
/**
|
|
23
|
+
* Builds a `Refund` from a `charge.refunded`/`charge.reversed` webhook
|
|
24
|
+
* payload, which is a transaction snapshot rather than a dedicated refund
|
|
25
|
+
* resource - Chapa doesn't send a refund id on these events, so `tx_ref`
|
|
26
|
+
* is used as the id.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
declare const RefundFromTransaction$inboundSchema: (data: ChapaTransaction) => Refund;
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
declare const Refund$inboundSchema: (data: Partial<ChapaRefund>, context: {
|
|
35
|
+
paymentId: string;
|
|
36
|
+
amount: number;
|
|
37
|
+
currency: string;
|
|
38
|
+
reason: string | null;
|
|
39
|
+
}) => Refund;
|
|
40
|
+
|
|
41
|
+
export { Checkout$inboundSchema, Invoice$inboundSchema, Payment$inboundSchema, Refund$inboundSchema, RefundFromTransaction$inboundSchema };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@paykit-sdk/core');
|
|
4
|
+
|
|
5
|
+
// src/utils/mapper.ts
|
|
6
|
+
var chapaStatusMap = {
|
|
7
|
+
success: "succeeded",
|
|
8
|
+
failed: "failed",
|
|
9
|
+
pending: "pending"
|
|
10
|
+
};
|
|
11
|
+
var resolveCustomer = (data) => data.email ? { email: data.email } : null;
|
|
12
|
+
var Payment$inboundSchema = (data, overridePaymentUrl) => {
|
|
13
|
+
const rawMeta = data.meta ?? {};
|
|
14
|
+
const metadata = core.omitInternalMetadata(rawMeta);
|
|
15
|
+
let itemId = null;
|
|
16
|
+
const paykitMeta = core.parseJSON(
|
|
17
|
+
rawMeta[core.PAYKIT_METADATA_KEY],
|
|
18
|
+
core.Schema.object({ item_id: core.Schema.string().optional() })
|
|
19
|
+
);
|
|
20
|
+
if (paykitMeta) itemId = paykitMeta.item_id ?? null;
|
|
21
|
+
const status = chapaStatusMap[data.status] ?? "pending";
|
|
22
|
+
return {
|
|
23
|
+
id: data.tx_ref,
|
|
24
|
+
amount: parseFloat(data.amount),
|
|
25
|
+
currency: data.currency,
|
|
26
|
+
customer: resolveCustomer(data),
|
|
27
|
+
status,
|
|
28
|
+
metadata,
|
|
29
|
+
item_id: itemId,
|
|
30
|
+
requires_action: status === "pending",
|
|
31
|
+
payment_url: overridePaymentUrl ?? null
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
var Checkout$inboundSchema = (init, transaction) => {
|
|
35
|
+
const rawMeta = transaction.meta ?? {};
|
|
36
|
+
const metadata = core.omitInternalMetadata(rawMeta);
|
|
37
|
+
let itemId = "";
|
|
38
|
+
let quantity = 1;
|
|
39
|
+
let type = null;
|
|
40
|
+
const paykitMeta = core.parseJSON(
|
|
41
|
+
rawMeta[core.PAYKIT_METADATA_KEY],
|
|
42
|
+
core.Schema.object({
|
|
43
|
+
item_id: core.Schema.string().optional(),
|
|
44
|
+
quantity: core.Schema.number().optional(),
|
|
45
|
+
type: core.billingModeSchema.optional()
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
if (paykitMeta) {
|
|
49
|
+
itemId = paykitMeta.item_id ?? "";
|
|
50
|
+
quantity = paykitMeta.quantity ?? 1;
|
|
51
|
+
type = paykitMeta.type ?? null;
|
|
52
|
+
}
|
|
53
|
+
const amount = typeof transaction.amount === "string" ? parseFloat(transaction.amount) : transaction.amount ?? 0;
|
|
54
|
+
return {
|
|
55
|
+
id: init.tx_ref,
|
|
56
|
+
customer: resolveCustomer({ email: transaction.email ?? null }),
|
|
57
|
+
payment_url: init.checkout_url ?? "",
|
|
58
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : null,
|
|
59
|
+
session_type: type ?? "one_time",
|
|
60
|
+
products: [{ id: itemId, quantity }],
|
|
61
|
+
currency: transaction.currency ?? "ETB",
|
|
62
|
+
amount
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
var Invoice$inboundSchema = (data) => {
|
|
66
|
+
const rawMeta = data.meta ?? {};
|
|
67
|
+
const metadata = core.omitInternalMetadata(rawMeta);
|
|
68
|
+
return {
|
|
69
|
+
id: data.reference,
|
|
70
|
+
customer: resolveCustomer(data),
|
|
71
|
+
subscription_id: null,
|
|
72
|
+
billing_mode: "one_time",
|
|
73
|
+
amount_paid: parseFloat(data.amount),
|
|
74
|
+
currency: data.currency,
|
|
75
|
+
status: "paid",
|
|
76
|
+
paid_at: data.updated_at,
|
|
77
|
+
line_items: null,
|
|
78
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : null,
|
|
79
|
+
custom_fields: null
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
var RefundFromTransaction$inboundSchema = (data) => {
|
|
83
|
+
const rawMeta = data.meta ?? {};
|
|
84
|
+
const metadata = core.omitInternalMetadata(rawMeta);
|
|
85
|
+
return {
|
|
86
|
+
id: data.tx_ref,
|
|
87
|
+
amount: parseFloat(data.amount),
|
|
88
|
+
currency: data.currency,
|
|
89
|
+
reason: null,
|
|
90
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : null
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
var Refund$inboundSchema = (data, context) => ({
|
|
94
|
+
id: data.ref_id ?? context.paymentId,
|
|
95
|
+
amount: data.amount ?? context.amount,
|
|
96
|
+
currency: data.currency ?? context.currency,
|
|
97
|
+
reason: context.reason,
|
|
98
|
+
metadata: null
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
exports.Checkout$inboundSchema = Checkout$inboundSchema;
|
|
102
|
+
exports.Invoice$inboundSchema = Invoice$inboundSchema;
|
|
103
|
+
exports.Payment$inboundSchema = Payment$inboundSchema;
|
|
104
|
+
exports.Refund$inboundSchema = Refund$inboundSchema;
|
|
105
|
+
exports.RefundFromTransaction$inboundSchema = RefundFromTransaction$inboundSchema;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { omitInternalMetadata, parseJSON, PAYKIT_METADATA_KEY, Schema, billingModeSchema } from '@paykit-sdk/core';
|
|
2
|
+
|
|
3
|
+
// src/utils/mapper.ts
|
|
4
|
+
var chapaStatusMap = {
|
|
5
|
+
success: "succeeded",
|
|
6
|
+
failed: "failed",
|
|
7
|
+
pending: "pending"
|
|
8
|
+
};
|
|
9
|
+
var resolveCustomer = (data) => data.email ? { email: data.email } : null;
|
|
10
|
+
var Payment$inboundSchema = (data, overridePaymentUrl) => {
|
|
11
|
+
const rawMeta = data.meta ?? {};
|
|
12
|
+
const metadata = omitInternalMetadata(rawMeta);
|
|
13
|
+
let itemId = null;
|
|
14
|
+
const paykitMeta = parseJSON(
|
|
15
|
+
rawMeta[PAYKIT_METADATA_KEY],
|
|
16
|
+
Schema.object({ item_id: Schema.string().optional() })
|
|
17
|
+
);
|
|
18
|
+
if (paykitMeta) itemId = paykitMeta.item_id ?? null;
|
|
19
|
+
const status = chapaStatusMap[data.status] ?? "pending";
|
|
20
|
+
return {
|
|
21
|
+
id: data.tx_ref,
|
|
22
|
+
amount: parseFloat(data.amount),
|
|
23
|
+
currency: data.currency,
|
|
24
|
+
customer: resolveCustomer(data),
|
|
25
|
+
status,
|
|
26
|
+
metadata,
|
|
27
|
+
item_id: itemId,
|
|
28
|
+
requires_action: status === "pending",
|
|
29
|
+
payment_url: overridePaymentUrl ?? null
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
var Checkout$inboundSchema = (init, transaction) => {
|
|
33
|
+
const rawMeta = transaction.meta ?? {};
|
|
34
|
+
const metadata = omitInternalMetadata(rawMeta);
|
|
35
|
+
let itemId = "";
|
|
36
|
+
let quantity = 1;
|
|
37
|
+
let type = null;
|
|
38
|
+
const paykitMeta = parseJSON(
|
|
39
|
+
rawMeta[PAYKIT_METADATA_KEY],
|
|
40
|
+
Schema.object({
|
|
41
|
+
item_id: Schema.string().optional(),
|
|
42
|
+
quantity: Schema.number().optional(),
|
|
43
|
+
type: billingModeSchema.optional()
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
if (paykitMeta) {
|
|
47
|
+
itemId = paykitMeta.item_id ?? "";
|
|
48
|
+
quantity = paykitMeta.quantity ?? 1;
|
|
49
|
+
type = paykitMeta.type ?? null;
|
|
50
|
+
}
|
|
51
|
+
const amount = typeof transaction.amount === "string" ? parseFloat(transaction.amount) : transaction.amount ?? 0;
|
|
52
|
+
return {
|
|
53
|
+
id: init.tx_ref,
|
|
54
|
+
customer: resolveCustomer({ email: transaction.email ?? null }),
|
|
55
|
+
payment_url: init.checkout_url ?? "",
|
|
56
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : null,
|
|
57
|
+
session_type: type ?? "one_time",
|
|
58
|
+
products: [{ id: itemId, quantity }],
|
|
59
|
+
currency: transaction.currency ?? "ETB",
|
|
60
|
+
amount
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
var Invoice$inboundSchema = (data) => {
|
|
64
|
+
const rawMeta = data.meta ?? {};
|
|
65
|
+
const metadata = omitInternalMetadata(rawMeta);
|
|
66
|
+
return {
|
|
67
|
+
id: data.reference,
|
|
68
|
+
customer: resolveCustomer(data),
|
|
69
|
+
subscription_id: null,
|
|
70
|
+
billing_mode: "one_time",
|
|
71
|
+
amount_paid: parseFloat(data.amount),
|
|
72
|
+
currency: data.currency,
|
|
73
|
+
status: "paid",
|
|
74
|
+
paid_at: data.updated_at,
|
|
75
|
+
line_items: null,
|
|
76
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : null,
|
|
77
|
+
custom_fields: null
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
var RefundFromTransaction$inboundSchema = (data) => {
|
|
81
|
+
const rawMeta = data.meta ?? {};
|
|
82
|
+
const metadata = omitInternalMetadata(rawMeta);
|
|
83
|
+
return {
|
|
84
|
+
id: data.tx_ref,
|
|
85
|
+
amount: parseFloat(data.amount),
|
|
86
|
+
currency: data.currency,
|
|
87
|
+
reason: null,
|
|
88
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : null
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
var Refund$inboundSchema = (data, context) => ({
|
|
92
|
+
id: data.ref_id ?? context.paymentId,
|
|
93
|
+
amount: data.amount ?? context.amount,
|
|
94
|
+
currency: data.currency ?? context.currency,
|
|
95
|
+
reason: context.reason,
|
|
96
|
+
metadata: null
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
export { Checkout$inboundSchema, Invoice$inboundSchema, Payment$inboundSchema, Refund$inboundSchema, RefundFromTransaction$inboundSchema };
|