currency_cloud 0.5 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +151 -8
  4. data/currency_cloud.gemspec +1 -0
  5. data/lib/currency_cloud.rb +14 -0
  6. data/lib/currency_cloud/actions/delete.rb +7 -1
  7. data/lib/currency_cloud/actions/save.rb +14 -0
  8. data/lib/currency_cloud/errors/api_error.rb +38 -2
  9. data/lib/currency_cloud/errors/error_utils.rb +14 -0
  10. data/lib/currency_cloud/errors/general_error.rb +5 -0
  11. data/lib/currency_cloud/errors/unexpected_error.rb +23 -1
  12. data/lib/currency_cloud/request_handler.rb +27 -20
  13. data/lib/currency_cloud/resource.rb +7 -1
  14. data/lib/currency_cloud/resources/balance.rb +3 -1
  15. data/lib/currency_cloud/resources/beneficiary.rb +2 -3
  16. data/lib/currency_cloud/resources/payment.rb +0 -2
  17. data/lib/currency_cloud/resources/settlement.rb +30 -9
  18. data/lib/currency_cloud/response_handler.rb +14 -15
  19. data/lib/currency_cloud/session.rb +4 -4
  20. data/lib/currency_cloud/version.rb +1 -1
  21. data/spec/currency_cloud/request_handler_spec.rb +32 -0
  22. data/spec/currency_cloud/resource_spec.rb +37 -0
  23. data/spec/currency_cloud_spec.rb +49 -5
  24. data/spec/integration/actions_spec.rb +28 -0
  25. data/spec/integration/errors_spec.rb +47 -0
  26. data/spec/integration/rates_spec.rb +1 -1
  27. data/spec/integration/settlements_spec.rb +67 -0
  28. data/spec/spec_helper.rb +3 -2
  29. data/spec/support/vcr_cassettes/Actions/can_first.yml +0 -36
  30. data/spec/support/vcr_cassettes/Actions/can_use_currency_to_retrieve_balance.yml +36 -0
  31. data/spec/support/vcr_cassettes/Actions/can_validate_beneficiaries.yml +38 -0
  32. data/spec/support/vcr_cassettes/Error/contains_full_details_for_api_error.yml +35 -0
  33. data/spec/support/vcr_cassettes/Error/is_raised_on_an_internal_server_error.yml +0 -34
  34. data/spec/support/vcr_cassettes/Rates/can_find.yml +3 -3
  35. data/spec/support/vcr_cassettes/Rates/can_provided_detailed_rate.yml +3 -3
  36. data/spec/support/vcr_cassettes/Reference/can_retrieve_beneficiary_required_details.yml +3 -3
  37. data/spec/support/vcr_cassettes/Reference/can_retrieve_conversion_dates.yml +3 -3
  38. data/spec/support/vcr_cassettes/Reference/can_retrieve_settlement_accounts.yml +3 -3
  39. data/spec/support/vcr_cassettes/Settlements/can_add_conversion.yml +102 -0
  40. data/spec/support/vcr_cassettes/Settlements/can_release.yml +69 -0
  41. data/spec/support/vcr_cassettes/Settlements/can_remove_conversion.yml +69 -0
  42. data/spec/support/vcr_cassettes/Settlements/can_unrelease.yml +69 -0
  43. metadata +26 -5
  44. data/Gemfile.lock +0 -99
  45. data/lib/currency_cloud/errors/config_error.rb +0 -5
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Settlements', :vcr => true do
4
+ before(:all) do
5
+ CurrencyCloud.reset_session
6
+ CurrencyCloud.environment = :demonstration
7
+ CurrencyCloud.token = '6f5f99d1b860fc47e8a186e3dce0d3f9'
8
+
9
+ @params = {
10
+ buy_currency: 'GBP',
11
+ sell_currency: 'USD',
12
+ fixed_side: 'buy',
13
+ amount: 1000,
14
+ reason: 'mortgage payment',
15
+ term_agreement: true
16
+ }
17
+
18
+ end
19
+
20
+ it 'can #add_conversion' do
21
+ conversion = CurrencyCloud::Conversion.create(@params)
22
+ settlement = CurrencyCloud::Settlement.create
23
+
24
+ updated_settlement = settlement.add_conversion(conversion.id)
25
+
26
+ expect(settlement).to eq(updated_settlement)
27
+
28
+ expect(settlement.conversion_ids).to eq( ["24d2ee7f-c7a3-4181-979e-9c58dbace992"])
29
+ expect(settlement.entries).to_not be_empty
30
+
31
+ gbp_currency = settlement.entries[0]
32
+ expect(gbp_currency).to include("GBP" => { "receive_amount" => "1000.00", "send_amount" => "0.00" })
33
+
34
+ usd_currency = settlement.entries[1]
35
+ expect(usd_currency).to include("USD" => { "receive_amount" => "0.00", "send_amount" => "1511.70" })
36
+
37
+ expect(settlement.updated_at).to eq('2015-05-04T20:40:56+00:00')
38
+ end
39
+
40
+ it 'can #remove_conversion' do
41
+ settlement = CurrencyCloud::Settlement.retrieve("63eeef54-3531-4e65-827a-7d0f37503fcc")
42
+ deleted_settlement = settlement.remove_conversion('24d2ee7f-c7a3-4181-979e-9c58dbace992')
43
+
44
+ expect(deleted_settlement).to_not be_nil
45
+ expect(deleted_settlement.type).to eq('bulk')
46
+ expect(deleted_settlement.created_at).to eq('2015-05-04T20:29:16+00:00')
47
+ expect(deleted_settlement.status).to eq('open')
48
+ end
49
+
50
+ it 'can #release' do
51
+ settlement = CurrencyCloud::Settlement.retrieve("51c619e0-0256-40ad-afba-ca4114b936f9")
52
+ released_settlement = settlement.release
53
+
54
+ expect(released_settlement).to eq(settlement)
55
+ expect(released_settlement.released_at).to eq('2015-05-04T21:44:23+00:00')
56
+ expect(released_settlement.status).to eq('released')
57
+ end
58
+
59
+ it 'can #unrelease' do
60
+ settlement = CurrencyCloud::Settlement.retrieve("51c619e0-0256-40ad-afba-ca4114b936f9")
61
+ unreleased_settlement = settlement.unrelease
62
+
63
+ expect(unreleased_settlement).to eq(settlement)
64
+ expect(unreleased_settlement.released_at).to eq('')
65
+ expect(unreleased_settlement.status).to eq('open')
66
+ end
67
+ end
@@ -1,4 +1,3 @@
1
- require 'currency_cloud'
2
1
  require 'pry'
