paybridge 0.5.0 → 0.6.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/README.md +61 -0
- package/dist/crypto/index.d.ts +3 -1
- package/dist/crypto/index.js +23 -0
- package/dist/crypto/ramp.d.ts +36 -0
- package/dist/crypto/ramp.js +179 -0
- package/dist/crypto/transak.d.ts +32 -0
- package/dist/crypto/transak.js +212 -0
- package/dist/index.js +35 -0
- package/dist/providers/mollie.d.ts +39 -0
- package/dist/providers/mollie.js +178 -0
- package/dist/providers/pesapal.d.ts +47 -0
- package/dist/providers/pesapal.js +236 -0
- package/dist/providers/square.d.ts +41 -0
- package/dist/providers/square.js +278 -0
- package/dist/types.d.ts +1 -1
- package/package.json +8 -2
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Mollie payment provider
|
|
4
|
+
* EU-focused payment gateway supporting 9 currencies
|
|
5
|
+
* @see https://docs.mollie.com/reference
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.MollieProvider = void 0;
|
|
9
|
+
const base_1 = require("./base");
|
|
10
|
+
const fetch_1 = require("../utils/fetch");
|
|
11
|
+
let webhookSecretWarned = false;
|
|
12
|
+
class MollieProvider extends base_1.PaymentProvider {
|
|
13
|
+
constructor(config) {
|
|
14
|
+
super();
|
|
15
|
+
this.name = 'mollie';
|
|
16
|
+
this.supportedCurrencies = ['EUR', 'USD', 'GBP', 'CHF', 'CAD', 'AUD', 'DKK', 'SEK', 'NOK'];
|
|
17
|
+
this.baseUrl = 'https://api.mollie.com/v2';
|
|
18
|
+
this.apiKey = config.apiKey;
|
|
19
|
+
this.webhookSecret = config.webhookSecret;
|
|
20
|
+
this.sandbox = config.sandbox ?? this.apiKey.startsWith('test_');
|
|
21
|
+
if (this.webhookSecret && !webhookSecretWarned) {
|
|
22
|
+
console.warn('[PayBridge:Mollie] Mollie has no webhook signature scheme. Webhook validation relies on getPayment() round-trip. Validate by source IP if possible.');
|
|
23
|
+
webhookSecretWarned = true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async apiRequest(method, path, data) {
|
|
27
|
+
const url = `${this.baseUrl}${path}`;
|
|
28
|
+
const response = await (0, fetch_1.timedFetchOrThrow)(url, {
|
|
29
|
+
method,
|
|
30
|
+
headers: {
|
|
31
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
},
|
|
34
|
+
body: data ? JSON.stringify(data) : undefined,
|
|
35
|
+
});
|
|
36
|
+
return (await response.json());
|
|
37
|
+
}
|
|
38
|
+
async createPayment(params) {
|
|
39
|
+
this.validateCurrency(params.currency);
|
|
40
|
+
const requestBody = {
|
|
41
|
+
amount: {
|
|
42
|
+
value: params.amount.toFixed(2),
|
|
43
|
+
currency: params.currency,
|
|
44
|
+
},
|
|
45
|
+
description: params.description || params.reference,
|
|
46
|
+
redirectUrl: params.urls.success,
|
|
47
|
+
cancelUrl: params.urls.cancel,
|
|
48
|
+
webhookUrl: params.urls.webhook,
|
|
49
|
+
metadata: {
|
|
50
|
+
reference: params.reference,
|
|
51
|
+
...params.metadata,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
const response = await this.apiRequest('POST', '/payments', requestBody);
|
|
55
|
+
return {
|
|
56
|
+
id: response.id,
|
|
57
|
+
checkoutUrl: response._links.checkout.href,
|
|
58
|
+
status: 'pending',
|
|
59
|
+
amount: params.amount,
|
|
60
|
+
currency: params.currency.toUpperCase(),
|
|
61
|
+
reference: params.reference,
|
|
62
|
+
provider: 'mollie',
|
|
63
|
+
createdAt: response.createdAt || new Date().toISOString(),
|
|
64
|
+
raw: response,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async createSubscription(_params) {
|
|
68
|
+
throw new Error('Mollie subscriptions require Customer + Mandate setup; not yet supported by paybridge. Use the Mollie Customers API directly or choose another provider.');
|
|
69
|
+
}
|
|
70
|
+
async getPayment(id) {
|
|
71
|
+
const response = await this.apiRequest('GET', `/payments/${id}`);
|
|
72
|
+
let status = 'pending';
|
|
73
|
+
if (response.status === 'paid') {
|
|
74
|
+
status = 'completed';
|
|
75
|
+
}
|
|
76
|
+
else if (response.status === 'failed' || response.status === 'expired') {
|
|
77
|
+
status = 'failed';
|
|
78
|
+
}
|
|
79
|
+
else if (response.status === 'canceled') {
|
|
80
|
+
status = 'cancelled';
|
|
81
|
+
}
|
|
82
|
+
else if (response.status === 'open' || response.status === 'pending') {
|
|
83
|
+
status = 'pending';
|
|
84
|
+
}
|
|
85
|
+
const currency = (response.amount?.currency || 'EUR').toUpperCase();
|
|
86
|
+
const amount = response.amount?.value ? parseFloat(response.amount.value) : 0;
|
|
87
|
+
return {
|
|
88
|
+
id: response.id,
|
|
89
|
+
checkoutUrl: response._links?.checkout?.href || '',
|
|
90
|
+
status,
|
|
91
|
+
amount,
|
|
92
|
+
currency,
|
|
93
|
+
reference: response.metadata?.reference || response.id,
|
|
94
|
+
provider: 'mollie',
|
|
95
|
+
createdAt: response.createdAt || new Date().toISOString(),
|
|
96
|
+
raw: response,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
async refund(params) {
|
|
100
|
+
const refundData = {
|
|
101
|
+
description: params.reason || 'Refund',
|
|
102
|
+
};
|
|
103
|
+
if (params.amount !== undefined) {
|
|
104
|
+
const currency = 'EUR';
|
|
105
|
+
refundData.amount = {
|
|
106
|
+
value: params.amount.toFixed(2),
|
|
107
|
+
currency,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const response = await this.apiRequest('POST', `/payments/${params.paymentId}/refunds`, refundData);
|
|
111
|
+
const currency = (response.amount?.currency || 'EUR').toUpperCase();
|
|
112
|
+
const amount = response.amount?.value ? parseFloat(response.amount.value) : 0;
|
|
113
|
+
let refundStatus = 'pending';
|
|
114
|
+
if (response.status === 'refunded') {
|
|
115
|
+
refundStatus = 'completed';
|
|
116
|
+
}
|
|
117
|
+
else if (response.status === 'failed') {
|
|
118
|
+
refundStatus = 'failed';
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
id: response.id,
|
|
122
|
+
status: refundStatus,
|
|
123
|
+
amount,
|
|
124
|
+
currency,
|
|
125
|
+
paymentId: params.paymentId,
|
|
126
|
+
createdAt: response.createdAt || new Date().toISOString(),
|
|
127
|
+
raw: response,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
parseWebhook(body, _headers) {
|
|
131
|
+
let paymentId;
|
|
132
|
+
if (typeof body === 'string') {
|
|
133
|
+
const parsed = new URLSearchParams(body);
|
|
134
|
+
paymentId = parsed.get('id') || '';
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
paymentId = body.id || '';
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
type: 'payment.pending',
|
|
141
|
+
payment: {
|
|
142
|
+
id: paymentId,
|
|
143
|
+
checkoutUrl: '',
|
|
144
|
+
status: 'pending',
|
|
145
|
+
amount: 0,
|
|
146
|
+
currency: 'EUR',
|
|
147
|
+
reference: paymentId,
|
|
148
|
+
provider: 'mollie',
|
|
149
|
+
createdAt: new Date().toISOString(),
|
|
150
|
+
},
|
|
151
|
+
raw: body,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Mollie webhooks have no signature verification scheme.
|
|
156
|
+
* Security comes from:
|
|
157
|
+
* 1. Validating source IP (caller's responsibility)
|
|
158
|
+
* 2. Calling getPayment(id) to verify actual status
|
|
159
|
+
*
|
|
160
|
+
* Always returns true to indicate no validation error (Mollie design limitation).
|
|
161
|
+
*/
|
|
162
|
+
verifyWebhook(_body, _headers) {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
getCapabilities() {
|
|
166
|
+
return {
|
|
167
|
+
fees: {
|
|
168
|
+
fixed: 0.25,
|
|
169
|
+
percent: 1.8,
|
|
170
|
+
currency: 'EUR',
|
|
171
|
+
},
|
|
172
|
+
currencies: this.supportedCurrencies,
|
|
173
|
+
country: 'EU',
|
|
174
|
+
avgLatencyMs: 350,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.MollieProvider = MollieProvider;
|
|
@@ -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 {};
|