Subaccounts APIを使う
概要
このトピックでは、パートナーがSubaccounts APIを使用してエンドカスタマーをうまく管理するユースケースについて説明します。
前提条件
を熟知している必要がある。 メインコンセプト Subaccounts API に関連付けられます。
サブアカウントの作成
パートナーはエンドカスタマーごとにSubaccountを作成し、エンドカスタマーごとに異なるAPIクレデンシャルを使用し、その支出を見ることができます。これは以下の図に示されている:

Subaccountsを作成するには、以下のコードを使用します:
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named create-subaccount.js and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
Create a class named CreateSubaccount and add the following code to the main method:
Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.subaccounts with the package containing CreateSubaccount:
Prerequisites
Add the following to build.gradle:
Create a class named CreateSubaccount and add the following code to the main method:
VonageClient client = VonageClient.builder()
.apiKey(VONAGE_API_KEY)
.apiSecret(VONAGE_API_SECRET)
.build();Write the code
Add the following to the main method of the CreateSubaccount class:
Account subaccount = client.getSubaccountsClient().createSubaccount(
CreateSubaccountRequest.builder()
.name(SUBACCOUNT_NAME)
.secret(SUBACCOUNT_SECRET)
.build()
);Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.subaccounts with the package containing CreateSubaccount:
Prerequisites
Create a file named CreateSubAccountRequest.cs and add the following code:
Add the following to CreateSubAccountRequest.cs:
Prerequisites
Create a file named create-subaccount.php and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named create-subaccount.rb and add the following code:
Run your code
Save this file to your machine and run it:
単位移行
パートナーは、エンドカスタマーがすべて同じ残高を共有していたため、エンドカスタマー間の支出を管理できませんでした。あるエンドカスタマーが、共有残高をすべて消費してしまうことがあり、他のパートナーのエンドカスタマーのVonage APIへのアクセスを事実上ブロックしていました。パートナーは個別の残高を設定し、そのエンド顧客にクレジット・リミットを割り当てることにしました。
注: パートナーは口座を前払いにすることもできたはずだ。
各Subaccountには、以下の図に示すように、個別の残高と与信限度額を割り当てることができる:

次のコード・スニペットは、指定されたクレジット額を Subaccount に割り当てる例です:
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named transfer-credit.js and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
Create a class named TransferCredit and add the following code to the main method:
Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.subaccounts with the package containing TransferCredit:
Prerequisites
Add the following to build.gradle:
Create a class named TransferCredit and add the following code to the main method:
VonageClient client = VonageClient.builder()
.apiKey(VONAGE_API_KEY)
.apiSecret(VONAGE_API_SECRET)
.build();Write the code
Add the following to the main method of the TransferCredit class:
MoneyTransfer receipt = client.getSubaccountsClient().transferCredit(
MoneyTransfer.builder()
.from(VONAGE_API_KEY).to(SUBACCOUNT_KEY)
.amount(SUBACCOUNT_CREDIT_AMOUNT).build()
);
System.out.println("Transfer successful: "+receipt.getId());Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.subaccounts with the package containing TransferCredit:
Prerequisites
Create a file named TransferCreditRequest.cs and add the following code:
Add the following to TransferCreditRequest.cs:
Prerequisites
Create a file named transfer-credit.php and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named transfer-credit.rb and add the following code:
Run your code
Save this file to your machine and run it:
すべてのSubaccountの残高確認
パートナーはモニタリングを導入することを決定する。以下のコード・スニペットを使って、すべてのSubaccountの残高を定期的にチェックすることができます:
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named get-subaccounts.js and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
Create a class named ListSubaccounts and add the following code to the main method:
Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.subaccounts with the package containing ListSubaccounts:
Prerequisites
Add the following to build.gradle:
Create a class named ListSubaccounts and add the following code to the main method:
VonageClient client = VonageClient.builder()
.apiKey(VONAGE_API_KEY)
.apiSecret(VONAGE_API_SECRET)
.build();Write the code
Add the following to the main method of the ListSubaccounts class:
ListSubaccountsResponse response = client.getSubaccountsClient().listSubaccounts();Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.subaccounts with the package containing ListSubaccounts:
Prerequisites
Create a file named GetSubAccountsRequest.cs and add the following code:
Add the following to GetSubAccountsRequest.cs:
Prerequisites
Create a file named get-subaccounts.php and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named list-subaccounts.rb and add the following code:
Run your code
Save this file to your machine and run it:
追加クレジット配分
しばらくして、パートナーはエンドカスタマー1(サブアカウント1)がクレジットをすべて使い切り(40のうち40)、これ以上APIコールができないことに気づいた。パートナーは、エンド・カスタマ1が支払いを行うのを待つか(そして今度はVonageに支払いを行い、対応する残高をサブアカウントに移す)、エンド・カスタマ1がVonage APIを使い続けられるようにエンド・カスタマのクレジット・リミットを直ちに増やすかの選択を迫られた。パートナーは追加クレジットを割り当てることにした。パートナーには 40 = |-60| - |-20| の利用可能クレジットがあり、20 をサブアカウントに割り当てることにしました。これは以下の図に示されています:

