TWINT payments
Learn how to accept TWINT, a popular payment method in Switzerland.
Caution
The content of this section refers to a Legacy product. You should use the Accept a payment guide for the most recent integration path instead. While Stripe still supports this product, this support might end if the product is deprecated.
TWINT is a single-use payment method used in Switzerland. It allows customers to authenticate and approve payments using an approved TWINT mobile app.
You get immediate notification on whether the payment succeeded or failed.
Set up StripeServer-side
First, you need a Stripe account. Register now.
To access the Stripe API from your application, use our official libraries:
Create a PaymentIntentServer-side
A PaymentIntent is an object that represents your intent to collect a payment from a customer and tracks the payment process. To create a PaymentIntent
that accepts a TWINT payment method, specify the amount to collect, chf
as the currency, and twint
in the payment_method_types list. If you maintain a list of payment method types that you pass when creating a PaymentIntent
, add twint
to it.
Retrieve the client secret
The PaymentIntent includes a client secret that the client side uses to securely complete the payment process. You can use different approaches to pass the client secret to the client side.
Collect payment method details and submit the paymentClient-side
When a customer clicks to pay with TWINT, use Stripe.js to submit the payment to Stripe. Stripe.js is the foundational JavaScript library for building payment flows. It automatically handles complexities like the redirect described below, and enables you to extend your integration to other payment methods. Include the Stripe.js script on your checkout page by adding it to the head
of your HTML file.
<head> <title>Checkout</title> <script src="https://js.stripe.com/basil/stripe.js"></script> </head>
Create an instance of Stripe.js with the following JavaScript on your checkout page.
// Set your publishable key. Remember to change this to your live publishable key in production! // See your keys here: https://dashboard.stripe.com/apikeys const stripe = Stripe(
);'pk_test_TYooMQauvdEDq54NiTphI7jx'
When you confirm the payment, pass the client secret.
Caution
Handle the client secret carefully, because it allows access to the PaymentIntent. Don’t log it, embed it in URLs, or expose it to anyone but the customer.
Use stripe.confirmTwintPayment to handle the redirect from your page to the local payment page. You must specify the return_
, which redirects the user after they complete the payment.
The customer selects the specific payment method on the local processor’s page.
// Redirects from the client to the payment processor stripe.confirmTwintPayment( '{{PAYMENT_INTENT_CLIENT_SECRET}}', { payment_method: { // Billing details is optional. billing_details: { name: 'Jenny Rosen', email: 'jenny@example.com' }, }, // Return URL where the customer should be redirected after the authorization. return_url: 'https://example.com/checkout/complete', } ).then(function(result) { if (result.error) { // Inform the customer that there was an error. console.log(result.error.message); } });
Point return_
to a page that provides the payment status by verifying the status of the PaymentIntent. When Stripe redirects the customer to that page, we append the following URL query parameters to the return_
for use in the verification call. You can also append your own query parameters when you specify the return_
. These parameters persist through the redirect process.
Parameter | Description |
---|---|
payment_ | The unique identifier for the PaymentIntent |
payment_ | The client secret of the PaymentIntent object |
Test TWINT integration
Test your TWINT integration with your test API keys by viewing the redirect page. You can test the successful payment case by authenticating the payment on the redirect page. The PaymentIntent transitions from requires_
to succeeded
. To test the case where the user fails to authenticate, use your test API keys and view the redirect page. On the redirect page, click Fail test payment. The PaymentIntent transitions from requires_
to requires_
.
OptionalHandle the TWINT redirect manually
We recommend relying on Stripe.js to handle TWINT redirects and payments client-side with confirmTwintPayment
. Using Stripe.js allows you to extend your integration to other payment methods. However, you can also manually redirect your customers on your server by following these steps:
Create and confirm a PaymentIntent with
payment_
of typemethod_ data twint
. By specifyingpayment_
, we create a PaymentMethod and immediately use it with this PaymentIntent.method_ data You must also specify the
return_
, which redirects the user after they complete the payment. You can provide your own query parameters in this URL. At the end of the redirect flow, the final URL includes these parameters.url The created
PaymentIntent
has a status ofrequires_
and aaction next_
of typeaction redirect_
.to_ url { "status": "requires_action", "next_action": { "type": "redirect_to_url", "redirect_to_url": { "url": "https://hooks.stripe.com/...", "return_url": "https://example.com/checkout/complete" } }, "id": "pi_xxx", "object": "payment_intent", "amount": 1000, "client_secret": "pi_xxx_secret_xxx", "confirm": "true", "confirmation_method": "automatic", "created": 1687432192, "currency": "chf", "livemode": true, "charges": { "data": [], "object": "list", "has_more": false, "url": "/v1/charges?payment_intent=pi_xxx" }, "payment_method_types": [ "twint" ] }
Redirect the customer to the URL provided in the
next_
property. The code example here is approximate; your web framework’s redirect method might be different.action. redirect_ to_ url. url When the customer finishes the payment process, we redirect them to the
return_
specified when you created the PaymentIntent. The URL includesurl payment_
andintent payment_
URL query parameters. If you included other parameters when you specified theintent_ client_ secret return_
, they’re also appended here.url We recommend that you rely on webhooks to confirm the status of a payment.
OptionalHandle post-payment events
Stripe sends a payment_intent.succeeded event when the payment completes. Use the Dashboard, a custom webhook, or a partner solution to receive these events and run actions, like sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow.
Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events also helps you accept more payment methods in the future. Learn about the differences between all supported payment methods.
Handle events manually in the Dashboard
Use the Dashboard to View your test payments in the Dashboard, send email receipts, handle payouts or retry failed payments.
Build a custom webhook
Build a custom webhook handler to listen for events and build custom asynchronous payment flows. Test and debug your webhook integration locally with the Stripe CLI.
Integrate a prebuilt app
Handle common business events, such as automation or marketing and sales, by integrating a partner application.