Skip to content

Commit b0b32dc

Browse files
committed
Added integration spec
1 parent 9bad1d2 commit b0b32dc

16 files changed

+224
-120
lines changed

.byebug_history

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,43 @@
11
continue
2+
resp.body
3+
resp = @http_request.get_request("quotes/#{quote_id}")
4+
@http_request.get_request("quotes/#{quote_id}")
5+
next
6+
url
7+
next
8+
url
9+
next
10+
step
11+
"/quotes/#{quote_id}"
12+
continue
13+
quote_id
14+
transferwise_response.body
15+
transferwise_response
16+
Quote.new(Response.new(transferwise_response).response)
17+
transferwise_response
18+
next
19+
exit
20+
Response.new(transferwise_response).response[0].details['payInReference'].split(' ')[1]
21+
Response.new(transferwise_response).response[0].details
22+
Response.new(transferwise_response).response.details
23+
Response.new(transferwise_response).response
24+
Response.new(transferwise_response)
25+
transferwise_response
26+
continue
27+
transferwise_response.body
28+
next
29+
continue
30+
target_account
31+
transferwise_response.body
32+
transferwise_response
33+
next
34+
continue
35+
target_account
36+
quote
37+
transferwise_response.body
38+
transferwise_response
39+
next
40+
continue
241
puts caller
342
caller
443
validation_params

bank_accounts.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
GBP:
2+
Account Name: TransferWise
3+
UK sort code: 20-95-61
4+
Account number: "53640809"
5+
Bank name: Barclays
6+
7+
AUD:
8+
Account Name: TransferWise Ltd
9+
Bsb Code: "182222"
10+
Account number: "303393375"
11+
Bank name: Macquarie Bank
12+
13+
USD:
14+
ABA RTN: "026073008"
15+
Account number: "2715100100"
16+
Account type: Checking
17+
Country: United States
18+
Bank name: Community Federal Savings Bank
19+
Our address: 89-16 Jamaica Avenue, Woodhaven, New York 11421

lib/transferwise-client/account.rb

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
11
module TransferwiseClient
22
# Create account
3-
class Account
3+
class Account < OpenStruct
44
attr_reader :errors
5-
def build(currency, account_holder_name, type, extra_params)
6-
@account_request = AccountRequest.new(currency, account_holder_name, type, extra_params)
7-
end
8-
9-
def valid?
10-
http_responses = HttpRequest.new.validation_request(@account_request.validation_params)
11-
validations = http_responses.map do |http_response|
12-
Response.new(http_response).response
13-
end
14-
errors = validations.map(&:errors)
15-
@errors = errors.compact.flatten.map { |error| { error['path'] => error['message'] } }
16-
@errors.empty?
17-
end
18-
19-
def save
20-
return nil unless valid?
215

22-
http_response = HttpRequest.new.send_request(@account_request)
23-
Response.new(http_response).response
6+
def initialize(response)
7+
super(response)
248
end
259
end
2610
end

lib/transferwise-client/client.rb

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,57 @@ module TransferwiseClient
22
# Create quote
33
class Client
44
def self.connect(auth_key)
5-
@auth_key = auth_key
6-
HttpRequest.new
5+
http_request = HttpRequest.new(auth_key)
6+
profile_request = ProfileRequest.new
7+
http_response = http_request.send_get_request(profile_request)
8+
profile_response = Response.new(http_response).response
9+
raise 'Cannot connect' if profile_response.empty?
10+
11+
TransferwiseClient::Client.new(auth_key, profile_response)
12+
end
13+
14+
attr_reader :profiles
15+
16+
def initialize(auth_key, profiles)
17+
@profiles = profiles
18+
@http_request = HttpRequest.new(auth_key)
19+
end
20+
21+
def create_account(profile_id, currency, account_holder_name, type, details)
22+
account_request = AccountRequest.new(profile_id, currency, account_holder_name, type, details)
23+
return nil unless account_request.valid?
24+
25+
transferwise_response = @http_request.send_request(account_request)
26+
Account.new(Response.new(transferwise_response).response.to_h)
27+
end
28+
29+
def create_quote(profile_id, source, target, target_amount)
30+
quote_request = QuoteRequest.new(profile_id, source, target, target_amount)
31+
return nil unless quote_request.valid?
32+
33+
transferwise_response = @http_request.send_request(quote_request)
34+
Quote.new(Response.new(transferwise_response).response.to_h)
35+
end
36+
37+
def create_transfer(quote_id, target_account_id, customer_transaction_id, reference)
38+
transfer_request = TransferRequest.new(quote_id, target_account_id, customer_transaction_id,
39+
reference)
40+
return nil unless transfer_request.valid?
41+
42+
transferwise_response = @http_request.send_request(transfer_request)
43+
Transfer.new(Response.new(transferwise_response).response.to_h)
44+
end
45+
46+
def member_reference(quote_id)
47+
quote_pay_method_request = QuotePayMethodRequest.new(quote_id)
48+
transferwise_response = @http_request.send_get_request(quote_pay_method_request)
49+
Response.new(transferwise_response).response[0].details['payInReference'].split(' ')[1]
50+
end
51+
52+
def payment_details(quote_id)
53+
transferwise_response = @http_request.get_request("quotes/#{quote_id}")
54+
quote = Quote.new(Response.new(transferwise_response).response.to_h)
55+
BANK_DETAILS[quote.source].merge('sourceAmount' => quote.sourceAmount)
756
end
857
end
958
end

lib/transferwise-client/http_request.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ def send_request(request)
1010
http_post(url, request.to_json)
1111
end
1212

13+
def send_get_request(request)
14+
url = URI("#{endpoint}/#{request.path}")
15+
http_get(url)
16+
end
17+
18+
def get_request(path)
19+
url = URI("#{endpoint}/#{path}")
20+
http_get(url)
21+
end
22+
1323
def validation_request(validation_params)
1424
validation_params.map do |params|
1525
url = URI("#{validation_url}/#{params[:path]}")
@@ -40,6 +50,7 @@ def http_get(url)
4050
http.use_ssl = true
4151
http_request = Net::HTTP::Get.new(url)
4252
http_request['Content-Type'] = 'application/json'
53+
http_request['Authorization'] = "Bearer #{auth_key}"
4354
http.request(http_request)
4455
end
4556

lib/transferwise-client/quote.rb

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
module TransferwiseClient
22
# Create quote
3-
class Quote
4-
def build(source, target, target_amount)
5-
@quote_request = QuoteRequest.new(source, target, target_amount)
6-
end
7-
8-
def valid?
9-
true
10-
end
3+
class Quote < OpenStruct
4+
attr_reader :errors
115

12-
def create
13-
http_response = HttpRequest.new.send_request(@quote_request)
14-
Response.new(http_response).response
6+
def initialize(response)
7+
super(response)
158
end
169
end
1710
end
Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
11
module TransferwiseClient
22
# Quote request class
33
class AccountRequest < Request
4-
def initialize(currency, account_holder_name, type,
5-
extra_params)
6-
self['profile'] = TransferwiseClient.configuration.profile_id
4+
def initialize(profile_id, currency, account_holder_name, type,
5+
details)
6+
self['profile'] = profile_id
77
self['currency'] = currency
88
self['type'] = type
99
self['accountHolderName'] = account_holder_name
1010
self['details'] = {}
1111
self['details']['legalType'] = 'BUSINESS'
12-
extra_params.each { |k, v| self['details'][k] = v }
12+
details.each { |k, v| self['details'][k] = v }
1313
end
1414

15+
def valid?
16+
http_responses = HttpRequest.new.validation_request(validation_params)
17+
validations = http_responses.map do |http_response|
18+
Response.new(http_response).response
19+
end
20+
errors = validations.map(&:errors)
21+
@errors = errors.compact.flatten.map { |error| { error['path'] => error['message'] } }
22+
@errors.empty?
23+
end
24+
25+
def path
26+
'accounts'
27+
end
28+
29+
private
30+
1531
def validation_params
1632
VALIDATIONS[self['currency']].map do |validation|
1733
params = validation['queryKey'].map do |query_key|
@@ -21,9 +37,5 @@ def validation_params
2137
{ path: validation['path'], params: params } unless params.empty?
2238
end.compact
2339
end
24-
25-
def path
26-
'accounts'
27-
end
2840
end
2941
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module TransferwiseClient
2+
# Quote request class
3+
class QuotePayMethodRequest < Request
4+
def initialize(quote_id)
5+
@quote_id = quote_id
6+
end
7+
8+
def valid?
9+
true
10+
end
11+
12+
def path
13+
"quotes/#{@quote_id}/pay-in-methods"
14+
end
15+
end
16+
end

lib/transferwise-client/request/quote_request.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
module TransferwiseClient
22
# Quote request class
33
class QuoteRequest < Request
4-
def initialize(source, target, target_amount)
5-
self['profile'] = PROFILE_ID
4+
def initialize(profile_id, source, target, target_amount)
5+
self['profile'] = profile_id
66
self['rateType'] = 'FIXED'
7-
self['type'] = 'BALANCE_PAYOUT'
7+
self['type'] = 'REGULAR'
88
self['source'] = source
99
self['target'] = target
1010
self['targetAmount'] = target_amount
1111
end
1212

13+
def valid?
14+
true
15+
end
16+
1317
def path
1418
'quotes'
1519
end

lib/transferwise-client/request/transfer_request.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ def initialize(quote, target_account, customer_transaction_id, reference)
99
self['details']['reference'] = reference
1010
end
1111

12+
def valid?
13+
true
14+
end
15+
1216
def path
1317
'transfers'
1418
end

0 commit comments

Comments
 (0)