WISEによる国際送金:APIとWebhook

WISEによる送金サービスのAPIとWebhookの使用例をここで別途記載します。WISEとはPaypalやStripe等と同様の国際送金サービスですが、送金時に適用される為替レートの変換率がほぼ市場での値と同等であり、手数料も低く抑えられています。送金手数料が低いのは、ドル、ユーロ、円など各通貨適用国にWISE専用の銀行口座を開設していて、金銭の移動処理をこれら口座から直接行っているためです。

国際送金例:他サービスとの比較
日本円20万円を米国に送金する場合のレートと手数料(マーケット:JPY130.35/USD)
手数料:送金額の0.41%から(下の例の場合0.628%)

隠れコストがないため、受信側は上記金額を確実に受取れます。

APIとWebhookの違い

  • API:クライアント側からサーバ側へリクエスト要求
  • Webhook:サーバ側からクライアント側へのお知らせ。APIにより条件などを設定。

サーバ側からのレスポンスはXMLやJSONフォーマットによるキー・バリューデータアレイ

WISE API

トークンと認証キーによる接続(OTT:ワンタイムトークン)

sca_with_public_key

キーペアの作成

$ openssl genrsa -out private.pem 2048
$ openssl rsa -pubout -in private.pem -out public.pem

アカウントの設定—>APIトークン—>公開キーの管理
から作成した公開キーをアップロード

Wise public API

Wise Payouts API
https://api-docs.wise.com/payouts#wise-payouts-api-documentation

PostmanによるAPIとWebhookの実装テスト

サンドボックス


TEST and LIVE environments

APIにより自身のWISEアカウント内を操作する場合

受取人のアカウント登録、受取人と送金額を指定した送金手続きの際のAPI
サンドボックスでのAPIテスト

APIのフォーク
Postmanの検索バーから"wise"で検索しAPI雛形サンプルを入手。自分のワークスペースへフォーク。

Environments:環境変数を設定
グローバル環境変数として以下定義
token : WISEアカウントからトークン(フルアクセス)を作成 46b5bf5d-6e57-4b48-a3e7-d2254c6f4cd2
host : サンドボックスのアドレス(https://api.sandbox.transferwise.tech)指定


送金元ユーザプロファイルの取得

GET
{{host}}/v1/profiles

取得データ

[
    {
        "id": 16452308,
        "type": "personal",
        "details": {
            "firstName": "sender",
            "lastName": "takanobu",
            "dateOfBirth": "1984-12-16",
            "phoneNumber": "+442038087139",
            "avatar": null,
            "occupation": null,
            "occupations": null,
            "primaryAddress": 37453125,
            "firstNameInKana": null,
            "lastNameInKana": null
        }
    },
    {
        "id": 16452309,
        "type": "business",
        "details": {
            "name": "sender sender Business",
            "registrationNumber": "07209813",
            "acn": null,
            "abn": null,
            "arbn": null,
            "companyType": "LIMITED",
            "companyRole": "OWNER",
            "descriptionOfBusiness": "IT_SERVICES",
            "primaryAddress": 37453126,
            "webpage": null,
            "businessCategory": "IT_SERVICES",
            "businessSubCategory": null
        }
    }
]

cURL

$ curl --location --request GET 'https://api.sandbox.transferwise.tech/v1/profiles' \
--header 'Authorization: Bearer 46b5bf5d-6e57-4b48-a3e7-d2254c6f4cd2'

受取人のアカウント登録

POST
{{host}}/v1/accounts

POSTデータ

{
    "accountHolderName": "Person USD",
    "currency": "USD",
    "type": "ABA",
    "details": {
      "address": {
        "city": "New York",
        "countryCode": "US",
        "postCode": "10025",
        "state": "NY",
        "firstLine": "158 Wall Street"
      },
      "legalType":"PRIVATE",
      "abartn": "064000020",
      "accountType": "CHECKING",
      "accountNumber": "16449988",
      "email": "example@foobar.com"
    }
  }

取得データ

{
    "id": 148365386,
    "business": null,
    "profile": 16452308,
    "accountHolderName": "Person USD",
    "currency": "USD",
    "country": "US",
    "type": "aba",
    "details": {
        "address": {
            "country": "US",
            "countryCode": "US",
            "firstLine": "158 Wall Street",
            "postCode": "10025",
            "city": "New York",
            "state": "NY"
        },
        "email": "example@foobar.com",
        "legalType": "PRIVATE",
        "accountHolderName": null,
        "accountNumber": "16449988",
        "sortCode": null,
        "abartn": "064000020",
        "accountType": "CHECKING",
        "bankgiroNumber": null,
        "ifscCode": null,
        "bsbCode": null,
        "institutionNumber": null,
        "transitNumber": null,
        "phoneNumber": null,
        "bankCode": null,
        "russiaRegion": null,
        "routingNumber": null,
        "branchCode": null,
        "cpf": null,
        "cardToken": null,
        "idType": null,
        "idNumber": null,
        "idCountryIso3": null,
        "idValidFrom": null,
        "idValidTo": null,
        "clabe": null,
        "swiftCode": null,
        "dateOfBirth": null,
        "clearingNumber": null,
        "bankName": null,
        "branchName": null,
        "businessNumber": null,
        "province": null,
        "city": null,
        "rut": null,
        "token": null,
        "cnpj": null,
        "payinReference": null,
        "pspReference": null,
        "orderId": null,
        "idDocumentType": null,
        "idDocumentNumber": null,
        "targetProfile": null,
        "targetUserId": null,
        "taxId": null,
        "job": null,
        "nationality": null,
        "interacAccount": null,
        "bban": null,
        "town": null,
        "postCode": null,
        "language": null,
        "billerCode": null,
        "customerReferenceNumber": null,
        "prefix": null,
        "IBAN": null,
        "iban": null,
        "bic": null,
        "BIC": null
    },
    "user": 5965245,
    "active": true,
    "ownedByCustomer": false
}

cURL

curl --location --request POST 'https://api.sandbox.transferwise.tech/v1/accounts' \
--header 'Authorization: Bearer 46b5bf5d-6e57-4b48-a3e7-d2254c6f4cd2' \
--header 'Content-Type: application/json' \
--header 'Cookie: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
--data-raw '{
    "accountHolderName": "Person USD",
    "currency": "USD",
    "type": "ABA",
    "details": {
      "address": {
        "city": "New York",
        "countryCode": "US",
        "postCode": "10025",
        "state": "NY",
        "firstLine": "158 Wall Street"
      },
      "legalType":"PRIVATE",
      "abartn": "064000020",
      "accountType": "CHECKING",
      "accountNumber": "16449988",
      "email": "example@foobar.com"
    }
  }'

