Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add customPaymentMethods option for stripe.elements #678

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion tests/types/src/valid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ const options: StripeElementsOptions = {
customer: 'cus_foo',
ephemeralKey: 'ek_test_foo',
},
customPaymentMethods: [
{
id: 'cpmt_123',
options: {
type: 'static',
},
},
],
};

const elements: StripeElements = stripe.elements(options);
Expand Down Expand Up @@ -149,6 +157,14 @@ const elementsClientSecret: StripeElements = stripe.elements({
customer: 'cus_foo',
ephemeralKey: 'ek_test_foo',
},
customPaymentMethods: [
{
id: 'cpmt_123',
options: {
type: 'static',
},
},
],
});

const elementsPMCProvided = stripe.elements({
Expand Down Expand Up @@ -225,7 +241,7 @@ const fetchUpdates = async () => {
};

const handleSubmit = async () => {
const {error} = await elements.submit();
const {error, selectedPaymentMethod} = await elements.submit();
};

const auBankAccountElement = elements.create('auBankAccount', {});
Expand Down
35 changes: 34 additions & 1 deletion types/stripe-js/elements-group.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ export interface StripeElements {
* Before confirming payment, call elements.submit() to validate the state of the
* Payment Element and collect any data required for wallets.
*/
submit(): Promise<{error?: StripeError}>;
submit(): Promise<
| {error?: StripeError; selectedPaymentMethod?: undefined}
| {selectedPaymentMethod: string; error?: undefined}
>;

/////////////////////////////
/// address
Expand Down Expand Up @@ -667,6 +670,14 @@ interface BaseStripeElementsOptions {
* Display saved PaymentMethods and Customer information.
*/
customerSessionClientSecret?: string;

/**
* Requires beta access:
* Contact [Stripe support](https://support.stripe.com/) for more information.
*
* Display Custom Payment Methods in the Payment Element that you are already registered with.
*/
customPaymentMethods?: CustomPaymentMethod[];
}

export interface StripeElementsOptionsClientSecret
Expand Down Expand Up @@ -1125,3 +1136,25 @@ export interface CustomerOptions {
*/
ephemeralKey: string;
}

export interface CustomPaymentMethod {
/**
* The Custom Payment Method id, prefixed with `cpmt_`.
*/
id: string;

/**
* Additional options to configure the Custom Payment Method.
*/
options: {
/**
* The payment form type.
*/
type: 'static';

/**
* Display additional information about the payment method, max 100 characters.
*/
subtitle?: string;
};
}
Loading