Create a Charge
Create a new charge to process a payment. Charges can be created using a token (for credit cards), source (for alternative payment methods), or customer ID (for saved cards).
API Credentials
Request Parametersโ
Required - 2 fieldsRequired Parameters
`amount`INTEGER(required)
Amount in smallest currency unit (satangs for THB, cents for USD, yen for JPY). For example, 100000 satangs = 1,000 THB.
`currency`STRING(required)
ISO 4217 three-letter currency code in lowercase.
Required - 1 of 3 fieldsPayment Method (one required)
`card`STRING(optional)
Token ID from Omise.js (e.g., tokn_test_...) or card ID from a customer (e.g., card_test_...). Required if customer and source not provided.
`source`STRING(optional)
Source ID for alternative payment methods like PromptPay, mobile banking, or QR codes. Required if card and customer not provided.
`customer`STRING(optional)
Customer ID. Will charge the customer's default card. Can be combined with card to specify a specific card. Required if card and source not provided.
Recommended - 5 fieldsRecommended Parameters
Additional - 5 fieldsAdditional Parameters
Responsesโ
200
Successful transactionCharge created successfully. Check the status field to determine next steps.
Possible charge statuses:
successful- Payment completed successfully. You got paid.pending- Charge not yet authorized or captured. Awaiting customer action.failed- Payment failed. Check failure_code and failure_message for details.reversed- Charge was reversed (uncaptured charges can be reversed).expired- Pending charge expired before authorization.
400
Bad requestRequest validation failed. Check the error message for details.
Common causes:
- Missing required fields (
amount,currency) - Invalid currency code
- No payment method provided (
card,source, orcustomer) - Invalid amount (below minimum)
401
UnauthorizedAuthentication failed. Invalid or missing API key.
Common causes:
- Missing Authorization header
- Invalid secret key
- Using public key instead of secret key
- Incorrect HTTP Basic Auth format
402
Payment requiredPayment processing failed.
Common causes:
- Insufficient funds
- Card declined by issuer
- Expired card
- 3D Secure authentication failed
- Invalid card number or CVV
Code samplesโ
- cURL
- Ruby
- Python
- Node.js
- PHP
- Java
- C#
- Go
curl https://api.omise.co/charges \
-u skey_test_5xuy4w91xqz7d1w9u0t: \
-d "amount=100000" \
-d "currency=thb" \
-d "card=tokn_test_5xuy4w91xqz7d1w9u0t"
require 'omise'
Omise.api_key = 'skey_test_5xuy4w91xqz7d1w9u0t'
charge = Omise::Charge.create({
amount: 100000,
currency: 'thb',
card: 'tokn_test_5xuy4w91xqz7d1w9u0t'
})
import omise
omise.api_secret = 'skey_test_5xuy4w91xqz7d1w9u0t'
charge = omise.Charge.create(
amount=100000,
currency='thb',
card='tokn_test_5xuy4w91xqz7d1w9u0t'
)
const omise = require('omise')({
secretKey: 'skey_test_5xuy4w91xqz7d1w9u0t'
});
const charge = await omise.charges.create({
amount: 100000,
currency: 'thb',
card: 'tokn_test_5xuy4w91xqz7d1w9u0t'
});
<?php
define('OMISE_SECRET_KEY', 'skey_test_5xuy4w91xqz7d1w9u0t');
$charge = OmiseCharge::create([
'amount' => 100000,
'currency' => 'thb',
'card' => 'tokn_test_5xuy4w91xqz7d1w9u0t'
]);
Client client = new Client.Builder()
.secretKey("skey_test_5xuy4w91xqz7d1w9u0t")
.build();
Charge charge = client.charges().create()
.amount(100000L)
.currency("thb")
.card("tokn_test_5xuy4w91xqz7d1w9u0t")
.send();
var client = new Client("skey_test_5xuy4w91xqz7d1w9u0t");
var charge = await client.Charges.Create(new CreateChargeRequest
{
Amount = 100000,
Currency = "thb",
Card = "tokn_test_5xuy4w91xqz7d1w9u0t"
});
client, _ := omise.NewClient(
"pkey_test_5xuy4w91xqz7d1w9u0t",
"skey_test_5xuy4w91xqz7d1w9u0t",
)
charge, _ := client.Charges().Create(&operations.CreateCharge{
Amount: 100000,
Currency: "thb",
Card: "tokn_test_5xuy4w91xqz7d1w9u0t",
})
Error and result codesโ
Common Error Codesโ
| Code | Description | Resolution |
|---|---|---|
bad_request | Missing or invalid parameters | Check all required fields are provided |
authentication_failure | Invalid API key | Verify your secret key is correct |
invalid_card | Card validation failed | Check card number, expiry, CVV |
insufficient_funds | Card has insufficient funds | Request different payment method |
stolen_or_lost_card | Card reported stolen/lost | Payment blocked for security |
failed_fraud_check | Failed fraud detection | Contact Omise support |
Charge Status Codesโ
| Status | Description |
|---|---|
successful | Payment completed successfully |
pending | Awaiting customer action (e.g., scan QR code) |
failed | Payment failed (see failure_code) |
reversed | Charge cancelled/reversed |
expired | Charge expired before payment |
Try it outโ
Required - 2 fields
Required - 1 of 3Payment Method (1 required)
Recommended - 5 fields
Additional - 5 fields