3
2
  require 'vcr'
4
3
 
@@ -8,4 +7,6 @@ VCR.configure do |c|
8
7
  c.configure_rspec_metadata!
9
8
  c.allow_http_connections_when_no_cassette = true
10
9
  c.default_cassette_options = {:record => :new_episodes}
11
- end
10
+ end
11
+
12
+ require 'currency_cloud'
@@ -6,42 +6,6 @@ http_interactions:
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
9
- headers:
10
- X-Auth-Token:
11
- - e5070d4a16c5ffe4ed9fb268a2a716be
12
- response:
13
- status:
14
- code: 200
15
- message: OK
16
- headers:
17
- Server:
18
- - nginx
19
- Date:
20
- - Sat, 25 Apr 2015 09:59:57 GMT
21
- Content-Type:
22
- - application/json;charset=utf-8
23
- Content-Length:
24
- - '1196'
25
- Connection:
26
- - keep-alive
27
- X-Request-Id:
28
- - '2771968283362454302'
29
- X-Content-Type-Options:
30
- - nosniff
31
- body:
32
- encoding: UTF-8
33
- string: '{"beneficiaries":[{"id":"081596c9-02de-483e-9f2a-4cf55dcdf98c","bank_account_holder_name":"Test
34
- User","name":"Test User","email":null,"payment_types":["regular"],"beneficiary_address":[],"beneficiary_country":null,"beneficiary_entity_type":null,"beneficiary_company_name":null,"beneficiary_first_name":null,"beneficiary_last_name":null,"beneficiary_city":null,"beneficiary_postcode":null,"beneficiary_state_or_province":null,"beneficiary_date_of_birth":null,"beneficiary_identification_type":null,"beneficiary_identification_value":null,"bank_country":"GB","bank_name":"HSBC
35
- BANK PLC","bank_account_type":null,"currency":"GBP","account_number":"41854372","routing_code_type_1":"sort_code","routing_code_value_1":"400730","routing_code_type_2":null,"routing_code_value_2":null,"bic_swift":null,"iban":null,"default_beneficiary":"false","creator_contact_id":"c4d838e8-1625-44c6-a9fb-39bcb1fe353d","bank_address":["5
36
- Wimbledon Hill Rd","Wimbledon","London"],"created_at":"2015-04-25T09:21:00+00:00","updated_at":"2015-04-25T09:21:00+00:00"}],"pagination":{"total_entries":1,"total_pages":1,"current_page":1,"per_page":1,"previous_page":-1,"next_page":-1,"order":"created_at","order_asc_desc":"asc"}}'
37
- http_version:
38
- recorded_at: Sat, 25 Apr 2015 09:59:57 GMT
39
- - request:
40
- method: get
41
- uri: https://devapi.thecurrencycloud.com/v2/beneficiaries/find
42
- body:
43
- encoding: UTF-8
44
- string: bank_account_holder_name=Test%20User&per_page=1
45
9
  headers:
