@paykit-sdk/medusajs 1.0.11 → 1.0.12

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/dist/index.js CHANGED
@@ -111,6 +111,13 @@ var PaykitMedusaJSAdapter = class extends utils.AbstractPaymentProvider {
111
111
  "Required: customer ID (account_holder) or email (data)"
112
112
  );
113
113
  }
114
+ const billingInfoParsed = core.billingSchema.safeParse(data?.billing);
115
+ if (data?.billing && !billingInfoParsed.success) {
116
+ throw new utils.MedusaError(
117
+ utils.MedusaError.Types.INVALID_DATA,
118
+ `Invalid billing information, ${billingInfoParsed.error.message} `
119
+ );
120
+ }
114
121
  if (typeof customer === "object" && "email" in customer) {
115
122
  const customerName = data?.name ? data.name : customer.email.split("@")[0];
116
123
  const [createdCustomer, createError] = await core.tryCatchAsync(
@@ -120,7 +127,8 @@ var PaykitMedusaJSAdapter = class extends utils.AbstractPaymentProvider {
120
127
  name: customerName,
121
128
  metadata: {
122
129
  PAYKIT_METADATA_KEY: JSON.stringify({ source: "medusa-paykit-adapter" })
123
- }
130
+ },
131
+ billing: billingInfoParsed.data ?? null
124
132
  })
125
133
  );
126
134
  if (createError) {
@@ -385,6 +393,13 @@ var PaykitMedusaJSAdapter = class extends utils.AbstractPaymentProvider {
385
393
  "Customer not found in context"
386
394
  );
387
395
  }
396
+ const billingInfoParsed = core.billingSchema.safeParse(data?.billing);
397
+ if (data?.billing && !billingInfoParsed.success) {
398
+ throw new utils.MedusaError(
399
+ utils.MedusaError.Types.INVALID_DATA,
400
+ `Invalid billing information, ${billingInfoParsed.error.message} `
401
+ );
402
+ }
388
403
  const [accountHolderResult, accountHolderError] = await core.tryCatchAsync(
389
404
  this.paykit.customers.create({
390
405
  email: customer.email,
@@ -392,7 +407,8 @@ var PaykitMedusaJSAdapter = class extends utils.AbstractPaymentProvider {
392
407
  phone: customer.phone,
393
408
  metadata: {
394
409
  PAYKIT_METADATA_KEY: JSON.stringify({ source: "medusa-paykit-adapter" })
395
- }
410
+ },
411
+ billing: billingInfoParsed.data ?? null
396
412
  })
397
413
  );
398
414
  if (accountHolderError) {
@@ -413,16 +429,14 @@ var PaykitMedusaJSAdapter = class extends utils.AbstractPaymentProvider {
413
429
  if (this.options.debug) {
414
430
  console.info("[PayKit] Updating account holder", context, data);
415
431
  }
416
- const { account_holder, customer, idempotency_key } = context;
432
+ const { account_holder, customer } = context;
417
433
  if (!account_holder.data?.id) {
418
434
  throw new utils.MedusaError(
419
435
  utils.MedusaError.Types.INVALID_DATA,
420
436
  "Account holder not found in context"
421
437
  );
422
438
  }
423
- if (!customer) {
424
- return {};
425
- }
439
+ if (!customer) return {};
426
440
  const accountHolderId = account_holder.data.id;
427
441
  const [accountHolderResult, accountHolderError] = await core.tryCatchAsync(
428
442
  this.paykit.customers.update(accountHolderId, {
@@ -433,7 +447,8 @@ var PaykitMedusaJSAdapter = class extends utils.AbstractPaymentProvider {
433
447
  metadata: core.stringifyMetadataValues(
434
448
  data?.metadata ?? {}
435
449
  )
436
- }
450
+ },
451
+ billing: data?.billing ? core.billingSchema.safeParse(data.billing).data : void 0
437
452
  })
438
453
  );
439
454
  if (accountHolderError) {
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ModuleProvider, Modules, AbstractPaymentProvider, MedusaError, PaymentSessionStatus, PaymentActions } from '@medusajs/framework/utils';
2
- import { providerSchema, PayKit, tryCatchAsync, validateRequiredKeys, stringifyMetadataValues, getURLFromHeaders } from '@paykit-sdk/core';
2
+ import { providerSchema, PayKit, billingSchema, tryCatchAsync, validateRequiredKeys, stringifyMetadataValues, getURLFromHeaders } from '@paykit-sdk/core';
3
3
  import { z } from 'zod';
4
4
 
5
5
  // src/index.ts
@@ -107,6 +107,13 @@ var PaykitMedusaJSAdapter = class extends AbstractPaymentProvider {
107
107
  "Required: customer ID (account_holder) or email (data)"
108
108
  );
109
109
  }
