@paykit-sdk/stripe 1.1.97 → 1.1.99

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
@@ -4166,7 +4166,9 @@ var paykitPayment$InboundSchema = (intent) => {
4166
4166
  customer: intent.customer ?? "",
4167
4167
  status: stripeToPaykitStatus(intent.status),
4168
4168
  metadata: core.omitInternalMetadata(intent.metadata ?? {}),
4169
- item_id: itemId
4169
+ item_id: itemId,
4170
+ requires_action: intent.status === "requires_action" || intent.status === "requires_confirmation",
4171
+ payment_url: intent.next_action?.redirect_to_url?.url ?? null
4170
4172
  };
4171
4173
  };
4172
4174
  var paykitRefund$InboundSchema = (refund) => {
@@ -4377,6 +4379,7 @@ var StripeProvider = class extends core.AbstractPayKitProvider {
4377
4379
  throw core.ValidationError.fromZodError(error, this.providerName, "updateSubscription");
4378
4380
  }
4379
4381
  const updatedSubscription = await this.stripe.subscriptions.update(id, {
4382
+ ...data.provider_metadata && { ...data.provider_metadata },
4380
4383
  metadata: core.stringifyMetadataValues(data.metadata ?? {})
4381
4384
  });
4382
4385
  return paykitSubscription$InboundSchema(updatedSubscription);
@@ -4412,11 +4415,15 @@ var StripeProvider = class extends core.AbstractPayKitProvider {
4412
4415
  method: "createPayment"
4413
4416
  });
4414
4417
  const { provider_metadata, customer, capture_method, ...rest } = data;
