Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@evanbacon/fix stripe bugs #509

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions with-stripe/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default function RootLayout() {
<Stack.Screen
name="index"
options={{
title: "Stripe Checkout",
headerLargeTitle: true,
headerSearchBarOptions: {},
}}
Expand Down
13 changes: 9 additions & 4 deletions with-stripe/app/api/payment-sheet+api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
import { stripe } from "@/utils/stripe-server";
import { CURRENCY } from "@/utils/config";

export async function POST(req: Request) {
export async function POST() {
// Use an existing Customer ID if this is a returning customer.
const customer = await stripe.customers.create();
const ephemeralKey = await stripe.ephemeralKeys.create({
customer: customer.id,
});
const ephemeralKey = await stripe.ephemeralKeys.create(
{
customer: customer.id,
},
{
apiVersion: "2024-06-20",
}
);
const paymentIntent = await stripe.paymentIntents.create({
amount: 1256,
currency: CURRENCY,
Expand Down
2 changes: 1 addition & 1 deletion with-stripe/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Image, ScrollView, Text, View } from "react-native";
export default function DonatePage(): JSX.Element {
return (
<ScrollView
style={{ flex: 1, maxWidth: 600, paddingBottom: 24 }}
style={{ flex: 1, paddingBottom: 24 }}
contentContainerStyle={{ padding: 16, gap: 8 }}
contentInsetAdjustmentBehavior="automatic"
>
Expand Down
12 changes: 2 additions & 10 deletions with-stripe/app/result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,13 @@ export default function ResultPage() {
}

const paymentIntent = data.payment_intent as Stripe.PaymentIntent;
const formattedContent = JSON.stringify(data, null, 2);

return (
<>
<h2>Status: {paymentIntent.status}</h2>
<h3>Checkout Session response:</h3>
<PrintObject content={data} />
<pre>{formattedContent}</pre>
</>
);
}

function PrintObject({
content,
}: {
content: Stripe.PaymentIntent | Stripe.Checkout.Session;
}): JSX.Element {
const formattedContent: string = JSON.stringify(content, null, 2);
return <pre>{formattedContent}</pre>;
}
2 changes: 1 addition & 1 deletion with-stripe/components/stripe-provider.web.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function ExpoStripeProvider(props) {
export default function ExpoStripeProvider(props: any) {
return <>{props.children}</>;
}
1 change: 1 addition & 0 deletions with-stripe/utils/stripe-server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Stripe from "stripe";

export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY as string, {
// This is required for deployment.
httpClient: Stripe.createFetchHttpClient(),
// https://github.com/stripe/stripe-node#configuration
apiVersion: "2024-06-20",
Expand Down