remitano 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +13 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +127 -0
  7. data/LICENSE.txt +20 -0
  8. data/README.md +115 -0
  9. data/Rakefile +51 -0
  10. data/bin/remitano +20 -0
  11. data/lib/remitano.rb +2 -0
  12. data/lib/remitano/client.rb +98 -0
  13. data/lib/remitano/client/action_confirmations.rb +29 -0
  14. data/lib/remitano/client/coin_accounts.rb +9 -0
  15. data/lib/remitano/client/coin_collection.rb +18 -0
  16. data/lib/remitano/client/coin_withdrawals.rb +24 -0
  17. data/lib/remitano/client/collection.rb +29 -0
  18. data/lib/remitano/client/fiat_accounts.rb +9 -0
  19. data/lib/remitano/client/fiat_collection.rb +18 -0
  20. data/lib/remitano/client/helper.rb +14 -0
  21. data/lib/remitano/client/merchant_charges.rb +24 -0
  22. data/lib/remitano/client/merchant_withdrawals.rb +38 -0
  23. data/lib/remitano/client/net.rb +100 -0
  24. data/lib/remitano/client/offers.rb +21 -0
  25. data/lib/remitano/client/orders.rb +26 -0
  26. data/lib/remitano/client/public/offers.rb +18 -0
  27. data/lib/remitano/client/public/price_ladders.rb +7 -0
  28. data/lib/remitano/client/public/rates.rb +12 -0
  29. data/lib/remitano/client/trades.rb +37 -0
  30. data/lib/remitano/version.rb +3 -0
  31. data/remitano.gemspec +40 -0
  32. data/spec/client/merchant_charges_spec.rb +66 -0
  33. data/spec/client/merchant_withdrawals_spec.rb +111 -0
  34. data/spec/coin_accounts_spec.rb +11 -0
  35. data/spec/fiat_accounts_spec.rb +11 -0
  36. data/spec/fixtures/vcr_cassettes/Remitano_Client_merchant_charges/_create/invalid_params/raises_error.yml +51 -0
  37. data/spec/fixtures/vcr_cassettes/Remitano_Client_merchant_charges/_create/valid_params/returns_created_charge.yml +53 -0
  38. data/spec/fixtures/vcr_cassettes/Remitano_Client_merchant_charges/_get/object_exists/returns_charge_data.yml +48 -0
  39. data/spec/fixtures/vcr_cassettes/Remitano_Client_merchant_charges/_get/object_not_found/raises_error.yml +46 -0
  40. data/spec/fixtures/vcr_cassettes/Remitano_Client_merchant_withdrawals/_create/invalid_params/raises_error.yml +52 -0
  41. data/spec/fixtures/vcr_cassettes/Remitano_Client_merchant_withdrawals/_create/valid_params/auto_confirms_withdrawal_with_htop_and_returns_created_withdrawal.yml +296 -0
  42. data/spec/fixtures/vcr_cassettes/Remitano_Client_merchant_withdrawals/_get/object_exists/returns_withdrawal_data.yml +48 -0
  43. data/spec/fixtures/vcr_cassettes/Remitano_Client_merchant_withdrawals/_get/object_not_found/raises_error.yml +46 -0
  44. data/spec/fixtures/vcr_cassettes/remitano/coin_accounts/me.yml +52 -0
  45. data/spec/fixtures/vcr_cassettes/remitano/fiat_accounts/me.yml +52 -0
  46. data/spec/fixtures/vcr_cassettes/remitano/my_offers/sell.yml +47 -0
  47. data/spec/fixtures/vcr_cassettes/remitano/offers/update.yml +94 -0
  48. data/spec/fixtures/vcr_cassettes/remitano/orders/cancel.yml +54 -0
  49. data/spec/fixtures/vcr_cassettes/remitano/orders/create.yml +54 -0
  50. data/spec/fixtures/vcr_cassettes/remitano/orders/open.yml +54 -0
  51. data/spec/fixtures/vcr_cassettes/remitano/price_ladders/sell.yml +48 -0
  52. data/spec/fixtures/vcr_cassettes/remitano/rates.yml +44 -0
  53. data/spec/fixtures/vcr_cassettes/remitano/trades/active.yml +46 -0
  54. data/spec/fixtures/vcr_cassettes/remitano/trades/completed.yml +46 -0
  55. data/spec/fixtures/vcr_cassettes/remitano/trades/release.yml +144 -0
  56. data/spec/offers_spec.rb +18 -0
  57. data/spec/orders_spec.rb +29 -0
  58. data/spec/public/price_ladders_spec.rb +11 -0
  59. data/spec/public/rates_spec.rb +10 -0
  60. data/spec/spec_helper.rb +25 -0
  61. data/spec/support/crendentials.rb +12 -0
  62. data/spec/support/request_usec.rb +5 -0
  63. data/spec/support/vcr.rb +22 -0
  64. data/spec/trades_spec.rb +39 -0
  65. metadata +329 -0
