This PHP class is completely standalone; it does not require composer to bring in other code. As such this is a light-weight module for easy inclusion into bigger projects.
It has been written for my own use, and as such does not include methods for all TransferWise API calls, but I welcome contributors to add methods to add access to other API calls.
A test program is included to :
- Confirm the class has been configured correctly, and is working OK;
- Show example code on how to use the class
A webserver with PHP, that you create/save new PHP files.
NEVER save your API keys in the main code files. In this tutorial, they are saved in a separate include file.
For added security, you can ignore all the non-SANDBOX instructions below and restrict your actions to the (safe) Sandbox environment.
- Strong Customer Authentication (SCA) keys
- Create sandbox sandbox_private.pem and sandbox_public.pem files
- Create production private.pem and public.pem files
- Transfer Wise
- Create Sandbox account (Personal and Business)
- Create API Token - Read only
- Create API Token - Full access
- Upload sandbox_public.pem file
- Create Production account (Personal, if not already created)
- Create API Token - Read only
- Create API Token - Full access
- Upload public.pem file
- Create Sandbox account (Personal and Business)
- Your Web Server
- Create configure.php. Enter the API Tokens.
- Create class_TransferWise.php
- Create test.php
- Create private/public pem files
- Your Web Browser
- Run test.php to get profileIDs
- Update configure.php with these profileIDs
- Run test.php to exercise the code in these modes:
- SANDBOX
- PRODUCTION (live)
Details on SCA are here: https://api-docs.transferwise.com/#payouts-guide-strong-customer-authentication
Two methods are given here to create your pairs of private/public pem files.
-
Method 1 - Create pem files online
- Visit: https://travistidwell.com/jsencrypt/demo/
- Disconnect your computer from all networks. (The web page above does not need the Internet. This is just an extra security measure.)
- Select Key Size = 2048
- Click Generate New Keys
- Create file on local PC called sandbox_public.pem
- Copy and Paste all the Private Key text into sandbox_public.pem. Save.
- Repeat steps above for files private.pem and public.pem
- Reconnect your computer to the network
-
Method 2 - Create pem files from Linux command line
- At the command line of a linux computer enter these commands
$ openssl genrsa -out sandbox_private.pem 2048 $ openssl rsa -pubout -in sandbox_private.pem -out sandbox_public.pem $ openssl genrsa -out private.pem 2048 $ openssl rsa -pubout -in private.pem -out public.pem
- Download the 4 files to your local PC
-
Visit https://sandbox.transferwise.tech/
- Register. Create a new account. Record your login details (email address/password)
- Open Settings page. https://sandbox.transferwise.tech/user/settings
- Add new API token: Full access
- Add new API token: Read only
- Click Manage public keys -> Add new key -> Continue
- Enter security code (i.e. 111111) -> Done
- Enter name: Sandbox Public Key
- Select your sandbox_public.pem file -> Add key
- Click Turn on SCA (This option will be On in all cases after 1-Oct-2020)
- Create a Business account. (This shares the same API tokens and Public key already created)
- Logout
-
Visit https://transferwise.com
- If you don't already have an account: Register. Create a new account. Record your login details (email address/password)
- Login
- Open Settings page. https://transferwise.com/user/settings
- Add new API token: Full access
- Add new API token: Read only
- Click Manage public keys -> Add new key -> Continue
- Enter security code -> Done
- Enter name: Public Key
- Select your public.pem file -> Add key
- Click Turn on SCA (This option will be On in all cases after 1-Oct-2020)
- Logout
- Login to your Web server
- Create a new folder that can be accessed via a URL. (e.g.) xxx/public_html/TransferWise
- Create a subfolder called includes. (e.g.) xxx/public_html/TransferWise/includes
- Create and save includes/configure.php in the includes folder. Copy and paste the 4 tokens created at TransferWise before saving.
- Create and save sandbox_private.pem in the includes folder
- Create and save private.pem in the includes folder
- Create and save class_TransferWise.php in the includes folder
- Create and save test.php in the main folder
- Restrict the permissions of the private.pem file to 0400 (= User Read only)
- Restrict the permissions of the includes folder to 0555
- Restrict the permissions of the main folder to 0555
Using your favourite web browser, visit your test.php page with a URL similar to this:
https://my.web.server/TransferWise/test.php?SANDBOX&UNKNOWN
You should see something like this (xxxxx will profile IDs):
TransferWise Server: Sandbox
Profile: UNKNOWN
get Profiles
See result
Please edit includes/configure.php to include these lines
define('SANDBOX_ID_PERSONAL','xxxxx');
define('SANDBOX_ID_BUSINESS','xxxxx');
On your web server, edit your includes/configure.php
file as instructed.
Visit your test.php page with a URL similar to this:
https://my.web.server/TransferWise/test.php?UNKNOWN
You should see something like this:
TransferWise Server: Production
Profile: UNKNOWN
get Profiles
See result
Please edit includes/configure.php to include these lines
define('PROFILE_ID_PERSONAL','xxxxx');
define('PROFILE_ID_BUSINESS','xxxxx');
Note: If you do not have a Business account in your live TransferWise profile, you will only see the PROFILE_ID_PERSONAL line.
On your web server, edit your includes/configure.php
file as instructed.
Visit your test.php page with a URL similar to this:
https://my.web.server/TransferWise/test.php?SANDBOX
You should now see something like this:
TransferWise Server: Sandbox
Profile: PERSONAL
get Acct Balance AUD
See result
Get Exch Rate
See result
Create an Address
See result
Create email Recipient
See result
Create GBP (sort_code) Recipient
See: https://api-docs.transferwise.com/#recipient-accounts-create-gbp-recipient
See result
Create GBP (IBAN) Recipient
See: https://api-docs.transferwise.com/#recipient-accounts-create-gbp-recipient
See result
Create USD Recipient
See: https://api-docs.transferwise.com/#recipient-accounts-create-usd-recipient
See result
Transfer Funds: Step 1 - Create Quote
See result
Transfer Funds: Step 2 - Create Recipient
See result
Transfer Funds: Step 3 - Create Transfer
See result
Transfer Funds: Step 4 - Fund Transfer
See result
Deleting account with id = ......
See result
Click on the See result icons to expand the response returned by TransferWise. You should see that each succeeded.
Visit your test.php page with a URL similar to this:
https://my.web.server/TransferWise/test.php
You should now see something like this:
TransferWise Server: Production
Profile: PERSONAL
get Acct Balance AUD
See result
Get Exch Rate
See result
Create an Address
See result
Create email Recipient
See result
Create GBP (sort_code) Recipient
See: https://api-docs.transferwise.com/#recipient-accounts-create-gbp-recipient
See result
Create GBP (IBAN) Recipient
See: https://api-docs.transferwise.com/#recipient-accounts-create-gbp-recipient
See result
Create USD Recipient
See: https://api-docs.transferwise.com/#recipient-accounts-create-usd-recipient
See result
Transfer Funds: Step 1 - Create Quote
See result
Transfer Funds: Step 2 - Create Recipient
See result
Transfer Funds: Step 3 - Create Transfer
See result
Transfer Funds: Step 4 - Fund Transfer
See result
Deleting account with id = ......
See result
Note that it is normal to see some errors. The test.php
file was trying to create real payment accounts with fake details, so they failed. If you edit test.php
with valid account details, it should work.