110
+ const billingInfoParsed = billingSchema.safeParse(data?.billing);
111
+ if (data?.billing && !billingInfoParsed.success) {
112
+ throw new MedusaError(
113
+ MedusaError.Types.INVALID_DATA,
114
+ `Invalid billing information, ${billingInfoParsed.error.message} `
115
+ );
116
+ }
110
117
  if (typeof customer === "object" && "email" in customer) {
111
118
  const customerName = data?.name ? data.name : customer.email.split("@")[0];
112
119
  const [createdCustomer, createError] = await tryCatchAsync(
@@ -116,7 +123,8 @@ var PaykitMedusaJSAdapter = class extends AbstractPaymentProvider {
116
123
  name: customerName,
117
124
  metadata: {
118
125
  PAYKIT_METADATA_KEY: JSON.stringify({ source: "medusa-paykit-adapter" })
119
- }
126
+ },
127
+ billing: billingInfoParsed.data ?? null
120
128
  })
121
129
  );
122
130
  if (createError) {
@@ -381,6 +389,13 @@ var PaykitMedusaJSAdapter = class extends AbstractPaymentProvider {
381
389
  "Customer not found in context"
382
390
  );
383
391
  }
392
+ const billingInfoParsed = billingSchema.safeParse(data?.billing);
393
+ if (data?.billing && !billingInfoParsed.success) {
394
+ throw new MedusaError(
395
+ MedusaError.Types.INVALID_DATA,
396
+ `Invalid billing information, ${billingInfoParsed.error.message} `
397
+ );
398
+ }
384
399
  const [accountHolderResult, accountHolderError] = await tryCatchAsync(
385
400
  this.paykit.customers.create({
386
401
  email: customer.email,
@@ -388,7 +403,8 @@ var PaykitMedusaJSAdapter = class extends AbstractPaymentProvider {
388
403
  phone: customer.phone,
389
404
  metadata: {
390
405
  PAYKIT_METADATA_KEY: JSON.stringify({ source: "medusa-paykit-adapter" })
391
- }
406
+ },
407
+ billing: billingInfoParsed.data ?? null
392
408
  })
393
409
  );
394
410
  if (accountHolderError) {
@@ -409,16 +425,14 @@ var PaykitMedusaJSAdapter = class extends AbstractPaymentProvider {
409
425
  if (this.options.debug) {
410
426
  console.info("[PayKit] Updating account holder", context, data);
411
427
  }
412
- const { account_holder, customer, idempotency_key } = context;
428
+ const { account_holder, customer } = context;
413
429
  if (!account_holder.data?.id) {
414
430
  throw new MedusaError(
415
431
  MedusaError.Types.INVALID_DATA,
416
432
  "Account holder not found in context"
417
433
  );
418
434
  }
419
- if (!customer) {
420
- return {};
421
- }
435
+ if (!customer) return {};
422
436
  const accountHolderId = account_holder.data.id;
423
437
  const [accountHolderResult, accountHolderError] = await tryCatchAsync(
424
438
  this.paykit.customers.update(accountHolderId, {
@@ -429,7 +443,8 @@ var PaykitMedusaJSAdapter = class extends AbstractPaymentProvider {
429
443
  metadata: stringifyMetadataValues(
430
444
  data?.metadata ?? {}
431
445
  )
432
- }
446
+ },
447
+ billing: data?.billing ? billingSchema.safeParse(data.billing).data : void 0
433
448
  })
434
449
  );
435
450
  if (accountHolderError) {
@@ -109,6 +109,13 @@ var PaykitMedusaJSAdapter = class extends utils.AbstractPaymentProvider {
109
109
  "Required: customer ID (account_holder) or email (data)"
110
110
  );
111
111
  }
112
+ const billingInfoParsed = core.billingSchema.safeParse(data?.billing);
113
+ if (data?.billing && !billingInfoParsed.success) {
114
+ throw new utils.MedusaError(
115
+ utils.MedusaError.Types.INVALID_DATA,
116
+ `Invalid billing information, ${billingInfoParsed.error.message} `
117
+ );
118
+ }
112
119
  if (typeof customer === "object" && "email" in customer) {
113
120
  const customerName = data?.name ? data.name : customer.email.split("@")[0];
114
121
  const [createdCustomer, createError] = await core.tryCatchAsync(
@@ -118,7 +125,8 @@ var PaykitMedusaJSAdapter = class extends utils.AbstractPaymentProvider {
118
125
  name: customerName,
119
126
  metadata: {
120
127
  PAYKIT_METADATA_KEY: JSON.stringify({ source: "medusa-paykit-adapter" })
121
- }
128
+ },
129
+ billing: billingInfoParsed.data ?? null
122
130
  })
123
131
  );
