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,335 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runners = void 0;
4
+ const index_1 = require("../index");
5
+ const crypto_1 = require("../crypto");
6
+ const timestamp = Date.now();
7
+ const testCustomer = {
8
+ name: 'Test User',
9
+ email: 'test@example.com',
10
+ phone: '0825551234',
11
+ };
12
+ const testUrls = {
13
+ success: 'https://example.com/success',
14
+ cancel: 'https://example.com/cancel',
15
+ webhook: 'https://example.com/webhook',
16
+ };
17
+ exports.runners = [
18
+ {
19
+ name: 'softycomp',
20
+ envRequired: ['SOFTYCOMP_API_KEY', 'SOFTYCOMP_SECRET_KEY'],
21
+ run: async () => {
22
+ const pay = new index_1.PayBridge({
23
+ provider: 'softycomp',
24
+ credentials: {
25
+ apiKey: process.env.SOFTYCOMP_API_KEY,
26
+ secretKey: process.env.SOFTYCOMP_SECRET_KEY,
27
+ },
28
+ sandbox: true,
29
+ });
30
+ const payment = await pay.createPayment({
31
+ amount: 1.0,
32
+ currency: 'ZAR',
33
+ reference: `cli-test-${timestamp}`,
34
+ customer: testCustomer,
35
+ urls: testUrls,
36
+ });
37
+ return { id: payment.id, checkoutUrl: payment.checkoutUrl, status: payment.status };
38
+ },
39
+ },
40
+ {
41
+ name: 'yoco',
42
+ envRequired: ['YOCO_API_KEY'],
43
+ run: async () => {
44
+ const pay = new index_1.PayBridge({
45
+ provider: 'yoco',
46
+ credentials: { apiKey: process.env.YOCO_API_KEY },
47
+ sandbox: true,
48
+ });
49
+ const payment = await pay.createPayment({
50
+ amount: 1.0,
51
+ currency: 'ZAR',
52
+ reference: `cli-test-${timestamp}`,
53
+ customer: testCustomer,
54
+ urls: testUrls,
55
+ });
56
+ return { id: payment.id, checkoutUrl: payment.checkoutUrl, status: payment.status };
57
+ },
58
+ },
59
+ {
60
+ name: 'ozow',
61
+ envRequired: ['OZOW_API_KEY', 'OZOW_SITE_CODE', 'OZOW_PRIVATE_KEY'],
62
+ run: async () => {
63
+ const pay = new index_1.PayBridge({
64
+ provider: 'ozow',
65
+ credentials: {
66
+ apiKey: process.env.OZOW_API_KEY,
67
+ siteCode: process.env.OZOW_SITE_CODE,
68
+ privateKey: process.env.OZOW_PRIVATE_KEY,
69
+ },
70
+ sandbox: true,
71
+ });
72
+ const payment = await pay.createPayment({
73
+ amount: 1.0,
74
+ currency: 'ZAR',
75
+ reference: `cli-test-${timestamp}`,
76
+ customer: testCustomer,
77
+ urls: testUrls,
78
+ });
79
+ return { id: payment.id, checkoutUrl: payment.checkoutUrl, status: payment.status };
80
+ },
81
+ },
82
+ {
83
+ name: 'payfast',
84
+ envRequired: ['PAYFAST_MERCHANT_ID', 'PAYFAST_MERCHANT_KEY'],
85
+ run: async () => {
86
+ const pay = new index_1.PayBridge({
87
+ provider: 'payfast',
88
+ credentials: {
89
+ merchantId: process.env.PAYFAST_MERCHANT_ID,
90
+ merchantKey: process.env.PAYFAST_MERCHANT_KEY,
91
+ passphrase: process.env.PAYFAST_PASSPHRASE,
92
+ },
93
+ sandbox: true,
94
+ });
95
+ const payment = await pay.createPayment({
96
+ amount: 1.0,
97
+ currency: 'ZAR',
98
+ reference: `cli-test-${timestamp}`,
99
+ customer: testCustomer,
100
+ urls: testUrls,
101
+ });
102
+ return { id: payment.id, checkoutUrl: payment.checkoutUrl, status: payment.status };
103
+ },
104
+ },
105
+ {
106
+ name: 'paystack',
107
+ envRequired: ['PAYSTACK_API_KEY'],
108
+ run: async () => {
109
+ const pay = new index_1.PayBridge({
110
+ provider: 'paystack',
111
+ credentials: { apiKey: process.env.PAYSTACK_API_KEY },
112
+ sandbox: true,
113
+ });
114
+ const payment = await pay.createPayment({
115
+ amount: 1.0,
116
+ currency: 'NGN',
117
+ reference: `cli-test-${timestamp}`,
118
+ customer: testCustomer,
119
+ urls: testUrls,
120
+ });
121
+ return { id: payment.id, checkoutUrl: payment.checkoutUrl, status: payment.status };
122
+ },
123
+ },
124
+ {
125
+ name: 'stripe',
126
+ envRequired: ['STRIPE_API_KEY'],
127
+ run: async () => {
128
+ const pay = new index_1.PayBridge({
129
+ provider: 'stripe',
130
+ credentials: { apiKey: process.env.STRIPE_API_KEY },
131
+ sandbox: true,
132
+ });
133
+ const payment = await pay.createPayment({
134
+ amount: 1.0,
135
+ currency: 'USD',
136
+ reference: `cli-test-${timestamp}`,
137
+ customer: testCustomer,
138
+ urls: testUrls,
139
+ });
140
+ return { id: payment.id, checkoutUrl: payment.checkoutUrl, status: payment.status };
141
+ },
142
+ },
143
+ {
144
+ name: 'peach',
145
+ envRequired: ['PEACH_ACCESS_TOKEN', 'PEACH_ENTITY_ID'],
146
+ run: async () => {
147
+ const pay = new index_1.PayBridge({
148
+ provider: 'peach',
149
+ credentials: {
150
+ apiKey: process.env.PEACH_ACCESS_TOKEN,
151
+ secretKey: process.env.PEACH_ENTITY_ID,
152
+ },
153
+ sandbox: true,
154
+ });
155
+ const payment = await pay.createPayment({
156
+ amount: 1.0,
157
+ currency: 'ZAR',
158
+ reference: `cli-test-${timestamp}`,
159
+ customer: testCustomer,
160
+ urls: testUrls,
161
+ });
162
+ return { id: payment.id, checkoutUrl: payment.checkoutUrl, status: payment.status };
163
+ },
164
+ },
165
+ {
166
+ name: 'flutterwave',
167
+ envRequired: ['FLUTTERWAVE_API_KEY'],
168
+ run: async () => {
169
+ const pay = new index_1.PayBridge({
170
+ provider: 'flutterwave',
171
+ credentials: { apiKey: process.env.FLUTTERWAVE_API_KEY },
172
+ sandbox: true,
173
+ });
174
+ const payment = await pay.createPayment({
175
+ amount: 1.0,
176
+ currency: 'NGN',
177
+ reference: `cli-test-${timestamp}`,
178
+ customer: testCustomer,
179
+ urls: testUrls,
180
+ });
181
+ return { id: payment.id, checkoutUrl: payment.checkoutUrl, status: payment.status };
182
+ },
183
+ },
184
+ {
185
+ name: 'adyen',
186
+ envRequired: ['ADYEN_API_KEY', 'ADYEN_MERCHANT_ACCOUNT'],
187
+ run: async () => {
188
+ const pay = new index_1.PayBridge({
189
+ provider: 'adyen',
190
+ credentials: {
191
+ apiKey: process.env.ADYEN_API_KEY,
192
+ merchantAccount: process.env.ADYEN_MERCHANT_ACCOUNT,
193
+ },
194
+ sandbox: true,
195
+ });
196
+ const payment = await pay.createPayment({
197
+ amount: 1.0,
198
+ currency: 'EUR',
199
+ reference: `cli-test-${timestamp}`,
200
+ customer: testCustomer,
201
+ urls: testUrls,
202
+ });
203
+ return { id: payment.id, checkoutUrl: payment.checkoutUrl, status: payment.status };
204
+ },
205
+ },
206
+ {
207
+ name: 'mercadopago',
208
+ envRequired: ['MERCADOPAGO_ACCESS_TOKEN'],
209
+ run: async () => {
210
+ const pay = new index_1.PayBridge({
211
+ provider: 'mercadopago',
212
+ credentials: { apiKey: process.env.MERCADOPAGO_ACCESS_TOKEN },
213
+ sandbox: true,
214
+ });
215
+ const payment = await pay.createPayment({
216
+ amount: 1.0,
217
+ currency: 'BRL',
218
+ reference: `cli-test-${timestamp}`,
219
+ customer: testCustomer,
220
+ urls: testUrls,
221
+ });
222
+ return { id: payment.id, checkoutUrl: payment.checkoutUrl, status: payment.status };
223
+ },
224
+ },
225
+ {
226
+ name: 'razorpay',
227
+ envRequired: ['RAZORPAY_KEY_ID', 'RAZORPAY_KEY_SECRET'],
228
+ run: async () => {
229
+ const pay = new index_1.PayBridge({
230
+ provider: 'razorpay',
231
+ credentials: {
232
+ apiKey: process.env.RAZORPAY_KEY_ID,
233
+ secretKey: process.env.RAZORPAY_KEY_SECRET,
234
+ },
235
+ sandbox: true,
236
+ });
237
+ const payment = await pay.createPayment({
238
+ amount: 1.0,
239
+ currency: 'INR',
240
+ reference: `cli-test-${timestamp}`,
241
+ customer: testCustomer,
242
+ urls: testUrls,
243
+ });
244
+ return { id: payment.id, checkoutUrl: payment.checkoutUrl, status: payment.status };
245
+ },
246
+ },
247
+ {
248
+ name: 'mollie',
249
+ envRequired: ['MOLLIE_API_KEY'],
250
+ run: async () => {
251
+ const pay = new index_1.PayBridge({
252
+ provider: 'mollie',
253
+ credentials: { apiKey: process.env.MOLLIE_API_KEY },
254
+ sandbox: true,
255
+ });
256
+ const payment = await pay.createPayment({
257
+ amount: 1.0,
258
+ currency: 'EUR',
259
+ reference: `cli-test-${timestamp}`,
260
+ customer: testCustomer,
261
+ urls: testUrls,
262
+ });
263
+ return { id: payment.id, checkoutUrl: payment.checkoutUrl, status: payment.status };
264
+ },
265
+ },
266
+ {
267
+ name: 'square',
268
+ envRequired: ['SQUARE_ACCESS_TOKEN', 'SQUARE_LOCATION_ID'],
269
+ run: async () => {
270
+ const pay = new index_1.PayBridge({
271
+ provider: 'square',
272
+ credentials: {
273
+ apiKey: process.env.SQUARE_ACCESS_TOKEN,
274
+ locationId: process.env.SQUARE_LOCATION_ID,
275
+ },
276
+ sandbox: true,
277
+ });
278
+ const payment = await pay.createPayment({
279
+ amount: 1.0,
280
+ currency: 'USD',
281
+ reference: `cli-test-${timestamp}`,
282
+ customer: testCustomer,
283
+ urls: testUrls,
284
+ });
285
+ return { id: payment.id, checkoutUrl: payment.checkoutUrl, status: payment.status };
286
+ },
287
+ },
288
+ {
289
+ name: 'pesapal',
290
+ envRequired: ['PESAPAL_CONSUMER_KEY', 'PESAPAL_CONSUMER_SECRET'],
291
+ run: async () => {
292
+ const pay = new index_1.PayBridge({
293
+ provider: 'pesapal',
294
+ credentials: {
295
+ apiKey: process.env.PESAPAL_CONSUMER_KEY,
296
+ secretKey: process.env.PESAPAL_CONSUMER_SECRET,
297
+ },
298
+ sandbox: true,
299
+ });
300
+ const payment = await pay.createPayment({
301
+ amount: 1.0,
302
+ currency: 'KES',
303
+ reference: `cli-test-${timestamp}`,
304
+ customer: testCustomer,
305
+ urls: testUrls,
306
+ });
307
+ return { id: payment.id, checkoutUrl: payment.checkoutUrl, status: payment.status };
308
+ },
309
+ },
310
+ {
311
+ name: 'moonpay',
312
+ envRequired: ['MOONPAY_API_KEY', 'MOONPAY_SECRET_KEY'],
313
+ run: async () => {
314
+ const ramp = new crypto_1.CryptoRamp({
315
+ provider: 'moonpay',
316
+ credentials: {
317
+ apiKey: process.env.MOONPAY_API_KEY,
318
+ secretKey: process.env.MOONPAY_SECRET_KEY,
319
+ },
320
+ sandbox: true,
321
+ });
322
+ const result = await ramp.createOnRamp({
323
+ fiatAmount: 1.0,
324
+ fiatCurrency: 'USD',
325
+ asset: 'BTC',
326
+ network: 'BTC',
327
+ destinationWallet: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa',
328
+ customer: testCustomer,
329
+ urls: testUrls,
330
+ reference: `cli-test-${timestamp}`,
331
+ });
332
+ return { id: result.id, checkoutUrl: result.checkoutUrl, status: result.status };
333
+ },
334
+ },
335
+ ];
@@ -0,0 +1,16 @@
1
+ export declare const colors: {
2
+ reset: string;
3
+ bright: string;
4
+ dim: string;
5
+ green: string;
6
+ yellow: string;
7
+ red: string;
8
+ cyan: string;
9
+ };
10
+ export declare function colorize(text: string, color: keyof typeof colors): string;
11
+ export declare function padEnd(str: string, length: number): string;
12
+ export declare function formatTable(rows: string[][], padding?: number): string;
13
+ export declare function readStdin(): Promise<string>;
14
+ export declare function parseHeaders(headerFlags: string[]): Record<string, string>;
15
+ export declare function printHelp(toStderr?: boolean): void;
16
+ export declare function printVersion(): void;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.colors = void 0;
4
+ exports.colorize = colorize;
5
+ exports.padEnd = padEnd;
6
+ exports.formatTable = formatTable;
7
+ exports.readStdin = readStdin;
8
+ exports.parseHeaders = parseHeaders;
9
+ exports.printHelp = printHelp;
10
+ exports.printVersion = printVersion;
11
+ exports.colors = {
12
+ reset: '\x1b[0m',
13
+ bright: '\x1b[1m',
14
+ dim: '\x1b[2m',
15
+ green: '\x1b[32m',
16
+ yellow: '\x1b[33m',
17
+ red: '\x1b[31m',
18
+ cyan: '\x1b[36m',
19
+ };
20
+ function colorize(text, color) {
21
+ return `${exports.colors[color]}${text}${exports.colors.reset}`;
22
+ }
23
+ function padEnd(str, length) {
24
+ while (str.length < length) {
25
+ str += ' ';
26
+ }
27
+ return str;
28
+ }
29
+ function formatTable(rows, padding = 2) {
30
+ if (rows.length === 0)
31
+ return '';
32
+ const colWidths = [];
33
+ for (const row of rows) {
34
+ row.forEach((cell, i) => {
35
+ colWidths[i] = Math.max(colWidths[i] || 0, cell.length);
36
+ });
37
+ }
38
+ return rows
39
+ .map((row) => row.map((cell, i) => padEnd(cell, colWidths[i])).join(' '.repeat(padding)))
40
+ .join('\n');
41
+ }
42
+ async function readStdin() {
43
+ const chunks = [];
44
+ for await (const chunk of process.stdin) {
45
+ chunks.push(chunk);
46
+ }
47
+ return Buffer.concat(chunks).toString('utf8');
48
+ }
49
+ function parseHeaders(headerFlags) {
50
+ const headers = {};
51
+ for (const flag of headerFlags) {
52
+ const [key, ...valueParts] = flag.split('=');
53
+ if (key && valueParts.length > 0) {
54
+ headers[key.trim()] = valueParts.join('=').trim();
55
+ }
56
+ }
57
+ return headers;
58
+ }
59
+ function printHelp(toStderr = false) {
60
+ const output = `
61
+ paybridge — unified payment SDK CLI
62
+
63
+ USAGE
64
+ paybridge <command> [options]
65
+
66
+ COMMANDS
67
+ test <provider> Run sandbox createPayment validation for a provider
68
+ test --all Run validation for every provider with env vars set
69
+ providers [--json] List all providers with capabilities (table or JSON)
70
+ webhook verify <p> Verify webhook signature (raw body from stdin)
71
+ webhook parse <p> Parse webhook event (raw body from stdin)
72
+ quote <p> [opts] Get a crypto on/off-ramp quote
73
+ help, -h, --help Print this help
74
+ version, -v Print version
75
+
76
+ PROVIDER ENV VARS
77
+ See SETUP.md or run 'paybridge test --all' for the full list.
78
+
79
+ EXAMPLES
80
+ paybridge providers
81
+ paybridge test stripe
82
+ STRIPE_API_KEY=sk_test_... paybridge test stripe
83
+ echo '{"id":"evt_x"}' | paybridge webhook parse paystack \\
84
+ --header x-paystack-signature=abc
85
+
86
+ Docs: https://github.com/kobie3717/paybridge
87
+ `.trim();
88
+ if (toStderr) {
89
+ console.error(output);
90
+ }
91
+ else {
92
+ console.log(output);
93
+ }
94
+ }
95
+ function printVersion() {
96
+ const pkg = require('../../package.json');
97
+ console.log(`paybridge v${pkg.version}`);
98
+ }
@@ -8,8 +8,10 @@ export * from './base';
8
8
  export * from './moonpay';