4418
+ let customerId = customer;
4415
4419
  if (typeof customer === "object") {
4416
- throw new core.InvalidTypeError("customer", "string (customer ID)", "object", {
4417
- provider: this.providerName,
4418
- method: "createPayment"
4420
+ const newCustomer = await this.createCustomer({
4421
+ email: customer.email,
4422
+ name: customer.email.split("@")[0],
4423
+ phone: "",
4424
+ metadata: {}
4419
4425
  });
4426
+ customerId = newCustomer.id;
4420
4427
  }
4421
4428
  const paymentMetadata = core.stringifyMetadataValues({
4422
4429
  ...rest.metadata,
@@ -4424,7 +4431,7 @@ var StripeProvider = class extends core.AbstractPayKitProvider {
4424
4431
  [core.PAYKIT_METADATA_KEY]: JSON.stringify({ itemId: data.item_id ?? null })
4425
4432
  });
4426
4433
  const customerWithDefaultPaymentMethod = await this.stripe.customers.retrieve(
4427
- customer,
4434
+ customerId,
4428
4435
  { expand: ["invoice_settings.default_payment_method"] }
4429
4436
  );
4430
4437
  if ("deleted" in customerWithDefaultPaymentMethod) {
@@ -4435,7 +4442,9 @@ var StripeProvider = class extends core.AbstractPayKitProvider {
4435
4442
  }
4436
4443
  let defaultPaymentMethod = customerWithDefaultPaymentMethod.invoice_settings?.default_payment_method;
4437
4444
  if (!defaultPaymentMethod) {
4438
- const paymentMethods = await this.stripe.paymentMethods.list({ customer });
4445
+ const paymentMethods = await this.stripe.paymentMethods.list({
4446
+ customer: customerId
4447
+ });
4439
4448
  if (paymentMethods.data.length === 0) {
4440
4449
  throw new core.ValidationError(
4441
4450
  `Customer ${customer} has no payment methods. Add a payment method for the customer before creating a payment intent`,
@@ -4448,7 +4457,7 @@ var StripeProvider = class extends core.AbstractPayKitProvider {
4448
4457
  currency: rest.currency,
4449
4458
  amount: rest.amount,
4450
4459
  metadata: paymentMetadata,
4451
- customer,
4460
+ customer: customerId,
4452
4461
  capture_method,
4453
4462
  confirm: true,
4454
4463
  // automatically confirms the payment
@@ -4766,10 +4775,12 @@ var StripeProvider = class extends core.AbstractPayKitProvider {
4766
4775
  provider: this.providerName
4767
4776
  });
4768
4777
  const result = await handler(event);
4769
- if (!result)
4770
- throw new core.WebhookError(`Unhandled event type: ${event.type}`, {
4771
- provider: this.providerName
4772
- });
4778
+ if (!result) {
4779
+ console.log(
4780
+ `Skipping event ${event.type} for provider: ${this.providerName} as no action needed`
4781
+ );
4782
+ return [];
4783
+ }
4773
4784
  return result;
4774
4785
  };
4775
4786
  const { debug = true, apiKey, ...rest } = opts;
package/dist/index.mjs CHANGED
@@ -4160,7 +4160,9 @@ var paykitPayment$InboundSchema = (intent) => {
4160
4160
  customer: intent.customer ?? "",
4161
4161
  status: stripeToPaykitStatus(intent.status),
4162
4162
  metadata: omitInternalMetadata(intent.metadata ?? {}),
4163
- item_id: itemId
4163
+ item_id: itemId,
4164
+ requires_action: intent.status === "requires_action" || intent.status === "requires_confirmation",
4165
+ payment_url: intent.next_action?.redirect_to_url?.url ?? null
4164
4166
  };
4165
4167
  };
4166
4168
  var paykitRefund$InboundSchema = (refund) => {
@@ -4371,6 +4373,7 @@ var StripeProvider = class extends AbstractPayKitProvider {
4371
4373
  throw ValidationError.fromZodError(error, this.providerName, "updateSubscription");
4372
4374
  }
4373
4375
  const updatedSubscription = await this.stripe.subscriptions.update(id, {
4376
+ ...data.provider_metadata && { ...data.provider_metadata },
4374
4377
  metadata: stringifyMetadataValues(data.metadata ?? {})
4375
4378
  });
4376
4379
  return paykitSubscription$InboundSchema(updatedSubscription);
@@ -4406,11 +4409,15 @@ var StripeProvider = class extends AbstractPayKitProvider {
4406
4409
  method: "createPayment"
4407
4410
  });
4408
4411
  const { provider_metadata, customer, capture_method, ...rest } = data;
4412
+ let customerId = customer;
4409
4413
  if (typeof customer === "object") {
4410
- throw new InvalidTypeError("customer", "string (customer ID)", "object", {
4411
- provider: this.providerName,
4412
- method: "createPayment"
4414
+ const newCustomer = await this.createCustomer({
4415
+ email: customer.email,
4416
+ name: customer.email.split("@")[0],
4417
+ phone: "",
4418
+ metadata: {}
4413
4419
  });
4420
+ customerId = newCustomer.id;
4414
4421
  }
4415
4422
  const paymentMetadata = stringifyMetadataValues({
4416
4423
  ...rest.metadata,
@@ -4418,7 +4425,7 @@ var StripeProvider = class extends AbstractPayKitProvider {
4418
4425
  [PAYKIT_METADATA_KEY]: JSON.stringify({ itemId: data.item_id ?? null })
4419
4426
  });
4420
4427
  const customerWithDefaultPaymentMethod = await this.stripe.customers.retrieve(
4421
- customer,
4428
+ customerId,
4422
4429
  { expand: ["invoice_settings.default_payment_method"] }
4423
4430
  );
4424
4431
  if ("deleted" in customerWithDefaultPaymentMethod) {
@@ -4429,7 +4436,9 @@ var StripeProvider = class extends AbstractPayKitProvider {
4429
4436
  }
4430
4437
  let defaultPaymentMethod = customerWithDefaultPaymentMethod.invoice_settings?.default_payment_method;
4431
4438
  if (!defaultPaymentMethod) {
4432
- const paymentMethods = await this.stripe.paymentMethods.list({ customer });
4439
+ const paymentMethods = await this.stripe.paymentMethods.list({
4440
+ customer: customerId
4441
+ });
4433
4442
  if (paymentMethods.data.length === 0) {
4434
4443
  throw new ValidationError(
4435
4444
  `Customer ${customer} has no payment methods. Add a payment method for the customer before creating a payment intent`,
@@ -4442,7 +4451,7 @@ var StripeProvider = class extends AbstractPayKitProvider {
4442
4451
  currency: rest.currency,
4443
4452
  amount: rest.amount,
4444
4453
  metadata: paymentMetadata,
4445
- customer,
4454
+ customer: customerId,
4446
4455
  capture_method,
4447
4456
  confirm: true,
4448
4457
  // automatically confirms the payment
@@ -4760,10 +4769,12 @@ var StripeProvider = class extends AbstractPayKitProvider {
4760
4769
  provider: this.providerName
4761
4770
  });
4762
4771
  const result = await handler(event);
4763
- if (!result)
4764
- throw new WebhookError(`Unhandled event type: ${event.type}`, {
4765
- provider: this.providerName
4766
- });
4772
+ if (!result) {
4773
+ console.log(
4774
+ `Skipping event ${event.type} for provider: ${this.providerName} as no action needed`
4775
+ );
4776
+ return [];
4777
+ }
4767
4778
  return result;
4768
4779
  };
4769
4780
  const { debug = true, apiKey, ...rest } = opts;
@@ -4166,7 +4166,9 @@ var paykitPayment$InboundSchema = (intent) => {
4166
4166
  customer: intent.customer ?? "",
4167
4167
  status: stripeToPaykitStatus(intent.status),
4168
4168
  metadata: core.omitInternalMetadata(intent.metadata ?? {}),
4169
- item_id: itemId
4169
+ item_id: itemId,
4170
+ requires_action: intent.status === "requires_action" || intent.status === "requires_confirmation",
4171
+ payment_url: intent.next_action?.redirect_to_url?.url ?? null
4170
4172
  };
4171
4173
  };
4172
4174
  var paykitRefund$InboundSchema = (refund) => {
@@ -4377,6 +4379,7 @@ var StripeProvider = class extends core.AbstractPayKitProvider {
4377
4379
  throw core.ValidationError.fromZodError(error, this.providerName, "updateSubscription");
4378
4380
  }
4379
4381
  const updatedSubscription = await this.stripe.subscriptions.update(id, {
4382
+ ...data.provider_metadata && { ...data.provider_metadata },
4380
4383
  metadata: core.stringifyMetadataValues(data.metadata ?? {})
4381
4384
  });
4382
4385
  return paykitSubscription$InboundSchema(updatedSubscription);
@@ -4412,11 +4415,15 @@ var StripeProvider = class extends core.AbstractPayKitProvider {
4412
4415
  method: "createPayment"
4413
4416
  });
4414
4417
  const { provider_metadata, customer, capture_method, ...rest } = data;
4418
+ let customerId = customer;
4415
4419
  if (typeof customer === "object") {
4416
- throw new core.InvalidTypeError("customer", "string (customer ID)", "object", {
4417
- provider: this.providerName,
4418
- method: "createPayment"
4420
+ const newCustomer = await this.createCustomer({
4421
+ email: customer.email,
4422
+ name: customer.email.split("@")[0],
4423
+ phone: "",
4424
+ metadata: {}
4419
4425
  });
4426
+ customerId = newCustomer.id;
4420
4427
  }
4421
4428
  const paymentMetadata = core.stringifyMetadataValues({
4422
4429
  ...rest.metadata,
@@ -4424,7 +4431,7 @@ var StripeProvider = class extends core.AbstractPayKitProvider {
4424
4431
  [core.PAYKIT_METADATA_KEY]: JSON.stringify({ itemId: data.item_id ?? null })
4425
4432
  });
4426
4433
  const customerWithDefaultPaymentMethod = await this.stripe.customers.retrieve(
4427
- customer,
4434
+ customerId,
4428
4435
  { expand: ["invoice_settings.default_payment_method"] }
4429
4436
  );
4430
4437
  if ("deleted" in customerWithDefaultPaymentMethod) {
@@ -4435,7 +4442,9 @@ var StripeProvider = class extends core.AbstractPayKitProvider {
4435
4442
  }
4436
4443
  let defaultPaymentMethod = customerWithDefaultPaymentMethod.invoice_settings?.default_payment_method;
4437
4444
  if (!defaultPaymentMethod) {
4438
- const paymentMethods = await this.stripe.paymentMethods.list({ customer });
4445
+ const paymentMethods = await this.stripe.paymentMethods.list({
4446
+ customer: customerId
4447
+ });
4439
4448
  if (paymentMethods.data.length === 0) {
4440
4449
  throw new core.ValidationError(
4441
4450
  `Customer ${customer} has no payment methods. Add a payment method for the customer before creating a payment intent`,
@@ -4448,7 +4457,7 @@ var StripeProvider = class extends core.AbstractPayKitProvider {
4448
4457
  currency: rest.currency,
4449
4458
  amount: rest.amount,
4450
4459
  metadata: paymentMetadata,
4451
- customer,
4460
+ customer: customerId,
4452
4461
  capture_method,
4453
4462
  confirm: true,
4454
4463
  // automatically confirms the payment
@@ -4766,10 +4775,12 @@ var StripeProvider = class extends core.AbstractPayKitProvider {
4766
4775
  provider: this.providerName
4767
4776
  });
4768
4777
  const result = await handler(event);
4769
- if (!result)
4770
- throw new core.WebhookError(`Unhandled event type: ${event.type}`, {
4771
- provider: this.providerName
4772
- });
4778
+ if (!result) {
4779
+ console.log(
4780
+ `Skipping event ${event.type} for provider: ${this.providerName} as no action needed`
4781
+ );
4782
+ return [];
4783
+ }
4773
4784
  return result;
4774
4785
  };
4775
4786
  const { debug = true, apiKey, ...rest } = opts;
@@ -4160,7 +4160,9 @@ var paykitPayment$InboundSchema = (intent) => {
4160
4160
  customer: intent.customer ?? "",
4161
4161
  status: stripeToPaykitStatus(intent.status),
4162
4162
  metadata: omitInternalMetadata(intent.metadata ?? {}),
4163
- item_id: itemId
4163
+ item_id: itemId,
4164
+ requires_action: intent.status === "requires_action" || intent.status === "requires_confirmation",
4165
+ payment_url: intent.next_action?.redirect_to_url?.url ?? null
4164
4166
  };
4165
4167
  };
4166
4168
  var paykitRefund$InboundSchema = (refund) => {
@@ -4371,6 +4373,7 @@ var StripeProvider = class extends AbstractPayKitProvider {
4371
4373
  throw ValidationError.fromZodError(error, this.providerName, "updateSubscription");
4372
4374
  }
4373
4375
  const updatedSubscription = await this.stripe.subscriptions.update(id, {
4376
+ ...data.provider_metadata && { ...data.provider_metadata },
4374
4377
  metadata: stringifyMetadataValues(data.metadata ?? {})
4375
4378
  });
4376
4379
  return paykitSubscription$InboundSchema(updatedSubscription);
@@ -4406,11 +4409,15 @@ var StripeProvider = class extends AbstractPayKitProvider {
4406
4409
  method: "createPayment"
4407
4410
  });
4408
4411
  const { provider_metadata, customer, capture_method, ...rest } = data;
4412
+ let customerId = customer;
4409
4413
  if (typeof customer === "object") {
4410
- throw new InvalidTypeError("customer", "string (customer ID)", "object", {
4411
- provider: this.providerName,
4412
- method: "createPayment"
4414
+ const newCustomer = await this.createCustomer({
4415
+ email: customer.email,
4416
+ name: customer.email.split("@")[0],
4417
+ phone: "",
4418
+ metadata: {}
4413
4419
  });
4420
+ customerId = newCustomer.id;
4414
4421
  }
4415
4422
  const paymentMetadata = stringifyMetadataValues({
4416
4423
  ...rest.metadata,
@@ -4418,7 +4425,7 @@ var StripeProvider = class extends AbstractPayKitProvider {
4418
4425
  [PAYKIT_METADATA_KEY]: JSON.stringify({ itemId: data.item_id ?? null })
4419
4426
  });
4420
4427
  const customerWithDefaultPaymentMethod = await this.stripe.customers.retrieve(
4421
- customer,
4428
+ customerId,
4422
4429
  { expand: ["invoice_settings.default_payment_method"] }
4423
4430
  );
4424
4431
  if ("deleted" in customerWithDefaultPaymentMethod) {
@@ -4429,7 +4436,9 @@ var StripeProvider = class extends AbstractPayKitProvider {
4429
4436
  }
4430
4437
  let defaultPaymentMethod = customerWithDefaultPaymentMethod.invoice_settings?.default_payment_method;
4431
4438
  if (!defaultPaymentMethod) {
4432
- const paymentMethods = await this.stripe.paymentMethods.list({ customer });
4439
+ const paymentMethods = await this.stripe.paymentMethods.list({
4440
+ customer: customerId
4441
+ });
4433
4442
  if (paymentMethods.data.length === 0) {
4434
4443
  throw new ValidationError(
4435
4444
  `Customer ${customer} has no payment methods. Add a payment method for the customer before creating a payment intent`,
@@ -4442,7 +4451,7 @@ var StripeProvider = class extends AbstractPayKitProvider {
4442
4451
  currency: rest.currency,
4443
4452
  amount: rest.amount,
4444
4453
  metadata: paymentMetadata,
4445
- customer,
4454
+ customer: customerId,
4446
4455
  capture_method,
4447
4456
  confirm: true,
4448
4457
  // automatically confirms the payment
@@ -4760,10 +4769,12 @@ var StripeProvider = class extends AbstractPayKitProvider {
4760
4769
  provider: this.providerName
4761
4770
  });
4762
4771
  const result = await handler(event);
4763
- if (!result)
4764
- throw new WebhookError(`Unhandled event type: ${event.type}`, {
4765
- provider: this.providerName
4766
- });
4772
+ if (!result) {
4773
+ console.log(
4774
+ `Skipping event ${event.type} for provider: ${this.providerName} as no action needed`
4775
+ );
4776
+ return [];
4777
+ }
4767
4778
  return result;
4768
4779
  };
4769
4780
  const { debug = true, apiKey, ...rest } = opts;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paykit-sdk/stripe",
3
- "version": "1.1.97",
3
+ "version": "1.1.99",
4
4
  "description": "Stripe provider for PayKit",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -8,6 +8,9 @@
8
8
  "files": [
9
9
  "dist"
10
10
  ],
11
+ "scripts": {
12
+ "build": "tsup"
13
+ },
11
14
  "keywords": [
12
15
  "stripe",
13
16
  "paykit",
@@ -20,13 +23,13 @@
20
23
  "stripe": "^18.2.1"
21
24
  },
22
25
  "peerDependencies": {
23
- "@paykit-sdk/core": ">=1.1.97"
26
+ "@paykit-sdk/core": ">=1.1.101"
24
27
  },
25
28
  "devDependencies": {
29
+ "@paykit-sdk/core": "workspace:*",
26
30
  "tsup": "^8.0.0",
27
31
  "typescript": "^5.0.0",
28
- "zod": "^3.24.2",
29
- "@paykit-sdk/core": "1.1.97"
32
+ "zod": "^3.24.2"
30
33
  },
31
34
  "publishConfig": {
32
35
  "access": "public"
@@ -37,8 +40,5 @@
37
40
  },
38
41
  "bugs": {
39
42
  "url": "https://github.com/devodii/paykit/issues"
40
- },
41
- "scripts": {
42
- "build": "tsup"
43
43
  }
44
- }
44
+ }