Payment System Integration

๐Ÿ’ณ Payment System Integration Guide

Complete instructions for integrating with our payment processing system

Overview

This guide provides instructions for integrating with KBank's K Payment Gateway using the Create Charge API. The payment gateway supports credit card and debit card payments through a secure, PCI-DSS compliant system.

๐Ÿ“Œ Important: All payment transactions are processed securely through KBank's PCI-DSS compliant payment gateway. Never store credit card information on your servers. For official documentation, visit: KBank API Portal

Getting Started

1. Obtain API Credentials

Before you can process payments, you'll need to:

  1. Register your application in the KBank API Portal
  2. Obtain your API Key (pkey) from KBank
  3. Obtain your Merchant ID (MID)
  4. Complete the merchant verification process with KBank

2. Create Charge API

The Create Charge API is used to process payment transactions through KBank's payment gateway.

POST https://kpaymentgateway.kasikornbank.com/api/v1/charges

Use this endpoint to create and process a payment charge.

POST https://kpaymentgateway.kasikornbank.com/api/v1/charges Authorization: Bearer YOUR_API_KEY Content-Type: application/json { "amount": 10000, "currency": "THB", "description": "Order #12345", "source": { "type": "card", "token": "tok_xxxxx" }, "metadata": { "orderId": "ORD-12345", "customerId": "cust_12345" } }

Payment Methods

KBank K Payment Gateway supports the following payment methods:

Method Type Description Status
Credit Card card Visa, Mastercard credit cards โœ… Active
Debit Card card Visa, Mastercard debit cards โœ… Active
Note: All card payments are processed through KBank's secure payment gateway with 3D Secure authentication support when required.

Payment Flow

Step 1: Initialize Payment UI

Use the KBank Payment UI to collect card information securely. The UI handles tokenization and 3D Secure authentication.

// Load KBank Payment Gateway script <script src="https://dev-kpaymentgateway.kasikornbank.com/ui/v2/kpayment.min.js" data-apikey="YOUR_API_KEY" data-amount="10000" data-currency="THB" data-payment-methods="card" data-name="Your Shop Name" data-mid="YOUR_MERCHANT_ID" data-customer-id="CUSTOMER_ID" ></script>

Step 2: Create Charge

After the payment UI collects the card token, create a charge using the Create Charge API:

POST https://kpaymentgateway.kasikornbank.com/api/v1/charges Authorization: Bearer YOUR_API_KEY Content-Type: application/json { "amount": 10000, "currency": "THB", "description": "Order #12345", "source": { "type": "card", "token": "tok_xxxxx" }, "metadata": { "orderId": "ORD-12345", "customerId": "cust_12345" } }

Step 3: Handle Response

The API will return a charge object with the payment status:

{ "id": "chg_xxxxx", "amount": 10000, "currency": "THB", "status": "succeeded", "description": "Order #12345", "created": 1234567890, "metadata": { "orderId": "ORD-12345", "customerId": "cust_12345" } }

Step 4: 3D Secure Authentication (if required)

If 3D Secure authentication is required, the response will include a redirect URL:

{ "id": "chg_xxxxx", "status": "pending", "redirect": { "url": "https://3ds.kasikornbank.com/authenticate/xxxxx", "returnUrl": "https://yoursite.com/payment/return" } }

Redirect the customer to the authentication URL, then handle the return callback.

Charge Status Codes

KBank Create Charge API returns the following status values:

Status Description
pending Charge is pending (e.g., waiting for 3D Secure authentication)
succeeded Charge completed successfully
failed Charge failed or was declined

Error Handling

Always handle payment errors gracefully:

{ "error": { "code": "card_declined", "message": "Your card was declined.", "type": "card_error", "decline_code": "generic_decline" } }

Common Error Codes

Security Best Practices

โš ๏ธ Security Reminders:

Testing

Use KBank's sandbox environment to test your integration:

POST https://dev-kpaymentgateway.kasikornbank.com/api/v1/charges

Sandbox Environment

โœ… Sandbox Mode: In sandbox mode, use test API keys and test card numbers provided by KBank. No real charges will be made. Refer to KBank's API documentation for specific test card numbers and scenarios.

API Reference

For complete API documentation, including request parameters, response formats, error codes, and webhook configuration, refer to the official KBank API Portal:

๐Ÿ“š Official Documentation: KBank Create Charge API Reference

The official documentation includes:

๐Ÿงช Test Payment UI

Enter your payment parameters below and launch the KBank payment UI with one click:

Your KBank API key (test or production)
Payment amount
Optional: Customer identifier
Optional: Merchant identifier
Optional: Will be auto-generated if empty
Use sandbox for testing, production for live payments
๐Ÿ’ก Tip: The payment UI will open in a new window. Make sure pop-ups are enabled for this site. All fields marked with * are required.

Support & Resources

Need help? Check out these resources: