Skip to content

Commit 8d32375

Browse files
Rename CustomCheckoutProvider to CheckoutProvider (#544)
* pl - bump @stripe/stripe-js to 5.0.0 * Rename CustomCheckoutProvider to CheckoutProvider * update Custom Checkout storybook
1 parent 5bd91df commit 8d32375

11 files changed

+503
-547
lines changed

examples/hooks/11-Custom-Checkout.js

+26-28
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,20 @@ import {loadStripe} from '@stripe/stripe-js';
33
import {
44
PaymentElement,
55
useStripe,
6-
CustomCheckoutProvider,
7-
useCustomCheckout,
6+
CheckoutProvider,
7+
useCheckout,
88
AddressElement,
99
} from '../../src';
1010

1111
import '../styles/common.css';
1212

13-
const CustomerDetails = () => {
14-
const {
15-
phoneNumber,
16-
updatePhoneNumber,
17-
email,
18-
updateEmail,
19-
} = useCustomCheckout();
20-
13+
const CustomerDetails = ({phoneNumber, setPhoneNumber, email, setEmail}) => {
2114
const handlePhoneNumberChange = (event) => {
22-
updatePhoneNumber(event.target.value);
15+
setPhoneNumber(event.target.value);
2316
};
2417

2518
const handleEmailChange = (event) => {
26-
updateEmail(event.target.value);
19+
setEmail(event.target.value);
2720
};
2821

2922
return (
@@ -52,48 +45,53 @@ const CustomerDetails = () => {
5245
};
5346

5447
const CheckoutForm = () => {
55-
const customCheckout = useCustomCheckout();
48+
const checkout = useCheckout();
5649
const [status, setStatus] = React.useState();
5750
const [loading, setLoading] = React.useState(false);
5851
const stripe = useStripe();
52+
const [phoneNumber, setPhoneNumber] = React.useState('');
53+
const [email, setEmail] = React.useState('');
5954

6055
React.useEffect(() => {
61-
const {confirmationRequirements} = customCheckout || {};
56+
const {confirmationRequirements} = checkout || {};
6257
setStatus(
6358
confirmationRequirements && confirmationRequirements.length > 0
6459
? `Missing: ${confirmationRequirements.join(', ')}`
6560
: ''
6661
);
67-
}, [customCheckout, setStatus]);
62+
}, [checkout, setStatus]);
6863

6964
const handleSubmit = async (event) => {
7065
event.preventDefault();
7166

72-
if (!stripe || !customCheckout) {
73-
return;
74-
}
75-
76-
const {canConfirm, confirm} = customCheckout;
77-
if (!canConfirm) {
67+
if (!stripe || !checkout) {
7868
return;
7969
}
8070

8171
try {
8272
setLoading(true);
83-
await confirm({return_url: window.location.href});
73+
await checkout.confirm({
74+
email,
75+
phoneNumber,
76+
returnUrl: window.location.href,
77+
});
8478
setLoading(false);
8579
} catch (err) {
8680
console.error(err);
8781
setStatus(err.message);
8882
}
8983
};
9084

91-
const buttonDisabled =
92-
!stripe || !customCheckout || !customCheckout.canConfirm || loading;
85+
const buttonDisabled = !stripe || !checkout || loading;
9386

9487
return (
9588
<form onSubmit={handleSubmit}>
96-
<CustomerDetails />
89+
<CustomerDetails
90+
email={email}
91+
setEmail={setEmail}
92+
phoneNumber={phoneNumber}
93+
setPhoneNumber={setPhoneNumber}
94+
/>
9795
<h3>Payment Details</h3>
9896
<PaymentElement />
9997
<h3>Billing Details</h3>
@@ -125,7 +123,7 @@ const App = () => {
125123
e.preventDefault();
126124
setStripePromise(
127125
loadStripe(pk, {
128-
betas: ['custom_checkout_beta_1'],
126+
betas: ['custom_checkout_beta_5'],
129127
})
130128
);
131129
};
@@ -171,12 +169,12 @@ const App = () => {
171169
</label>
172170
</form>
173171
{stripePromise && clientSecret && (
174-
<CustomCheckoutProvider
172+
<CheckoutProvider
175173
stripe={stripePromise}
176174
options={{clientSecret, elementsOptions: {appearance: {theme}}}}
177175
>
178176
<CheckoutForm />
179-
</CustomCheckoutProvider>
177+
</CheckoutProvider>
180178
)}
181179
</>
182180
);

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"@rollup/plugin-replace": "^5.0.5",
7070
"@rollup/plugin-terser": "^0.4.4",
7171
"@storybook/react": "^6.5.0-beta.8",
72-
"@stripe/stripe-js": "^4.9.0",
72+
"@stripe/stripe-js": "^5.0.0",
7373
"@testing-library/jest-dom": "^5.16.4",
7474
"@testing-library/react": "^13.1.1",
7575
"@testing-library/react-hooks": "^8.0.0",
@@ -108,7 +108,7 @@
108108
"@types/react": "18.0.5"
109109
},
110110
"peerDependencies": {
111-
"@stripe/stripe-js": "^1.44.1 || ^2.0.0 || ^3.0.0 || ^4.0.0",
111+
"@stripe/stripe-js": "^1.44.1 || ^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0",
112112
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
113113
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
114114
}

0 commit comments

Comments
 (0)