トランザクション履歴の表示
トランザクション履歴は、Omiseアカウント残高に影響するすべてのアクティビティの完全な記録を提供します。このガイドでは、トランザクションデータの表示、フィルタリング、検索、およびエクスポートについて説明します。
概要
トランザクション履歴には以下が含まれます:
- チャージ: 受け取った顧客の支払い
- 返金: 顧客に返金された金額
- 振込: 受取人への支払い
- 手数料: プラットフォームおよびトランザクション手数料
- 調整: 手動残高修正
- 紛争: チャージバック関連のトランザクション
主要な機能
- 完全な履歴: 残高に影響するすべてのトランザクション
- 高度なフィルタリング: タイプ、日付、金額、ステータスでフィルター
- 検索機能: 特定のトランザクションを素早く検索
- ページネーション: 大量のトランザクションを処理
- エクスポートオプション: レポート用のデータダウンロード
- リアルタイム更新: トランザクションが発生すると表示
トランザクションの取得
すべてのトランザクションをリスト
- Node.js
- Python
- Ruby
- PHP
const omise = require('omise')({
secretKey: 'skey_test_123456789',
});
// 最近のトランザクションを取得
async function getTransactions(limit = 20) {
try {
const transactions = await omise.transactions.list({
limit: limit,
order: 'reverse_chronological'
});
console.log(`${transactions.total}件のトランザクションを発見しました`);
console.log(`${transactions.total}件中${transactions.data.length}件を表示中`);
transactions.data.forEach(txn => {
console.log(`${txn.id}: ${txn.type} - ${txn.amount / 100} ${txn.currency.toUpperCase()}`);
});
return transactions;
} catch (error) {
console.error('トランザクションの取得に失敗しました:', error.message);
throw error;
}
}
// ページネーション付きトランザクション取得
async function getPaginatedTransactions(page = 1, perPage = 20) {
const offset = (page - 1) * perPage;
const transactions = await omise.transactions.list({
limit: perPage,
offset: offset,
order: 'reverse_chronological'
});
return {
data: transactions.data,
pagination: {
page: page,
per_page: perPage,
total: transactions.total,
total_pages: Math.ceil(transactions.total / perPage),
has_more: transactions.data.length === perPage
}
};
}
// 日付範囲でトランザクションを取得
async function getTransactionsByDateRange(startDate, endDate) {
const from = new Date(startDate).toISOString();
const to = new Date(endDate).toISOString();
const transactions = await omise.transactions.list({
from: from,
to: to,
order: 'reverse_chronological'
});
console.log(`${startDate}から${endDate}までのトランザクション:`);
console.log(`合計: ${transactions.total}`);
return transactions;
}
// 使用例
getTransactions(10);
getPaginatedTransactions(1, 20).then(result => {
console.log(`${result.pagination.total_pages}ページ中${result.pagination.page}ページ目`);
});
import omise
from datetime import datetime, timedelta
omise.api_secret = 'skey_test_123456789'
def get_transactions(limit=20):
"""最近のトランザクションを取得"""
try:
transactions = omise.Transaction.retrieve(
limit=limit,
order='reverse_chronological'
)
print(f"{transactions.total}件のトランザクションを発見しました")
print(f"{transactions.total}件中{len(transactions.data)}件を表示中")
for txn in transactions.data:
print(f"{txn.id}: {txn.type} - {txn.amount / 100} {txn.currency.upper()}")
return transactions
except omise.errors.BaseError as e:
print(f"トランザクションの取得に失敗しました: {str(e)}")
raise
def get_paginated_transactions(page=1, per_page=20):
"""ページネーション付きトランザクション取得"""
offset = (page - 1) * per_page
transactions = omise.Transaction.retrieve(
limit=per_page,
offset=offset,
order='reverse_chronological'
)
return {
'data': transactions.data,
'pagination': {
'page': page,
'per_page': per_page,
'total': transactions.total,
'total_pages': (transactions.total + per_page - 1) // per_page,
'has_more': len(transactions.data) == per_page
}
}
# 使用例
get_transactions(10)
result = get_paginated_transactions(1, 20)
print(f"{result['pagination']['total_pages']}ページ中{result['pagination']['page']}ページ目")
require 'omise'
require 'date'
Omise.api_key = 'skey_test_123456789'
def get_transactions(limit = 20)
begin
transactions = Omise::Transaction.retrieve(
limit: limit,
order: 'reverse_chronological'
)
puts "#{transactions.total}件のトランザクションを発見しました"
puts "#{transactions.total}件中#{transactions.data.length}件を表示中"
transactions.data.each do |txn|
puts "#{txn.id}: #{txn.type} - #{txn.amount / 100.0} #{txn.currency.upcase}"
end
transactions
rescue Omise::Error => e
puts "トランザクションの取得に失敗しました: #{e.message}"
raise
end
end
# 使用例
transactions = get_transactions(10)
<?php
require_once 'vendor/autoload.php';
define('OMISE_SECRET_KEY', 'skey_test_123456789');
function getTransactions($limit = 20) {
try {
$transactions = OmiseTransaction::retrieve([
'limit' => $limit,
'order' => 'reverse_chronological'
]);
echo "{$transactions['total']}件のトランザクションを発見しました\n";
echo count($transactions['data']) . "件中{$transactions['total']}件を表示中\n";
foreach ($transactions['data'] as $txn) {
echo "{$txn['id']}: {$txn['type']} - " . ($txn['amount'] / 100) . " " . strtoupper($txn['currency']) . "\n";
}
return $transactions;
} catch (Exception $e) {
echo "トランザクションの取得に失敗しました: {$e->getMessage()}\n";
throw $e;
}
}
getTransactions(10);
?>
APIレスポンス
{
"object": "list",
"data": [
{
"object": "transaction",
"id": "trxn_test_5xyz789abc",
"type": "credit",
"amount": 100000,
"currency": "thb",
"created": "2024-01-15T10:30:00Z",
"source": "chrg_test_123456789"
}
],
"limit": 20,
"offset": 0,
"total": 150,
"location": "/transactions",
"order": "chronological",
"from": "2024-01-01T00:00:00Z",
"to": "2024-01-31T23:59:59Z"
}
フィルタリングと検索
高度なフィルタリング
class TransactionFilter {
constructor() {
this.filters = {};
}
async byDateRange(startDate, endDate) {
this.filters.from = new Date(startDate).toISOString();
this.filters.to = new Date(endDate).toISOString();
return this;
}
async byType(type) {
this.filters.type = type; // 'credit' または 'debit'
return this;
}
async byAmountRange(minAmount, maxAmount) {
this.filters.minAmount = minAmount;
this.filters.maxAmount = maxAmount;
return this;
}
async execute() {
const transactions = await omise.transactions.list({
from: this.filters.from,
to: this.filters.to,
limit: 100,
order: 'reverse_chronological'
});
let filtered = transactions.data;
if (this.filters.type) {
filtered = filtered.filter(txn => txn.type === this.filters.type);
}
if (this.filters.minAmount || this.filters.maxAmount) {
filtered = filtered.filter(txn => {
if (this.filters.minAmount && txn.amount < this.filters.minAmount) return false;
if (this.filters.maxAmount && txn.amount > this.filters.maxAmount) return false;
return true;
});
}
return filtered;
}
}
// 使用例
const filter = new TransactionFilter();
const results = await filter
.byDateRange('2024-01-01', '2024-01-31')
.byType('credit')
.byAmountRange(100000, 1000000)
.execute();
console.log(`${results.length}件のマッチするトランザクションを発見しました`);
トランザクションのエクスポート
CSVへのエクスポート
import csv
from datetime import datetime, timedelta
def export_transactions_csv(start_date, end_date, filename='transactions.csv'):
"""トランザクションをCSVにエクスポート"""
# トランザクションを取得
transactions = omise.Transaction.retrieve(
created={
'gte': start_date.isoformat(),
'lte': end_date.isoformat()
},
limit=1000,
order='chronological'
)
# CSVに書き込み
with open(filename, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
# ヘッダーを書き込み
writer.writerow([
'トランザクションID',
'日付',
'タイプ',
'金額',
'通貨',
'ソース',
'説明'
])
# データを書き込み
for txn in transactions.data:
writer.writerow([
txn.id,
datetime.fromtimestamp(txn.created).strftime('%Y-%m-%d %H:%M:%S'),
txn.type,
txn.amount / 100,
txn.currency.upper(),
txn.source if hasattr(txn, 'source') else 'N/A',
f"{txn.type.capitalize()}トランザクション"
])
print(f"{len(transactions.data)}