@medusajs/payment-stripe 0.0.3 → 1.0.0-rc-20241001083650
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/core/stripe-base.d.ts +6 -7
- package/dist/core/stripe-base.d.ts.map +1 -0
- package/dist/core/stripe-base.js +238 -440
- package/dist/core/stripe-base.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +1 -1
- package/dist/services/index.js.map +1 -0
- package/dist/services/stripe-bancontact.d.ts +1 -0
- package/dist/services/stripe-bancontact.d.ts.map +1 -0
- package/dist/services/stripe-bancontact.js +14 -35
- package/dist/services/stripe-bancontact.js.map +1 -0
- package/dist/services/stripe-blik.d.ts +1 -0
- package/dist/services/stripe-blik.d.ts.map +1 -0
- package/dist/services/stripe-blik.js +14 -35
- package/dist/services/stripe-blik.js.map +1 -0
- package/dist/services/stripe-giropay.d.ts +1 -0
- package/dist/services/stripe-giropay.d.ts.map +1 -0
- package/dist/services/stripe-giropay.js +14 -35
- package/dist/services/stripe-giropay.js.map +1 -0
- package/dist/services/stripe-ideal.d.ts +1 -0
- package/dist/services/stripe-ideal.d.ts.map +1 -0
- package/dist/services/stripe-ideal.js +14 -35
- package/dist/services/stripe-ideal.js.map +1 -0
- package/dist/services/stripe-provider.d.ts +1 -0
- package/dist/services/stripe-provider.d.ts.map +1 -0
- package/dist/services/stripe-provider.js +11 -32
- package/dist/services/stripe-provider.js.map +1 -0
- package/dist/services/stripe-przelewy24.d.ts +1 -0
- package/dist/services/stripe-przelewy24.d.ts.map +1 -0
- package/dist/services/stripe-przelewy24.js +14 -35
- package/dist/services/stripe-przelewy24.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/index.d.ts +11 -7
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -0
- package/dist/utils/get-smallest-unit.d.ts +17 -0
- package/dist/utils/get-smallest-unit.d.ts.map +1 -0
- package/dist/utils/get-smallest-unit.js +68 -0
- package/dist/utils/get-smallest-unit.js.map +1 -0
- package/package.json +15 -16
@@ -0,0 +1,68 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getSmallestUnit = getSmallestUnit;
|
4
|
+
exports.getAmountFromSmallestUnit = getAmountFromSmallestUnit;
|
5
|
+
const utils_1 = require("@medusajs/framework/utils");
|
6
|
+
function getCurrencyMultiplier(currency) {
|
7
|
+
const currencyMultipliers = {
|
8
|
+
0: [
|
9
|
+
"BIF",
|
10
|
+
"CLP",
|
11
|
+
"DJF",
|
12
|
+
"GNF",
|
13
|
+
"JPY",
|
14
|
+
"KMF",
|
15
|
+
"KRW",
|
16
|
+
"MGA",
|
17
|
+
"PYG",
|
18
|
+
"RWF",
|
19
|
+
"UGX",
|
20
|
+
"VND",
|
21
|
+
"VUV",
|
22
|
+
"XAF",
|
23
|
+
"XOF",
|
24
|
+
"XPF",
|
25
|
+
],
|
26
|
+
3: ["BHD", "IQD", "JOD", "KWD", "OMR", "TND"],
|
27
|
+
};
|
28
|
+
currency = currency.toUpperCase();
|
29
|
+
let power = 2;
|
30
|
+
for (const [key, value] of Object.entries(currencyMultipliers)) {
|
31
|
+
if (value.includes(currency)) {
|
32
|
+
power = parseInt(key, 10);
|
33
|
+
break;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
return Math.pow(10, power);
|
37
|
+
}
|
38
|
+
/**
|
39
|
+
* Converts an amount to the format required by Stripe based on currency.
|
40
|
+
* https://docs.stripe.com/currencies
|
41
|
+
* @param {BigNumberInput} amount - The amount to be converted.
|
42
|
+
* @param {string} currency - The currency code (e.g., 'USD', 'JOD').
|
43
|
+
* @returns {number} - The converted amount in the smallest currency unit.
|
44
|
+
*/
|
45
|
+
function getSmallestUnit(amount, currency) {
|
46
|
+
const multiplier = getCurrencyMultiplier(currency);
|
47
|
+
let amount_ = Math.round(new utils_1.BigNumber(utils_1.MathBN.mult(amount, multiplier)).numeric) /
|
48
|
+
multiplier;
|
49
|
+
const smallestAmount = new utils_1.BigNumber(utils_1.MathBN.mult(amount_, multiplier));
|
50
|
+
let numeric = smallestAmount.numeric;
|
51
|
+
// Check if the currency requires rounding to the nearest ten
|
52
|
+
if (multiplier === 1e3) {
|
53
|
+
numeric = Math.ceil(numeric / 10) * 10;
|
54
|
+
}
|
55
|
+
return parseInt(numeric.toString().split(".").shift(), 10);
|
56
|
+
}
|
57
|
+
/**
|
58
|
+
* Converts an amount from the smallest currency unit to the standard unit based on currency.
|
59
|
+
* @param {BigNumberInput} amount - The amount in the smallest currency unit.
|
60
|
+
* @param {string} currency - The currency code (e.g., 'USD', 'JOD').
|
61
|
+
* @returns {number} - The converted amount in the standard currency unit.
|
62
|
+
*/
|
63
|
+
function getAmountFromSmallestUnit(amount, currency) {
|
64
|
+
const multiplier = getCurrencyMultiplier(currency);
|
65
|
+
const standardAmount = new utils_1.BigNumber(utils_1.MathBN.div(amount, multiplier));
|
66
|
+
return standardAmount.numeric;
|
67
|
+
}
|
68
|
+
//# sourceMappingURL=get-smallest-unit.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"get-smallest-unit.js","sourceRoot":"","sources":["../../src/utils/get-smallest-unit.ts"],"names":[],"mappings":";;AA4CA,0CAmBC;AAQD,8DAOC;AA7ED,qDAA6D;AAE7D,SAAS,qBAAqB,CAAC,QAAQ;IACrC,MAAM,mBAAmB,GAAG;QAC1B,CAAC,EAAE;YACD,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;SACN;QACD,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KA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ACvC,MAAsB,EACtB,QAAgB;IAEhB,MAAM,UAAU,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAA;IAClD,MAAM,cAAc,GAAG,IAAI,iBAAS,CAAC,cAAM,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAA;IACpE,OAAO,cAAc,CAAC,OAAO,CAAA;AAC/B,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@medusajs/payment-stripe",
|
3
|
-
"version": "0.0
|
3
|
+
"version": "1.0.0-rc-20241001083650",
|
4
4
|
"description": "Stripe payment provider for Medusa",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"repository": {
|
@@ -9,36 +9,35 @@
|
|
9
9
|
"directory": "packages/payment-stripe"
|
10
10
|
},
|
11
11
|
"files": [
|
12
|
-
"dist"
|
12
|
+
"dist",
|
13
|
+
"!dist/**/__tests__",
|
14
|
+
"!dist/**/__mocks__",
|
15
|
+
"!dist/**/__fixtures__"
|
13
16
|
],
|
14
17
|
"engines": {
|
15
|
-
"node": ">=
|
18
|
+
"node": ">=20"
|
16
19
|
},
|
17
20
|
"author": "Medusa",
|
18
21
|
"license": "MIT",
|
19
22
|
"scripts": {
|
20
|
-
"prepublishOnly": "cross-env NODE_ENV=production tsc --build",
|
21
23
|
"test": "jest --passWithNoTests src",
|
22
|
-
"build": "rimraf dist && tsc
|
24
|
+
"build": "rimraf dist && tsc --build ./tsconfig.json",
|
23
25
|
"watch": "tsc --watch"
|
24
26
|
},
|
25
27
|
"devDependencies": {
|
26
|
-
"@medusajs/
|
27
|
-
"@
|
28
|
-
"
|
29
|
-
"
|
30
|
-
"jest": "^25.5.4",
|
28
|
+
"@medusajs/framework": "1.0.0-rc-20241001083650",
|
29
|
+
"@swc/core": "^1.7.28",
|
30
|
+
"@swc/jest": "^0.2.36",
|
31
|
+
"jest": "^29.7.0",
|
31
32
|
"rimraf": "^5.0.1",
|
32
|
-
"typescript": "^
|
33
|
+
"typescript": "^5.6.2"
|
33
34
|
},
|
34
35
|
"peerDependencies": {
|
35
|
-
"@medusajs/
|
36
|
+
"@medusajs/framework": "1.0.0-rc-20241001083650",
|
37
|
+
"awilix": "^8.0.1"
|
36
38
|
},
|
37
39
|
"dependencies": {
|
38
|
-
"
|
39
|
-
"body-parser": "^1.19.0",
|
40
|
-
"express": "^4.17.1",
|
41
|
-
"stripe": "latest"
|
40
|
+
"stripe": "^15.5.0"
|
42
41
|
},
|
43
42
|
"gitHead": "81a7ff73d012fda722f6e9ef0bd9ba0232d37808",
|
44
43
|
"keywords": [
|