@@ -0,0 +1,3 @@
1
+ module Remitano
2
+ VERSION = "1.5.0"
3
+ end
data/remitano.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: remitano 0.4.0 ruby lib
6
+ lib = File.expand_path('../lib', __FILE__)
7
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
8
+ require "remitano/version"
9
+
10
+ Gem::Specification.new do |spec|
11
+ spec.name = "remitano"
12
+ spec.version = Remitano::VERSION
13
+
14
+ spec.authors = ["Phuong Nguyen"]
15
+ spec.description = "Ruby API for use with remitano."
16
+ spec.email = "phuongnd08@gmail.com"
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.homepage = "http://github.com/remitano/remitano-ruby"
19
+ spec.licenses = ["MIT"]
20
+ spec.require_paths = ["lib"]
21
+ spec.summary = "Remitano Ruby API"
22
+
23
+ spec.add_runtime_dependency("activesupport", [">= 4.2.10"])
24
+ spec.add_runtime_dependency("rest-client", [">= 1.7.3"])
25
+ spec.add_runtime_dependency("ruby-hmac", ["= 0.4.0"])
26
+ spec.add_runtime_dependency("api-auth", ["~> 2.1.0"])
27
+ spec.add_runtime_dependency("hashie")
28
+ spec.add_runtime_dependency("rotp")
29
+ spec.add_development_dependency("rspec", [">= 0"])
30
+ spec.add_development_dependency("rspec-mocks", [">= 3.8"])
31
+ spec.add_development_dependency("rdoc", ["~> 3.12"])
32
+ spec.add_development_dependency("bundler")
33
+ spec.add_development_dependency("jeweler", ["~> 1.8.4"])
34
+ spec.add_development_dependency("dotenv", ["~> 2.0.0"])
35
+ spec.add_development_dependency("vcr", ["~> 4.0.0"])
36
+ spec.add_development_dependency("webmock", ["~> 3.3.0"])
37
+ spec.add_development_dependency("byebug")
38
+ spec.add_development_dependency("thor")
39
+ end
40
+
@@ -0,0 +1,66 @@
1
+ require "spec_helper"
2
+
3
+ describe "Remitano::Client#merchant_charges" do
4
+ describe "#get", :vcr do
5
+ context "object not found" do
6
+ it "raises error" do
7
+ client = Remitano::Client.default
8
+ expect do
9
+ client.merchant_charges.get("invalid_id")
10
+ end.to raise_error(Remitano::Client::Request::RequestError, "Error 404 {\"error\":\"Not found\"}")
11
+ end
12
+ end
13
+
14
+ context "object exists" do
15
+ it "returns charge data" do
16
+ client = Remitano::Client.default
17
+ result = client.merchant_charges.get(19)
18
+ expect(result).to eq(
19
+ "cancelled_or_completed_callback_url" => "http://sample.com/123/callback",
20
+ "coin_amount" => 100.0,
21
+ "coin_currency" => "usdt",
22
+ "created_at_timestamp" => 1620093168,
23
+ "id" => 19,
24
+ "remitano_payment_url" => "localhost:3200/payment_gateway/pay/MDR1248236781",
25
+ "status" => "completed"
26
+ )
27
+ end
28
+ end
29
+ end
30
+
31
+ describe "#create", :vcr do
32
+ context "invalid params" do
33
+ it "raises error" do
34
+ client = Remitano::Client.default
35
+ expect do
36
+ client.merchant_charges.create(
37
+ coin_currency: "btc",
38
+ coin_amount: 10.99,
39
+ cancelled_or_completed_callback_url: "http://sample.com/123/callback"
40
+ )
41
+ end.to raise_error(Remitano::Client::Request::RequestError, "Error 400 {\"error\":\"coin_currency does not have a valid value\"}")
42
+ end
43
+ end
44
+
45
+ context "valid params" do
46
+ it "returns created charge" do
47
+ client = Remitano::Client.default
48
+
49
+ result = client.merchant_charges.create(
50
+ coin_currency: "usdt",
51
+ coin_amount: 10.99,
52
+ cancelled_or_completed_callback_url: "http://sample.com/123/callback"
53
+ )
54
+ expect(result).to eq(
55
+ "cancelled_or_completed_callback_url" => "http://sample.com/123/callback",
56
+ "coin_amount" => 10.99,
57
+ "coin_currency" => "usdt",
58
+ "created_at_timestamp" => 1621497377,
59
+ "id" => 22,
60
+ "remitano_payment_url" => "localhost:3200/payment_gateway/pay/MDR5588788611",
61
+ "status" => "pending"
62
+ )
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,111 @@
1
+ require "spec_helper"
2
+
3
+ describe "Remitano::Client#merchant_withdrawals" do
4
+ describe "#get", :vcr do
5
+ context "object not found" do
6
+ it "raises error" do
7
+ client = Remitano::Client.default
8
+ expect do
9
+ client.merchant_withdrawals.get("invalid_id")
10
+ end.to raise_error(Remitano::Client::Request::RequestError, "Error 404 {\"error\":\"Not found\"}")
11
+ end
12
+ end
13
+
14
+ context "object exists" do
15
+ it "returns withdrawal data" do
16
+ client = Remitano::Client.default
17
+ result = client.merchant_withdrawals.get(1)
18
+ expect(result).to eq(
19
+ "action_confirmation_id" => nil,
20
+ "cancelled_or_completed_callback_url" => "http://dummy.com/111",
21
+ "coin_address" => "3BDS42pbFgxDn9uMSCBiWE5BcWFBVPPCAA",
22
+ "coin_amount" => 100.0,
23
+ "coin_currency" => "usdt",
24
+ "coin_fee" => 0.0,
25
+ "created_at_timestamp" => 1621401962,
26
+ "destination_tag" => nil,
27
+ "id" => 1,
28
+ "merchant_withdrawal_ref" => "mwr2",
29
+ "otp_counter" => nil,
30
+ "receiver_pay_fee" => nil,
31
+ "remitano_phone_number" => nil,
32
+ "remitano_username" => nil,
33
+ "status" => "cancelled"
34
+ )
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "#create", :vcr do
40
+ context "invalid params" do
41
+ it "raises error" do
42
+ client = Remitano::Client.default
43
+ expect do
44
+ client.merchant_withdrawals.create(
45
+ merchant_withdrawal_ref: "akh9r1h29e1",
46
+ coin_currency: "xrp",
47
+ coin_amount: 10.99,
48
+ receiver_pay_fee: true,
49
+ cancelled_or_completed_callback_url: "http://sample.com/123/callback",
50
+ coin_address: "rLpumSZQNJ6Cve7hfQcdkG9rJbJhkSV8AD0",
51
+ destination_tag: 1710676231
52
+ )
53
+ end.to raise_error(
54
+ Remitano::Client::Request::RequestError,
55
+ "Error 422 {\"error\":\"Merchant withdrawal ref has already been taken, Coin address is invalid\"}"
56
+ )
57
+ end
58
+ end
59
+
60
+ context "valid params" do
61
+ it "auto confirms withdrawal with htop and returns created withdrawal" do
62
+ client = Remitano::Client.default
63
+ expect(client.action_confirmations).to receive(:confirm_by_hotp!).and_call_original
64
+ create_result = client.merchant_withdrawals.create(
65
+ merchant_withdrawal_ref: "akh9r1h29e16",
66
+ coin_currency: "xrp",
67
+ coin_amount: 10.99,
68
+ receiver_pay_fee: true,
69
+ cancelled_or_completed_callback_url: "http://sample.com/123/callback",
70
+ coin_address: "rLpumSZQNJ6Cve7hfQcdkG9rJbJhkSV8AD",
71
+ destination_tag: 1710676231
72
+ )
73
+ expect(create_result).to eq(
74
+ "action_confirmation_id" => 32,
75
+ "cancelled_or_completed_callback_url" => "http://sample.com/123/callback",
76
+ "coin_address" => "rLpumSZQNJ6Cve7hfQcdkG9rJbJhkSV8AD",
77
+ "coin_amount" => 10.99,
78
+ "coin_currency" => "xrp",
79
+ "coin_fee" => 0.00002,
80
+ "created_at_timestamp" => 1621786247,
81
+ "destination_tag" => 1710676231,
82
+ "id" => 16,
83
+ "merchant_withdrawal_ref" => "akh9r1h29e16",
84
+ "otp_counter" => 32,
85
+ "receiver_pay_fee" => true,
86
+ "remitano_phone_number" => nil,
87
+ "remitano_username" => nil,
88
+ "status" => "pending"
89
+ )
90
+ get_result = client.merchant_withdrawals.get(create_result["id"])
91
+ expect(get_result).to eq(
92
+ "action_confirmation_id" => nil,
93
+ "cancelled_or_completed_callback_url" => "http://sample.com/123/callback",
94
+ "coin_address" => "rLpumSZQNJ6Cve7hfQcdkG9rJbJhkSV8AD",
95
+ "coin_amount" => 10.99,
96
+ "coin_currency" => "xrp",
97
+ "coin_fee" => 0.00002,
98
+ "created_at_timestamp" => 1621786247,
99
+ "destination_tag" => 1710676231,
100
+ "id" => 16,
101
+ "merchant_withdrawal_ref" => "akh9r1h29e16",
102
+ "otp_counter" => nil,
103
+ "receiver_pay_fee" => true,
104
+ "remitano_phone_number" => nil,
105
+ "remitano_username" => nil,
106
+ "status" => "processing"
107
+ )
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Remitano::Client#coin_accounts" do
4
+ describe :me, vcr: {cassette_name: 'remitano/coin_accounts/me'} do
5
+ subject { Remitano::Client.default.coin_accounts("btc") }
6
+ it "returns my btc coin account" do
7
+ result = subject.me
8
+ expect(result.main.address).to eq("1NHy9krGCkkyNswx4Zu1MzxKRmnJ7j8W7c")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Remitano::Client#fiat_accounts" do
4
+ describe :me, vcr: {cassette_name: 'remitano/fiat_accounts/me'} do
5
+ subject { Remitano::Client.default.fiat_accounts("zar") }
6
+ it "returns my zar fiat account" do
7
+ result = subject.me
8
+ expect(result.balance).to eq(0)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,51 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: REMITANO_SERVER/api/v1/merchant/merchant_deposit_requests
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"coin_currency":"btc","coin_amount":10.99,"cancelled_or_completed_callback_url":"http://sample.com/123/callback","usec":0}'
9
+ headers:
10
+ Accept:
11
+ - "*/*"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - rest-client/2.0.2 (darwin18.6.0 x86_64) ruby/2.4.3p205
16
+ Content-Type:
17
+ - application/json
18
+ Date:
19
+ - Thu, 20 May 2021 07:56:17 GMT
20
+ Authorization:
21
+ - APIAuth REMITANO_KEY:akR0rFptWoW1vcCrks1V0xJT+Zc=
22
+ Content-Length:
23
+ - '123'
24
+ Host:
25
+ - localhost:3100
26
+ response:
27
+ status:
28
+ code: 400
29
+ message: Bad Request
30
+ headers:
31
+ Content-Type:
32
+ - application/json
33
+ Cache-Control:
34
+ - no-cache
35
+ Set-Cookie:
36
+ - _admin_session=5a6392301594387531dc5fe15078d4c7; path=/; expires=Sun, 20 Jun
37
+ 2021 07:56:17 -0000; HttpOnly; SameSite=Lax
38
+ X-Request-Id:
39
+ - 8743d580-4833-436c-a7ad-2bdb1ce0d92b
40
+ X-Runtime:
41
+ - '0.188461'
42
+ Vary:
43
+ - Origin
44
+ Content-Length:
45
+ - '53'
46
+ body:
47
+ encoding: UTF-8
48
+ string: '{"error":"coin_currency does not have a valid value"}'
49
+ http_version:
50
+ recorded_at: Thu, 20 May 2021 07:56:17 GMT
51
+ recorded_with: VCR 4.0.0
@@ -0,0 +1,53 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: REMITANO_SERVER/api/v1/merchant/merchant_deposit_requests
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"coin_currency":"usdt","coin_amount":10.99,"cancelled_or_completed_callback_url":"http://sample.com/123/callback","usec":0}'
9
+ headers:
10
+ Accept:
11
+ - "*/*"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - rest-client/2.0.2 (darwin18.6.0 x86_64) ruby/2.4.3p205
16
+ Content-Type:
17
+ - application/json
18
+ Date:
19
+ - Thu, 20 May 2021 07:56:16 GMT
20
+ Authorization:
21
+ - APIAuth REMITANO_KEY:0pdHyvw02icAuAn3g/zRfu3J2Po=
22
+ Content-Length:
23
+ - '124'
24
+ Host:
25
+ - localhost:3100
26
+ response:
27
+ status:
28
+ code: 201
29
+ message: Created
30
+ headers:
31
+ Content-Type:
32
+ - application/json
33
+ Etag:
34
+ - W/"0ece713edd013b8fab04d54b911fc1bb"
35
+ Cache-Control:
36
+ - max-age=0, private, must-revalidate
37
+ Set-Cookie:
38
+ - _admin_session=47d8924b33b14bf08df29e7d044352a0; path=/; expires=Sun, 20 Jun
39
+ 2021 07:56:17 -0000; HttpOnly; SameSite=Lax
40
+ X-Request-Id:
41
+ - a73a5639-b76a-48fa-9e1a-e964ee60bad4
42
+ X-Runtime:
43
+ - '0.417483'
44
+ Vary:
45
+ - Origin
46
+ Content-Length:
47
+ - '250'
48
+ body:
49
+ encoding: UTF-8
50
+ string: '{"id":22,"coin_currency":"usdt","coin_amount":10.99,"status":"pending","cancelled_or_completed_callback_url":"http://sample.com/123/callback","remitano_payment_url":"localhost:3200/payment_gateway/pay/MDR5588788611","created_at_timestamp":1621497377}'
51
+ http_version:
52
+ recorded_at: Thu, 20 May 2021 07:56:17 GMT
53
+ recorded_with: VCR 4.0.0
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: REMITANO_SERVER/api/v1/merchant/merchant_deposit_requests/19?usec=0
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - "*/*"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - rest-client/2.0.2 (darwin18.6.0 x86_64) ruby/2.4.3p205
16
+ Content-Type:
17
+ - application/json
18
+ Date:
19
+ - Thu, 20 May 2021 07:56:17 GMT
20
+ Authorization:
21
+ - APIAuth REMITANO_KEY:VadfZMIlT9uCpiuPji5d7maRt84=
22
+ Host:
23
+ - localhost:3100
24
+ response:
25
+ status:
26
+ code: 200
27
+ message: OK
28
+ headers:
29
+ Content-Type:
30
+ - application/json
31
+ Etag:
32
+ - W/"6a2f6607a585f23c1a8ca6136a01f504"
33
+ Cache-Control:
34
+ - max-age=0, private, must-revalidate
35
+ X-Request-Id:
36
+ - 84cc3beb-3954-43ab-8b00-7e5429dc14c5
37
+ X-Runtime:
38
+ - '0.132881'
39
+ Vary:
40
+ - Origin
41
+ Content-Length:
42
+ - '252'
43
+ body:
44
+ encoding: UTF-8
45
+ string: '{"id":19,"coin_currency":"usdt","coin_amount":100.0,"status":"completed","cancelled_or_completed_callback_url":"http://sample.com/123/callback","remitano_payment_url":"localhost:3200/payment_gateway/pay/MDR1248236781","created_at_timestamp":1620093168}'
46
+ http_version:
47
+ recorded_at: Thu, 20 May 2021 07:56:17 GMT
48
+ recorded_with: VCR 4.0.0
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: REMITANO_SERVER/api/v1/merchant/merchant_deposit_requests/invalid_id?usec=0
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - "*/*"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - rest-client/2.0.2 (darwin18.6.0 x86_64) ruby/2.4.3p205
16
+ Content-Type:
17
+ - application/json
18
+ Date:
19
+ - Thu, 20 May 2021 07:56:17 GMT
20
+ Authorization:
21
+ - APIAuth REMITANO_KEY:2z3GK2whsVNlxz9NZmGsyOKMYmU=
22
+ Host:
23
+ - localhost:3100
24
+ response:
25
+ status:
26
+ code: 404
27
+ message: Not Found
28
+ headers:
29
+ Content-Type:
30
+ - application/json
31
+ Cache-Control:
32
+ - no-cache
33
+ X-Request-Id:
34
+ - 2040d34e-fc09-4384-aed9-f4ed3eb030ea
35
+ X-Runtime:
36
+ - '0.173408'
37
+ Vary:
38
+ - Origin
39
+ Content-Length:
40
+ - '21'
41
+ body:
42
+ encoding: UTF-8
43
+ string: '{"error":"Not found"}'
44
+ http_version:
45
+ recorded_at: Thu, 20 May 2021 07:56:17 GMT
46
+ recorded_with: VCR 4.0.0