@easypayment/medusa-paypal 0.2.3 → 0.2.4

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.
@@ -12,7 +12,7 @@ async function GET(req, res) {
12
12
  const client_token = await paypal.generateClientToken({ locale: "en_US" }).catch(() => "");
13
13
  const cartId = req.query?.cart_id || "";
14
14
  const query = req.scope.resolve("query");
15
- let currency = (0, currencies_1.normalizeCurrencyCode)(apiDetails?.apiDetails?.currency_code || process.env.PAYPAL_CURRENCY || "USD");
15
+ let currency = (0, currencies_1.normalizeCurrencyCode)(apiDetails?.apiDetails?.currency_code || process.env.PAYPAL_CURRENCY || "EUR");
16
16
  if (cartId) {
17
17
  const { data: carts } = await query.graph({
18
18
  entity: "cart",
@@ -144,7 +144,7 @@ async function POST(req, res) {
144
144
  const apiDetails = settings.data?.api_details || {};
145
145
  const configuredCurrency = typeof apiDetails.currency_code === "string"
146
146
  ? (0, currencies_1.normalizeCurrencyCode)(apiDetails.currency_code)
147
- : (0, currencies_1.normalizeCurrencyCode)(process.env.PAYPAL_CURRENCY || "USD");
147
+ : (0, currencies_1.normalizeCurrencyCode)(process.env.PAYPAL_CURRENCY || "EUR");
148
148
  const currency = (0, currencies_1.normalizeCurrencyCode)(cart.region?.currency_code || cart.currency_code || configuredCurrency);
149
149
  (0, currencies_1.assertPayPalCurrencySupported)({
150
150
  currencyCode: currency,
@@ -42,7 +42,7 @@ class PayPalAdvancedCardProvider extends utils_1.AbstractPaymentProvider {
42
42
  if (typeof apiDetails.currency_code === "string" && apiDetails.currency_code.trim()) {
43
43
  return (0, currencies_1.normalizeCurrencyCode)(apiDetails.currency_code);
44
44
  }
45
- return (0, currencies_1.normalizeCurrencyCode)(process.env.PAYPAL_CURRENCY || "USD");
45
+ return (0, currencies_1.normalizeCurrencyCode)(process.env.PAYPAL_CURRENCY || "EUR");
46
46
  }
47
47
  async getPayPalAccessToken() {
48
48
  const paypal = this.resolvePayPalService();
@@ -92,7 +92,7 @@ class PayPalAdvancedCardProvider extends utils_1.AbstractPaymentProvider {
92
92
  const data = (input.data || {});
93
93
  const amount = Number(data.amount ?? 0);
94
94
  const currencyOverride = await this.resolveCurrencyOverride();
95
- const currencyCode = (0, currencies_1.normalizeCurrencyCode)(data.currency_code || currencyOverride || "USD");
95
+ const currencyCode = (0, currencies_1.normalizeCurrencyCode)(data.currency_code || currencyOverride || "EUR");
96
96
  (0, currencies_1.assertPayPalCurrencySupported)({
97
97
  currencyCode,
98
98
  paypalCurrencyOverride: currencyOverride,
@@ -169,7 +169,7 @@ class PayPalAdvancedCardProvider extends utils_1.AbstractPaymentProvider {
169
169
  }
170
170
  async initiatePayment(input) {
171
171
  const currencyOverride = await this.resolveCurrencyOverride();
172
- const currencyCode = (0, currencies_1.normalizeCurrencyCode)(input.currency_code || currencyOverride || "USD");
172
+ const currencyCode = (0, currencies_1.normalizeCurrencyCode)(input.currency_code || currencyOverride || "EUR");
173
173
  (0, currencies_1.assertPayPalCurrencySupported)({
174
174
  currencyCode,
175
175
  paypalCurrencyOverride: currencyOverride,
@@ -186,7 +186,7 @@ class PayPalAdvancedCardProvider extends utils_1.AbstractPaymentProvider {
186
186
  }
187
187
  async updatePayment(input) {
188
188
  const currencyOverride = await this.resolveCurrencyOverride();
189
- const currencyCode = (0, currencies_1.normalizeCurrencyCode)(input.currency_code || currencyOverride || "USD");
189
+ const currencyCode = (0, currencies_1.normalizeCurrencyCode)(input.currency_code || currencyOverride || "EUR");
190
190
  (0, currencies_1.assertPayPalCurrencySupported)({
191
191
  currencyCode,
192
192
  paypalCurrencyOverride: currencyOverride,
@@ -229,7 +229,7 @@ class PayPalAdvancedCardProvider extends utils_1.AbstractPaymentProvider {
229
229
  let order = null;
230
230
  let authorization = null;
231
231
  if (!orderId) {
232
- const value = (0, amounts_1.formatAmountForPayPal)(amount, currencyCode || "USD");
232
+ const value = (0, amounts_1.formatAmountForPayPal)(amount, currencyCode || "EUR");
233
233
  const orderPayload = {
234
234
  intent: orderIntent,
235
235
  purchase_units: [
@@ -237,7 +237,7 @@ class PayPalAdvancedCardProvider extends utils_1.AbstractPaymentProvider {
237
237
  reference_id: data.cart_id || data.payment_collection_id || undefined,
238
238
  custom_id: data.session_id || data.cart_id || data.payment_collection_id || undefined,
239
239
  amount: {
240
- currency_code: currencyCode || "USD",
240
+ currency_code: currencyCode || "EUR",
241
241
  value,
242
242
  },
243
243
  },
@@ -383,8 +383,8 @@ class PayPalAdvancedCardProvider extends utils_1.AbstractPaymentProvider {
383
383
  const capturePayload = amount > 0
384
384
  ? {
385
385
  amount: {
386
- currency_code: currencyCode || "USD",
387
- value: (0, amounts_1.formatAmountForPayPal)(amount, currencyCode || "USD"),
386
+ currency_code: currencyCode || "EUR",
387
+ value: (0, amounts_1.formatAmountForPayPal)(amount, currencyCode || "EUR"),
388
388
  },
389
389
  ...(typeof isFinalCapture === "boolean"
390
390
  ? { is_final_capture: isFinalCapture }
@@ -459,7 +459,7 @@ class PayPalAdvancedCardProvider extends utils_1.AbstractPaymentProvider {
459
459
  }
460
460
  const requestId = this.getIdempotencyKey(_input, `refund-${captureId}`);
461
461
  const amount = Number(data.amount ?? 0);
462
- const currencyCode = (0, currencies_1.normalizeCurrencyCode)(data.currency_code || process.env.PAYPAL_CURRENCY || "USD");
462
+ const currencyCode = (0, currencies_1.normalizeCurrencyCode)(data.currency_code || process.env.PAYPAL_CURRENCY || "EUR");
463
463
  const { accessToken, base } = await this.getPayPalAccessToken();
464
464
  const refundPayload = amount > 0
465
465
  ? {
@@ -53,7 +53,7 @@ class PayPalPaymentProvider extends utils_1.AbstractPaymentProvider {
53
53
  if (typeof apiDetails.currency_code === "string" && apiDetails.currency_code.trim()) {
54
54
  return (0, currencies_1.normalizeCurrencyCode)(apiDetails.currency_code);
55
55
  }
56
- return (0, currencies_1.normalizeCurrencyCode)(process.env.PAYPAL_CURRENCY || "USD");
56
+ return (0, currencies_1.normalizeCurrencyCode)(process.env.PAYPAL_CURRENCY || "EUR");
57
57
  }
58
58
  async getPayPalAccessToken() {
59
59
  const paypal = this.resolvePayPalService();
@@ -106,7 +106,7 @@ class PayPalPaymentProvider extends utils_1.AbstractPaymentProvider {
106
106
  const data = (input.data || {});
107
107
  const amount = Number(data.amount ?? 0);
108
108
  const currencyOverride = await this.resolveCurrencyOverride();
109
- const currencyCode = (0, currencies_1.normalizeCurrencyCode)(data.currency_code || currencyOverride || "USD");
109
+ const currencyCode = (0, currencies_1.normalizeCurrencyCode)(data.currency_code || currencyOverride || "EUR");
110
110
  (0, currencies_1.assertPayPalCurrencySupported)({
111
111
  currencyCode,
112
112
  paypalCurrencyOverride: currencyOverride,
@@ -248,7 +248,7 @@ class PayPalPaymentProvider extends utils_1.AbstractPaymentProvider {
248
248
  const providerId = input.data?.provider_id;
249
249
  try {
250
250
  const currencyOverride = await this.resolveCurrencyOverride();
251
- const currencyCode = (0, currencies_1.normalizeCurrencyCode)(input.currency_code || currencyOverride || "USD");
251
+ const currencyCode = (0, currencies_1.normalizeCurrencyCode)(input.currency_code || currencyOverride || "EUR");
252
252
  (0, currencies_1.assertPayPalCurrencySupported)({
253
253
  currencyCode,
254
254
  paypalCurrencyOverride: currencyOverride,
@@ -293,7 +293,7 @@ class PayPalPaymentProvider extends utils_1.AbstractPaymentProvider {
293
293
  }
294
294
  async updatePayment(input) {
295
295
  const currencyOverride = await this.resolveCurrencyOverride();
296
- const currencyCode = (0, currencies_1.normalizeCurrencyCode)(input.currency_code || currencyOverride || "USD");
296
+ const currencyCode = (0, currencies_1.normalizeCurrencyCode)(input.currency_code || currencyOverride || "EUR");
297
297
  (0, currencies_1.assertPayPalCurrencySupported)({
298
298
  currencyCode,
299
299
  paypalCurrencyOverride: currencyOverride,
@@ -324,7 +324,7 @@ class PayPalPaymentProvider extends utils_1.AbstractPaymentProvider {
324
324
  let order = null;
325
325
  let authorization = null;
326
326
  if (!orderId) {
327
- const value = (0, amounts_1.formatAmountForPayPal)(amount, currencyCode || "USD");
327
+ const value = (0, amounts_1.formatAmountForPayPal)(amount, currencyCode || "EUR");
328
328
  const orderPayload = {
329
329
  intent: orderIntent,
330
330
  purchase_units: [
@@ -332,7 +332,7 @@ class PayPalPaymentProvider extends utils_1.AbstractPaymentProvider {
332
332
  reference_id: data.cart_id || data.payment_collection_id || undefined,
333
333
  custom_id: data.session_id || data.cart_id || data.payment_collection_id || undefined,
334
334
  amount: {
335
- currency_code: currencyCode || "USD",
335
+ currency_code: currencyCode || "EUR",
336
336
  value,
337
337
  },
338
338
  },
@@ -550,8 +550,8 @@ class PayPalPaymentProvider extends utils_1.AbstractPaymentProvider {
550
550
  const capturePayload = amount > 0
551
551
  ? {
552
552
  amount: {
553
- currency_code: currencyCode || "USD",
554
- value: (0, amounts_1.formatAmountForPayPal)(amount, currencyCode || "USD"),
553
+ currency_code: currencyCode || "EUR",
554
+ value: (0, amounts_1.formatAmountForPayPal)(amount, currencyCode || "EUR"),
555
555
  },
556
556
  ...(typeof isFinalCapture === "boolean"
557
557
  ? { is_final_capture: isFinalCapture }
@@ -653,8 +653,8 @@ class PayPalPaymentProvider extends utils_1.AbstractPaymentProvider {
653
653
  const refundPayload = amount > 0
654
654
  ? {
655
655
  amount: {
656
- currency_code: currencyCode || "USD",
657
- value: (0, amounts_1.formatAmountForPayPal)(amount, currencyCode || "USD"),
656
+ currency_code: currencyCode || "EUR",
657
+ value: (0, amounts_1.formatAmountForPayPal)(amount, currencyCode || "EUR"),
658
658
  },
659
659
  }
660
660
  : {};
@@ -61,7 +61,7 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
61
61
  }
62
62
  if (!apiDetails.currency_code) {
63
63
  const raw = (process.env.PAYPAL_CURRENCY || "").trim();
64
- apiDetails.currency_code = raw ? (0, currencies_1.normalizeCurrencyCode)(raw) : "USD";
64
+ apiDetails.currency_code = raw ? (0, currencies_1.normalizeCurrencyCode)(raw) : "EUR";
65
65
  changed = true;
66
66
  }
67
67
  if (!apiDetails.storefront_url) {
@@ -30,7 +30,7 @@ const PAYPAL_SUPPORTED_CURRENCIES = new Set([
30
30
  "TWD",
31
31
  "USD",
32
32
  ]);
33
- function normalizeCurrencyCode(code, fallback = "USD") {
33
+ function normalizeCurrencyCode(code, fallback = "EUR") {
34
34
  const trimmed = String(code || "").trim();
35
35
  return (trimmed || fallback).toUpperCase();
36
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easypayment/medusa-paypal",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Industry-standard PayPal integration for Medusa v2",
5
5
  "license": "MIT",
6
6
  "main": "./.medusa/server/src/index.js",
@@ -21,7 +21,7 @@ export async function GET(req: MedusaRequest, res: MedusaResponse) {
21
21
  const query = req.scope.resolve("query")
22
22
 
23
23
  let currency = normalizeCurrencyCode(
24
- apiDetails?.apiDetails?.currency_code || process.env.PAYPAL_CURRENCY || "USD"
24
+ apiDetails?.apiDetails?.currency_code || process.env.PAYPAL_CURRENCY || "EUR"
25
25
  )
26
26
  if (cartId) {
27
27
  const { data: carts } = await query.graph({
@@ -187,7 +187,7 @@ export async function POST(req: MedusaRequest, res: MedusaResponse) {
187
187
  const configuredCurrency =
188
188
  typeof apiDetails.currency_code === "string"
189
189
  ? normalizeCurrencyCode(apiDetails.currency_code)
190
- : normalizeCurrencyCode(process.env.PAYPAL_CURRENCY || "USD")
190
+ : normalizeCurrencyCode(process.env.PAYPAL_CURRENCY || "EUR")
191
191
 
192
192
  const currency = normalizeCurrencyCode(
193
193
  cart.region?.currency_code || cart.currency_code || configuredCurrency
@@ -78,7 +78,7 @@ class PayPalAdvancedCardProvider extends AbstractPaymentProvider<Options> {
78
78
  if (typeof apiDetails.currency_code === "string" && apiDetails.currency_code.trim()) {
79
79
  return normalizeCurrencyCode(apiDetails.currency_code)
80
80
  }
81
- return normalizeCurrencyCode(process.env.PAYPAL_CURRENCY || "USD")
81
+ return normalizeCurrencyCode(process.env.PAYPAL_CURRENCY || "EUR")
82
82
  }
83
83
 
84
84
  private async getPayPalAccessToken() {
@@ -142,7 +142,7 @@ class PayPalAdvancedCardProvider extends AbstractPaymentProvider<Options> {
142
142
  const amount = Number(data.amount ?? 0)
143
143
  const currencyOverride = await this.resolveCurrencyOverride()
144
144
  const currencyCode = normalizeCurrencyCode(
145
- data.currency_code || currencyOverride || "USD"
145
+ data.currency_code || currencyOverride || "EUR"
146
146
  )
147
147
  assertPayPalCurrencySupported({
148
148
  currencyCode,
@@ -229,7 +229,7 @@ class PayPalAdvancedCardProvider extends AbstractPaymentProvider<Options> {
229
229
  async initiatePayment(input: InitiatePaymentInput): Promise<InitiatePaymentOutput> {
230
230
  const currencyOverride = await this.resolveCurrencyOverride()
231
231
  const currencyCode = normalizeCurrencyCode(
232
- input.currency_code || currencyOverride || "USD"
232
+ input.currency_code || currencyOverride || "EUR"
233
233
  )
234
234
  assertPayPalCurrencySupported({
235
235
  currencyCode,
@@ -250,7 +250,7 @@ class PayPalAdvancedCardProvider extends AbstractPaymentProvider<Options> {
250
250
  async updatePayment(input: UpdatePaymentInput): Promise<UpdatePaymentOutput> {
251
251
  const currencyOverride = await this.resolveCurrencyOverride()
252
252
  const currencyCode = normalizeCurrencyCode(
253
- input.currency_code || currencyOverride || "USD"
253
+ input.currency_code || currencyOverride || "EUR"
254
254
  )
255
255
  assertPayPalCurrencySupported({
256
256
  currencyCode,
@@ -303,7 +303,7 @@ class PayPalAdvancedCardProvider extends AbstractPaymentProvider<Options> {
303
303
  let authorization: Record<string, any> | null = null
304
304
 
305
305
  if (!orderId) {
306
- const value = formatAmountForPayPal(amount, currencyCode || "USD")
306
+ const value = formatAmountForPayPal(amount, currencyCode || "EUR")
307
307
  const orderPayload = {
308
308
  intent: orderIntent,
309
309
  purchase_units: [
@@ -311,7 +311,7 @@ class PayPalAdvancedCardProvider extends AbstractPaymentProvider<Options> {
311
311
  reference_id: data.cart_id || data.payment_collection_id || undefined,
312
312
  custom_id: data.session_id || data.cart_id || data.payment_collection_id || undefined,
313
313
  amount: {
314
- currency_code: currencyCode || "USD",
314
+ currency_code: currencyCode || "EUR",
315
315
  value,
316
316
  },
317
317
  },
@@ -489,8 +489,8 @@ class PayPalAdvancedCardProvider extends AbstractPaymentProvider<Options> {
489
489
  amount > 0
490
490
  ? {
491
491
  amount: {
492
- currency_code: currencyCode || "USD",
493
- value: formatAmountForPayPal(amount, currencyCode || "USD"),
492
+ currency_code: currencyCode || "EUR",
493
+ value: formatAmountForPayPal(amount, currencyCode || "EUR"),
494
494
  },
495
495
  ...(typeof isFinalCapture === "boolean"
496
496
  ? { is_final_capture: isFinalCapture }
@@ -579,7 +579,7 @@ class PayPalAdvancedCardProvider extends AbstractPaymentProvider<Options> {
579
579
  const requestId = this.getIdempotencyKey(_input, `refund-${captureId}`)
580
580
  const amount = Number(data.amount ?? 0)
581
581
  const currencyCode = normalizeCurrencyCode(
582
- data.currency_code || process.env.PAYPAL_CURRENCY || "USD"
582
+ data.currency_code || process.env.PAYPAL_CURRENCY || "EUR"
583
583
  )
584
584
  const { accessToken, base } = await this.getPayPalAccessToken()
585
585
  const refundPayload: Record<string, any> =
@@ -89,7 +89,7 @@ class PayPalPaymentProvider extends AbstractPaymentProvider<Options> {
89
89
  if (typeof apiDetails.currency_code === "string" && apiDetails.currency_code.trim()) {
90
90
  return normalizeCurrencyCode(apiDetails.currency_code)
91
91
  }
92
- return normalizeCurrencyCode(process.env.PAYPAL_CURRENCY || "USD")
92
+ return normalizeCurrencyCode(process.env.PAYPAL_CURRENCY || "EUR")
93
93
  }
94
94
 
95
95
  private async getPayPalAccessToken() {
@@ -155,7 +155,7 @@ class PayPalPaymentProvider extends AbstractPaymentProvider<Options> {
155
155
  const amount = Number(data.amount ?? 0)
156
156
  const currencyOverride = await this.resolveCurrencyOverride()
157
157
  const currencyCode = normalizeCurrencyCode(
158
- data.currency_code || currencyOverride || "USD"
158
+ data.currency_code || currencyOverride || "EUR"
159
159
  )
160
160
  assertPayPalCurrencySupported({
161
161
  currencyCode,
@@ -330,7 +330,7 @@ class PayPalPaymentProvider extends AbstractPaymentProvider<Options> {
330
330
  try {
331
331
  const currencyOverride = await this.resolveCurrencyOverride()
332
332
  const currencyCode = normalizeCurrencyCode(
333
- input.currency_code || currencyOverride || "USD"
333
+ input.currency_code || currencyOverride || "EUR"
334
334
  )
335
335
  assertPayPalCurrencySupported({
336
336
  currencyCode,
@@ -379,7 +379,7 @@ class PayPalPaymentProvider extends AbstractPaymentProvider<Options> {
379
379
  async updatePayment(input: UpdatePaymentInput): Promise<UpdatePaymentOutput> {
380
380
  const currencyOverride = await this.resolveCurrencyOverride()
381
381
  const currencyCode = normalizeCurrencyCode(
382
- input.currency_code || currencyOverride || "USD"
382
+ input.currency_code || currencyOverride || "EUR"
383
383
  )
384
384
  assertPayPalCurrencySupported({
385
385
  currencyCode,
@@ -419,7 +419,7 @@ class PayPalPaymentProvider extends AbstractPaymentProvider<Options> {
419
419
  let authorization: any = null
420
420
 
421
421
  if (!orderId) {
422
- const value = formatAmountForPayPal(amount, currencyCode || "USD")
422
+ const value = formatAmountForPayPal(amount, currencyCode || "EUR")
423
423
 
424
424
  const orderPayload = {
425
425
  intent: orderIntent,
@@ -428,7 +428,7 @@ class PayPalPaymentProvider extends AbstractPaymentProvider<Options> {
428
428
  reference_id: data.cart_id || data.payment_collection_id || undefined,
429
429
  custom_id: data.session_id || data.cart_id || data.payment_collection_id || undefined,
430
430
  amount: {
431
- currency_code: currencyCode || "USD",
431
+ currency_code: currencyCode || "EUR",
432
432
  value,
433
433
  },
434
434
  },
@@ -698,8 +698,8 @@ class PayPalPaymentProvider extends AbstractPaymentProvider<Options> {
698
698
  amount > 0
699
699
  ? {
700
700
  amount: {
701
- currency_code: currencyCode || "USD",
702
- value: formatAmountForPayPal(amount, currencyCode || "USD"),
701
+ currency_code: currencyCode || "EUR",
702
+ value: formatAmountForPayPal(amount, currencyCode || "EUR"),
703
703
  },
704
704
  ...(typeof isFinalCapture === "boolean"
705
705
  ? { is_final_capture: isFinalCapture }
@@ -821,8 +821,8 @@ class PayPalPaymentProvider extends AbstractPaymentProvider<Options> {
821
821
  amount > 0
822
822
  ? {
823
823
  amount: {
824
- currency_code: currencyCode || "USD",
825
- value: formatAmountForPayPal(amount, currencyCode || "USD"),
824
+ currency_code: currencyCode || "EUR",
825
+ value: formatAmountForPayPal(amount, currencyCode || "EUR"),
826
826
  },
827
827
  }
828
828
  : {}
@@ -70,7 +70,7 @@ class PayPalModuleService extends MedusaService({
70
70
 
71
71
  if (!apiDetails.currency_code) {
72
72
  const raw = (process.env.PAYPAL_CURRENCY || "").trim()
73
- apiDetails.currency_code = raw ? normalizeCurrencyCode(raw) : "USD"
73
+ apiDetails.currency_code = raw ? normalizeCurrencyCode(raw) : "EUR"
74
74
  changed = true
75
75
  }
76
76
  if (!apiDetails.storefront_url) {
@@ -31,7 +31,7 @@ type CurrencyCheck = {
31
31
  errors: string[]
32
32
  }
33
33
 
34
- export function normalizeCurrencyCode(code?: string, fallback = "USD") {
34
+ export function normalizeCurrencyCode(code?: string, fallback = "EUR") {
35
35
  const trimmed = String(code || "").trim()
36
36
  return (trimmed || fallback).toUpperCase()
37
37
  }