Skip to content

Conversation

@hideokamoto-stripe
Copy link
Contributor

@hideokamoto-stripe hideokamoto-stripe commented Nov 7, 2024

Summary

Here is a part of the content of Cloudflare Developer Spotlight program.
We're going to introduce the use case based tutorial using Cloudflare Turnstile.

Post address in the local env:
http://localhost:1111/turnstile/tutorials/protecting-your-payment-form-from-attackers-bots-using-turnstile

If you have any question, feedback, or concern, please feel free let us know.

Thanks.

Screenshots (optional)

スクリーンショット 2024-11-07 15 51 12

Documentation checklist

@db-cloudflare
Copy link
Contributor

Amazing work! Left come small suggestions throughout. Once both the style guide review and technical review have been complete we can merge this PR.


import { Render, TabItem, Tabs } from "~/components";

This tutorial shows how you can build a more secure payment form using Turnstile. You can learn how to block bot access on the checkout page and trigger additional authentication flows by integrating Turnstile with Stripe
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This tutorial shows how you can build a more secure payment form using Turnstile. You can learn how to block bot access on the checkout page and trigger additional authentication flows by integrating Turnstile with Stripe
This tutorial shows how you can build a more secure payment form using Turnstile. You can learn how to block bot access on the checkout page and trigger additional authentication flows by integrating Turnstile with Stripe.

Comment on lines 46 to 47
To efficiently create and manage multiple APIs, let's use [`Hono`](https://hono.dev). Hono is an open-source application framework released by a Cloudflare Developer Advocate. It is lightweight and allows for the creation of multiple API paths, as well as efficient request and response handling.
Open your command line interface (CLI) and run the following command:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To efficiently create and manage multiple APIs, let's use [`Hono`](https://hono.dev). Hono is an open-source application framework released by a Cloudflare Developer Advocate. It is lightweight and allows for the creation of multiple API paths, as well as efficient request and response handling.
Open your command line interface (CLI) and run the following command:
To efficiently create and manage multiple APIs, let's use [`Hono`](https://hono.dev). Hono is an open-source application framework released by a Cloudflare Developer Advocate. It is lightweight and allows for the creation of multiple API paths, as well as efficient request and response handling.
Open your command line interface (CLI) and run the following command:


https://dashboard.stripe.com/test/apikeys

And place each keys into the `.dev.vars` file like the following:
Copy link
Contributor

@patriciasantaana patriciasantaana Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
And place each keys into the `.dev.vars` file like the following:
Then, place each key into the `.dev.vars` file like the following:

Comment on lines 198 to 199
After that, you can generate TypeScript type definition by running the `npm run cf-typegen` command.
```sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
After that, you can generate TypeScript type definition by running the `npm run cf-typegen` command.
```sh
After that, you can generate TypeScript type definition by running the `npm run cf-typegen` command.
```sh

})
```

Now we're ready for application development. In the next steps, we'll develop a payment form using Turnstile and Stripe.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Now we're ready for application development. In the next steps, we'll develop a payment form using Turnstile and Stripe.
Now we are ready for application development. In the next steps, we will develop a payment form using Turnstile and Stripe.

+TURNSTILE_SITE_KEY = '2x00000000000000000000AB'
```

If you restart the application now, you'll notice that you can't submit the payment form.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you restart the application now, you'll notice that you can't submit the payment form.
If you restart the application now, you will notice that you cannot submit the payment form.

Comment on lines 525 to 526
Then, add the process to call the created API.
By executing this before calling Stripe's JavaScript SDK in the form's submit event, we can decide whether to proceed with the payment based on the server-side validation result:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Then, add the process to call the created API.
By executing this before calling Stripe's JavaScript SDK in the form's submit event, we can decide whether to proceed with the payment based on the server-side validation result:
Then, add the process to call the created API.
By executing this before calling Stripe's JavaScript SDK in the form's submit event, we can decide whether to proceed with the payment based on the server-side validation result:

Comment on lines 574 to 575
By adding this step, we now perform a two-stage check using Turnstile before the payment process.
Since we're saving the Turnstile authentication result in the Stripe data, it's also easier to investigate if a user reports a payment failure.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
By adding this step, we now perform a two-stage check using Turnstile before the payment process.
Since we're saving the Turnstile authentication result in the Stripe data, it's also easier to investigate if a user reports a payment failure.
By adding this step, we now perform a two-stage check using Turnstile before the payment process.
Since we are saving the Turnstile authentication result in the Stripe data, it is also easier to investigate if a user reports a payment failure.


## Conclusion

In online payments, it's necessary to protect applications from bot attacks such as card testing and DDoS.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In online payments, it's necessary to protect applications from bot attacks such as card testing and DDoS.
In online payments, it is necessary to protect applications from bot attacks such as card testing and DDoS attacks.

Copy link
Contributor

@patriciasantaana patriciasantaana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few edits!

Hello Hono!
```

