Skip to content

Commit

Permalink
Replace onRequest*Intent with elements.submit()
Browse files Browse the repository at this point in the history
  • Loading branch information
alexoser-stripe committed Mar 15, 2023
1 parent f7e8933 commit ce30c59
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 58 deletions.
44 changes: 0 additions & 44 deletions tests/types/src/invalid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,28 +156,6 @@ elements.create('expressCheckout', {
// @ts-expect-error at least one of elements or clientSecret is required
stripe.confirmPayment({confirmParams: {return_url: ''}});

stripe.confirmPayment({
elements,
clientSecret: '',
// @ts-expect-error clientSecret and onRequestPaymentIntent are incompatible
onRequestPaymentIntent: () => {},
});

stripe
.confirmPayment({
elements,
confirmParams: {
return_url: '',
},
redirect: 'always',
// @ts-expect-error onRequestPaymentIntent result must include clientSecret
onRequestPaymentIntent: async () => ({}),
})
.then((res) => {
if (res.error) {
}
});

stripe
.confirmPayment({elements, confirmParams: {return_url: ''}})
.then((res) => {
Expand Down Expand Up @@ -207,13 +185,6 @@ stripe
// @ts-expect-error either elements or clientSecret is required
stripe.confirmSetup({confirmParams: {return_url: ''}});

stripe.confirmSetup({
elements,
clientSecret: '',
// @ts-expect-error clientSecret and onRequestSetupIntent are incompatible
onRequestSetupIntent: () => {},
});

stripe.confirmSetup({elements, confirmParams: {return_url: ''}}).then((res) => {
if (res.error) {
}
Expand All @@ -234,21 +205,6 @@ stripe
}
});

stripe
.confirmSetup({
elements,
confirmParams: {
return_url: '',
},
redirect: 'always',
// @ts-expect-error onRequestSetupIntent result must include clientSecret
onRequestSetupIntent: async () => ({}),
})
.then((res) => {
if (res.error) {
}
});

stripe.processOrder({elements, confirmParams: {return_url: ''}}).then((res) => {
if (res.error) {
}
Expand Down
9 changes: 4 additions & 5 deletions tests/types/src/valid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ const fetchUpdates = async () => {
const {error} = await elements.fetchUpdates();
};

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

const auBankAccountElement = elements.create('auBankAccount', {});

const retrievedAuBankAccountElement: StripeAuBankAccountElement | null = elements.getElement(
Expand Down Expand Up @@ -2641,7 +2645,6 @@ stripe
}) => null
);

const handleOnRequestIntent = async () => ({clientSecret: '', status: ''});
// confirmPayment: redirect: 'always' without clientSecret
stripe
.confirmPayment({
Expand All @@ -2661,7 +2664,6 @@ stripe
return_url: '',
},
redirect: 'always',
onRequestPaymentIntent: handleOnRequestIntent,
})
.then((res) => {
if (res.error) {
Expand Down Expand Up @@ -2711,7 +2713,6 @@ stripe
elements,
redirect: 'if_required',
confirmParams: {},
onRequestPaymentIntent: handleOnRequestIntent,
})
.then((res) => {
if (res.error) {
Expand Down Expand Up @@ -2765,7 +2766,6 @@ stripe
return_url: '',
},
redirect: 'always',
onRequestSetupIntent: handleOnRequestIntent,
})
.then((res) => {
if (res.error) {
Expand Down Expand Up @@ -2815,7 +2815,6 @@ stripe
elements,
redirect: 'if_required',
confirmParams: {},
onRequestSetupIntent: handleOnRequestIntent,
})
.then((res) => {
if (res.error) {
Expand Down
7 changes: 7 additions & 0 deletions types/stripe-js/elements-group.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
StripeExpressCheckoutElement,
StripeExpressCheckoutElementOptions,
} from './elements';
import {StripeError} from './stripe';

export interface StripeElements {
/**
Expand All @@ -64,6 +65,12 @@ export interface StripeElements {
*/
fetchUpdates(): Promise<{error?: {message: string; status?: string}}>;

/**
* 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}>;

/////////////////////////////
/// address
/////////////////////////////
Expand Down
5 changes: 0 additions & 5 deletions types/stripe-js/payment-intents.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ export {
CreatePaymentMethodFromElements,
} from '../api';

export type OnRequestIntentResult = Promise<{
clientSecret: string;
status?: string;
}>;

export interface CreatePaymentMethodAlipayData
extends PaymentMethodCreateParams {
type: 'alipay';
Expand Down
4 changes: 0 additions & 4 deletions types/stripe-js/stripe.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export interface Stripe {
confirmPayment(options: {
elements: StripeElements;
confirmParams?: Partial<paymentIntents.ConfirmPaymentData>;
onRequestPaymentIntent?: () => paymentIntents.OnRequestIntentResult;
redirect: 'if_required';
}): Promise<PaymentIntentResult>;

Expand Down Expand Up @@ -103,7 +102,6 @@ export interface Stripe {
confirmPayment(options: {
elements: StripeElements;
confirmParams: paymentIntents.ConfirmPaymentData;
onRequestPaymentIntent?: () => paymentIntents.OnRequestIntentResult;
redirect?: 'always';
}): Promise<never | {error: StripeError}>;

Expand Down Expand Up @@ -678,7 +676,6 @@ export interface Stripe {
confirmSetup(options: {
elements: StripeElements;
confirmParams?: Partial<paymentIntents.ConfirmPaymentData>;
onRequestSetupIntent?: () => paymentIntents.OnRequestIntentResult;
redirect: 'if_required';
}): Promise<SetupIntentResult>;

Expand Down Expand Up @@ -710,7 +707,6 @@ export interface Stripe {
confirmSetup(options: {
elements: StripeElements;
confirmParams: paymentIntents.ConfirmPaymentData;
onRequestSetupIntent?: () => paymentIntents.OnRequestIntentResult;
redirect?: 'always';
}): Promise<never | {error: StripeError}>;

Expand Down

0 comments on commit ce30c59

Please sign in to comment.