顧客オブジェクトを使用すると、ビジネスがサービスを提供する顧客を作成および管理できます。連絡先の詳細、住所、請求履歴などの重要な情報を保存し、これらはサブスクリプションの作成や支払いの処理に不可欠です。
顧客オブジェクト
顧客オブジェクトは、システム内の一意の顧客を表します。
| Attribute | Type | Description |
|---|---|---|
id | string | 顧客オブジェクトの一意の識別子。cus_で始まります。 |
did | string | 顧客の分散型識別子(DID)。 |
livemode | boolean | オブジェクトがライブモードで存在する場合はtrue、テストモードで存在する場合はfalse。 |
name | string | 顧客の氏名。 |
email | string | 顧客の主要なメールアドレス。 |
phone | string | 顧客の主要な電話番号。 |
address | object | 顧客の請求先住所。以下のアドレスオブジェクトのプロパティを参照してください。 |
balance | string | 顧客の現在のクレジット残高。 |
delinquent | boolean | 顧客に支払い期限を過ぎた請求があるかどうか。 |
metadata | object | オブジェクトに添付できるキーと値のペアのセット。 |
created_at | string | 顧客が作成されたときのタイムスタンプ。 |
updated_at | string | 顧客オブジェクトが最後に更新されたときのタイムスタンプ。 |
アドレスオブジェクトのプロパティ
| Attribute | Type | Description |
|---|---|---|
country | string | 2文字の国コード(ISO 3166-1 alpha-2)。 |
state | string | 州、省、県、または地域。 |
city | string | 市、区、郊外、町、または村。 |
line1 | string | 住所1(例:通り、私書箱、会社名)。 |
line2 | string | 住所2(例:アパート、スイート、ユニット、建物)。 |
postal_code | string | 郵便番号。 |
顧客の取得
一意のIDまたはDIDを指定して、既存の顧客の詳細を取得します。
パラメータ
| Name | Type | Description |
|---|---|---|
id | string | 取得する顧客の識別子(cus_...またはDID)。 |
戻り値
指定されたIDを持つ顧客が存在する場合、TCustomerExpandedオブジェクトを返します。
例
Retrieve a Customer
async function retrieveCustomer(customerId) {
try {
const customer = await payment.customers.retrieve(customerId);
console.log('Retrieved customer:', customer);
return customer;
} catch (error) {
console.error('Error retrieving customer:', error.message);
}
}
// Example usage with a customer ID
retrieveCustomer('cus_xxxxxxxxxxxxxxxx');レスポンスの例
Example Customer Object
{
"id": "cus_xxxxxxxxxxxxxxxx",
"did": "zNK...",
"livemode": true,
"name": "John Doe",
"email": "john.doe@example.com",
"phone": "+15551234567",
"address": {
"country": "US",
"state": "CA",
"city": "San Francisco",
"line1": "123 Main Street",
"line2": "Apt 4B",
"postal_code": "94105"
},
"balance": "100.00",
"delinquent": false,
"metadata": {},
"created_at": "2023-10-27T10:00:00.000Z",
"updated_at": "2023-10-27T10:00:00.000Z"
}顧客の更新
渡されたパラメータの値を設定して、指定された顧客を更新します。指定されなかったパラメータは変更されません。
パラメータ
| Name | Type | Description |
|---|---|---|
id | string | 更新する顧客の識別子。 |
data | object | 更新するフィールドを含むオブジェクト。詳細は以下を参照してください。 |
データオブジェクトのプロパティ
| Attribute | Type | Description |
|---|---|---|
name | string | 顧客の氏名。 |
email | string | 顧客のメールアドレス。 |
phone | string | 顧客の電話番号。 |
address | object | 顧客の請求先住所。アドレスオブジェクトの構造に従います。 |
metadata | object | 顧客と共に保存するキーと値のペアのセット。 |
戻り値
更新されたTCustomerオブジェクトを返します。
例
Update a Customer
async function updateCustomerDetails(customerId) {
try {
const updatedCustomer = await payment.customers.update(customerId, {
email: 'john.new.doe@example.com',
metadata: {
internal_id: 'user-456'
}
});
console.log('Customer updated successfully:', updatedCustomer);
return updatedCustomer;
} catch (error) {
console.error('Error updating customer:', error.message);
}
}
updateCustomerDetails('cus_xxxxxxxxxxxxxxxx');全顧客の一覧表示
顧客のページ分割されたリストを返します。
パラメータ
| Name | Type | Description |
|---|---|---|
params | object | ページネーションおよびフィルタリングパラメータを含むオブジェクト。 |
Paramsオブジェクトのプロパティ
| Attribute | Type | Description |
|---|---|---|
did | string | 任意。特定のDIDを持つ顧客にリストをフィルタリングします。 |
page | number | 任意。取得するページ番号。デフォルトは1です。 |
pageSize | number | 任意。1ページあたりに取得する顧客数。デフォルトは20です。 |
戻り値
TCustomerExpandedオブジェクトのlistとページネーション詳細を含むページ分割されたオブジェクトを返します。
例
List Customers
async function listCustomers() {
try {
const response = await payment.customers.list({ pageSize: 5 });
console.log(`Total customers: ${response.count}`);
console.log('First page of customers:', response.list);
return response;
} catch (error) {
console.error('Error listing customers:', error.message);
}
}
listCustomers();レスポンスの例
Paginated Customer List
{
"count": 50,
"list": [
{
"id": "cus_xxxxxxxxxxxxxxxx",
"did": "zNK...",
"name": "John Doe",
"email": "john.doe@example.com",
// ... other customer fields
}
// ... more customer objects
],
"paging": {
"page": 1,
"pageSize": 5
}
}顧客の検索
検索クエリに一致する顧客のページ分割されたリストを返します。検索は名前、メールアドレス、DIDなどのフィールドに対して実行されます。
パラメータ
| Name | Type | Description |
|---|---|---|
params | object | 検索およびページネーションパラメータを含むオブジェクト。 |
Paramsオブジェクトのプロパティ
| Attribute | Type | Description |
|---|---|---|
query | string | 検索文字列。 |
page | number | 任意。取得するページ番号。デフォルトは1です。 |
pageSize | number | 任意。1ページあたりに取得する顧客数。デフォルトは20です。 |
戻り値
検索クエリに一致するTCustomerExpandedオブジェクトのlistを含むページ分割されたオブジェクトを返します。
例
Search for Customers
async function searchForCustomer(query) {
try {
const results = await payment.customers.search({ query: query });
console.log(`Found ${results.count} customer(s) matching '${query}':`, results.list);
return results;
} catch (error) {
console.error('Error searching for customers:', error.message);
}
}
searchForCustomer('john.doe');延滞請求書の取得
特定の顧客の回収不能な請求書のリストを、通貨ごとにグループ化された支払期日総額の要約と共に取得します。
パラメータ
| Name | Type | Description |
|---|---|---|
id | string | 顧客の識別子。 |
戻り値
顧客、その延滞請求書のリスト、および支払期日額の要約を含むオブジェクト。
例
Get Overdue Invoices
async function getOverdueInvoices(customerId) {
try {
const overdueData = await payment.customers.overdueInvoices(customerId);
console.log('Overdue invoices data:', overdueData);
return overdueData;
} catch (error) {
console.error('Error retrieving overdue invoices:', error.message);
}
}
getOverdueInvoices('cus_xxxxxxxxxxxxxxxx');レスポンスの例
Overdue Invoices Response
{
"customer": {
"id": "cus_xxxxxxxxxxxxxxxx",
// ... customer details
},
"invoices": [
{
"id": "in_yyyyyyyyyyyyyyyy",
"status": "uncollectible",
"amount_remaining": "2500",
"currency_id": "curr_zzzzzzzzzzzzzzzz",
// ... other invoice details
}
],
"summary": {
"curr_zzzzzzzzzzzzzzzz": {
"amount": "2500",
"currency": {
// ... payment currency details
},
"method": {
// ... payment method details
}
}
}
}