paybridge 0.1.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/LICENSE +21 -0
- package/README.md +408 -0
- package/dist/index.d.ts +147 -0
- package/dist/index.js +227 -0
- package/dist/providers/base.d.ts +48 -0
- package/dist/providers/base.js +29 -0
- package/dist/providers/ozow.d.ts +33 -0
- package/dist/providers/ozow.js +203 -0
- package/dist/providers/softycomp.d.ts +34 -0
- package/dist/providers/softycomp.js +292 -0
- package/dist/providers/yoco.d.ts +30 -0
- package/dist/providers/yoco.js +158 -0
- package/dist/types.d.ts +167 -0
- package/dist/types.js +5 -0
- package/dist/utils/currency.d.ts +28 -0
- package/dist/utils/currency.js +67 -0
- package/package.json +50 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Currency conversion utilities
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.toMinorUnit = toMinorUnit;
|
|
7
|
+
exports.toMajorUnit = toMajorUnit;
|
|
8
|
+
exports.getDecimalPlaces = getDecimalPlaces;
|
|
9
|
+
exports.formatCurrency = formatCurrency;
|
|
10
|
+
exports.validateAmount = validateAmount;
|
|
11
|
+
/**
|
|
12
|
+
* Convert major currency unit to minor unit (cents)
|
|
13
|
+
* @example toMinorUnit(299.00, 'ZAR') => 29900
|
|
14
|
+
*/
|
|
15
|
+
function toMinorUnit(amount, currency) {
|
|
16
|
+
const decimals = getDecimalPlaces(currency);
|
|
17
|
+
return Math.round(amount * Math.pow(10, decimals));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Convert minor unit (cents) to major currency unit
|
|
21
|
+
* @example toMajorUnit(29900, 'ZAR') => 299.00
|
|
22
|
+
*/
|
|
23
|
+
function toMajorUnit(amount, currency) {
|
|
24
|
+
const decimals = getDecimalPlaces(currency);
|
|
25
|
+
return amount / Math.pow(10, decimals);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get decimal places for currency
|
|
29
|
+
* Most currencies use 2 decimal places, some use 0
|
|
30
|
+
*/
|
|
31
|
+
function getDecimalPlaces(currency) {
|
|
32
|
+
// Zero decimal currencies
|
|
33
|
+
const zeroDecimalCurrencies = ['JPY', 'KRW', 'VND', 'CLP'];
|
|
34
|
+
if (zeroDecimalCurrencies.includes(currency)) {
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
return 2;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Format amount with currency symbol
|
|
41
|
+
* @example formatCurrency(299.00, 'ZAR') => "R299.00"
|
|
42
|
+
*/
|
|
43
|
+
function formatCurrency(amount, currency) {
|
|
44
|
+
const symbols = {
|
|
45
|
+
ZAR: 'R',
|
|
46
|
+
USD: '$',
|
|
47
|
+
EUR: '€',
|
|
48
|
+
GBP: '£',
|
|
49
|
+
NGN: '₦',
|
|
50
|
+
};
|
|
51
|
+
const symbol = symbols[currency] || currency;
|
|
52
|
+
const decimals = getDecimalPlaces(currency);
|
|
53
|
+
return `${symbol}${amount.toFixed(decimals)}`;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Validate amount is positive and has correct decimal places
|
|
57
|
+
*/
|
|
58
|
+
function validateAmount(amount, currency) {
|
|
59
|
+
if (amount <= 0) {
|
|
60
|
+
throw new Error('Amount must be positive');
|
|
61
|
+
}
|
|
62
|
+
const decimals = getDecimalPlaces(currency);
|
|
63
|
+
const multiplier = Math.pow(10, decimals);
|
|
64
|
+
if (Math.round(amount * multiplier) !== amount * multiplier) {
|
|
65
|
+
throw new Error(`Amount must have at most ${decimals} decimal places for ${currency}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "paybridge",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "One API, every payment provider. Unified payment SDK for Node.js — SoftyComp, Yoco, Ozow, and more.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepublishOnly": "npm run build",
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"payments",
|
|
14
|
+
"south-africa",
|
|
15
|
+
"payment-gateway",
|
|
16
|
+
"yoco",
|
|
17
|
+
"ozow",
|
|
18
|
+
"softycomp",
|
|
19
|
+
"payfast",
|
|
20
|
+
"nodejs",
|
|
21
|
+
"typescript",
|
|
22
|
+
"fintech",
|
|
23
|
+
"payment-integration",
|
|
24
|
+
"unified-api",
|
|
25
|
+
"zar",
|
|
26
|
+
"payment-sdk"
|
|
27
|
+
],
|
|
28
|
+
"author": "Kobie Wentzel",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/kobie3717/paybridge.git"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/kobie3717/paybridge/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/kobie3717/paybridge#readme",
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"README.md",
|
|
41
|
+
"LICENSE"
|
|
42
|
+
],
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=18.0.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^18.19.130",
|
|
48
|
+
"typescript": "^5.9.3"
|
|
49
|
+
}
|
|
50
|
+
}
|