46
10
  X-Auth-Token:
47
11
  - 4df5b3e5882a412f148dcd08fa4e5b73
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://devapi.thecurrencycloud.com/v2/balances/GBP
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-Auth-Token:
11
+ - 616ad15a2b961ded94ef4e121bf0f67c
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Server:
18
+ - nginx
19
+ Date:
20
+ - Sun, 03 May 2015 17:51:04 GMT
21
+ Content-Type:
22
+ - application/json;charset=utf-8
23
+ Content-Length:
24
+ - '217'
25
+ Connection:
26
+ - keep-alive
27
+ X-Request-Id:
28
+ - '2778003612846482730'
29
+ X-Content-Type-Options:
30
+ - nosniff
31
+ body:
32
+ encoding: UTF-8
33
+ string: '{"id":"5a998e06-3eb7-46d6-ba58-f749864159ce","account_id":"e7483671-5dc6-0132-e126-002219414986","currency":"GBP","amount":"999866.78","created_at":"2014-12-04T09:50:35+00:00","updated_at":"2015-03-23T14:33:37+00:00"}'
34
+ http_version:
35
+ recorded_at: Sun, 03 May 2015 17:51:05 GMT
36
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://devapi.thecurrencycloud.com/v2/beneficiaries/validate
6
+ body:
7
+ encoding: UTF-8
8
+ string: bank_country=GB&currency=GBP&account_number=12345678&routing_code_type_1=sort_code&routing_code_value_1=123456&payment_types[]=regular
9
+ headers:
10
+ X-Auth-Token:
11
+ - bbdd421bdda373ea69670c9101fa9197
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Server:
18
+ - nginx
19
+ Date:
20
+ - Sun, 03 May 2015 16:55:03 GMT
21
+ Content-Type:
22
+ - application/json;charset=utf-8
23
+ Content-Length:
24
+ - '732'
25
+ Connection:
26
+ - keep-alive
27
+ X-Request-Id:
28
+ - '2777975414238700878'
29
+ X-Content-Type-Options:
30
+ - nosniff
31
+ body:
32
+ encoding: UTF-8
33
+ string: '{"payment_types":["regular"],"bank_country":"GB","bank_name":"HSBC
34
+ BANK PLC","bank_account_type":null,"currency":"GBP","account_number":"12345678","routing_code_type_1":"sort_code","beneficiary_address":[],"beneficiary_country":null,"beneficiary_entity_type":null,"beneficiary_company_name":null,"beneficiary_first_name":null,"beneficiary_last_name":null,"beneficiary_city":null,"beneficiary_postcode":null,"beneficiary_state_or_province":null,"beneficiary_date_of_birth":null,"beneficiary_identification_type":null,"beneficiary_identification_value":null,"routing_code_value_1":"123456","routing_code_type_2":null,"routing_code_value_2":null,"bic_swift":null,"iban":null,"bank_address":["5
35
+ Wimbledon Hill Rd","Wimbledon","London"]}'
36
+ http_version:
37
+ recorded_at: Sun, 03 May 2015 16:55:03 GMT
38
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,35 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://devapi.thecurrencycloud.com/v2/authenticate/api
6
+ body:
7
+ encoding: UTF-8
8
+ string: login_id=non-existent-login-id&api_key=ef0fd50fca1fb14c1fab3a8436b9ecb57528f0
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 400
13
+ message: Bad Request
14
+ headers:
15
+ Server:
16
+ - nginx
17
+ Content-Type:
18
+ - application/json;charset=utf-8
19
+ Date:
20
+ - Wed, 29 Apr 2015 22:46:53 GMT
21
+ X-Request-Id:
22
+ - '2775253392756800903'
23
+ X-Content-Type-Options:
24
+ - nosniff
25
+ Connection:
26
+ - close
27
+ Content-Length:
28
+ - '190'
29
+ body:
30
+ encoding: UTF-8
31
+ string: '{"error_code":"auth_invalid_user_login_details","error_messages":{"api_key":[{"code":"api_key_length_is_invalid","message":"api_key
32
+ should be 64 character(s) long","params":{"length":64}}]}}'
33
+ http_version:
34
+ recorded_at: Wed, 29 Apr 2015 22:46:53 GMT
35
+ recorded_with: VCR 2.9.3
@@ -32,38 +32,4 @@ http_interactions:
32
32
  general application error occurred","params":{"request_id":2771875643610572878}}]}}'
