事前構築済み決済フォーム
UI、バリデーション、トークン化を自動的に処理するプロフェッショナルなすぐに使える決済フォームには
OmiseCardを使用します。
概要
事前構築済み決済フォーム(OmiseCard)は、決済を受け付ける最速の方法です。モーダルダイアログとして完全な決済UIを提供します:
- ✅ 事前構築済みUI - すぐに使えるプロフェッショナルなデザイン
- ✅ 50以上の決済方法 - カード、ウォレット、QR、バンキング
- ✅ 組み込みバリデーション - リアルタイムフィールドバリデーション
- ✅ モバイル最適化 - レスポンシブデザイン
- ✅ 多言語対応 - 英語、タイ語、日本語
- ✅ PCI準拠 - デフォルトで安全
最適な用途:
- クイック統合
- 決済方法間で一貫したUX
- デザインリソースのないチーム
- モバイル最適化されたチェックアウト

クイックスタート
基本的な実装
<!DOCTYPE html>
<html>
<head>
<title>Checkout</title>
</head>
<body>
<h1>Checkout</h1>
<p>Total: ฿100.25</p>
<button id="pay-button">Pay Now</button>
<script src="https://cdn.omise.co/omise.js"></script>
<script>
// Configure OmiseCard
OmiseCard.configure({
publicKey: "pkey_test_YOUR_PUBLIC_KEY",
amount: 10025, // Amount in smallest unit (satangs/cents)
currency: "THB",
defaultPaymentMethod: "credit_card",
onCreateTokenSuccess: (nonce) => {
console.log('Token/Source created:', nonce);
// Send to your server
submitPayment(nonce);
},
onFormClosed: () => {
console.log('Payment form closed');
}
});
// Open form on button click
document.getElementById('pay-button').addEventListener('click', () => {
OmiseCard.open();
});
function submitPayment(nonce) {
fetch('/api/charge', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
token: nonce,
amount: 10025
})
})
.then(response => response.json())
.then(data => {
if (data.authorize_uri) {
// Redirect for 3D Secure or payment completion
window.location.href = data.authorize_uri;
} else {
// Payment successful
window.location.href = '/success';
}
});
}
</script>
</body>
</html>
データ属性メソ ッド
For simple integrations, use data attributes:
<form>
<script
src="https://cdn.omise.co/omise.js"
data-key="pkey_test_YOUR_PUBLIC_KEY"
data-amount="10025"
data-currency="THB"
data-default-payment-method="credit_card"
data-button-label="Pay ฿100.25"
data-submit-label="Submit Payment"
data-location="no">
</script>
</form>
設定オプション
必須オプション
OmiseCard.configure({
// Required
publicKey: "pkey_test_YOUR_PUBLIC_KEY",
amount: 10025,
currency: "THB",
// Callbacks
onCreateTokenSuccess: (nonce) => {
// Handle token/source creation
}
});
すべてのオプション
OmiseCard.configure({
// ===== Required =====
publicKey: "pkey_test_YOUR_PUBLIC_KEY",
amount: 10025, // Amount in smallest unit
currency: "THB", // THB, JPY, SGD, MYR
// ===== Payment Methods =====
defaultPaymentMethod: "credit_card", // Default selected method
otherPaymentMethods: [ // Available methods
"promptpay",
"truemoney",
"rabbit_linepay",
"mobile_banking_scb",
"mobile_banking_kbank",
"paynow",
"grabpay",
"shopeepay",
"fpx",
"duitnow_qr",
"boost",
"touch_n_go",
"alipay",
"wechat_pay",
"installment_bay",
"installment_first_choice",
"installment_kbank",
"installment_ktc",
"installment_scb"
],
// ===== UI Customization =====
frameLabel: "Your Company Name", // Company name shown in form
frameDescription: "Invoice #1234", // Description/reference
submitLabel: "Pay Now", // Submit button text
buttonLabel: "Pay with Card", // Trigger button text (data-attribute)
locale: "en", // en, th, ja
image: "https://example.com/logo.png", // Company logo URL
// ===== Customer Data =====
name: "John Doe", // Pre-fill customer name
email: "john@example.com", // Pre-fill email
phoneNumber: "+66876543210", // Pre-fill phone (for TrueMoney, etc.)
// ===== Location =====
location: "yes", // Ask for billing address (yes/no)
// ===== Callbacks =====
onCreateTokenSuccess: (nonce) => {
// Called when token/source created
// nonce is token ID (tokn_...) or source ID (src_...)
},
onFormClosed: () => {
// Called when user closes the form
},
// ===== Metadata =====
metadata: { // Optional metadata
order_id: "ORD-1234",
customer_id: "CUST-5678"
}
});
決済方法の設定
クレジット/デビットカード
OmiseCard.configure({
publicKey: "pkey_test_YOUR_PUBLIC_KEY",
amount: 50000,
currency: "THB",
defaultPaymentMethod: "credit_card",
location: "yes", // Recommended for cards
onCreateTokenSuccess: (token) => {
console.log('Card token:', token); // tokn_test_...
}
});
PromptPay (QR Code)
OmiseCard.configure({
publicKey: "pkey_test_YOUR_PUBLIC_KEY",
amount: 50000,
currency: "THB",
defaultPaymentMethod: "promptpay",
onCreateTokenSuccess: (source) => {
console.log('PromptPay source:', source); // src_test_...
// Redirect to authorize_uri to show QR code
}
});
TrueMoneyウォレット
OmiseCard.configure({
publicKey: "pkey_test_YOUR_PUBLIC_KEY",
amount: 50000,
currency: "THB",
defaultPaymentMethod: "truemoney",
phoneNumber: "+66876543210", // Pre-fill phone
onCreateTokenSuccess: (source) => {
console.log('TrueMoney source:', source);
}
});
Mobile Banking
OmiseCard.configure({
publicKey: "pkey_test_YOUR_PUBLIC_KEY",
amount: 50000,
currency: "THB",
defaultPaymentMethod: "mobile_banking_scb",
otherPaymentMethods: [
"mobile_banking_kbank",
"mobile_banking_bay",
"mobile_banking_ktb"
],
onCreateTokenSuccess: (source) => {
console.log('Mobile banking source:', source);
}
});
複数の決済方法
OmiseCard.configure({
publicKey: "pkey_test_YOUR_PUBLIC_KEY",
amount: 50000,
currency: "THB",
frameLabel: "ACME Store",
frameDescription: "Order #12345",
defaultPaymentMethod: "credit_card",
otherPaymentMethods: [
"promptpay",
"truemoney",
"rabbit_linepay",
"mobile_banking_scb",
"mobile_banking_kbank",
"shopeepay",
"grabpay"
],
onCreateTokenSuccess: (nonce) => {
if (nonce.startsWith('tokn_')) {
console.log('Card token:', nonce);
} else {
console.log('Source created:', nonce);
}
submitPayment(nonce);
}
});
決済フォームは、タイと東南アジアで人気のある幅広い代替決済方法をサポートしています:

