Skip to main content

TossPayments Integration

Accept Korean payment methods including credit/debit cards, bank transfers, virtual accounts, and mobile payments using TossPayments.

Prerequisites

Before you begin, make sure you have:
Use test mode keys during development. Test keys use the test_ck_ and test_sk_ prefixes. Switch to live keys only when you’re ready to accept real payments.

Environment Variables

Add the following environment variables to your API server:
For your frontend application, add the client key:
Never expose TOSS_SECRET_KEY or TOSS_WEBHOOK_SECRET to the client. These must only be used server-side.

Checkout Flow

The TossPayments checkout flow involves four steps: creating a cart, initiating checkout, completing payment with the TossPayments Widget SDK, and confirming the payment server-side.

Webhook Setup

Headless Commerce listens for TossPayments webhook events to handle asynchronous payment updates (e.g., virtual account deposits, cancellations). Configure webhooks in the TossPayments Developer Center:
  1. Go to Developer CenterWebhook Settings
  2. Enter your webhook URL: https://api.headlesscommerce.io/v1/webhooks/tosspayments
  3. Select the events to receive
  4. Save the Webhook secret and set it as TOSS_WEBHOOK_SECRET

Webhook Signature Verification

TossPayments signs webhook payloads using HMAC-SHA256. The signature is included in the x-tosspayments-signature header. Headless Commerce verifies this automatically, but if you need to implement custom verification:

Event Types

Testing

Test mode keys

Use test mode API keys during development. Test transactions are simulated and do not process real payments.

Test payments

In test mode, the TossPayments widget displays simulated payment flows:
  • Credit card: Select any card brand and complete the simulated authentication
  • Bank transfer: The transfer is instantly simulated as successful
  • Virtual account: A test virtual account is created and you can simulate a deposit
  • Mobile payment: Simulated mobile payment flow
TossPayments test mode does not use specific test card numbers like Stripe. Instead, the entire payment widget operates in a sandbox environment where all payment methods are simulated.

Testing webhooks locally

Use a tunneling tool like ngrok to forward webhook events to your local server:

Error Handling

Handle payment errors in both the checkout and confirmation steps: Checkout errors:
Payment confirmation errors:

Handling the failure redirect

When a payment fails, TossPayments redirects to your failUrl with error details:
Common TossPayments error codes:

Next Steps

Webhooks

Learn about all webhook events and payload formats.

Stripe

Set up Stripe for global payment methods.

API Reference

Explore all checkout and payment endpoints.

SDKs

Full SDK reference with every resource and method.