33
33
  http_version:
34
34
  recorded_at: Sat, 25 Apr 2015 06:52:42 GMT
35
- - request:
36
- method: get
37
- uri: https://devapi.thecurrencycloud.com/v2/beneficiaries/081596c9-02de-483e-9f2a-4cf55dcdf98c
38
- body:
39
- encoding: US-ASCII
40
- string: ''
41
- headers:
42
- X-Auth-Token:
43
- - 656485646b068f6e9c81e3d885fa54f5
44
- response:
45
- status:
46
- code: 404
47
- message: Not Found
48
- headers:
49
- Server:
50
- - nginx
51
- Date:
52
- - Sat, 25 Apr 2015 11:21:38 GMT
53
- Content-Type:
54
- - application/json;charset=utf-8
55
- Content-Length:
56
- - '159'
57
- Connection:
58
- - keep-alive
59
- X-Request-Id:
60
- - '2772009396693571416'
61
- X-Content-Type-Options:
62
- - nosniff
63
- body:
64
- encoding: UTF-8
65
- string: '{"error_code":"beneficiary_not_found","error_messages":{"id":[{"code":"beneficiary_not_found","message":"Beneficiary
66
- was not found for this id","params":{}}]}}'
67
- http_version:
68
- recorded_at: Sat, 25 Apr 2015 11:21:38 GMT
69
35
  recorded_with: VCR 2.9.3
@@ -2,10 +2,10 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://devapi.thecurrencycloud.com/v2/rates/find
5
+ uri: https://devapi.thecurrencycloud.com/v2/rates/find?currency_pair=GBPUSD,EURGBP
6
6
  body:
