-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest.php
234 lines (207 loc) · 7.54 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
//
// Filename: .../test.php
//
// Usage:
// https://my.web.server/TransferWise/test.php[?OPTIONS]
// where OPTIONS is zero or more of the below, in any order, joined by '&'
// SANDBOX = Use TransferWise Sandbox server (otherwise use Production server)
// BUSINESS = Use TransferWise Business account
// UNKNOWN = Query for ProfileIDs
//
// e.g.
// https://my.web.server/TransferWise/test.php Use TransferWise Production server, Personal acct
// https://my.web.server/TransferWise/test.php?UNKNOWN Use TransferWise Production server, Unknown acct
// https://my.web.server/TransferWise/test.php?BUSINESS Use TransferWise Production server, Business acct
// https://my.web.server/TransferWise/test.php?SANDBOX Use TransferWise Sandbox server, Personal acct
// https://my.web.server/TransferWise/test.php?SANDBOX&UNKNOWN Use TransferWise Sandbox server, Unknown acct
// https://my.web.server/TransferWise/test.php?SANDBOX&BUSINESS Use TransferWise Sandbox server, Business acct
?>
<!DOCTYPE html>
<head>
<title>TransferWise Test</title>
</head>
<body>
<?php
include('includes/class_TransferWise.php');
//Set profileId
echo 'TransferWise Server: ';
if(isset($_GET['SANDBOX'])){
echo 'Sandbox';
$profileName = 'SANDBOX_ID_';
} else {
echo 'Production';
$profileName = 'PROFILE_ID_';
}
if(isset($_GET['UNKNOWN']) ){
$profileSuffix = 'UNKNOWN';
} elseif(isset($_GET['BUSINESS']) ) {
$profileSuffix = 'BUSINESS';
} else {
$profileSuffix = 'PERSONAL';
}
echo "<br>Profile: $profileSuffix<br>";
$profileName .= $profileSuffix;
$profileId = (defined($profileName))?constant($profileName):$profileName;
//Create Read Only instance
$tw = new TransferWise($profileId);
if(strstr($profileId,'_UNKNOWN') !== false) {
//Phase 1 - IDs unknown
$profiles=json_decode($tw->getProfiles());
echo '<hr>get Profiles <br>';
echo '<details><summary>See result</summary>';
echo '<pre>'.print_r($profiles,1).'</pre>';
echo '</details>';
$profilePrefix = strtok($profileId,'_');
echo "Please edit includes/configure.php to include these lines\n\n";
echo '<pre>';
foreach($profiles as $profile){
echo "define('$profilePrefix".'_ID_'.strtoupper($profile->type)."','$profile->id');\n";
}
echo '</pre>';
exit;
}
$currency='AUD';
echo "<hr>get Acct Balance $currency<br>";
echo '<details><summary>See result</summary>';
echo '<pre>';
$accountBalance = json_decode($tw->getAccountBalance($currency));
echo print_r($accountBalance,1);
echo '</pre>';
echo '</details>';
if(!isset($_GET['SANDBOX'])){ //Cannot get statement in Sandbox
echo "<hr>get Statement $currency<br>";
echo '<details><summary>See result</summary>';
echo '<pre>';
echo print_r(json_decode($tw->getStatement($currency,'json',gmdate("Y-m-d\TH:i:s\Z", strtotime('-1 month')))),1);
echo '</pre>';
echo '</details>';
}
echo "<hr>Get Exch Rate<br>";
echo '<details><summary>See result</summary>';
echo '<pre>';
echo print_r(json_decode($tw->getExchangeRate('USD','EUR')),1);
echo '</pre>';
echo '</details>';
unset ($tw);
//Create Full Access instance
$tw = new TransferWise($profileId, false);
echo "<hr>Create an Address<br>";
echo '<details>';
echo '<summary>See result</summary>';
echo '<pre>';
echo print_r(json_decode($tw->postCreateAddress('GB', 'Fred', 'E16JJ', 'London', '')),1);
echo '</pre>';
echo '</details>';
echo "<hr>Create email Recipient<br>";
$details = new stdClass();
$details->email = 'jean@boggs.com';
echo '<details>';
echo '<summary>See result</summary>';
echo '<pre>';
echo print_r(json_decode($tw->postCreateAccount('Jean Bloggs', 'GBP', 'email', $details)),1);
echo '</pre>';
echo '</details>';
// Create payment recipients
// Each currency has different requirements for creating a payment recipient.
// See https://api-docs.transferwise.com/#recipient-accounts-create-xxx-recipient
// where xxx = 3 character currency (e.g. USD, GBP, ...)
$url = 'https://api-docs.transferwise.com/#recipient-accounts-create-gbp-recipient';
echo "<hr>Create GBP (sort_code) Recipient<br>";
echo "See: <a href=\"$url\">$url</a><br>";
$details = new stdClass();
$details->legalType = 'PRIVATE';
$details->sortCode = '40-30-20';
$details->accountNumber = '12345678';
echo '<details>';
echo '<summary>See result</summary>';
echo '<pre>';
echo print_r(json_decode($tw->postCreateAccount('Jean Bloggs', 'GBP', 'sort_code', $details)),1);
echo '</pre>';
echo '</details>';
$url = 'https://api-docs.transferwise.com/#recipient-accounts-create-gbp-recipient';
echo "<hr>Create GBP (IBAN) Recipient<br>";
echo "See: <a href=\"$url\">$url</a><br>";
$details = new stdClass();
$details->legalType = 'PRIVATE';
$details->IBAN = 'GB33BUKB20201555555555';
echo '<details>';
echo '<summary>See result</summary>';
echo '<pre>';
echo print_r(json_decode($tw->postCreateAccount('Jean Bloggs', 'GBP', 'iban', $details)),1);
echo '</pre>';
echo '</details>';
$url = 'https://api-docs.transferwise.com/#recipient-accounts-create-usd-recipient';
echo "<hr>Create USD Recipient<br>";
echo "See: <a href=\"$url\">$url</a><br>";
$details = new stdClass();
$details->legalType = 'PRIVATE';
$details->abartn = '111000025';
$details->accountNumber = '12345678';
$details->accountType = 'CHECKING';
$details->address = new stdClass();
$details->address->country = 'GB';
$details->address->city = 'London';
$details->address->postCode = '10025';
$details->address->firstLine = '50 Branson Ave';
echo '<details><summary>See result</summary>';
echo '<pre>';
echo print_r(json_decode($tw->postCreateAccount('Jean Bloggs', 'USD', 'aba', $details)),1);
echo '</pre>';
echo '</details>';
// Check DELETE works
// 1. Create an account
// 2. Delete same
$details = new stdClass();
$details->legalType = 'PRIVATE';
$details->abartn = '111000025';
$details->accountNumber = '12345678';
$details->accountType = 'CHECKING';
$details->address = new stdClass();
$details->address->country = 'US';
$details->address->city = 'Houston';
$details->address->state = 'TX';
$details->address->postCode = '77777';
$details->address->firstLine = '99 Any St';
echo "<hr>Transfer Funds: Step 1 - Create Quote<br>";
echo '<details>';
echo '<summary>See result</summary>';
echo '<pre>';
$Quote=json_decode($tw->postCreateQuote('BALANCE_PAYOUT','USD','USD',10 ));
echo print_r($Quote,1);
echo '</pre>';
echo '</details>';
echo "<hr>Transfer Funds: Step 2 - Create Recipient<br>";
echo '<details>';
echo '<summary>See result</summary>';
echo '<pre>';
$recipientAcct = json_decode($tw->postCreateAccount('Dummy Name', 'USD', 'aba', $details));
$recipientAcctId = $recipientAcct->id;
echo print_r($recipientAcct,1);
echo '</pre>';
echo '</details>';
echo "<hr>Transfer Funds: Step 3 - Create Transfer<br>";
echo '<details>';
echo '<summary>See result</summary>';
echo '<pre>';
$Transfer = json_decode($tw->postCreateTransfer($recipientAcctId,$Quote->id,'Test','verification.transfers.purpose.pay.bills','verification.source.of.funds.other'));
$TransferId = $Transfer->id;
echo print_r($Transfer,1);
echo '</pre>';
echo '</details>';
echo "<hr>Transfer Funds: Step 4 - Fund Transfer<br>";
echo '<details>';
echo '<summary>See result</summary>';
echo '<pre>';
echo print_r(json_decode($tw->postFundTransfer($TransferId)),1);
echo '</pre>';
echo '</details>';
echo "<hr>Deleting account with id = $recipientAcctId ......<br>";
echo '<details><summary>See result</summary>';
echo '<pre>';
echo print_r(json_decode($tw->deleteAccount($recipientAcctId)),1);
echo '</pre>';
echo '</details>';
?>
</body>
</html>