So far, we've covered how to create a Cloudflare Worker project and introduced tools and open-source projects like the `C3` command and the `Hono` framework that streamline development with Cloudflare. Leveraging these features will help you develop applications on Cloudflare Workers more smoothly.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
So far, we've covered how to create a Cloudflare Worker project and introduced tools and open-source projects like the `C3` command and the `Hono` framework that streamline development with Cloudflare. Leveraging these features will help you develop applications on Cloudflare Workers more smoothly.
So far, we've covered how to create a Worker project using `C3` and introduced the open source `Hono` framework that streamlines web-application development with Workers.

@hideokamoto-stripe
Copy link
Contributor Author

Thank you @db-cloudflare and @patriciasantaana for reviewing!
I updated this draft 👍

Copy link
Member

@megaconfidence megaconfidence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I shared some suggestions, but otherwise this article looks good to me.


<Render file="c3-definition" product="workers" />

To efficiently create and manage multiple APIs, let's use [`Hono`](https://hono.dev). Hono is an open-source application framework released by a Cloudflare Developer Advocate. It is lightweight and allows for the creation of multiple API paths, as well as efficient request and response handling.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To efficiently create and manage multiple APIs, let's use [`Hono`](https://hono.dev). Hono is an open-source application framework released by a Cloudflare Developer Advocate. It is lightweight and allows for the creation of multiple API paths, as well as efficient request and response handling.
To efficiently create and manage multiple APIs, let's use [`Hono`](https://hono.dev). It is lightweight and allows for the creation of multiple API paths, as well as efficient request and response handling.


You can obtain test site keys and secret keys for Turnstile from the [Turnstile documentation](/turnstile/reference/testing/).

Get the publishable key and secret key for Stripe from the [Stripe dashboard].(https://dashboard.stripe.com/test/apikeys)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Get the publishable key and secret key for Stripe from the [Stripe dashboard].(https://dashboard.stripe.com/test/apikeys)
Get the publishable key and secret key for Stripe from the [Stripe dashboard](https://dashboard.stripe.com/test/apikeys).

Add JavaScript code to our application to implement bot detection using Turnstile.
By adding this implementation, the order form submission process will be disabled until the Turnstile bot detection process is completed and it is confirmed that the access request is not from a bot.

```diff
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```diff
```diff lang="ts"


Next, implement the code to create a payment form in `src/index.tsx`. The following code creates a [Payment Intent](https://docs.stripe.com/api/payment_intents) on the server side:

```diff
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```diff
```diff lang="ts"


Then, add the following code to display the payment form. Edit `src/index.tsx`:

```diff
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```diff
```diff lang="ts"


By executing this before calling Stripe's JavaScript SDK in the form's submit event, we can decide whether to proceed with the payment based on the server-side validation result:

```diff
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```diff
```diff lang="ts"


## Conclusion

In online payments, it ss necessary to protect applications from bot attacks such as card testing and DDoS attacks.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In online payments, it ss necessary to protect applications from bot attacks such as card testing and DDoS attacks.
In online payments, it is necessary to protect applications from bot attacks such as card testing and DDoS attacks.

@hideokamoto-stripe
Copy link
Contributor Author

@megaconfidence
Thanks you for reviewing my post!
I updated this draft.

Best.

Copy link
Member

@megaconfidence megaconfidence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jason-cf jason-cf enabled auto-merge (squash) December 17, 2024 16:04
@jason-cf jason-cf merged commit fe18bb1 into cloudflare:production Dec 17, 2024
6 checks passed
@workers-devprod workers-devprod added the contribution [Holopin] Recognizes a docs contribution, big or small label Dec 17, 2024
@holopin-bot
Copy link

holopin-bot bot commented Dec 17, 2024

Congratulations @hideokamoto-stripe, the maintainer of this repository has issued you a holobyte! Here it is: https://holopin.io/holobyte/cm4sobh0f71550cl4l290iw8n

This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account.
Or if you're new to Holopin, you can simply sign up with GitHub, which will do the trick!

@punkeel
Copy link
Member

punkeel commented Jan 1, 2025

Thanks for the tutorial @hideokamoto-stripe! Do you think it would be interesting to record metadata.ephemeral_id (see server side validation docs) as a Stripe metadata, if returned by the /siteverify endpoint?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution [Holopin] Recognizes a docs contribution, big or small developer-spotlight DevRel Tasks that need support from developer relations. product:turnstile size/l

Projects

None yet

Development

Successfully merging this pull request may close these issues.