7
- encoding: UTF-8
8
- string: currency_pair=GBPUSD%2CEURGBP
7
+ encoding: US-ASCII
8
+ string: ''
9
9
  headers:
10
10
  X-Auth-Token:
11
11
  - 242993ca94b9d1c6c1d8f7d3275a6f36
@@ -2,10 +2,10 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://devapi.thecurrencycloud.com/v2/rates/detailed
5
+ uri: https://devapi.thecurrencycloud.com/v2/rates/detailed?amount=10000&buy_currency=GBP&fixed_side=buy&sell_currency=USD
6
6
  body:
7
- encoding: UTF-8
8
- string: buy_currency=GBP&sell_currency=USD&fixed_side=buy&amount=10000
7
+ encoding: US-ASCII
8
+ string: ''
9
9
  headers:
10
10
  X-Auth-Token:
11
11
  - 242993ca94b9d1c6c1d8f7d3275a6f36
@@ -2,10 +2,10 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://devapi.thecurrencycloud.com/v2/reference/beneficiary_required_details
5
+ uri: https://devapi.thecurrencycloud.com/v2/reference/beneficiary_required_details?bank_account_country=GB&beneficiary_country=GB&currency=GBP
6
6
  body:
7
- encoding: UTF-8
8
- string: currency=GBP&bank_account_country=GB&beneficiary_country=GB
7
+ encoding: US-ASCII
8
+ string: ''
9
9
  headers:
10
10
  X-Auth-Token:
11
11
  - 1c9da5726314246acfb09ec5651307a5
@@ -2,10 +2,10 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://devapi.thecurrencycloud.com/v2/reference/conversion_dates
5
+ uri: https://devapi.thecurrencycloud.com/v2/reference/conversion_dates?conversion_pair=GBPUSD
6
6
  body:
7
- encoding: UTF-8
8
- string: conversion_pair=GBPUSD
7
+ encoding: US-ASCII
8
+ string: ''
9
9
  headers:
10
10
  X-Auth-Token:
11
11
  - 1c9da5726314246acfb09ec5651307a5
@@ -2,10 +2,10 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://devapi.thecurrencycloud.com/v2/reference/settlement_accounts
5
+ uri: https://devapi.thecurrencycloud.com/v2/reference/settlement_accounts?currency=GBP
6
6
  body:
7
- encoding: UTF-8
8
- string: currency=GBP
7
+ encoding: US-ASCII
8
+ string: ''
9
9
  headers:
10
10
  X-Auth-Token:
11
11
  - 1c9da5726314246acfb09ec5651307a5