9
9
  export * from './yellowcard';
10
10
  export * from './mock';
11
+ export * from './transak';
12
+ export * from './ramp';
11
13
  export * from './router';
12
- export type CryptoProvider = 'moonpay' | 'yellowcard' | 'mock';
14
+ export type CryptoProvider = 'moonpay' | 'yellowcard' | 'mock' | 'transak' | 'ramp';
13
15
  export interface CryptoRampConfig {
14
16
  provider: CryptoProvider;
15
17
  credentials: {
@@ -21,11 +21,15 @@ exports.CryptoRamp = void 0;
21
21
  const moonpay_1 = require("./moonpay");
22
22
  const yellowcard_1 = require("./yellowcard");
23
23
  const mock_1 = require("./mock");
24
+ const transak_1 = require("./transak");
25
+ const ramp_1 = require("./ramp");
24
26
  __exportStar(require("./types"), exports);
25
27
  __exportStar(require("./base"), exports);
26
28
  __exportStar(require("./moonpay"), exports);
27
29
  __exportStar(require("./yellowcard"), exports);
28
30
  __exportStar(require("./mock"), exports);
31
+ __exportStar(require("./transak"), exports);
32
+ __exportStar(require("./ramp"), exports);
29
33
  __exportStar(require("./router"), exports);
30
34
  class CryptoRamp {
31
35
  constructor(config) {
@@ -59,6 +63,25 @@ class CryptoRamp {
59
63
  sandbox,
60
64
  webhookSecret,
61
65
  });
66
+ case 'transak':
67
+ if (!credentials.apiKey || !credentials.secretKey) {
68
+ throw new Error('Transak requires apiKey and secretKey');
69
+ }
70
+ return new transak_1.TransakProvider({
71
+ apiKey: credentials.apiKey,
72
+ apiSecret: credentials.secretKey,
73
+ sandbox,
74
+ webhookSecret,
75
+ });
76
+ case 'ramp':
77
+ if (!credentials.apiKey) {
78
+ throw new Error('Ramp Network requires apiKey (hostApiKey)');
79
+ }
80
+ return new ramp_1.RampProvider({
81
+ hostApiKey: credentials.apiKey,
82
+ webhookSecret,
83
+ sandbox,
84
+ });
62
85
  case 'mock':
63
86
  return new mock_1.MockCryptoRampProvider();
64
87
  default:
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Ramp Network crypto on/off-ramp provider
3
+ * @see https://docs.ramp.network/
4
+ */
5
+ import { CryptoRampProvider } from './base';
6
+ import { OnRampParams, OffRampParams, RampQuote, RampResult, CryptoRampCapabilities } from './types';
7
+ interface RampConfig {
8
+ hostApiKey: string;
9
+ webhookSecret?: string;
10
+ sandbox: boolean;
11
+ }
12
+ export declare class RampProvider extends CryptoRampProvider {
13
+ readonly name = "ramp";
14
+ private hostApiKey;
15
+ private webhookSecret?;
16
+ private sandbox;
17
+ private widgetUrl;
18
+ private apiUrl;
19
+ constructor(config: RampConfig);
20
+ getQuote(_direction: 'on' | 'off', fiatAmount: number, _fiatCurrency: string, _cryptoAsset: string, _network: string): Promise<RampQuote>;
21
+ createOnRamp(params: OnRampParams): Promise<RampResult>;
22
+ createOffRamp(params: OffRampParams): Promise<RampResult>;
23
+ getRamp(id: string): Promise<RampResult>;
24
+ parseWebhook(body: any, _headers?: any): any;
25
+ /**
26
+ * Ramp Network webhook verification (HMAC placeholder).
27
+ *
28
+ * TODO(verify): Ramp Network uses ECDSA secp256k1 for webhook signatures.
29
+ * This implementation uses HMAC-SHA256 as a placeholder. Production deployments
30
+ * should implement ECDSA verification using Ramp's public key.
31
+ */
32
+ verifyWebhook(body: string | Buffer, headers?: any): boolean;
33
+ getCapabilities(): CryptoRampCapabilities;
34
+ private mapRampStatus;
35
+ }
36
+ export {};