送金データの作成
POST
{{host}}/v2/quotes

POSTデータ

{
	"sourceCurrency": "USD",
	"targetCurrency": "USD",
	"sourceAmount": 400,
	"targetAmount": null,
	"profile": 16452308  
}

取得データ

{
    "sourceAmount": 400.00,
    "guaranteedTargetAmountAllowed": false,
    "targetAmountAllowed": true,
    "paymentOptions": [
        {
            "formattedEstimatedDelivery": "by May 11th",
            "estimatedDeliveryDelays": [],
            "allowedProfileTypes": [
                "PERSONAL",
                "BUSINESS"
            ],
            "feePercentage": 0.0059,
            "estimatedDelivery": "2022-05-11T12:30:00Z",
            "sourceCurrency": "USD",
            "sourceAmount": 400.00,
            "targetAmount": 397.63,
            "disabled": false,
            "targetCurrency": "USD",
            "payOut": "BANK_TRANSFER",
            "fee": {
                "transferwise": 1.13,
                "payIn": 1.24,
                "discount": 0,
                "total": 2.37,
                "priceSetId": 132,
                "partner": 0.0
            },
            "price": {
                "priceSetId": 132,
                "total": {
                    "type": "TOTAL",
                    "label": "Total fees",
                    "value": {
                        "amount": 2.37,
                        "currency": "USD",
                        "label": "2.37 USD"
                    }
                },
                "items": [
                    {
                        "type": "PAYIN",
                        "label": "fee",
                        "value": {
                            "amount": 1.24,
                            "currency": "USD",
                            "label": "1.24 USD"
                        }
                    },
                    {
                        "type": "TRANSFERWISE",
                        "label": "Our fee",
                        "value": {
                            "amount": 1.13,
                            "currency": "USD",
                            "label": "1.13 USD"
                        }
                    }
                ]
            },
            "payIn": "DIRECT_DEBIT"
        },

.....
.....
.....

    "rateTimestamp": "2022-05-10T09:31:29Z",
    "clientId": "transferwise-personal-tokens",
    "id": "af8fc283-4130-4f54-a486-a4a0ced0b9f5",
    "type": "REGULAR",
    "sourceCurrency": "USD",
    "status": "PENDING",
    "profile": 16452308,
    "rate": 1,
    "targetCurrency": "USD",
    "createdTime": "2022-05-10T09:31:29Z",
    "user": 5965245,
    "rateType": "FIXED",
    "rateExpirationTime": "2022-06-09T09:31:29Z",
    "payOut": "BANK_TRANSFER",
    "guaranteedTargetAmount": false,
    "providedAmountType": "SOURCE",
    "expirationTime": "2022-05-10T10:01:29Z",
    "payInCountry": "GB",
    "funding": "POST"
}

cURL

$ curl --location --request POST 'https://api.sandbox.transferwise.tech/v2/quotes' \
--header 'Authorization: Bearer 46b5bf5d-6e57-4b48-a3e7-d2254c6f4cd2' \
--header 'Content-Type: application/json' \
--data-raw '{
	"sourceCurrency": "USD",
	"targetCurrency": "USD",
	"sourceAmount": 400,
	"targetAmount": null,
	"profile": 16452308  
}'

