現在の口座残高を確認する
APIリクエストを行い、レスポンスでアカウントの残高を受け取ることで、いつでもVonageアカウントの残高を確認することができます。
| キー | 説明 |
|---|---|
VONAGE_API_KEY | Your Vonage API key (see it on your dashboard). |
VONAGE_API_SECRET | Your Vonage API secret (also available on your dashboard). |
Write the code
Add the following to account-balance.sh:
curl "https://rest.nexmo.com/account/get-balance" -u "$VONAGE_API_KEY:$VONAGE_API_SECRET"Run your code
Save this file to your machine and run it:
Prerequisites
npm install @vonage/server-sdkCreate a file named account-balance.js and add the following code:
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
apiKey: VONAGE_API_KEY,
apiSecret: VONAGE_API_SECRET,
});Write the code
Add the following to account-balance.js:
vonage.accounts.getBalance()
.then((resp) => {
console.log(`${resp.value.toFixed(2)} EUR`);
})
.catch((error) => console.error(error));Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk-kotlin:2.1.1'Create a class named GetBalance and add the following code to the main method:
val client = Vonage {
apiKey(VONAGE_API_KEY)
apiSecret(VONAGE_API_SECRET)
}Write the code
Add the following to the main method of the GetBalance class:
val balance = client.account.getBalance()
println("Balance: €${balance.value}")Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.account with the package containing GetBalance:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk:9.3.1'Create a class named GetBalance 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 GetBalance class:
BalanceResponse response = client.getAccountClient().getBalance();
System.out.printf("Balance: %s EUR\n", response.getValue());
System.out.printf("Auto-reload Enabled: %s\n", response.isAutoReload());Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.account with the package containing GetBalance:
Prerequisites
Install-Package VonageCreate a file named GetBalance.cs and add the following code:
using Vonage;
using Vonage.Request;
using System;Add the following to GetBalance.cs:
var response = await client.AccountClient.GetAccountBalanceAsync();
Write the code
Add the following to GetBalance.cs:
Console.WriteLine($"Current Account Balance: {response.Value}");Prerequisites
composer require vonage/clientCreate a file named account-balance.php and add the following code:
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);Write the code
Add the following to account-balance.php:
$response = $client->account()->getBalance();
echo round($response->getBalance(), 2) . " EUR\n";Run your code
Save this file to your machine and run it:
Prerequisites
pip install vonage python-dotenvWrite the code
Add the following to get-balance.py:
from vonage import Auth, Vonage
from vonage_account import Balance
client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET))
balance: Balance = client.account.get_balance()
print(f'{balance.value:0.2f} EUR, auto-reload: {balance.auto_reload}')Run your code
Save this file to your machine and run it:
Prerequisites
gem install vonageCreate a file named get-balance.rb and add the following code:
Run your code
Save this file to your machine and run it:
この例では、口座の現在の残高をユーロで出力します。