[stripe-v3] Add new confirmCardPayment(), confirmSepaDebitSetup(), etc. (#40857)

Add typings for these 4 new PaymentIntent-related functions:
- `confirmCardPayment()`
- `confirmSepaDebitPayment()`
- `confirmCardSetup()`
- `confirmSepaDebitSetup()`

Also mark old ones as deprecated, for easier understanding:
- `handleCardPayment()`
- `handleCardSetup()`

References:
https://stripe.com/docs/stripe-js/reference#stripe-confirm-card-payment
https://stripe.com/docs/stripe-js/reference#stripe-confirm-sepa-debit-payment
https://stripe.com/docs/stripe-js/reference#stripe-confirm-card-setup
https://stripe.com/docs/stripe-js/reference#stripe-confirm-sepa-debit-setup
This commit is contained in:
Adrien Vergé
2019-12-19 17:06:50 -08:00
committed by Ben Lichtman
parent b75e866ada
commit db3ff1623a
2 changed files with 226 additions and 0 deletions
+143
View File
@@ -44,27 +44,49 @@ declare namespace stripe {
retrievePaymentIntent(
clientSecret: string,
): Promise<PaymentIntentResponse>;
/** @deprecated */
handleCardPayment(
clientSecret: string,
element: elements.Element,
options?: HandleCardPaymentOptions,
): Promise<PaymentIntentResponse>;
/** @deprecated */
handleCardPayment(
clientSecret: string,
options?: HandleCardPaymentWithoutElementsOptions,
): Promise<PaymentIntentResponse>;
confirmCardPayment(
clientSecret: string,
data?: ConfirmCardPaymentData,
options?: ConfirmCardPaymentOptions,
): Promise<PaymentIntentResponse>;
handleCardAction(
clientSecret: string,
): Promise<PaymentIntentResponse>;
confirmSepaDebitPayment(
clientSecret: string,
data?: ConfirmSepaDebitPaymentData,
): Promise<PaymentIntentResponse>;
/** @deprecated */
handleCardSetup(
clientSecret: string,
element: elements.Element,
data?: HandleCardSetupOptions,
): Promise<SetupIntentResponse>;
/** @deprecated */
handleCardSetup(
clientSecret: string,
data?: HandleCardSetupOptionsWithoutElementsOptions,
): Promise<SetupIntentResponse>;
confirmCardSetup(
clientSecret: string,
data?: ConfirmCardSetupData,
options?: ConfirmCardSetupOptions,
): Promise<SetupIntentResponse>;
confirmSepaDebitSetup(
clientSecret: string,
data?: ConfirmSepaDebitSetupData,
): Promise<SetupIntentResponse>;
confirmPaymentIntent(
clientSecret: string,
element: elements.Element,
@@ -479,6 +501,67 @@ declare namespace stripe {
*/
source?: string;
}
interface ConfirmCardPaymentData {
/*
* Pass an object to confirm using data collected by a card or
* cardNumber Element or an with an existing token and to supply
* additional data relevant to the PaymentMethod, such as billing
* details:
*/
payment_method?: string | {
/*
* Uses the provided card or cardNumber Element to create a
* PaymentMethod to use for confirmation.
*/
card: elements.Element | {
/*
* Converts the provided token into a PaymentMethod to use for
* confirmation.
*/
token: string,
},
/**
* The billing_details associated with the card.
*/
billing_details?: BillingDetails,
};
}
interface ConfirmCardPaymentOptions {
/*
* Set this to false if you want to handle next actions yourself, or if
* you want to defer next action handling until later (e.g. for use in
* the PaymentRequest API). Default is true.
*/
handleActions?: boolean;
}
interface ConfirmSepaDebitPaymentData {
/**
* Pass an object to confirm using data collected by an iban Element or
* by passing data directly and to supply additional required billing
* details:
*/
payment_method?: string | {
/**
* An iban Element.
*/
sepa_debit: elements.Element | {
/*
* An IBAN account number.
*/
iban: string,
},
/**
* The customer's billing_details. name and email are required.
*/
billing_details: {
name: string,
email: string,
}
};
}
interface HandleCardSetupOptions {
/**
* Use this parameter to supply additional data relevant to
@@ -561,6 +644,66 @@ declare namespace stripe {
};
}
interface ConfirmCardSetupData {
/*
* Pass an object to confirm using data collected by a card or
* cardNumber Element or an with an existing token and to supply
* additional data relevant to the PaymentMethod, such as billing
* details:
*/
payment_method?: string | {
/*
* Uses the provided card or cardNumber Element to create a
* PaymentMethod to use for confirmation.
*/
card: elements.Element | {
/*
* Converts the provided token into a PaymentMethod to use for
* confirmation.
*/
token: string,
},
/**
* The billing_details associated with the card.
*/
billing_details?: BillingDetails,
};
}
interface ConfirmCardSetupOptions {
/*
* Set this to false if you want to handle next actions yourself, or if
* you want to defer next action handling until later (e.g. for use in
* the PaymentRequest API). Default is true.
*/
handleActions?: boolean;
}
interface ConfirmSepaDebitSetupData {
/**
* Pass an object to confirm using data collected by an iban Element or
* by passing data directly and to supply additional required billing
* details:
*/
payment_method?: string | {
/**
* An iban Element.
*/
sepa_debit: elements.Element | {
/*
* An IBAN account number.
*/
iban: string,
},
/**
* The customer's billing_details. name and email are required.
*/
billing_details: {
name: string,
email: string,
}
};
}
interface PaymentMethodResponse {
paymentMethod?: paymentMethod.PaymentMethod;
error?: Error;
+83
View File
@@ -277,6 +277,44 @@ describe("Stripe elements", () => {
console.log(result.paymentIntent.source);
}
});
stripe.confirmCardPayment(
'pi_18eYalAHEMiOZZp1l9ZTjSU0_secret_NibvRz4PMmJqjfb0sqmT7aq2',
{
payment_method: {
card,
billing_details: {
name: 'Jenny Rosen',
},
}
}
).then(result => {
if (result.error) {
console.error(result.error.message);
} else if (result.paymentIntent) {
console.log(result.paymentIntent.source);
}
});
const ibanElement = elements.create('iban');
stripe.confirmSepaDebitPayment(
'pi_18eYalAHEMiOZZp1l9ZTjSU0_secret_NibvRz4PMmJqjfb0sqmT7aq2',
{
payment_method: {
sepa_debit: ibanElement,
billing_details: {
name: 'Jenny Rosen',
email: 'jenny@example.com',
},
}
}
).then(result => {
if (result.error) {
console.error(result.error.message);
} else if (result.paymentIntent) {
console.log(result.paymentIntent.source);
}
});
});
it("should handle card setup", () => {
@@ -301,6 +339,51 @@ describe("Stripe elements", () => {
});
});
it("should confirm card setup", () => {
const card = elements.create('card');
stripe.confirmCardSetup(
'pi_18eYalAHEMiOZZp1l9ZTjSU0_secret_NibvRz4PMmJqjfb0sqmT7aq2',
{
payment_method: {
card,
billing_details: {
name: 'Jenny Rosen',
},
}
}
).then(result => {
if (result.error) {
console.error(result.error.message);
} else if (result.setupIntent) {
console.log(result.setupIntent.id);
}
});
});
it("should confirm SEPA debit setup", () => {
const ibanElement = elements.create('iban');
stripe.confirmSepaDebitSetup(
'pi_18eYalAHEMiOZZp1l9ZTjSU0_secret_NibvRz4PMmJqjfb0sqmT7aq2',
{
payment_method: {
sepa_debit: ibanElement,
billing_details: {
name: 'Jenny Rosen',
email: 'jenny@example.com',
},
}
}
).then(result => {
if (result.error) {
console.error(result.error.message);
} else if (result.setupIntent) {
console.log(result.setupIntent.id);
}
});
});
it("should get card element", () => {
elements.create('card');
const card = elements.getElement('card');