paybridge 0.5.0 → 0.7.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.
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Pesapal payment provider
3
+ * East Africa-focused payment gateway (Kenya, Uganda, Tanzania)
4
+ * @see https://developer.pesapal.com/
5
+ */
6
+ import { PaymentProvider } from './base';
7
+ import { CreatePaymentParams, PaymentResult, CreateSubscriptionParams, SubscriptionResult, RefundParams, RefundResult, WebhookEvent } from '../types';
8
+ import { ProviderCapabilities } from '../routing-types';
9
+ interface PesapalConfig {
10
+ consumerKey: string;
11
+ consumerSecret: string;
12
+ notificationId?: string;
13
+ username?: string;
14
+ webhookSecret?: string;
15
+ sandbox?: boolean;
16
+ }
17
+ export declare class PesapalProvider extends PaymentProvider {
18
+ readonly name = "pesapal";
19
+ readonly supportedCurrencies: string[];
20
+ private consumerKey;
21
+ private consumerSecret;
22
+ private notificationId?;
23
+ private username?;
24
+ private webhookSecret?;
25
+ private sandbox;
26
+ private baseUrl;
27
+ private tokenCache?;
28
+ constructor(config: PesapalConfig);
29
+ private getToken;
30
+ private apiRequest;
31
+ createPayment(params: CreatePaymentParams): Promise<PaymentResult>;
32
+ createSubscription(_params: CreateSubscriptionParams): Promise<SubscriptionResult>;
33
+ getPayment(id: string): Promise<PaymentResult>;
34
+ refund(params: RefundParams): Promise<RefundResult>;
35
+ parseWebhook(body: any, _headers?: any): WebhookEvent;
36
+ /**
37
+ * Pesapal IPN has no signature verification scheme.
38
+ * Security comes from:
39
+ * 1. Validating source IP (caller's responsibility)
40
+ * 2. Calling getPayment(id) to verify actual status
41
+ *
42
+ * Always returns true to indicate no validation error (Pesapal design limitation).
43
+ */
44
+ verifyWebhook(_body: string | Buffer, _headers?: any): boolean;
45
+ getCapabilities(): ProviderCapabilities;
46
+ }
47
+ export {};
@@ -0,0 +1,236 @@
1
+ "use strict";
2
+ /**
3
+ * Pesapal payment provider
4
+ * East Africa-focused payment gateway (Kenya, Uganda, Tanzania)
5
+ * @see https://developer.pesapal.com/
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.PesapalProvider = void 0;
42
+ const crypto = __importStar(require("crypto"));
43
+ const base_1 = require("./base");
44
+ const fetch_1 = require("../utils/fetch");
45
+ let webhookSecretWarned = false;
46
+ class PesapalProvider extends base_1.PaymentProvider {
47
+ constructor(config) {
48
+ super();
49
+ this.name = 'pesapal';
50
+ this.supportedCurrencies = ['KES', 'UGX', 'TZS', 'USD'];
51
+ this.consumerKey = config.consumerKey;
52
+ this.consumerSecret = config.consumerSecret;
53
+ this.notificationId = config.notificationId;
54
+ this.username = config.username;
55
+ this.webhookSecret = config.webhookSecret;
56
+ this.sandbox = config.sandbox ?? false;
57
+ this.baseUrl = this.sandbox
58
+ ? 'https://cybqa.pesapal.com/pesapalv3'
59
+ : 'https://pay.pesapal.com/v3';
60
+ if (this.webhookSecret && !webhookSecretWarned) {
61
+ console.warn('[PayBridge:Pesapal] Pesapal IPN has no webhook signature scheme. Webhook validation relies on getPayment() round-trip. Validate by source IP if possible.');
62
+ webhookSecretWarned = true;
63
+ }
64
+ }
65
+ async getToken() {
66
+ const now = Date.now();
67
+ if (this.tokenCache && this.tokenCache.expiresAt > now + 60000) {
68
+ return this.tokenCache.token;
69
+ }
70
+ const response = await (0, fetch_1.timedFetchOrThrow)(`${this.baseUrl}/api/Auth/RequestToken`, {
71
+ method: 'POST',
72
+ headers: {
73
+ 'Content-Type': 'application/json',
74
+ },
75
+ body: JSON.stringify({
76
+ consumer_key: this.consumerKey,
77
+ consumer_secret: this.consumerSecret,
78
+ }),
79
+ });
80
+ const data = (await response.json());
81
+ this.tokenCache = {
82
+ token: data.token,
83
+ expiresAt: now + 4 * 60 * 1000,
84
+ };
85
+ return this.tokenCache.token;
86
+ }
87
+ async apiRequest(method, path, data) {
88
+ const token = await this.getToken();
89
+ const url = `${this.baseUrl}${path}`;
90
+ const response = await (0, fetch_1.timedFetchOrThrow)(url, {
91
+ method,
92
+ headers: {
93
+ Authorization: `Bearer ${token}`,
94
+ 'Content-Type': 'application/json',
95
+ },
96
+ body: data ? JSON.stringify(data) : undefined,
97
+ });
98
+ return (await response.json());
99
+ }
100
+ async createPayment(params) {
101
+ this.validateCurrency(params.currency);
102
+ const requestBody = {
103
+ id: params.reference,
104
+ currency: params.currency,
105
+ amount: params.amount,
106
+ description: params.description || params.reference,
107
+ callback_url: params.urls.success,
108
+ billing_address: {
109
+ email_address: params.customer.email,
110
+ phone_number: params.customer.phone || '',
111
+ first_name: params.customer.name.split(' ')[0] || params.customer.name,
112
+ last_name: params.customer.name.split(' ').slice(1).join(' ') || '',
113
+ },
114
+ };
115
+ if (this.notificationId) {
116
+ requestBody.notification_id = this.notificationId;
117
+ }
118
+ const response = await this.apiRequest('POST', '/api/Transactions/SubmitOrderRequest', requestBody);
119
+ return {
120
+ id: response.order_tracking_id,
121
+ checkoutUrl: response.redirect_url,
122
+ status: 'pending',
123
+ amount: params.amount,
124
+ currency: params.currency.toUpperCase(),
125
+ reference: response.merchant_reference || params.reference,
126
+ provider: 'pesapal',
127
+ createdAt: new Date().toISOString(),
128
+ raw: response,
129
+ };
130
+ }
131
+ async createSubscription(_params) {
132
+ throw new Error('Pesapal subscriptions not yet supported by paybridge. Use the Pesapal Recurring Billing API directly.');
133
+ }
134
+ async getPayment(id) {
135
+ const response = await this.apiRequest('GET', `/api/Transactions/GetTransactionStatus?orderTrackingId=${id}`);
136
+ let status = 'pending';
137
+ if (response.payment_status_description === 'Completed') {
138
+ status = 'completed';
139
+ }
140
+ else if (response.payment_status_description === 'Failed' || response.payment_status_description === 'Invalid') {
141
+ status = 'failed';
142
+ }
143
+ else if (response.payment_status_description === 'Pending') {
144
+ status = 'pending';
145
+ }
146
+ const currency = (response.currency || 'KES').toUpperCase();
147
+ const amount = response.amount || 0;
148
+ return {
149
+ id,
150
+ checkoutUrl: '',
151
+ status,
152
+ amount,
153
+ currency,
154
+ reference: response.merchant_reference || id,
155
+ provider: 'pesapal',
156
+ createdAt: response.created_date || new Date().toISOString(),
157
+ raw: response,
158
+ };
159
+ }
160
+ async refund(params) {
161
+ if (!this.username) {
162
+ throw new Error('Pesapal refunds require username config (merchant username)');
163
+ }
164
+ const refundData = {
165
+ confirmation_code: params.paymentId,
166
+ username: this.username,
167
+ remarks: params.reason || 'Refund',
168
+ };
169
+ if (params.amount !== undefined) {
170
+ refundData.amount = params.amount;
171
+ }
172
+ const response = await this.apiRequest('POST', '/api/Transactions/RefundRequest', refundData);
173
+ const currency = (response.currency || 'KES').toUpperCase();
174
+ const amount = response.amount || 0;
175
+ return {
176
+ id: response.refund_id || response.id || crypto.randomUUID(),
177
+ status: response.status === 'Success' ? 'completed' : 'pending',
178
+ amount,
179
+ currency,
180
+ paymentId: params.paymentId,
181
+ createdAt: response.created_date || new Date().toISOString(),
182
+ raw: response,
183
+ };
184
+ }
185
+ parseWebhook(body, _headers) {
186
+ let orderTrackingId;
187
+ let merchantReference;
188
+ if (typeof body === 'string') {
189
+ const parsed = new URLSearchParams(body);
190
+ orderTrackingId = parsed.get('OrderTrackingId') || '';
191
+ merchantReference = parsed.get('OrderMerchantReference') || orderTrackingId;
192
+ }
193
+ else {
194
+ orderTrackingId = body.OrderTrackingId || body.order_tracking_id || '';
195
+ merchantReference = body.OrderMerchantReference || body.merchant_reference || orderTrackingId;
196
+ }
197
+ return {
198
+ type: 'payment.pending',
199
+ payment: {
200
+ id: orderTrackingId,
201
+ checkoutUrl: '',
202
+ status: 'pending',
203
+ amount: 0,
204
+ currency: 'KES',
205
+ reference: merchantReference,
206
+ provider: 'pesapal',
207
+ createdAt: new Date().toISOString(),
208
+ },
209
+ raw: body,
210
+ };
211
+ }
212
+ /**
213
+ * Pesapal IPN has no signature verification scheme.
214
+ * Security comes from:
215
+ * 1. Validating source IP (caller's responsibility)
216
+ * 2. Calling getPayment(id) to verify actual status
217
+ *
218
+ * Always returns true to indicate no validation error (Pesapal design limitation).
219
+ */
220
+ verifyWebhook(_body, _headers) {
221
+ return true;
222
+ }
223
+ getCapabilities() {
224
+ return {
225
+ fees: {
226
+ fixed: 0,
227
+ percent: 3.5,
228
+ currency: 'KES',
229
+ },
230
+ currencies: this.supportedCurrencies,
231
+ country: 'KE',
232
+ avgLatencyMs: 900,
233
+ };
234
+ }
235
+ }
236
+ exports.PesapalProvider = PesapalProvider;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Square payment provider
3
+ * Payment Links API supporting USD, CAD, GBP, AUD, EUR, JPY
4
+ * @see https://developer.squareup.com/reference/square
5
+ */
6
+ import { PaymentProvider } from './base';
7
+ import { CreatePaymentParams, PaymentResult, CreateSubscriptionParams, SubscriptionResult, RefundParams, RefundResult, WebhookEvent } from '../types';
8
+ import { ProviderCapabilities } from '../routing-types';
9
+ interface SquareConfig {
10
+ accessToken: string;
11
+ locationId: string;
12
+ notificationUrl?: string;
13
+ webhookSecret?: string;
14
+ sandbox?: boolean;
15
+ }
16
+ export declare class SquareProvider extends PaymentProvider {
17
+ readonly name = "square";
18
+ readonly supportedCurrencies: string[];
19
+ private accessToken;
20
+ private locationId;
21
+ private notificationUrl?;
22
+ private webhookSecret?;
23
+ private sandbox;
24
+ private baseUrl;
25
+ constructor(config: SquareConfig);
26
+ private apiRequest;
27
+ createPayment(params: CreatePaymentParams): Promise<PaymentResult>;
28
+ createSubscription(_params: CreateSubscriptionParams): Promise<SubscriptionResult>;
29
+ getPayment(id: string): Promise<PaymentResult>;
30
+ refund(params: RefundParams): Promise<RefundResult>;
31
+ parseWebhook(body: any, _headers?: any): WebhookEvent;
32
+ /**
33
+ * Verify webhook signature using Square's HMAC-SHA256 scheme.
34
+ *
35
+ * Square signs the concatenation of: notificationUrl + rawBody
36
+ * TODO(verify): Confirm Square's current signing scheme matches this implementation.
37
+ */
38
+ verifyWebhook(body: string | Buffer, headers?: any): boolean;
39
+ getCapabilities(): ProviderCapabilities;
40
+ }
41
+ export {};
@@ -0,0 +1,278 @@
1
+ "use strict";
2
+ /**
3
+ * Square payment provider
4
+ * Payment Links API supporting USD, CAD, GBP, AUD, EUR, JPY
5
+ * @see https://developer.squareup.com/reference/square
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.SquareProvider = void 0;
42
+ const crypto = __importStar(require("crypto"));
43
+ const base_1 = require("./base");
44
+ const currency_1 = require("../utils/currency");
45
+ const fetch_1 = require("../utils/fetch");
46
+ class SquareProvider extends base_1.PaymentProvider {
47
+ constructor(config) {
48
+ super();
49
+ this.name = 'square';
50
+ this.supportedCurrencies = ['USD', 'CAD', 'GBP', 'AUD', 'EUR', 'JPY'];
51
+ this.accessToken = config.accessToken;
52
+ this.locationId = config.locationId;
53
+ this.notificationUrl = config.notificationUrl;
54
+ this.webhookSecret = config.webhookSecret;
55
+ this.sandbox = config.sandbox ?? false;
56
+ this.baseUrl = this.sandbox
57
+ ? 'https://connect.squareupsandbox.com/v2'
58
+ : 'https://connect.squareup.com/v2';
59
+ }
60
+ async apiRequest(method, path, data) {
61
+ const url = `${this.baseUrl}${path}`;
62
+ const response = await (0, fetch_1.timedFetchOrThrow)(url, {
63
+ method,
64
+ headers: {
65
+ Authorization: `Bearer ${this.accessToken}`,
66
+ 'Content-Type': 'application/json',
67
+ 'Square-Version': '2024-09-19',
68
+ },
69
+ body: data ? JSON.stringify(data) : undefined,
70
+ });
71
+ return (await response.json());
72
+ }
73
+ async createPayment(params) {
74
+ this.validateCurrency(params.currency);
75
+ const amountInMinorUnits = (0, currency_1.toMinorUnit)(params.amount, params.currency);
76
+ const requestBody = {
77
+ idempotency_key: crypto.randomUUID(),
78
+ quick_pay: {
79
+ name: params.description || params.reference,
80
+ price_money: {
81
+ amount: amountInMinorUnits,
82
+ currency: params.currency,
83
+ },
84
+ location_id: this.locationId,
85
+ },
86
+ checkout_options: {
87
+ redirect_url: params.urls.success,
88
+ ask_for_shipping_address: false,
89
+ },
90
+ pre_populated_data: {
91
+ buyer_email: params.customer.email,
92
+ },
93
+ };
94
+ const response = await this.apiRequest('POST', '/checkout/payment-links', requestBody);
95
+ const link = response.payment_link;
96
+ return {
97
+ id: link.id,
98
+ checkoutUrl: link.url,
99
+ status: 'pending',
100
+ amount: params.amount,
101
+ currency: params.currency.toUpperCase(),
102
+ reference: params.reference,
103
+ provider: 'square',
104
+ createdAt: link.created_at || new Date().toISOString(),
105
+ raw: response,
106
+ };
107
+ }
108
+ async createSubscription(_params) {
109
+ throw new Error('Square subscriptions require multi-step Catalog + Customer + Plan setup; not yet supported by paybridge. Use the Square Subscriptions API directly or choose another provider.');
110
+ }
111
+ async getPayment(id) {
112
+ const linkResponse = await this.apiRequest('GET', `/online-checkout/payment-links/${id}`);
113
+ const link = linkResponse.payment_link;
114
+ const orderId = link.order_id;
115
+ const orderResponse = await this.apiRequest('GET', `/orders/${orderId}`);
116
+ const order = orderResponse.order;
117
+ let status = 'pending';
118
+ if (order.state === 'COMPLETED') {
119
+ status = 'completed';
120
+ }
121
+ else if (order.state === 'CANCELED') {
122
+ status = 'cancelled';
123
+ }
124
+ else if (order.state === 'OPEN') {
125
+ status = 'pending';
126
+ }
127
+ const currency = order.total_money?.currency || 'USD';
128
+ const amount = order.total_money?.amount ? (0, currency_1.toMajorUnit)(order.total_money.amount, currency) : 0;
129
+ return {
130
+ id: link.id,
131
+ checkoutUrl: link.url || '',
132
+ status,
133
+ amount,
134
+ currency: currency.toUpperCase(),
135
+ reference: link.id,
136
+ provider: 'square',
137
+ createdAt: link.created_at || new Date().toISOString(),
138
+ raw: { link, order },
139
+ };
140
+ }
141
+ async refund(params) {
142
+ const currency = 'USD';
143
+ const amountInMinorUnits = params.amount ? (0, currency_1.toMinorUnit)(params.amount, currency) : undefined;
144
+ const refundData = {
145
+ idempotency_key: crypto.randomUUID(),
146
+ payment_id: params.paymentId,
147
+ reason: params.reason || 'Refund',
148
+ };
149
+ if (amountInMinorUnits !== undefined) {
150
+ refundData.amount_money = {
151
+ amount: amountInMinorUnits,
152
+ currency,
153
+ };
154
+ }
155
+ const response = await this.apiRequest('POST', '/refunds', refundData);
156
+ const refund = response.refund;
157
+ const refundCurrency = refund.amount_money?.currency || currency;
158
+ const refundAmount = refund.amount_money?.amount
159
+ ? (0, currency_1.toMajorUnit)(refund.amount_money.amount, refundCurrency)
160
+ : 0;
161
+ return {
162
+ id: refund.id,
163
+ status: refund.status === 'COMPLETED' ? 'completed' : 'pending',
164
+ amount: refundAmount,
165
+ currency: refundCurrency.toUpperCase(),
166
+ paymentId: params.paymentId,
167
+ createdAt: refund.created_at || new Date().toISOString(),
168
+ raw: response,
169
+ };
170
+ }
171
+ parseWebhook(body, _headers) {
172
+ const event = typeof body === 'string' ? JSON.parse(body) : body;
173
+ const typeMap = {
174
+ 'payment.created': 'payment.completed',
175
+ 'payment.updated': 'payment.pending',
176
+ 'refund.created': 'refund.completed',
177
+ 'refund.updated': 'refund.completed',
178
+ };
179
+ let eventType = typeMap[event.type] || 'payment.pending';
180
+ const data = event.data?.object?.payment || event.data?.object?.refund || {};
181
+ if (event.type === 'payment.updated' && data.status === 'COMPLETED') {
182
+ eventType = 'payment.completed';
183
+ }
184
+ else if (event.type === 'payment.updated' && data.status === 'FAILED') {
185
+ eventType = 'payment.failed';
186
+ }
187
+ else if (event.type === 'payment.updated' && data.status === 'CANCELED') {
188
+ eventType = 'payment.cancelled';
189
+ }
190
+ let payment;
191
+ let refund;
192
+ if (event.type.startsWith('payment.')) {
193
+ const currency = data.amount_money?.currency || 'USD';
194
+ let status = 'pending';
195
+ if (data.status === 'COMPLETED') {
196
+ status = 'completed';
197
+ }
198
+ else if (data.status === 'FAILED') {
199
+ status = 'failed';
200
+ }
201
+ else if (data.status === 'CANCELED') {
202
+ status = 'cancelled';
203
+ }
204
+ payment = {
205
+ id: data.id,
206
+ checkoutUrl: '',
207
+ status,
208
+ amount: data.amount_money?.amount ? (0, currency_1.toMajorUnit)(data.amount_money.amount, currency) : 0,
209
+ currency: currency.toUpperCase(),
210
+ reference: data.id,
211
+ provider: 'square',
212
+ createdAt: data.created_at || new Date().toISOString(),
213
+ };
214
+ }
215
+ else if (event.type.startsWith('refund.')) {
216
+ const currency = data.amount_money?.currency || 'USD';
217
+ refund = {
218
+ id: data.id,
219
+ status: data.status === 'COMPLETED' ? 'completed' : 'pending',
220
+ amount: data.amount_money?.amount ? (0, currency_1.toMajorUnit)(data.amount_money.amount, currency) : 0,
221
+ currency: currency.toUpperCase(),
222
+ paymentId: data.payment_id || '',
223
+ createdAt: data.created_at || new Date().toISOString(),
224
+ };
225
+ }
226
+ return {
227
+ type: eventType,
228
+ payment,
229
+ refund,
230
+ raw: event,
231
+ };
232
+ }
233
+ /**
234
+ * Verify webhook signature using Square's HMAC-SHA256 scheme.
235
+ *
236
+ * Square signs the concatenation of: notificationUrl + rawBody
237
+ * TODO(verify): Confirm Square's current signing scheme matches this implementation.
238
+ */
239
+ verifyWebhook(body, headers) {
240
+ if (!this.webhookSecret || !this.notificationUrl) {
241
+ return false;
242
+ }
243
+ const signature = headers?.['x-square-hmacsha256-signature'];
244
+ if (!signature) {
245
+ return false;
246
+ }
247
+ const rawBody = typeof body === 'string' ? body : body.toString('utf8');
248
+ const signedString = `${this.notificationUrl}${rawBody}`;
249
+ const computedSig = crypto
250
+ .createHmac('sha256', this.webhookSecret)
251
+ .update(signedString)
252
+ .digest('base64');
253
+ try {
254
+ const computedBuffer = Buffer.from(computedSig, 'base64');
255
+ const expectedBuffer = Buffer.from(signature, 'base64');
256
+ if (computedBuffer.length !== expectedBuffer.length) {
257
+ return false;
258
+ }
259
+ return crypto.timingSafeEqual(computedBuffer, expectedBuffer);
260
+ }
261
+ catch {
262
+ return false;
263
+ }
264
+ }
265
+ getCapabilities() {
266
+ return {
267
+ fees: {
268
+ fixed: 0.10,
269
+ percent: 2.6,
270
+ currency: 'USD',
271
+ },
272
+ currencies: this.supportedCurrencies,
273
+ country: 'US',
274
+ avgLatencyMs: 400,
275
+ };
276
+ }
277
+ }
278
+ exports.SquareProvider = SquareProvider;
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * PayBridge — Unified payment SDK types
3
3
  */