@@ -0,0 +1,102 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://devapi.thecurrencycloud.com/v2/conversions/create
6
+ body:
7
+ encoding: UTF-8
8
+ string: buy_currency=GBP&sell_currency=USD&fixed_side=buy&amount=1000&reason=mortgage%20payment&term_agreement=true
9
+ headers:
10
+ X-Auth-Token:
11
+ - 6f5f99d1b860fc47e8a186e3dce0d3f9
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Server:
18
+ - nginx
19
+ Date:
20
+ - Mon, 04 May 2015 20:28:29 GMT
21
+ Content-Type:
22
+ - application/json;charset=utf-8
23
+ Content-Length:
24
+ - '865'
25
+ Connection:
26
+ - keep-alive
27
+ X-Request-Id:
28
+ - '2778807612227406608'
29
+ X-Content-Type-Options:
30
+ - nosniff
31
+ body:
32
+ encoding: UTF-8
33
+ string: '{"id":"24d2ee7f-c7a3-4181-979e-9c58dbace992","settlement_date":"2015-05-06T14:00:00+00:00","conversion_date":"2015-05-06T00:00:00+00:00","short_reference":"20150504-PGRNVJ","creator_contact_id":"c4d838e8-1625-44c6-a9fb-39bcb1fe353d","account_id":"8ec3a69b-02d1-4f09-9a6b-6bd54a61b3a8","currency_pair":"GBPUSD","status":"awaiting_funds","buy_currency":"GBP","sell_currency":"USD","client_buy_amount":"1000.00","client_sell_amount":"1511.70","fixed_side":"buy","mid_market_rate":"1.5118","core_rate":"1.5117","partner_rate":"","partner_status":"funds_arrived","partner_buy_amount":"0.00","partner_sell_amount":"0.00","client_rate":"1.5117","deposit_required":false,"deposit_amount":"0.00","deposit_currency":"","deposit_status":"not_required","deposit_required_at":"","payment_ids":[],"created_at":"2015-05-04T20:28:29+00:00","updated_at":"2015-05-04T20:28:29+00:00"}'
34
+ http_version:
35
+ recorded_at: Mon, 04 May 2015 20:28:29 GMT
36
+ - request:
37
+ method: post
38
+ uri: https://devapi.thecurrencycloud.com/v2/settlements/create
39
+ body:
40
+ encoding: US-ASCII
41
+ string: ''
42
+ headers:
43
+ X-Auth-Token:
44
+ - 6f5f99d1b860fc47e8a186e3dce0d3f9
45
+ response:
46
+ status:
47
+ code: 200
48
+ message: OK
49
+ headers:
50
+ Server:
51
+ - nginx
52
+ Date:
53
+ - Mon, 04 May 2015 20:29:16 GMT
54
+ Content-Type:
55
+ - application/json;charset=utf-8
56
+ Content-Length:
57
+ - '243'
58
+ Connection:
59
+ - keep-alive
60
+ X-Request-Id:
61
+ - '2778808011768427319'
62
+ X-Content-Type-Options:
63
+ - nosniff
64
+ body:
65
+ encoding: UTF-8
66
+ string: '{"id":"63eeef54-3531-4e65-827a-7d0f37503fcc","status":"open","short_reference":"20150504-RKNNBH","type":"bulk","conversion_ids":[],"entries":[],"created_at":"2015-05-04T20:29:16+00:00","updated_at":"2015-05-04T20:29:16+00:00","released_at":""}'
67
+ http_version:
68
+ recorded_at: Mon, 04 May 2015 20:29:16 GMT
69
+ - request:
70
+ method: post
71
+ uri: https://devapi.thecurrencycloud.com/v2/settlements/63eeef54-3531-4e65-827a-7d0f37503fcc/add_conversion
72
+ body:
73
+ encoding: UTF-8
74
+ string: conversion_id=24d2ee7f-c7a3-4181-979e-9c58dbace992
75
+ headers:
76
+ X-Auth-Token:
77
+ - 6f5f99d1b860fc47e8a186e3dce0d3f9
78
+ response:
79
+ status:
80
+ code: 200
81
+ message: OK
82
+ headers:
83
+ Server:
84
+ - nginx
85
+ Date:
86
+ - Mon, 04 May 2015 20:40:57 GMT
87
+ Content-Type:
88
+ - application/json;charset=utf-8
89
+ Content-Length:
90
+ - '396'
91
+ Connection:
92
+ - keep-alive
93
+ X-Request-Id:
94
+ - '2778813884314110346'
95
+ X-Content-Type-Options:
96
+ - nosniff
97
+ body:
98
+ encoding: UTF-8
99
+ string: '{"id":"63eeef54-3531-4e65-827a-7d0f37503fcc","status":"open","short_reference":"20150504-RKNNBH","type":"bulk","conversion_ids":["24d2ee7f-c7a3-4181-979e-9c58dbace992"],"entries":[{"GBP":{"receive_amount":"1000.00","send_amount":"0.00"}},{"USD":{"receive_amount":"0.00","send_amount":"1511.70"}}],"created_at":"2015-05-04T20:29:16+00:00","updated_at":"2015-05-04T20:40:56+00:00","released_at":""}'
100
+ http_version:
101
+ recorded_at: Mon, 04 May 2015 20:40:57 GMT
102
+ recorded_with: VCR 2.9.3