月末残高振替
月末にパートナーはVonageから|-20| + |-50| = 70ユーロの請求書を受け取った(すべてのアカウントからのすべての支出に対して)。エンドカスタマ1(サブアカウント1)は、使用した50ユーロのうち45ユーロをカバーした。したがって、パートナーは€45をサブアカウント1の残高に送金した。これは以下の図に示されている:

次のコードは、残高をSubaccountsに移す方法を示しています:
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named transfer-balance.js and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
Create a class named TransferBalance and add the following code to the main method:
Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.subaccounts with the package containing TransferBalance:
Prerequisites
Add the following to build.gradle:
Create a class named TransferBalance and add the following code to the main method:
VonageClient client = VonageClient.builder()
.apiKey(VONAGE_API_KEY)
.apiSecret(VONAGE_API_SECRET)
.build();Write the code
Add the following to the main method of the TransferBalance class:
MoneyTransfer receipt = client.getSubaccountsClient().transferBalance(
MoneyTransfer.builder()
.from(VONAGE_API_KEY).to(SUBACCOUNT_KEY)
.amount(SUBACCOUNT_BALANCE_AMOUNT).build()
);
System.out.println("Transfer successful: "+receipt.getId());Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.subaccounts with the package containing TransferBalance:
Prerequisites
Create a file named TransferBalanceRequest.cs and add the following code:
Add the following to TransferBalanceRequest.cs:
Prerequisites
Create a file named transfer-balance.php and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named transfer-balance.rb and add the following code:
Run your code
Save this file to your machine and run it:
サブアカウントの一時停止
パートナーは、サブアカウントの支出をコントロールできることを気に入り、個々の残高と30ユーロのクレジットをエンドカスタマー2(サブアカウント2)に割り当てることにした。サブアカウントの支出を監視していたパートナーは、サブアカウント2が残高の25ユーロを消費していることに気づいた。サブアカウント2の支出率に憂慮したパートナーは、サブアカウント2を一時的に停止することにした。サブアカウントを一時停止するコードをここに示す:
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named suspend-subaccount.js and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
Create a class named SuspendSubaccount and add the following code to the main method:
Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.subaccounts with the package containing SuspendSubaccount:
Prerequisites
Add the following to build.gradle:
Create a class named DeactivateSubaccount and add the following code to the main method:
VonageClient client = VonageClient.builder()
.apiKey(VONAGE_API_KEY)
.apiSecret(VONAGE_API_SECRET)
.build();Write the code
Add the following to the main method of the DeactivateSubaccount class:
Account subaccount = client.getSubaccountsClient().updateSubaccount(
UpdateSubaccountRequest.builder(SUBACCOUNT_KEY).suspended(true).build()
);Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.subaccounts with the package containing DeactivateSubaccount:
Prerequisites
Create a file named SuspendAccountRequest.cs and add the following code:
Add the following to SuspendAccountRequest.cs:
Prerequisites
Create a file named suspend-subaccount.php and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named suspend-subaccount.rb and add the following code:
Run your code
Save this file to your machine and run it:
Subaccountの再有効化
サブアカウント2との協議の結果、パートナーはサブアカウント2のアカウントを再有効化することを決定します。これは以下のコードで実現できる:
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named reactivate-subaccount.js and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
Create a class named ReactivateSubaccount and add the following code to the main method:
Write the code
Add the following to the main method of the ReactivateSubaccount class:
Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.subaccounts with the package containing ReactivateSubaccount:
Prerequisites
Add the following to build.gradle:
Create a class named ReactivateSubaccount and add the following code to the main method:
VonageClient client = VonageClient.builder()
.apiKey(VONAGE_API_KEY)
.apiSecret(VONAGE_API_SECRET)
.build();Write the code
Add the following to the main method of the ReactivateSubaccount class:
Account subaccount = client.getSubaccountsClient().updateSubaccount(
UpdateSubaccountRequest.builder(SUBACCOUNT_KEY).suspended(false).build()
);Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.subaccounts with the package containing ReactivateSubaccount:
Prerequisites
Create a file named EnableAccountRequest.cs and add the following code:
Add the following to EnableAccountRequest.cs:
Prerequisites
Create a file named reactivate-subaccount.php and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named reactivate-subaccount.rb and add the following code:
Run your code
Save this file to your machine and run it:
概要
このトピックでは、典型的なシナリオでエンドカスタマーを管理するために Subaccounts API を使用する方法について見てきました。