124
132
  if (createError) {
@@ -383,6 +391,13 @@ var PaykitMedusaJSAdapter = class extends utils.AbstractPaymentProvider {
383
391
  "Customer not found in context"
384
392
  );
385
393
  }
394
+ const billingInfoParsed = core.billingSchema.safeParse(data?.billing);
395
+ if (data?.billing && !billingInfoParsed.success) {
396
+ throw new utils.MedusaError(
397
+ utils.MedusaError.Types.INVALID_DATA,
398
+ `Invalid billing information, ${billingInfoParsed.error.message} `
399
+ );
400
+ }
386
401
  const [accountHolderResult, accountHolderError] = await core.tryCatchAsync(
387
402
  this.paykit.customers.create({
388
403
  email: customer.email,
@@ -390,7 +405,8 @@ var PaykitMedusaJSAdapter = class extends utils.AbstractPaymentProvider {
390
405
  phone: customer.phone,
391
406
  metadata: {
392
407
  PAYKIT_METADATA_KEY: JSON.stringify({ source: "medusa-paykit-adapter" })
393
- }
408
+ },
409
+ billing: billingInfoParsed.data ?? null
394
410
  })
395
411
  );
396
412
  if (accountHolderError) {
@@ -411,16 +427,14 @@ var PaykitMedusaJSAdapter = class extends utils.AbstractPaymentProvider {
411
427
  if (this.options.debug) {
412
428
  console.info("[PayKit] Updating account holder", context, data);
413
429
  }
414
- const { account_holder, customer, idempotency_key } = context;
430
+ const { account_holder, customer } = context;
415
431
  if (!account_holder.data?.id) {
416
432
  throw new utils.MedusaError(
417
433
  utils.MedusaError.Types.INVALID_DATA,
418
434
  "Account holder not found in context"
419
435
  );
420
436
  }
421
- if (!customer) {
422
- return {};
423
- }
437
+ if (!customer) return {};
424
438
  const accountHolderId = account_holder.data.id;
425
439
  const [accountHolderResult, accountHolderError] = await core.tryCatchAsync(
426
440
  this.paykit.customers.update(accountHolderId, {
@@ -431,7 +445,8 @@ var PaykitMedusaJSAdapter = class extends utils.AbstractPaymentProvider {
431
445
  metadata: core.stringifyMetadataValues(
432
446
  data?.metadata ?? {}
433
447
  )
434
- }
448
+ },
449
+ billing: data?.billing ? core.billingSchema.safeParse(data.billing).data : void 0
435
450
  })
436
451
  );
437
452
  if (accountHolderError) {
@@ -1,5 +1,5 @@
1
1
  import { AbstractPaymentProvider, MedusaError, PaymentSessionStatus, PaymentActions } from '@medusajs/framework/utils';
2
- import { providerSchema, PayKit, tryCatchAsync, validateRequiredKeys, stringifyMetadataValues, getURLFromHeaders } from '@paykit-sdk/core';
2
+ import { providerSchema, PayKit, billingSchema, tryCatchAsync, validateRequiredKeys, stringifyMetadataValues, getURLFromHeaders } from '@paykit-sdk/core';
3
3
  import { z } from 'zod';
4
4
 
5
5
  // src/providers/paykit-provider.ts
@@ -107,6 +107,13 @@ var PaykitMedusaJSAdapter = class extends AbstractPaymentProvider {
107
107
  "Required: customer ID (account_holder) or email (data)"
108
108
  );
109
109
  }
110
+ const billingInfoParsed = billingSchema.safeParse(data?.billing);
111
+ if (data?.billing && !billingInfoParsed.success) {
112
+ throw new MedusaError(
113
+ MedusaError.Types.INVALID_DATA,
114
+ `Invalid billing information, ${billingInfoParsed.error.message} `
115
+ );
116
+ }
110
117
  if (typeof customer === "object" && "email" in customer) {
111
118
  const customerName = data?.name ? data.name : customer.email.split("@")[0];
112
119
  const [createdCustomer, createError] = await tryCatchAsync(
@@ -116,7 +123,8 @@ var PaykitMedusaJSAdapter = class extends AbstractPaymentProvider {
116
123
  name: customerName,
117
124
  metadata: {
118
125
  PAYKIT_METADATA_KEY: JSON.stringify({ source: "medusa-paykit-adapter" })
119
- }
126
+ },
127
+ billing: billingInfoParsed.data ?? null
120
128
  })
121
129
  );
