-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Adding a new tutorial for Turnstile [Developer Spotlight program] #18035
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
Adding a new tutorial for Turnstile [Developer Spotlight program] #18035
Conversation
...ocs/turnstile/tutorials/protecting-your-payment-form-from-attackers-bots-using-turnstile.mdx
Outdated
Show resolved
Hide resolved
...ocs/turnstile/tutorials/protecting-your-payment-form-from-attackers-bots-using-turnstile.mdx
Outdated
Show resolved
Hide resolved
...ocs/turnstile/tutorials/protecting-your-payment-form-from-attackers-bots-using-turnstile.mdx
Outdated
Show resolved
Hide resolved
...ocs/turnstile/tutorials/protecting-your-payment-form-from-attackers-bots-using-turnstile.mdx
Outdated
Show resolved
Hide resolved
...ocs/turnstile/tutorials/protecting-your-payment-form-from-attackers-bots-using-turnstile.mdx
Outdated
Show resolved
Hide resolved
...ocs/turnstile/tutorials/protecting-your-payment-form-from-attackers-bots-using-turnstile.mdx
Outdated
Show resolved
Hide resolved
...ocs/turnstile/tutorials/protecting-your-payment-form-from-attackers-bots-using-turnstile.mdx
Outdated
Show resolved
Hide resolved
...ocs/turnstile/tutorials/protecting-your-payment-form-from-attackers-bots-using-turnstile.mdx
Outdated
Show resolved
Hide resolved
...ocs/turnstile/tutorials/protecting-your-payment-form-from-attackers-bots-using-turnstile.mdx
Outdated
Show resolved
Hide resolved
...ocs/turnstile/tutorials/protecting-your-payment-form-from-attackers-bots-using-turnstile.mdx
Outdated
Show resolved
Hide resolved
|
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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. |
| 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| And place each keys into the `.dev.vars` file like the following: | |
| Then, place each key into the `.dev.vars` file like the following: |
| After that, you can generate TypeScript type definition by running the `npm run cf-typegen` command. | ||
| ```sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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. |
| 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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: |
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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. | |
patriciasantaana
left a comment
There was a problem hiding this 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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. |
...ocs/turnstile/tutorials/protecting-your-payment-form-from-attackers-bots-using-turnstile.mdx
Outdated
Show resolved
Hide resolved
|
Thank you @db-cloudflare and @patriciasantaana for reviewing! |
megaconfidence
left a comment
There was a problem hiding this 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ```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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ```diff | |
| ```diff lang="ts" |
|
|
||
| Then, add the following code to display the payment form. Edit `src/index.tsx`: | ||
|
|
||
| ```diff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ```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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ```diff | |
| ```diff lang="ts" |
|
|
||
| ## Conclusion | ||
|
|
||
| In online payments, it ss necessary to protect applications from bot attacks such as card testing and DDoS attacks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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. |
|
@megaconfidence Best. |
megaconfidence
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
|
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. |
|
Thanks for the tutorial @hideokamoto-stripe! Do you think it would be interesting to record |
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)
Documentation checklist