開閉
プログラムでフォームを開く
// Configure first
OmiseCard.configure({ /* options */ });
// Open on button click
document.getElementById('pay-button').addEventListener('click', () => {
OmiseCard.open();
});
// Or open immediately
OmiseCard.open();
プログラムでフォームを閉じる
// フォームを閉じる
OmiseCard.close();
フォーム閉じるイベントを処理
OmiseCard.configure({
// ... other options
onFormClosed: () => {
console.log('User closed payment form');
// Optional: Show message or redirect
}
});
レスポンスの処理
トークン vs ソース
コールバックはトークン(カード用)またはソース(その他の方法用)のいずれかを受け取ります:
onCreateTokenSuccess: (nonce) => {
if (nonce.startsWith('tokn_')) {
// Card token - charge immediately
console.log('Card token:', nonce);
chargeCard(nonce);
} else if (nonce.startsWith('src_')) {
// Source - redirect for completion
console.log('Source:', nonce);
createCharge(nonce);
}
}
決済の処理
async function submitPayment(nonce) {
try {
const response = await fetch('/api/charge', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
token: nonce,
amount: 10025,
currency: 'THB'
})
});
const data = await response.json();
if (data.authorize_uri) {
// Redirect for 3D Secure or payment completion
window.location.href = data.authorize_uri;
} else if (data.status === 'successful') {
// Payment successful
window.location.href = '/success?charge=' + data.id;
} else if (data.status === 'failed') {
// Payment failed
alert('Payment failed: ' + data.failure_message);
} else {
// Pending status - wait for webhook
window.location.href = '/pending';
}
} catch (error) {
console.error('Error:', error);
alert('Payment error. Please try again.');
}
}
フレームワーク統合
React
import { useEffect } from 'react';
function CheckoutPage({ amount, currency, orderId }) {
useEffect(() => {
// Configure OmiseCard
window.OmiseCard.configure({
publicKey: process.env.REACT_APP_OMISE_PUBLIC_KEY,
amount: amount,
currency: currency,
frameLabel: "ACME Store",
frameDescription: `Order #${orderId}`,
defaultPaymentMethod: "credit_card",
onCreateTokenSuccess: handleTokenSuccess,
onFormClosed: () => console.log('Form closed')
});
}, [amount, currency, orderId]);
const handleTokenSuccess = async (nonce) => {
try {
const response = await fetch('/api/charge', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token: nonce, amount, currency })
});
const data = await response.json();
if (data.authorize_uri) {
window.location.href = data.authorize_uri;
} else {
window.location.href = '/success';
}
} catch (error) {
console.error('Payment error:', error);
}
};
const openPaymentForm = () => {
window.OmiseCard.open();
};
return (
<div>
<h1>Checkout</h1>
<p>Total: {currency} {(amount / 100).toFixed(2)}</p>
<button onClick={openPaymentForm}>
Pay Now
</button>
</div>
);
}
Vue.js
<template>
<div>
<h1>Checkout</h1>
<p>Total: {{ currency }} {{ (amount / 100).toFixed(2) }}</p>
<button @click="openPaymentForm">Pay Now</button>
</div>
</template>
<script>
export default {
props: ['amount', 'currency', 'orderId'],
mounted() {
window.OmiseCard.configure({
publicKey: import.meta.env.VITE_OMISE_PUBLIC_KEY,
amount: this.amount,
currency: this.currency,
frameLabel: "ACME Store",
frameDescription: `Order #${this.orderId}`,
defaultPaymentMethod: "credit_card",
onCreateTokenSuccess: this.handleTokenSuccess,
onFormClosed: () => console.log('Form closed')
});
},
methods: {
openPaymentForm() {
window.OmiseCard.open();
},
async handleTokenSuccess(nonce) {
const response = await fetch('/api/charge', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
token: nonce,
amount: this.amount,
currency: this.currency
})
});
const data = await response.json();
if (data.authorize_uri) {
window.location.href = data.authorize_uri;
} else {
window.location.href = '/success';
}
}
}
};
</script>
カスタマイゼーション
ローカライゼーション
OmiseCard.configure({
// ... other options
locale: "th", // en (English), th (Thai), ja (Japanese)
});
カスタムブランディング
OmiseCard.configure({
// ... other options
frameLabel: "Your Company Name",
frameDescription: "Invoice #1234",
image: "https://yourcompany.com/logo.png", // Square logo recommended
submitLabel: "Complete Payment"
});