122
130
  if (createError) {
@@ -381,6 +389,13 @@ var PaykitMedusaJSAdapter = class extends AbstractPaymentProvider {
381
389
  "Customer not found in context"
382
390
  );
383
391
  }
392
+ const billingInfoParsed = billingSchema.safeParse(data?.billing);
393
+ if (data?.billing && !billingInfoParsed.success) {
394
+ throw new MedusaError(
395
+ MedusaError.Types.INVALID_DATA,
396
+ `Invalid billing information, ${billingInfoParsed.error.message} `
397
+ );
398
+ }
384
399
  const [accountHolderResult, accountHolderError] = await tryCatchAsync(
385
400
  this.paykit.customers.create({
386
401
  email: customer.email,
@@ -388,7 +403,8 @@ var PaykitMedusaJSAdapter = class extends AbstractPaymentProvider {
388
403
  phone: customer.phone,
389
404
  metadata: {
390
405
  PAYKIT_METADATA_KEY: JSON.stringify({ source: "medusa-paykit-adapter" })
391
- }
406
+ },
407
+ billing: billingInfoParsed.data ?? null
392
408
  })
393
409
  );
394
410
  if (accountHolderError) {
@@ -409,16 +425,14 @@ var PaykitMedusaJSAdapter = class extends AbstractPaymentProvider {
409
425
  if (this.options.debug) {
410
426
  console.info("[PayKit] Updating account holder", context, data);
411
427
  }
412
- const { account_holder, customer, idempotency_key } = context;
428
+ const { account_holder, customer } = context;
413
429
  if (!account_holder.data?.id) {
414
430
  throw new MedusaError(
415
431
  MedusaError.Types.INVALID_DATA,
416
432
  "Account holder not found in context"
417
433
  );
418
434
  }
419
- if (!customer) {
420
- return {};
421
- }
435
+ if (!customer) return {};
422
436
  const accountHolderId = account_holder.data.id;
423
437
  const [accountHolderResult, accountHolderError] = await tryCatchAsync(
424
438
  this.paykit.customers.update(accountHolderId, {
@@ -429,7 +443,8 @@ var PaykitMedusaJSAdapter = class extends AbstractPaymentProvider {
429
443
  metadata: stringifyMetadataValues(
430
444
  data?.metadata ?? {}
431
445
  )
432
- }
446
+ },
447
+ billing: data?.billing ? billingSchema.safeParse(data.billing).data : void 0
433
448
  })
434
449
  );
435
450
  if (accountHolderError) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paykit-sdk/medusajs",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "MedusaJS Integrations for Paykit",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",