Skip to content

Commit

Permalink
Add ECE custom error message types (#723)
Browse files Browse the repository at this point in the history
* Add ece custom error message types

* Prettier
  • Loading branch information
cskillingstad-stripe authored Feb 28, 2025
1 parent 73cab60 commit af12a8e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/types/src/invalid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ expressCheckoutElement.on('shippingaddresschange', ({address, resolve}) => {
});

expressCheckoutElement.on('confirm', ({paymentFailed}) => {
// @ts-expect-error Can only fail a payment for a reason of 'fail' or 'invalid-shipping-address'
// @ts-expect-error Can only fail a payment for a reason of 'fail', 'invalid_shipping_address', 'invalid_billing_address', 'invalid_payment_data', or 'address_unserviceable'
paymentFailed({reason: 'pizza-time'});
});

Expand Down
4 changes: 4 additions & 0 deletions tests/types/src/valid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,10 @@ expressCheckoutElement.on('confirm', ({paymentFailed, expressPaymentType}) => {
paymentFailed();
paymentFailed({});
paymentFailed({reason: 'invalid_shipping_address'});
paymentFailed({reason: 'invalid_billing_address'});
paymentFailed({reason: 'invalid_payment_data'});
paymentFailed({reason: 'address_unserviceable'});
paymentFailed({message: 'Test error message'});
});

expressCheckoutElement.on(
Expand Down
8 changes: 7 additions & 1 deletion types/stripe-js/elements/express-checkout.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,13 @@ export interface StripeExpressCheckoutElementConfirmEvent {
* Callback when a payment is unsuccessful. Optionally, specifying a reason will show a more detailed error in the payment interface.
*/
paymentFailed: (payload?: {
reason?: 'fail' | 'invalid_shipping_address';
reason?:
| 'fail'
| 'invalid_shipping_address'
| 'invalid_billing_address'
| 'invalid_payment_data'
| 'address_unserviceable';
message?: string;
}) => void;

billingDetails?: BillingDetails;
Expand Down

0 comments on commit af12a8e

Please sign in to comment.