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:- A TossPayments account — sign up at tosspayments.com if you don’t have one
- Your API keys from the TossPayments Developer Center
- A working Headless Commerce store with at least one product
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: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:- Go to Developer Center → Webhook Settings
- Enter your webhook URL:
https://api.headlesscommerce.io/v1/webhooks/tosspayments - Select the events to receive
- 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 thex-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:Handling the failure redirect
When a payment fails, TossPayments redirects to yourfailUrl with error details:
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.