Skip to content

Commit

Permalink
[Types] Add optional payment_method in confirmPayment param type defi…
Browse files Browse the repository at this point in the history
…nition (#501)

* Add optional payment_method confirmPayment param

* Add type tests

* prettier/lint fix
  • Loading branch information
brendanm-stripe authored Sep 14, 2023
1 parent 9331f74 commit 2344f18
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/types/src/invalid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ elements.create('expressCheckout', {
// @ts-expect-error at least one of elements or clientSecret is required
stripe.confirmPayment({confirmParams: {return_url: ''}});

stripe.confirmPayment({
clientSecret: '',
// @ts-expect-error Existing payment method by ID string only, not object
confirmParams: {return_url: '', payment_method: {}},
});

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

stripe.confirmSetup({
clientSecret: '',
// @ts-expect-error Existing payment method by ID string only, not object
confirmParams: {return_url: '', payment_method: {}},
});

stripe.confirmSetup({elements, confirmParams: {return_url: ''}}).then((res) => {
if (res.error) {
}
Expand Down
32 changes: 32 additions & 0 deletions tests/types/src/valid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2813,6 +2813,22 @@ stripe
}
});

// confirmPayment redirect: 'if_required' with clientSecret and existing PM
stripe
.confirmPayment({
clientSecret: '',
redirect: 'if_required',
confirmParams: {
payment_method: '',
},
})
.then((res) => {
if (res.error) {
}
if (res.paymentIntent) {
}
});

// confirmSetup: redirect: 'always' without clientSecret
stripe
.confirmSetup({
Expand Down Expand Up @@ -2915,6 +2931,22 @@ stripe
}
});

// confirmSetup redirect: 'if_required' with clientSecret and existing PM
stripe
.confirmSetup({
clientSecret: '',
redirect: 'if_required',
confirmParams: {
payment_method: '',
},
})
.then((res) => {
if (res.error) {
}
if (res.setupIntent) {
}
});

stripe
.processOrder({
elements,
Expand Down
7 changes: 7 additions & 0 deletions types/stripe-js/payment-intents.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,13 @@ export interface ConfirmPaymentData extends PaymentIntentConfirmParams {
billing_details?: PaymentMethodCreateParams.BillingDetails;
};

/**
* Optional `id` of an existing [PaymentMethod](https://stripe.com/docs/api/payment_methods).
*
* @docs https://stripe.com/docs/js/payment_intents/confirm_payment#confirm_payment_intent-options-confirmParams-payment_method
*/
payment_method?: string;

/**
* Specifies which fields in the response should be expanded.
*/
Expand Down

0 comments on commit 2344f18

Please sign in to comment.