全アカウント情報の取得(受取人含む)
GET
{{host}}/v1/accounts

取得データ

[
    {
        "id": 148363248,
        "business": null,
        "profile": 16452308,
        "accountHolderName": "Person JPY",
        "currency": "USD",
        "country": "US",
        "type": "aba",
        "details": {
            "address": {
                "country": "US",
                "countryCode": "US",
                "firstLine": "158 Wall Street",
                "postCode": "10025",
                "city": "New York",
                "state": "NY"
            },
            "email": "example@foobar.com",
            "legalType": "PRIVATE",
            "accountHolderName": null,
            "accountNumber": "16449985",
            "sortCode": null,
            "abartn": "064000020",
            "accountType": "CHECKING",
            "bankgiroNumber": null,
            "ifscCode": null,
            "bsbCode": null,
            "institutionNumber": null,
            "transitNumber": null,
            "phoneNumber": null,
            "bankCode": null,
            "russiaRegion": null,
            "routingNumber": null,
            "branchCode": null,
            "cpf": null,
            "cardToken": null,
            "idType": null,
            "idNumber": null,
            "idCountryIso3": null,
            "idValidFrom": null,
            "idValidTo": null,
            "clabe": null,
            "swiftCode": null,
            "dateOfBirth": null,
            "clearingNumber": null,
            "bankName": null,
            "branchName": null,
            "businessNumber": null,
            "province": null,
            "city": null,
            "rut": null,
            "token": null,
            "cnpj": null,
            "payinReference": null,
            "pspReference": null,
            "orderId": null,
            "idDocumentType": null,
            "idDocumentNumber": null,
            "targetProfile": null,
            "targetUserId": null,
            "taxId": null,
            "job": null,
            "nationality": null,
            "interacAccount": null,
            "bban": null,
            "town": null,
            "postCode": null,
            "language": null,
            "billerCode": null,
            "customerReferenceNumber": null,
            "prefix": null,
            "IBAN": null,
            "iban": null,
            "bic": null,
            "BIC": null
        },
        "user": 5965245,
        "active": true,
        "ownedByCustomer": false
    },

.....
.....
.....

cURL

curl --location --request GET 'https://api.sandbox.transferwise.tech/v1/accounts' \
--header 'Authorization: Bearer 46b5bf5d-6e57-4b48-a3e7-d2254c6f4cd2'

GUIDの取得

下記サイトを利用して自動生成・取得

GET
https://www.uuidgenerator.net/api/guid

取得データ

4f2b7bfe-ac3f-4b32-88ec-15401057b339

cURL

$ curl --location --request GET 'https://www.uuidgenerator.net/api/guid'

送金手続き

POST
{{host}}/v1/transfers

POSTデータ

{
    "targetAccount": 148363248,
    "quoteUuid": "af8fc283-4130-4f54-a486-a4a0ced0b9f5",
    "customerTransactionId": "4f2b7bfe-ac3f-4b32-88ec-15401057b339",
    "details": {
        "reference": "my ref",
        "transferPurpose": "verification.transfers.purpose.pay.bills"
    }
}

取得データ

{
    "id": 50788162,
    "user": 5965245,
    "targetAccount": 148363248,
    "sourceAccount": 148360930,
    "quote": null,
    "quoteUuid": "af8fc283-4130-4f54-a486-a4a0ced0b9f5",
    "status": "processing",
    "reference": "my ref",
    "rate": 1.0,
    "created": "2022-05-10 09:32:09",
    "business": null,
    "transferRequest": null,
    "details": {
        "reference": "my ref"
    },
    "hasActiveIssues": false,
    "sourceCurrency": "USD",
    "sourceValue": 398.95,
    "targetCurrency": "USD",
    "targetValue": 398.95,
    "customerTransactionId": "4f2b7bfe-ac3f-4b32-88ec-15401057b339"
}

cURL

$ curl --location --request POST 'https://api.sandbox.transferwise.tech/v1/transfers' \
--header 'Authorization: Bearer 46b5bf5d-6e57-4b48-a3e7-d2254c6f4cd2' \
--header 'Content-Type: application/json' \
--data-raw '{
    "targetAccount": 148363248,
    "quoteUuid": "af8fc283-4130-4f54-a486-a4a0ced0b9f5",
    "customerTransactionId": "4f2b7bfe-ac3f-4b32-88ec-15401057b339",
    "details": {
        "reference": "my ref",
        "transferPurpose": "verification.transfers.purpose.pay.bills"
    }
}'