@paykit-sdk/stripe 1.1.105 → 1.2.1
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 +0 -226
- package/dist/index.mjs +0 -226
- package/dist/stripe-provider.d.mts +0 -1
- package/dist/stripe-provider.d.ts +0 -1
- package/dist/stripe-provider.js +0 -226
- package/dist/stripe-provider.mjs +0 -226
- package/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -656,232 +656,6 @@ var StripeProvider = class extends core.AbstractPayKitProvider {
|
|
|
656
656
|
);
|
|
657
657
|
return Refund$inboundSchema(refund);
|
|
658
658
|
};
|
|
659
|
-
this.handleWebhook1 = async (params, webhookSecret) => {
|
|
660
|
-
if (!webhookSecret) {
|
|
661
|
-
throw new core.WebhookError(
|
|
662
|
-
"webhookSecret is required for Stripe webhook verification",
|
|
663
|
-
{ provider: this.providerName }
|
|
664
|
-
);
|
|
665
|
-
}
|
|
666
|
-
const { body, headersAsObject } = params;
|
|
667
|
-
const headers = new Headers(headersAsObject);
|
|
668
|
-
const stripeSignature = headers.get("stripe-signature");
|
|
669
|
-
if (!stripeSignature) {
|
|
670
|
-
throw new core.WebhookError("Missing Stripe signature", {
|
|
671
|
-
provider: this.providerName
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
const event = this.stripe.webhooks.constructEvent(
|
|
675
|
-
body,
|
|
676
|
-
stripeSignature,
|
|
677
|
-
webhookSecret
|
|
678
|
-
);
|
|
679
|
-
const stripePaymentIntentUpdateEventsWithHandlers = [
|
|
680
|
-
"payment_intent.processing",
|
|
681
|
-
"payment_intent.requires_action",
|
|
682
|
-
"payment_intent.amount_capturable_updated",
|
|
683
|
-
"payment_intent.partially_funded"
|
|
684
|
-
];
|
|
685
|
-
const webhookHandlers = {
|
|
686
|
-
/**
|
|
687
|
-
* Invoice
|
|
688
|
-
*/
|
|
689
|
-
"checkout.session.completed": async (event2) => {
|
|
690
|
-
const data = event2.data.object;
|
|
691
|
-
if (data.mode !== "payment") return null;
|
|
692
|
-
const customFields = data.custom_fields.reduce(
|
|
693
|
-
(acc, field) => {
|
|
694
|
-
if (field.type == "dropdown") {
|
|
695
|
-
acc[field.key] = field.dropdown?.value;
|
|
696
|
-
} else if (field.type == "text") {
|
|
697
|
-
acc[field.key] = field.text?.value;
|
|
698
|
-
} else if (field.type == "numeric") {
|
|
699
|
-
acc[field.key] = field.numeric?.value;
|
|
700
|
-
}
|
|
701
|
-
return acc;
|
|
702
|
-
},
|
|
703
|
-
{}
|
|
704
|
-
);
|
|
705
|
-
const invoiceData = {
|
|
706
|
-
id: data.id,
|
|
707
|
-
status: core.invoiceStatusSchema.parse("paid"),
|
|
708
|
-
paid_at: new Date(event2.created * 1e3).toISOString(),
|
|
709
|
-
amount_paid: data.amount_total ?? 0,
|
|
710
|
-
currency: data.currency ?? "",
|
|
711
|
-
metadata: core.omitInternalMetadata(data.metadata ?? {}),
|
|
712
|
-
customer: {
|
|
713
|
-
id: typeof data.customer === "string" ? data.customer : data.customer?.id ?? ""
|
|
714
|
-
},
|
|
715
|
-
billing_mode: core.billingModeSchema.parse("one_time"),
|
|
716
|
-
subscription_id: null,
|
|
717
|
-
custom_fields: customFields ?? null,
|
|
718
|
-
line_items: data.line_items?.data.map((item) => ({
|
|
719
|
-
id: item.price.id,
|
|
720
|
-
quantity: item.quantity
|
|
721
|
-
})) ?? []
|
|
722
|
-
};
|
|
723
|
-
const invoice = {
|
|
724
|
-
type: "invoice.generated",
|
|
725
|
-
created: event2.created,
|
|
726
|
-
id: event2.id,
|
|
727
|
-
data: invoiceData
|
|
728
|
-
};
|
|
729
|
-
return [core.paykitEvent$InboundSchema(invoice)];
|
|
730
|
-
},
|
|
731
|
-
"invoice.paid": async (event2) => {
|
|
732
|
-
const data = event2.data.object;
|
|
733
|
-
const relevantBillingReasons = [
|
|
734
|
-
"subscription_create",
|
|
735
|
-
"subscription_cycle"
|
|
736
|
-
];
|
|
737
|
-
if (data.status !== "paid" && !relevantBillingReasons.includes(data.billing_reason))
|
|
738
|
-
return null;
|
|
739
|
-
const invoice = {
|
|
740
|
-
type: "invoice.generated",
|
|
741
|
-
created: event2.created,
|
|
742
|
-
id: event2.id,
|
|
743
|
-
data: Invoice$inboundSchema({
|
|
744
|
-
...data,
|
|
745
|
-
billingMode: "recurring"
|
|
746
|
-
})
|
|
747
|
-
};
|
|
748
|
-
return [core.paykitEvent$InboundSchema(invoice)];
|
|
749
|
-
},
|
|
750
|
-
/**
|
|
751
|
-
* Customer
|
|
752
|
-
*/
|
|
753
|
-
"customer.created": async (event2) => {
|
|
754
|
-
const data = event2.data.object;
|
|
755
|
-
const customer = {
|
|
756
|
-
type: "customer.created",
|
|
757
|
-
created: event2.created,
|
|
758
|
-
id: event2.id,
|
|
759
|
-
data: Customer$inboundSchema(data)
|
|
760
|
-
};
|
|
761
|
-
return [core.paykitEvent$InboundSchema(customer)];
|
|
762
|
-
},
|
|
763
|
-
"customer.updated": async (event2) => {
|
|
764
|
-
const data = event2.data.object;
|
|
765
|
-
const customer = {
|
|
766
|
-
type: "customer.updated",
|
|
767
|
-
created: event2.created,
|
|
768
|
-
id: event2.id,
|
|
769
|
-
data: Customer$inboundSchema(data)
|
|
770
|
-
};
|
|
771
|
-
return [core.paykitEvent$InboundSchema(customer)];
|
|
772
|
-
},
|
|
773
|
-
"customer.deleted": async (event2) => {
|
|
774
|
-
const customer = {
|
|
775
|
-
type: "customer.deleted",
|
|
776
|
-
created: event2.created,
|
|
777
|
-
id: event2.id,
|
|
778
|
-
data: null
|
|
779
|
-
};
|
|
780
|
-
return [core.paykitEvent$InboundSchema(customer)];
|
|
781
|
-
},
|
|
782
|
-
/**
|
|
783
|
-
* Subscription
|
|
784
|
-
*/
|
|
785
|
-
"customer.subscription.created": async (event2) => {
|
|
786
|
-
const data = event2.data.object;
|
|
787
|
-
const subscription = Subscription$inboundSchema(data);
|
|
788
|
-
return [
|
|
789
|
-
core.paykitEvent$InboundSchema({
|
|
790
|
-
type: "subscription.created",
|
|
791
|
-
created: event2.created,
|
|
792
|
-
id: event2.id,
|
|
793
|
-
data: subscription
|
|
794
|
-
})
|
|
795
|
-
];
|
|
796
|
-
},
|
|
797
|
-
"customer.subscription.updated": async (event2) => {
|
|
798
|
-
const data = event2.data.object;
|
|
799
|
-
const subscription = Subscription$inboundSchema(data);
|
|
800
|
-
return [
|
|
801
|
-
core.paykitEvent$InboundSchema({
|
|
802
|
-
type: "subscription.updated",
|
|
803
|
-
created: event2.created,
|
|
804
|
-
id: event2.id,
|
|
805
|
-
data: subscription
|
|
806
|
-
})
|
|
807
|
-
];
|
|
808
|
-
},
|
|
809
|
-
"customer.subscription.deleted": async (event2) => {
|
|
810
|
-
const subscription = null;
|
|
811
|
-
return [
|
|
812
|
-
core.paykitEvent$InboundSchema({
|
|
813
|
-
type: "subscription.canceled",
|
|
814
|
-
created: event2.created,
|
|
815
|
-
id: event2.id,
|
|
816
|
-
data: subscription
|
|
817
|
-
})
|
|
818
|
-
];
|
|
819
|
-
},
|
|
820
|
-
"payment_intent.created": async (event2) => {
|
|
821
|
-
const data = event2.data.object;
|
|
822
|
-
const payment = Payment$inboundSchema(data);
|
|
823
|
-
return [
|
|
824
|
-
core.paykitEvent$InboundSchema({
|
|
825
|
-
type: "payment.created",
|
|
826
|
-
created: event2.created,
|
|
827
|
-
id: event2.id,
|
|
828
|
-
data: payment
|
|
829
|
-
})
|
|
830
|
-
];
|
|
831
|
-
},
|
|
832
|
-
...stripePaymentIntentUpdateEventsWithHandlers.map(
|
|
833
|
-
() => async (event2) => {
|
|
834
|
-
const data = event2.data.object;
|
|
835
|
-
const payment = Payment$inboundSchema(data);
|
|
836
|
-
return [
|
|
837
|
-
core.paykitEvent$InboundSchema({
|
|
838
|
-
type: "payment.updated",
|
|
839
|
-
created: event2.created,
|
|
840
|
-
id: event2.id,
|
|
841
|
-
data: payment
|
|
842
|
-
})
|
|
843
|
-
];
|
|
844
|
-
}
|
|
845
|
-
),
|
|
846
|
-
"payment_intent.canceled": async (event2) => {
|
|
847
|
-
const data = event2.data.object;
|
|
848
|
-
const payment = Payment$inboundSchema(data);
|
|
849
|
-
return [
|
|
850
|
-
core.paykitEvent$InboundSchema({
|
|
851
|
-
type: "payment.failed",
|
|
852
|
-
created: event2.created,
|
|
853
|
-
id: event2.id,
|
|
854
|
-
data: payment
|
|
855
|
-
})
|
|
856
|
-
];
|
|
857
|
-
},
|
|
858
|
-
"refund.created": async (event2) => {
|
|
859
|
-
const data = event2.data.object;
|
|
860
|
-
const refund = Refund$inboundSchema(data);
|
|
861
|
-
return [
|
|
862
|
-
core.paykitEvent$InboundSchema({
|
|
863
|
-
type: "refund.created",
|
|
864
|
-
created: event2.created,
|
|
865
|
-
id: event2.id,
|
|
866
|
-
data: refund
|
|
867
|
-
})
|
|
868
|
-
];
|
|
869
|
-
}
|
|
870
|
-
};
|
|
871
|
-
const handler = webhookHandlers[event.type];
|
|
872
|
-
if (!handler)
|
|
873
|
-
throw new core.WebhookError(`Unhandled event type: ${event.type}`, {
|
|
874
|
-
provider: this.providerName
|
|
875
|
-
});
|
|
876
|
-
const result = await handler(event);
|
|
877
|
-
if (!result) {
|
|
878
|
-
console.log(
|
|
879
|
-
`Skipping event ${event.type} for provider: ${this.providerName} as no action needed`
|
|
880
|
-
);
|
|
881
|
-
return [];
|
|
882
|
-
}
|
|
883
|
-
return result;
|
|
884
|
-
};
|
|
885
659
|
this.handleWebhook = async (params, webhookSecret) => {
|
|
886
660
|
if (!webhookSecret) {
|
|
887
661
|
throw new core.WebhookError(
|
package/dist/index.mjs
CHANGED
|
@@ -650,232 +650,6 @@ var StripeProvider = class extends AbstractPayKitProvider {
|
|
|
650
650
|
);
|
|
651
651
|
return Refund$inboundSchema(refund);
|
|
652
652
|
};
|
|
653
|
-
this.handleWebhook1 = async (params, webhookSecret) => {
|
|
654
|
-
if (!webhookSecret) {
|
|
655
|
-
throw new WebhookError(
|
|
656
|
-
"webhookSecret is required for Stripe webhook verification",
|
|
657
|
-
{ provider: this.providerName }
|
|
658
|
-
);
|
|
659
|
-
}
|
|
660
|
-
const { body, headersAsObject } = params;
|
|
661
|
-
const headers = new Headers(headersAsObject);
|
|
662
|
-
const stripeSignature = headers.get("stripe-signature");
|
|
663
|
-
if (!stripeSignature) {
|
|
664
|
-
throw new WebhookError("Missing Stripe signature", {
|
|
665
|
-
provider: this.providerName
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
const event = this.stripe.webhooks.constructEvent(
|
|
669
|
-
body,
|
|
670
|
-
stripeSignature,
|
|
671
|
-
webhookSecret
|
|
672
|
-
);
|
|
673
|
-
const stripePaymentIntentUpdateEventsWithHandlers = [
|
|
674
|
-
"payment_intent.processing",
|
|
675
|
-
"payment_intent.requires_action",
|
|
676
|
-
"payment_intent.amount_capturable_updated",
|
|
677
|
-
"payment_intent.partially_funded"
|
|
678
|
-
];
|
|
679
|
-
const webhookHandlers = {
|
|
680
|
-
/**
|
|
681
|
-
* Invoice
|
|
682
|
-
*/
|
|
683
|
-
"checkout.session.completed": async (event2) => {
|
|
684
|
-
const data = event2.data.object;
|
|
685
|
-
if (data.mode !== "payment") return null;
|
|
686
|
-
const customFields = data.custom_fields.reduce(
|
|
687
|
-
(acc, field) => {
|
|
688
|
-
if (field.type == "dropdown") {
|
|
689
|
-
acc[field.key] = field.dropdown?.value;
|
|
690
|
-
} else if (field.type == "text") {
|
|
691
|
-
acc[field.key] = field.text?.value;
|
|
692
|
-
} else if (field.type == "numeric") {
|
|
693
|
-
acc[field.key] = field.numeric?.value;
|
|
694
|
-
}
|
|
695
|
-
return acc;
|
|
696
|
-
},
|
|
697
|
-
{}
|
|
698
|
-
);
|
|
699
|
-
const invoiceData = {
|
|
700
|
-
id: data.id,
|
|
701
|
-
status: invoiceStatusSchema.parse("paid"),
|
|
702
|
-
paid_at: new Date(event2.created * 1e3).toISOString(),
|
|
703
|
-
amount_paid: data.amount_total ?? 0,
|
|
704
|
-
currency: data.currency ?? "",
|
|
705
|
-
metadata: omitInternalMetadata(data.metadata ?? {}),
|
|
706
|
-
customer: {
|
|
707
|
-
id: typeof data.customer === "string" ? data.customer : data.customer?.id ?? ""
|
|
708
|
-
},
|
|
709
|
-
billing_mode: billingModeSchema.parse("one_time"),
|
|
710
|
-
subscription_id: null,
|
|
711
|
-
custom_fields: customFields ?? null,
|
|
712
|
-
line_items: data.line_items?.data.map((item) => ({
|
|
713
|
-
id: item.price.id,
|
|
714
|
-
quantity: item.quantity
|
|
715
|
-
})) ?? []
|
|
716
|
-
};
|
|
717
|
-
const invoice = {
|
|
718
|
-
type: "invoice.generated",
|
|
719
|
-
created: event2.created,
|
|
720
|
-
id: event2.id,
|
|
721
|
-
data: invoiceData
|
|
722
|
-
};
|
|
723
|
-
return [paykitEvent$InboundSchema(invoice)];
|
|
724
|
-
},
|
|
725
|
-
"invoice.paid": async (event2) => {
|
|
726
|
-
const data = event2.data.object;
|
|
727
|
-
const relevantBillingReasons = [
|
|
728
|
-
"subscription_create",
|
|
729
|
-
"subscription_cycle"
|
|
730
|
-
];
|
|
731
|
-
if (data.status !== "paid" && !relevantBillingReasons.includes(data.billing_reason))
|
|
732
|
-
return null;
|
|
733
|
-
const invoice = {
|
|
734
|
-
type: "invoice.generated",
|
|
735
|
-
created: event2.created,
|
|
736
|
-
id: event2.id,
|
|
737
|
-
data: Invoice$inboundSchema({
|
|
738
|
-
...data,
|
|
739
|
-
billingMode: "recurring"
|
|
740
|
-
})
|
|
741
|
-
};
|
|
742
|
-
return [paykitEvent$InboundSchema(invoice)];
|
|
743
|
-
},
|
|
744
|
-
/**
|
|
745
|
-
* Customer
|
|
746
|
-
*/
|
|
747
|
-
"customer.created": async (event2) => {
|
|
748
|
-
const data = event2.data.object;
|
|
749
|
-
const customer = {
|
|
750
|
-
type: "customer.created",
|
|
751
|
-
created: event2.created,
|
|
752
|
-
id: event2.id,
|
|
753
|
-
data: Customer$inboundSchema(data)
|
|
754
|
-
};
|
|
755
|
-
return [paykitEvent$InboundSchema(customer)];
|
|
756
|
-
},
|
|
757
|
-
"customer.updated": async (event2) => {
|
|
758
|
-
const data = event2.data.object;
|
|
759
|
-
const customer = {
|
|
760
|
-
type: "customer.updated",
|
|
761
|
-
created: event2.created,
|
|
762
|
-
id: event2.id,
|
|
763
|
-
data: Customer$inboundSchema(data)
|
|
764
|
-
};
|
|
765
|
-
return [paykitEvent$InboundSchema(customer)];
|
|
766
|
-
},
|
|
767
|
-
"customer.deleted": async (event2) => {
|
|
768
|
-
const customer = {
|
|
769
|
-
type: "customer.deleted",
|
|
770
|
-
created: event2.created,
|
|
771
|
-
id: event2.id,
|
|
772
|
-
data: null
|
|
773
|
-
};
|
|
774
|
-
return [paykitEvent$InboundSchema(customer)];
|
|
775
|
-
},
|
|
776
|
-
/**
|
|
777
|
-
* Subscription
|
|
778
|
-
*/
|
|
779
|
-
"customer.subscription.created": async (event2) => {
|
|
780
|
-
const data = event2.data.object;
|
|
781
|
-
const subscription = Subscription$inboundSchema(data);
|
|
782
|
-
return [
|
|
783
|
-
paykitEvent$InboundSchema({
|
|
784
|
-
type: "subscription.created",
|
|
785
|
-
created: event2.created,
|
|
786
|
-
id: event2.id,
|
|
787
|
-
data: subscription
|
|
788
|
-
})
|
|
789
|
-
];
|
|
790
|
-
},
|
|
791
|
-
"customer.subscription.updated": async (event2) => {
|
|
792
|
-
const data = event2.data.object;
|
|
793
|
-
const subscription = Subscription$inboundSchema(data);
|
|
794
|
-
return [
|
|
795
|
-
paykitEvent$InboundSchema({
|
|
796
|
-
type: "subscription.updated",
|
|
797
|
-
created: event2.created,
|
|
798
|
-
id: event2.id,
|
|
799
|
-
data: subscription
|
|
800
|
-
})
|
|
801
|
-
];
|
|
802
|
-
},
|
|
803
|
-
"customer.subscription.deleted": async (event2) => {
|
|
804
|
-
const subscription = null;
|
|
805
|
-
return [
|
|
806
|
-
paykitEvent$InboundSchema({
|
|
807
|
-
type: "subscription.canceled",
|
|
808
|
-
created: event2.created,
|
|
809
|
-
id: event2.id,
|
|
810
|
-
data: subscription
|
|
811
|
-
})
|
|
812
|
-
];
|
|
813
|
-
},
|
|
814
|
-
"payment_intent.created": async (event2) => {
|
|
815
|
-
const data = event2.data.object;
|
|
816
|
-
const payment = Payment$inboundSchema(data);
|
|
817
|
-
return [
|
|
818
|
-
paykitEvent$InboundSchema({
|
|
819
|
-
type: "payment.created",
|
|
820
|
-
created: event2.created,
|
|
821
|
-
id: event2.id,
|
|
822
|
-
data: payment
|
|
823
|
-
})
|
|
824
|
-
];
|
|
825
|
-
},
|
|
826
|
-
...stripePaymentIntentUpdateEventsWithHandlers.map(
|
|
827
|
-
() => async (event2) => {
|
|
828
|
-
const data = event2.data.object;
|
|
829
|
-
const payment = Payment$inboundSchema(data);
|
|
830
|
-
return [
|
|
831
|
-
paykitEvent$InboundSchema({
|
|
832
|
-
type: "payment.updated",
|
|
833
|
-
created: event2.created,
|
|
834
|
-
id: event2.id,
|
|
835
|
-
data: payment
|
|
836
|
-
})
|
|
837
|
-
];
|
|
838
|
-
}
|
|
839
|
-
),
|
|
840
|
-
"payment_intent.canceled": async (event2) => {
|
|
841
|
-
const data = event2.data.object;
|
|
842
|
-
const payment = Payment$inboundSchema(data);
|
|
843
|
-
return [
|
|
844
|
-
paykitEvent$InboundSchema({
|
|
845
|
-
type: "payment.failed",
|
|
846
|
-
created: event2.created,
|
|
847
|
-
id: event2.id,
|
|
848
|
-
data: payment
|
|
849
|
-
})
|
|
850
|
-
];
|
|
851
|
-
},
|
|
852
|
-
"refund.created": async (event2) => {
|
|
853
|
-
const data = event2.data.object;
|
|
854
|
-
const refund = Refund$inboundSchema(data);
|
|
855
|
-
return [
|
|
856
|
-
paykitEvent$InboundSchema({
|
|
857
|
-
type: "refund.created",
|
|
858
|
-
created: event2.created,
|
|
859
|
-
id: event2.id,
|
|
860
|
-
data: refund
|
|
861
|
-
})
|
|
862
|
-
];
|
|
863
|
-
}
|
|
864
|
-
};
|
|
865
|
-
const handler = webhookHandlers[event.type];
|
|
866
|
-
if (!handler)
|
|
867
|
-
throw new WebhookError(`Unhandled event type: ${event.type}`, {
|
|
868
|
-
provider: this.providerName
|
|
869
|
-
});
|
|
870
|
-
const result = await handler(event);
|
|
871
|
-
if (!result) {
|
|
872
|
-
console.log(
|
|
873
|
-
`Skipping event ${event.type} for provider: ${this.providerName} as no action needed`
|
|
874
|
-
);
|
|
875
|
-
return [];
|
|
876
|
-
}
|
|
877
|
-
return result;
|
|
878
|
-
};
|
|
879
653
|
this.handleWebhook = async (params, webhookSecret) => {
|
|
880
654
|
if (!webhookSecret) {
|
|
881
655
|
throw new WebhookError(
|
|
@@ -49,7 +49,6 @@ declare class StripeProvider extends AbstractPayKitProvider implements PayKitPro
|
|
|
49
49
|
* Refund management
|
|
50
50
|
*/
|
|
51
51
|
createRefund: (params: CreateRefundSchema<StripeMetadata["refund"]>) => Promise<Refund>;
|
|
52
|
-
handleWebhook1: (params: WebhookHandlerConfig, webhookSecret: string | null) => Promise<Array<WebhookEventPayload>>;
|
|
53
52
|
handleWebhook: (params: WebhookHandlerConfig, webhookSecret: string | null) => Promise<Array<WebhookEventPayload<StripeRawEvents>>>;
|
|
54
53
|
}
|
|
55
54
|
|
|
@@ -49,7 +49,6 @@ declare class StripeProvider extends AbstractPayKitProvider implements PayKitPro
|
|
|
49
49
|
* Refund management
|
|
50
50
|
*/
|
|
51
51
|
createRefund: (params: CreateRefundSchema<StripeMetadata["refund"]>) => Promise<Refund>;
|
|
52
|
-
handleWebhook1: (params: WebhookHandlerConfig, webhookSecret: string | null) => Promise<Array<WebhookEventPayload>>;
|
|
53
52
|
handleWebhook: (params: WebhookHandlerConfig, webhookSecret: string | null) => Promise<Array<WebhookEventPayload<StripeRawEvents>>>;
|
|
54
53
|
}
|
|
55
54
|
|
package/dist/stripe-provider.js
CHANGED
|
@@ -656,232 +656,6 @@ var StripeProvider = class extends core.AbstractPayKitProvider {
|
|
|
656
656
|
);
|
|
657
657
|
return Refund$inboundSchema(refund);
|
|
658
658
|
};
|
|
659
|
-
this.handleWebhook1 = async (params, webhookSecret) => {
|
|
660
|
-
if (!webhookSecret) {
|
|
661
|
-
throw new core.WebhookError(
|
|
662
|
-
"webhookSecret is required for Stripe webhook verification",
|
|
663
|
-
{ provider: this.providerName }
|
|
664
|
-
);
|
|
665
|
-
}
|
|
666
|
-
const { body, headersAsObject } = params;
|
|
667
|
-
const headers = new Headers(headersAsObject);
|
|
668
|
-
const stripeSignature = headers.get("stripe-signature");
|
|
669
|
-
if (!stripeSignature) {
|
|
670
|
-
throw new core.WebhookError("Missing Stripe signature", {
|
|
671
|
-
provider: this.providerName
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
const event = this.stripe.webhooks.constructEvent(
|
|
675
|
-
body,
|
|
676
|
-
stripeSignature,
|
|
677
|
-
webhookSecret
|
|
678
|
-
);
|
|
679
|
-
const stripePaymentIntentUpdateEventsWithHandlers = [
|
|
680
|
-
"payment_intent.processing",
|
|
681
|
-
"payment_intent.requires_action",
|
|
682
|
-
"payment_intent.amount_capturable_updated",
|
|
683
|
-
"payment_intent.partially_funded"
|
|
684
|
-
];
|
|
685
|
-
const webhookHandlers = {
|
|
686
|
-
/**
|
|
687
|
-
* Invoice
|
|
688
|
-
*/
|
|
689
|
-
"checkout.session.completed": async (event2) => {
|
|
690
|
-
const data = event2.data.object;
|
|
691
|
-
if (data.mode !== "payment") return null;
|
|
692
|
-
const customFields = data.custom_fields.reduce(
|
|
693
|
-
(acc, field) => {
|
|
694
|
-
if (field.type == "dropdown") {
|
|
695
|
-
acc[field.key] = field.dropdown?.value;
|
|
696
|
-
} else if (field.type == "text") {
|
|
697
|
-
acc[field.key] = field.text?.value;
|
|
698
|
-
} else if (field.type == "numeric") {
|
|
699
|
-
acc[field.key] = field.numeric?.value;
|
|
700
|
-
}
|
|
701
|
-
return acc;
|
|
702
|
-
},
|
|
703
|
-
{}
|
|
704
|
-
);
|
|
705
|
-
const invoiceData = {
|
|
706
|
-
id: data.id,
|
|
707
|
-
status: core.invoiceStatusSchema.parse("paid"),
|
|
708
|
-
paid_at: new Date(event2.created * 1e3).toISOString(),
|
|
709
|
-
amount_paid: data.amount_total ?? 0,
|
|
710
|
-
currency: data.currency ?? "",
|
|
711
|
-
metadata: core.omitInternalMetadata(data.metadata ?? {}),
|
|
712
|
-
customer: {
|
|
713
|
-
id: typeof data.customer === "string" ? data.customer : data.customer?.id ?? ""
|
|
714
|
-
},
|
|
715
|
-
billing_mode: core.billingModeSchema.parse("one_time"),
|
|
716
|
-
subscription_id: null,
|
|
717
|
-
custom_fields: customFields ?? null,
|
|
718
|
-
line_items: data.line_items?.data.map((item) => ({
|
|
719
|
-
id: item.price.id,
|
|
720
|
-
quantity: item.quantity
|
|
721
|
-
})) ?? []
|
|
722
|
-
};
|
|
723
|
-
const invoice = {
|
|
724
|
-
type: "invoice.generated",
|
|
725
|
-
created: event2.created,
|
|
726
|
-
id: event2.id,
|
|
727
|
-
data: invoiceData
|
|
728
|
-
};
|
|
729
|
-
return [core.paykitEvent$InboundSchema(invoice)];
|
|
730
|
-
},
|
|
731
|
-
"invoice.paid": async (event2) => {
|
|
732
|
-
const data = event2.data.object;
|
|
733
|
-
const relevantBillingReasons = [
|
|
734
|
-
"subscription_create",
|
|
735
|
-
"subscription_cycle"
|
|
736
|
-
];
|
|
737
|
-
if (data.status !== "paid" && !relevantBillingReasons.includes(data.billing_reason))
|
|
738
|
-
return null;
|
|
739
|
-
const invoice = {
|
|
740
|
-
type: "invoice.generated",
|
|
741
|
-
created: event2.created,
|
|
742
|
-
id: event2.id,
|
|
743
|
-
data: Invoice$inboundSchema({
|
|
744
|
-
...data,
|
|
745
|
-
billingMode: "recurring"
|
|
746
|
-
})
|
|
747
|
-
};
|
|
748
|
-
return [core.paykitEvent$InboundSchema(invoice)];
|
|
749
|
-
},
|
|
750
|
-
/**
|
|
751
|
-
* Customer
|
|
752
|
-
*/
|
|
753
|
-
"customer.created": async (event2) => {
|
|
754
|
-
const data = event2.data.object;
|
|
755
|
-
const customer = {
|
|
756
|
-
type: "customer.created",
|
|
757
|
-
created: event2.created,
|
|
758
|
-
id: event2.id,
|
|
759
|
-
data: Customer$inboundSchema(data)
|
|
760
|
-
};
|
|
761
|
-
return [core.paykitEvent$InboundSchema(customer)];
|
|
762
|
-
},
|
|
763
|
-
"customer.updated": async (event2) => {
|
|
764
|
-
const data = event2.data.object;
|
|
765
|
-
const customer = {
|
|
766
|
-
type: "customer.updated",
|
|
767
|
-
created: event2.created,
|
|
768
|
-
id: event2.id,
|
|
769
|
-
data: Customer$inboundSchema(data)
|
|
770
|
-
};
|
|
771
|
-
return [core.paykitEvent$InboundSchema(customer)];
|
|
772
|
-
},
|
|
773
|
-
"customer.deleted": async (event2) => {
|
|
774
|
-
const customer = {
|
|
775
|
-
type: "customer.deleted",
|
|
776
|
-
created: event2.created,
|
|
777
|
-
id: event2.id,
|
|
778
|
-
data: null
|
|
779
|
-
};
|
|
780
|
-
return [core.paykitEvent$InboundSchema(customer)];
|
|
781
|
-
},
|
|
782
|
-
/**
|
|
783
|
-
* Subscription
|
|
784
|
-
*/
|
|
785
|
-
"customer.subscription.created": async (event2) => {
|
|
786
|
-
const data = event2.data.object;
|
|
787
|
-
const subscription = Subscription$inboundSchema(data);
|
|
788
|
-
return [
|
|
789
|
-
core.paykitEvent$InboundSchema({
|
|
790
|
-
type: "subscription.created",
|
|
791
|
-
created: event2.created,
|
|
792
|
-
id: event2.id,
|
|
793
|
-
data: subscription
|
|
794
|
-
})
|
|
795
|
-
];
|
|
796
|
-
},
|
|
797
|
-
"customer.subscription.updated": async (event2) => {
|
|
798
|
-
const data = event2.data.object;
|
|
799
|
-
const subscription = Subscription$inboundSchema(data);
|
|
800
|
-
return [
|
|
801
|
-
core.paykitEvent$InboundSchema({
|
|
802
|
-
type: "subscription.updated",
|
|
803
|
-
created: event2.created,
|
|
804
|
-
id: event2.id,
|
|
805
|
-
data: subscription
|
|
806
|
-
})
|
|
807
|
-
];
|
|
808
|
-
},
|
|
809
|
-
"customer.subscription.deleted": async (event2) => {
|
|
810
|
-
const subscription = null;
|
|
811
|
-
return [
|
|
812
|
-
core.paykitEvent$InboundSchema({
|
|
813
|
-
type: "subscription.canceled",
|
|
814
|
-
created: event2.created,
|
|
815
|
-
id: event2.id,
|
|
816
|
-
data: subscription
|
|
817
|
-
})
|
|
818
|
-
];
|
|
819
|
-
},
|
|
820
|
-
"payment_intent.created": async (event2) => {
|
|
821
|
-
const data = event2.data.object;
|
|
822
|
-
const payment = Payment$inboundSchema(data);
|
|
823
|
-
return [
|
|
824
|
-
core.paykitEvent$InboundSchema({
|
|
825
|
-
type: "payment.created",
|
|
826
|
-
created: event2.created,
|
|
827
|
-
id: event2.id,
|
|
828
|
-
data: payment
|
|
829
|
-
})
|
|
830
|
-
];
|
|
831
|
-
},
|
|
832
|
-
...stripePaymentIntentUpdateEventsWithHandlers.map(
|
|
833
|
-
() => async (event2) => {
|
|
834
|
-
const data = event2.data.object;
|
|
835
|
-
const payment = Payment$inboundSchema(data);
|
|
836
|
-
return [
|
|
837
|
-
core.paykitEvent$InboundSchema({
|
|
838
|
-
type: "payment.updated",
|
|
839
|
-
created: event2.created,
|
|
840
|
-
id: event2.id,
|
|
841
|
-
data: payment
|
|
842
|
-
})
|
|
843
|
-
];
|
|
844
|
-
}
|
|
845
|
-
),
|
|
846
|
-
"payment_intent.canceled": async (event2) => {
|
|
847
|
-
const data = event2.data.object;
|
|
848
|
-
const payment = Payment$inboundSchema(data);
|
|
849
|
-
return [
|
|
850
|
-
core.paykitEvent$InboundSchema({
|
|
851
|
-
type: "payment.failed",
|
|
852
|
-
created: event2.created,
|
|
853
|
-
id: event2.id,
|
|
854
|
-
data: payment
|
|
855
|
-
})
|
|
856
|
-
];
|
|
857
|
-
},
|
|
858
|
-
"refund.created": async (event2) => {
|
|
859
|
-
const data = event2.data.object;
|
|
860
|
-
const refund = Refund$inboundSchema(data);
|
|
861
|
-
return [
|
|
862
|
-
core.paykitEvent$InboundSchema({
|
|
863
|
-
type: "refund.created",
|
|
864
|
-
created: event2.created,
|
|
865
|
-
id: event2.id,
|
|
866
|
-
data: refund
|
|
867
|
-
})
|
|
868
|
-
];
|
|
869
|
-
}
|
|
870
|
-
};
|
|
871
|
-
const handler = webhookHandlers[event.type];
|
|
872
|
-
if (!handler)
|
|
873
|
-
throw new core.WebhookError(`Unhandled event type: ${event.type}`, {
|
|
874
|
-
provider: this.providerName
|
|
875
|
-
});
|
|
876
|
-
const result = await handler(event);
|
|
877
|
-
if (!result) {
|
|
878
|
-
console.log(
|
|
879
|
-
`Skipping event ${event.type} for provider: ${this.providerName} as no action needed`
|
|
880
|
-
);
|
|
881
|
-
return [];
|
|
882
|
-
}
|
|
883
|
-
return result;
|
|
884
|
-
};
|
|
885
659
|
this.handleWebhook = async (params, webhookSecret) => {
|
|
886
660
|
if (!webhookSecret) {
|
|
887
661
|
throw new core.WebhookError(
|
package/dist/stripe-provider.mjs
CHANGED
|
@@ -650,232 +650,6 @@ var StripeProvider = class extends AbstractPayKitProvider {
|
|
|
650
650
|
);
|
|
651
651
|
return Refund$inboundSchema(refund);
|
|
652
652
|
};
|
|
653
|
-
this.handleWebhook1 = async (params, webhookSecret) => {
|
|
654
|
-
if (!webhookSecret) {
|
|
655
|
-
throw new WebhookError(
|
|
656
|
-
"webhookSecret is required for Stripe webhook verification",
|
|
657
|
-
{ provider: this.providerName }
|
|
658
|
-
);
|
|
659
|
-
}
|
|
660
|
-
const { body, headersAsObject } = params;
|
|
661
|
-
const headers = new Headers(headersAsObject);
|
|
662
|
-
const stripeSignature = headers.get("stripe-signature");
|
|
663
|
-
if (!stripeSignature) {
|
|
664
|
-
throw new WebhookError("Missing Stripe signature", {
|
|
665
|
-
provider: this.providerName
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
const event = this.stripe.webhooks.constructEvent(
|
|
669
|
-
body,
|
|
670
|
-
stripeSignature,
|
|
671
|
-
webhookSecret
|
|
672
|
-
);
|
|
673
|
-
const stripePaymentIntentUpdateEventsWithHandlers = [
|
|
674
|
-
"payment_intent.processing",
|
|
675
|
-
"payment_intent.requires_action",
|
|
676
|
-
"payment_intent.amount_capturable_updated",
|
|
677
|
-
"payment_intent.partially_funded"
|
|
678
|
-
];
|
|
679
|
-
const webhookHandlers = {
|
|
680
|
-
/**
|
|
681
|
-
* Invoice
|
|
682
|
-
*/
|
|
683
|
-
"checkout.session.completed": async (event2) => {
|
|
684
|
-
const data = event2.data.object;
|
|
685
|
-
if (data.mode !== "payment") return null;
|
|
686
|
-
const customFields = data.custom_fields.reduce(
|
|
687
|
-
(acc, field) => {
|
|
688
|
-
if (field.type == "dropdown") {
|
|
689
|
-
acc[field.key] = field.dropdown?.value;
|
|
690
|
-
} else if (field.type == "text") {
|
|
691
|
-
acc[field.key] = field.text?.value;
|
|
692
|
-
} else if (field.type == "numeric") {
|
|
693
|
-
acc[field.key] = field.numeric?.value;
|
|
694
|
-
}
|
|
695
|
-
return acc;
|
|
696
|
-
},
|
|
697
|
-
{}
|
|
698
|
-
);
|
|
699
|
-
const invoiceData = {
|
|
700
|
-
id: data.id,
|
|
701
|
-
status: invoiceStatusSchema.parse("paid"),
|
|
702
|
-
paid_at: new Date(event2.created * 1e3).toISOString(),
|
|
703
|
-
amount_paid: data.amount_total ?? 0,
|
|
704
|
-
currency: data.currency ?? "",
|
|
705
|
-
metadata: omitInternalMetadata(data.metadata ?? {}),
|
|
706
|
-
customer: {
|
|
707
|
-
id: typeof data.customer === "string" ? data.customer : data.customer?.id ?? ""
|
|
708
|
-
},
|
|
709
|
-
billing_mode: billingModeSchema.parse("one_time"),
|
|
710
|
-
subscription_id: null,
|
|
711
|
-
custom_fields: customFields ?? null,
|
|
712
|
-
line_items: data.line_items?.data.map((item) => ({
|
|
713
|
-
id: item.price.id,
|
|
714
|
-
quantity: item.quantity
|
|
715
|
-
})) ?? []
|
|
716
|
-
};
|
|
717
|
-
const invoice = {
|
|
718
|
-
type: "invoice.generated",
|
|
719
|
-
created: event2.created,
|
|
720
|
-
id: event2.id,
|
|
721
|
-
data: invoiceData
|
|
722
|
-
};
|
|
723
|
-
return [paykitEvent$InboundSchema(invoice)];
|
|
724
|
-
},
|
|
725
|
-
"invoice.paid": async (event2) => {
|
|
726
|
-
const data = event2.data.object;
|
|
727
|
-
const relevantBillingReasons = [
|
|
728
|
-
"subscription_create",
|
|
729
|
-
"subscription_cycle"
|
|
730
|
-
];
|
|
731
|
-
if (data.status !== "paid" && !relevantBillingReasons.includes(data.billing_reason))
|
|
732
|
-
return null;
|
|
733
|
-
const invoice = {
|
|
734
|
-
type: "invoice.generated",
|
|
735
|
-
created: event2.created,
|
|
736
|
-
id: event2.id,
|
|
737
|
-
data: Invoice$inboundSchema({
|
|
738
|
-
...data,
|
|
739
|
-
billingMode: "recurring"
|
|
740
|
-
})
|
|
741
|
-
};
|
|
742
|
-
return [paykitEvent$InboundSchema(invoice)];
|
|
743
|
-
},
|
|
744
|
-
/**
|
|
745
|
-
* Customer
|
|
746
|
-
*/
|
|
747
|
-
"customer.created": async (event2) => {
|
|
748
|
-
const data = event2.data.object;
|
|
749
|
-
const customer = {
|
|
750
|
-
type: "customer.created",
|
|
751
|
-
created: event2.created,
|
|
752
|
-
id: event2.id,
|
|
753
|
-
data: Customer$inboundSchema(data)
|
|
754
|
-
};
|
|
755
|
-
return [paykitEvent$InboundSchema(customer)];
|
|
756
|
-
},
|
|
757
|
-
"customer.updated": async (event2) => {
|
|
758
|
-
const data = event2.data.object;
|
|
759
|
-
const customer = {
|
|
760
|
-
type: "customer.updated",
|
|
761
|
-
created: event2.created,
|
|
762
|
-
id: event2.id,
|
|
763
|
-
data: Customer$inboundSchema(data)
|
|
764
|
-
};
|
|
765
|
-
return [paykitEvent$InboundSchema(customer)];
|
|
766
|
-
},
|
|
767
|
-
"customer.deleted": async (event2) => {
|
|
768
|
-
const customer = {
|
|
769
|
-
type: "customer.deleted",
|
|
770
|
-
created: event2.created,
|
|
771
|
-
id: event2.id,
|
|
772
|
-
data: null
|
|
773
|
-
};
|
|
774
|
-
return [paykitEvent$InboundSchema(customer)];
|
|
775
|
-
},
|
|
776
|
-
/**
|
|
777
|
-
* Subscription
|
|
778
|
-
*/
|
|
779
|
-
"customer.subscription.created": async (event2) => {
|
|
780
|
-
const data = event2.data.object;
|
|
781
|
-
const subscription = Subscription$inboundSchema(data);
|
|
782
|
-
return [
|
|
783
|
-
paykitEvent$InboundSchema({
|
|
784
|
-
type: "subscription.created",
|
|
785
|
-
created: event2.created,
|
|
786
|
-
id: event2.id,
|
|
787
|
-
data: subscription
|
|
788
|
-
})
|
|
789
|
-
];
|
|
790
|
-
},
|
|
791
|
-
"customer.subscription.updated": async (event2) => {
|
|
792
|
-
const data = event2.data.object;
|
|
793
|
-
const subscription = Subscription$inboundSchema(data);
|
|
794
|
-
return [
|
|
795
|
-
paykitEvent$InboundSchema({
|
|
796
|
-
type: "subscription.updated",
|
|
797
|
-
created: event2.created,
|
|
798
|
-
id: event2.id,
|
|
799
|
-
data: subscription
|
|
800
|
-
})
|
|
801
|
-
];
|
|
802
|
-
},
|
|
803
|
-
"customer.subscription.deleted": async (event2) => {
|
|
804
|
-
const subscription = null;
|
|
805
|
-
return [
|
|
806
|
-
paykitEvent$InboundSchema({
|
|
807
|
-
type: "subscription.canceled",
|
|
808
|
-
created: event2.created,
|
|
809
|
-
id: event2.id,
|
|
810
|
-
data: subscription
|
|
811
|
-
})
|
|
812
|
-
];
|
|
813
|
-
},
|
|
814
|
-
"payment_intent.created": async (event2) => {
|
|
815
|
-
const data = event2.data.object;
|
|
816
|
-
const payment = Payment$inboundSchema(data);
|
|
817
|
-
return [
|
|
818
|
-
paykitEvent$InboundSchema({
|
|
819
|
-
type: "payment.created",
|
|
820
|
-
created: event2.created,
|
|
821
|
-
id: event2.id,
|
|
822
|
-
data: payment
|
|
823
|
-
})
|
|
824
|
-
];
|
|
825
|
-
},
|
|
826
|
-
...stripePaymentIntentUpdateEventsWithHandlers.map(
|
|
827
|
-
() => async (event2) => {
|
|
828
|
-
const data = event2.data.object;
|
|
829
|
-
const payment = Payment$inboundSchema(data);
|
|
830
|
-
return [
|
|
831
|
-
paykitEvent$InboundSchema({
|
|
832
|
-
type: "payment.updated",
|
|
833
|
-
created: event2.created,
|
|
834
|
-
id: event2.id,
|
|
835
|
-
data: payment
|
|
836
|
-
})
|
|
837
|
-
];
|
|
838
|
-
}
|
|
839
|
-
),
|
|
840
|
-
"payment_intent.canceled": async (event2) => {
|
|
841
|
-
const data = event2.data.object;
|
|
842
|
-
const payment = Payment$inboundSchema(data);
|
|
843
|
-
return [
|
|
844
|
-
paykitEvent$InboundSchema({
|
|
845
|
-
type: "payment.failed",
|
|
846
|
-
created: event2.created,
|
|
847
|
-
id: event2.id,
|
|
848
|
-
data: payment
|
|
849
|
-
})
|
|
850
|
-
];
|
|
851
|
-
},
|
|
852
|
-
"refund.created": async (event2) => {
|
|
853
|
-
const data = event2.data.object;
|
|
854
|
-
const refund = Refund$inboundSchema(data);
|
|
855
|
-
return [
|
|
856
|
-
paykitEvent$InboundSchema({
|
|
857
|
-
type: "refund.created",
|
|
858
|
-
created: event2.created,
|
|
859
|
-
id: event2.id,
|
|
860
|
-
data: refund
|
|
861
|
-
})
|
|
862
|
-
];
|
|
863
|
-
}
|
|
864
|
-
};
|
|
865
|
-
const handler = webhookHandlers[event.type];
|
|
866
|
-
if (!handler)
|
|
867
|
-
throw new WebhookError(`Unhandled event type: ${event.type}`, {
|
|
868
|
-
provider: this.providerName
|
|
869
|
-
});
|
|
870
|
-
const result = await handler(event);
|
|
871
|
-
if (!result) {
|
|
872
|
-
console.log(
|
|
873
|
-
`Skipping event ${event.type} for provider: ${this.providerName} as no action needed`
|
|
874
|
-
);
|
|
875
|
-
return [];
|
|
876
|
-
}
|
|
877
|
-
return result;
|
|
878
|
-
};
|
|
879
653
|
this.handleWebhook = async (params, webhookSecret) => {
|
|
880
654
|
if (!webhookSecret) {
|
|
881
655
|
throw new WebhookError(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paykit-sdk/stripe",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Stripe provider for PayKit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build": "tsup"
|
|
13
13
|
},
|
|
14
|
+
"paykit": {
|
|
15
|
+
"type": "provider"
|
|
16
|
+
},
|
|
14
17
|
"keywords": [
|
|
15
18
|
"stripe",
|
|
16
19
|
"paykit",
|
|
@@ -23,7 +26,7 @@
|
|
|
23
26
|
"stripe": "^18.2.1"
|
|
24
27
|
},
|
|
25
28
|
"peerDependencies": {
|
|
26
|
-
"@paykit-sdk/core": ">=1.
|
|
29
|
+
"@paykit-sdk/core": ">=1.2.0"
|
|
27
30
|
},
|
|
28
31
|
"devDependencies": {
|
|
29
32
|
"@paykit-sdk/core": "workspace:*",
|