This project demonstrates how to integrate Iyzico payment gateway with a Next.js application, featuring a beautiful credit card form with real-time card preview and support for both regular and 3D Secure payments.
- 💳 Real-time credit card preview
- 🔄 Live form validation
- 📱 Responsive design
- 🔒 Secure payment processing
- ⚡ Server-side payment handling with Next.js Server Actions
- 🎨 Modern UI with Tailwind CSS
- 🔐 3D Secure Payment Support
- 🔄 Automatic card type detection
- ✨ Real-time form validation
- 🌐 Support for multiple currencies (TRY, USD, EUR)
Before you begin, ensure you have:
- Node.js 18.17 or later
- Yarn package manager (recommended)
- An Iyzico merchant account and API credentials
- Clone the repository:
git clone https://github.com/yourusername/iyzico-nextjs-demo.git
cd iyzico-nextjs-demo- Install dependencies:
yarn install- Create a
.envfile in the root directory with your Iyzico credentials:
IYZIPAY_URI=https://sandbox-api.iyzipay.com # or https://api.iyzipay.com for production
IYZIPAY_API_KEY=your_api_key
IYZIPAY_SECRET_KEY=your_secret_key
NEXT_PUBLIC_BASE_URL=http://localhost:3000 # Your application URL for 3D Secure callbackRun the development server:
yarn devOpen http://localhost:3000 to view the payment form.
src/
├── app/
│ ├── actions/
│ │ └── payment.ts # Server actions for payment processing
│ ├── api/
│ │ └── payment/
│ │ └── 3ds-callback/ # 3D Secure callback handling
│ ├── types/
│ │ └── payment.ts # TypeScript types for payment
│ └── page.tsx # Main payment page
├── components/
│ ├── card/
│ │ ├── CardBack.tsx # Credit card back view
│ │ ├── CardForm.tsx # Payment form component
│ │ ├── CardFront.tsx # Credit card front view
│ │ └── CardPreview.tsx # Credit card preview component
│ ├── PaymentForm.tsx # Main payment form container
│ └── ThreeDSForm.tsx # 3D Secure form handler
└── lib/
└── iyzico.ts # Iyzico configuration
- User fills in the card details
- Payment is processed directly through Iyzico
- Response is handled and displayed to the user
- User fills in the card details and opts for 3D Secure
- Initial request is sent to Iyzico
- User is redirected to bank's 3D Secure page
- User enters SMS/verification code
- Bank validates and redirects back to the application
- Payment completion is handled and result displayed
For testing purposes, you can use Iyzico's test cards:
- Success (Non-3D): 5890040000000016
- Failure (Non-3D): 5890040000000017
- Success (3D): 4603450000000000
- Failure (3D): 4603451000000000
For 3D Secure test cards:
- Any SMS code will work in the sandbox environment
- Use any valid future date for expiration
- Use any 3-digit number for CVC
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions or run into issues, please open an issue in the repository.