4
- export type Provider = 'softycomp' | 'yoco' | 'ozow' | 'payfast' | 'paystack' | 'stripe' | 'peach' | 'flutterwave' | 'adyen' | 'mercadopago' | 'razorpay';
4
+ export type Provider = 'softycomp' | 'yoco' | 'ozow' | 'payfast' | 'paystack' | 'stripe' | 'peach' | 'flutterwave' | 'adyen' | 'mercadopago' | 'razorpay' | 'mollie' | 'square' | 'pesapal';
5
5
  export type PaymentStatus = 'pending' | 'completed' | 'failed' | 'cancelled' | 'refunded';
6
6
  export type SubscriptionInterval = 'weekly' | 'monthly' | 'yearly';
7
7
  export type Currency = 'ZAR' | 'USD' | 'EUR' | 'GBP' | 'NGN' | 'KES' | 'UGX' | 'GHS' | string;
package/package.json CHANGED
@@ -1,14 +1,19 @@
1
1
  {
2
2
  "name": "paybridge",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "One API for fiat + crypto payments. Multi-provider routing, automatic failover, MoonPay on/off-ramp. SA-first, global-ready.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "bin": {
8
+ "paybridge": "dist/cli/index.js"
9
+ },
7
10
  "scripts": {
8
11
  "build": "tsc",
12
+ "build:cli": "npm run build && node scripts/post-build.js",
9
13
  "clean": "rm -rf dist",
10
- "prepack": "npm run clean && npm run build",
11
- "prepublishOnly": "npm run clean && npm run build",
14
+ "cli": "node dist/cli/index.js",
15
+ "prepack": "npm run clean && npm run build:cli",
16
+ "prepublishOnly": "npm run clean && npm run build:cli",
12
17
  "test": "tsc && tsc --project tsconfig.test.json && node --test 'dist-test/**/*.test.js'",
13
18
  "test:e2e:moonpay": "tsx tests/e2e/moonpay-sandbox.ts",
14
19
  "test:e2e:yellowcard": "tsx tests/e2e/yellowcard-sandbox.ts",
@@ -33,7 +38,15 @@
33
38
  "mercadopago",
34
39
  "razorpay",
35
40
  "india",
36
- "latam"
41
+ "latam",
42
+ "mollie",
43
+ "square",
44
+ "pesapal",
45
+ "transak",
46
+ "ramp",
47
+ "east-africa",
48
+ "cli",
49
+ "command-line"
37
50
  ],
38
51
  "author": "Kobie Wentzel",
39
52
  "license": "MIT",