TypeScript/Node.jsでPayPayのモバイルAPIを利用するためのクライアントライブラリです。
- 完全なTypeScriptサポート
- async/awaitパターンによる非同期処理
- 型安全性とIDEの自動補完
- 送金、受け取り、チャット、残高確認などの包括的な機能
npm install paypay-tsまたは
yarn add paypay-ts# 依存関係のインストール
npm install
# TypeScriptのビルド
npm run build
# 開発モードでの実行
npm run dev
# サンプルコードの実行
npm run example- ログインを3回連続で失敗するとアカウントが一時ロックされます
- 大量のセッション作成はアカウント凍結のリスクがあります
- 日本国内からのアクセスのみサポートされています
- 本番環境では適切なエラーハンドリングを実装してください
- レート制限を考慮した実装を行ってください
- 海外からのアクセスにはプロキシの使用を検討してください
import { PayPay } from 'paypay-ts';
async function main() {
try {
// 電話番号とパスワードでログイン開始
const paypay = new PayPay("080-1234-5678", "your-password");
// 2FA認証(URLまたはIDを入力)
const url = "TK4602"; // または完全なURL
await paypay.login(url);
console.log("アクセストークン:", paypay.access_token);
console.log("リフレッシュトークン:", paypay.refresh_token);
console.log("デバイスUUID:", paypay.device_uuid);
} catch (error) {
console.error("エラー:", error);
}
}
main();// アクセストークンが既にある場合
const paypay = new PayPay(undefined, undefined, undefined, undefined, "your-access-token");
// 登録済みデバイスUUIDでのログイン
const paypay2 = new PayPay("080-1234-5678", "password", "registered-device-uuid");2FA認証を完了してログインします。
アクセストークンを更新します。
残高情報を取得します。
const balance = await paypay.getBalance();
console.log("総残高:", balance.all_balance);
console.log("使用可能残高:", balance.useable_balance);
console.log("マネーライト:", balance.money_light);
console.log("マネー:", balance.money);
console.log("ポイント:", balance.points);取引履歴を取得します。
ポイント履歴を取得します。
createLink(amount: number, passcode?: string, pochibukuro?: boolean, theme?: string): Promise<CreateLink>
送金リンクを作成します。
const link = await paypay.createLink(1000, "1234");
console.log("リンクURL:", link.link);
console.log("チャットルームID:", link.chat_room_id);リンク情報を確認します。
リンクから送金を受け取ります。
リンクを辞退します。
リンクをキャンセルします。
sendMoney(amount: number, receiverId: string, pochibukuro?: boolean, theme?: string): Promise<SendMoney>
直接送金します。
チャットルーム一覧を取得します。
getChatRoomMessages(chatRoomId: string, prev?: number, next?: number, include?: boolean): Promise<PayPayResponse>
チャットメッセージを取得します。
メッセージを送信します。
プロフィール情報を取得します。
ユーザーを検索します。
チャットルームを初期化します。
P2Pコード(QRコード)を作成します。
残高の優先度を設定します。
セッションを維持します(Bot検知回避用)。
// 文字列で指定
const paypay = new PayPay("080-1234-5678", "password", undefined, undefined, undefined, "http://proxy.example.com:8080");
// オブジェクトで指定
const paypay2 = new PayPay("080-1234-5678", "password", undefined, undefined, undefined, {
http: "http://proxy.example.com:8080",
https: "https://proxy.example.com:8080"
});import { PayPay } from 'paypay-ts';
class PayPayBot {
private paypay: PayPay;
constructor(accessToken: string) {
this.paypay = new PayPay(undefined, undefined, undefined, undefined, accessToken);
}
async sendPayment(amount: number, receiverId: string, message?: string) {
try {
// 送金実行
const result = await this.paypay.sendMoney(amount, receiverId);
// メッセージ送信(オプション)
if (message) {
await this.paypay.sendMessage(result.chat_room_id, message);
}
return result;
} catch (error) {
console.error("送金エラー:", error);
throw error;
}
}
async checkBalance() {
const balance = await this.paypay.getBalance();
return {
total: balance.all_balance,
available: balance.useable_balance
};
}
}class LinkMonitor {
private paypay: PayPay;
constructor(accessToken: string) {
this.paypay = new PayPay(undefined, undefined, undefined, undefined, accessToken);
}
async monitorLink(url: string, autoAccept: boolean = false, passcode?: string) {
try {
const linkInfo = await this.paypay.linkCheck(url);
console.log(`送信者: ${linkInfo.sender_name}`);
console.log(`金額: ${linkInfo.amount}円`);
console.log(`ステータス: ${linkInfo.status}`);
if (autoAccept && linkInfo.status === "PENDING") {
await this.paypay.linkReceive(url, passcode, linkInfo);
console.log("自動受け取り完了");
}
return linkInfo;
} catch (error) {
console.error("リンク監視エラー:", error);
throw error;
}
}
}import { PayPay, PayPayError, PayPayLoginError, PayPayNetworkError } from 'paypay-ts';
try {
const paypay = new PayPay("080-1234-5678", "password");
await paypay.login("TK4602");
} catch (error) {
if (error instanceof PayPayLoginError) {
console.error("ログインエラー:", error.message);
// ログイン関連のエラー処理
} else if (error instanceof PayPayNetworkError) {
console.error("ネットワークエラー:", error.message);
// ネットワーク関連のエラー処理
} else if (error instanceof PayPayError) {
console.error("PayPayエラー:", error.message);
// 一般的なPayPayエラー処理
} else {
console.error("予期しないエラー:", error);
}
}このライブラリは完全なTypeScript型定義を提供しています:
GetBalance- 残高情報LinkInfo- リンク情報CreateLink- リンク作成結果SendMoney- 送金結果Profile- プロフィール情報P2PUser- ユーザー情報PayPayResponse- APIレスポンス
MIT License