moip2 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +6 -12
- data/Gemfile +0 -1
- data/Gemfile.lock +4 -4
- data/README.md +142 -14
- data/changelog.md +55 -3
- data/examples/ecommerce/payment-with-boleto.rb +129 -0
- data/examples/ecommerce/payment-with-credit-card.rb +119 -0
- data/examples/ecommerce/payment-with-hash.rb +101 -0
- data/examples/marketplace/create-classical-account-company.rb +74 -0
- data/examples/marketplace/create-classical-account-without-company.rb +47 -0
- data/examples/marketplace/moip-connect.rb +31 -0
- data/examples/marketplace/payment-with-escrow.rb +88 -0
- data/examples/marketplace/payment-with-pre-authorization.rb +87 -0
- data/examples/marketplace/shared-cart.rb +220 -0
- data/lib/moip2/api.rb +17 -2
- data/lib/moip2/balances_api.rb +18 -0
- data/lib/moip2/bank_accounts_api.rb +51 -0
- data/lib/moip2/client.rb +11 -11
- data/lib/moip2/connect_api.rb +2 -13
- data/lib/moip2/connect_client.rb +11 -0
- data/lib/moip2/entry_api.rb +21 -0
- data/lib/moip2/multi_payment_api.rb +8 -0
- data/lib/moip2/order_api.rb +2 -1
- data/lib/moip2/resource/balances.rb +12 -0
- data/lib/moip2/resource/bank_account.rb +12 -0
- data/lib/moip2/resource/entry.rb +13 -0
- data/lib/moip2/version.rb +1 -1
- data/lib/moip2/webhooks_api.rb +20 -4
- data/lib/moip2.rb +7 -0
- data/moip2.gemspec +2 -0
- data/spec/moip2/balances_api_spec.rb +22 -0
- data/spec/moip2/bank_accounts_api_spec.rb +173 -0
- data/spec/moip2/client_spec.rb +13 -76
- data/spec/moip2/connect_api_spec.rb +1 -1
- data/spec/moip2/connect_client_spec.rb +63 -0
- data/spec/moip2/customer_api_spec.rb +3 -3
- data/spec/moip2/entry_api_spec.rb +43 -0
- data/spec/moip2/multi_payment_api_spec.rb +32 -2
- data/spec/moip2/order_api_spec.rb +24 -1
- data/spec/moip2/response_spec.rb +2 -6
- data/spec/moip2/webhooks_spec.rb +87 -11
- data/spec/moip2_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -14
- data/vcr_cassettes/bank_account_create_fail.yml +39 -0
- data/vcr_cassettes/bank_account_create_sucess.yml +41 -0
- data/vcr_cassettes/bank_account_deleted_existent.yml +38 -0
- data/vcr_cassettes/bank_account_deleted_nonexistent.yml +38 -0
- data/vcr_cassettes/bank_account_find_all.yml +9525 -0
- data/vcr_cassettes/bank_account_show_existent.yml +40 -0
- data/vcr_cassettes/bank_account_show_nonexistent.yml +38 -0
- data/vcr_cassettes/bank_account_update.yml +41 -0
- data/vcr_cassettes/capture_multi_payment_sucess.yml +44 -0
- data/vcr_cassettes/find_all_entries.yml +63 -0
- data/vcr_cassettes/find_all_orders_q_search.yml +39 -0
- data/vcr_cassettes/{get_webhooks.yml → find_all_webhooks.yml} +1 -1
- data/vcr_cassettes/find_all_webhooks_event.yml +42 -0
- data/vcr_cassettes/find_all_webhooks_limit.yml +48 -0
- data/vcr_cassettes/find_all_webhooks_multi_params.yml +38 -0
- data/vcr_cassettes/find_all_webhooks_no_filter.yml +58 -0
- data/vcr_cassettes/find_all_webhooks_offset.yml +58 -0
- data/vcr_cassettes/find_all_webhooks_resource_id.yml +38 -0
- data/vcr_cassettes/get_balances.yml +44 -0
- data/vcr_cassettes/show_entries.yml +43 -0
- data/vcr_cassettes/void_multi_payment_sucess.yml +46 -0
- metadata +50 -4
@@ -0,0 +1,51 @@
|
|
1
|
+
module Moip2
|
2
|
+
class BankAccountsApi
|
3
|
+
attr_reader :client
|
4
|
+
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
def create(account_id, bank_account)
|
10
|
+
Resource::BankAccount.new client, client.post(
|
11
|
+
base_account_path(account_id),
|
12
|
+
bank_account,
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def show(bank_account_id)
|
17
|
+
Resource::BankAccount.new client, client.get(
|
18
|
+
base_bank_account_path(bank_account_id),
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete(bank_account_id)
|
23
|
+
Resource::BankAccount.new client, client.delete(
|
24
|
+
base_bank_account_path(bank_account_id),
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def update(bank_account_id, bank_account)
|
29
|
+
Resource::BankAccount.new client, client.put(
|
30
|
+
base_bank_account_path(bank_account_id),
|
31
|
+
bank_account,
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_all(account_id)
|
36
|
+
Resource::BankAccount.new client, client.get(
|
37
|
+
base_account_path(account_id),
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def base_bank_account_path(bank_account_id)
|
44
|
+
"/v2/bankaccounts/#{bank_account_id}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def base_account_path(account_id)
|
48
|
+
"/v2/accounts/#{account_id}/bankaccounts"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/moip2/client.rb
CHANGED
@@ -4,12 +4,12 @@ module Moip2
|
|
4
4
|
|
5
5
|
attr_reader :env, :auth, :uri
|
6
6
|
|
7
|
-
def initialize(env = :sandbox, auth = nil,
|
7
|
+
def initialize(env = :sandbox, auth = nil, opts = {})
|
8
8
|
@env = env.to_sym
|
9
9
|
@auth = auth
|
10
10
|
@opts = opts
|
11
11
|
|
12
|
-
@uri =
|
12
|
+
@uri = get_base_uri
|
13
13
|
self.class.base_uri @uri
|
14
14
|
end
|
15
15
|
|
@@ -62,20 +62,20 @@ module Moip2
|
|
62
62
|
create_response resp
|
63
63
|
end
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
def get_base_uri(env)
|
68
|
-
return ENV["base_uri"] if ENV["base_uri"]
|
69
|
-
|
70
|
-
@env = env.to_sym
|
71
|
-
|
65
|
+
def host
|
72
66
|
if production?
|
73
|
-
"
|
67
|
+
"api.moip.com.br"
|
74
68
|
else
|
75
|
-
"
|
69
|
+
"sandbox.moip.com.br"
|
76
70
|
end
|
77
71
|
end
|
78
72
|
|
73
|
+
private
|
74
|
+
|
75
|
+
def get_base_uri
|
76
|
+
"https://#{host}"
|
77
|
+
end
|
78
|
+
|
79
79
|
def create_response(resp)
|
80
80
|
raise NotFoundError, "Resource not found" if resp.code == 404
|
81
81
|
|
data/lib/moip2/connect_api.rb
CHANGED
@@ -2,25 +2,14 @@ module Moip2
|
|
2
2
|
class ConnectApi
|
3
3
|
attr_reader :client
|
4
4
|
|
5
|
-
CONNECT_SANDBOX = "connect-sandbox.moip.com.br".freeze
|
6
|
-
CONNECT_PRODUCTION = "connect.moip.com.br".freeze
|
7
|
-
|
8
5
|
def initialize(client)
|
9
6
|
@client = client
|
10
7
|
end
|
11
8
|
|
12
|
-
def self.connect_uri(production = false)
|
13
|
-
production ? CONNECT_PRODUCTION : CONNECT_SANDBOX
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.host(env = :sandbox)
|
17
|
-
"https://#{connect_uri(env == :production)}"
|
18
|
-
end
|
19
|
-
|
20
9
|
def authorize_url(client_id, redirect_uri, scope)
|
21
10
|
URI::HTTPS.build(
|
22
|
-
host:
|
23
|
-
path:
|
11
|
+
host: client.host,
|
12
|
+
path: "/oauth/authorize",
|
24
13
|
query: URI.encode_www_form(
|
25
14
|
response_type: "code",
|
26
15
|
client_id: client_id,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Moip2
|
2
|
+
class EntryApi
|
3
|
+
attr_reader :client
|
4
|
+
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
def base_path
|
10
|
+
"/v2/entries"
|
11
|
+
end
|
12
|
+
|
13
|
+
def show(id)
|
14
|
+
Resource::Entry.new client, client.get("#{base_path}/#{id}")
|
15
|
+
end
|
16
|
+
|
17
|
+
def find_all
|
18
|
+
Resource::Entry.new client, client.get("#{base_path}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -17,5 +17,13 @@ module Moip2
|
|
17
17
|
def show(multi_payment_id)
|
18
18
|
Resource::MultiPayment.new client.get("/v2/multipayments/#{multi_payment_id}")
|
19
19
|
end
|
20
|
+
|
21
|
+
def capture(multi_payment_id)
|
22
|
+
Resource::MultiPayment.new client.post("/v2/multipayments/#{multi_payment_id}/capture", {})
|
23
|
+
end
|
24
|
+
|
25
|
+
def void(multi_payment_id)
|
26
|
+
Resource::MultiPayment.new client.post("/v2/multipayments/#{multi_payment_id}/void", {})
|
27
|
+
end
|
20
28
|
end
|
21
29
|
end
|
data/lib/moip2/order_api.rb
CHANGED
@@ -18,13 +18,14 @@ module Moip2
|
|
18
18
|
Resource::Order.new client, client.get("#{base_path}/#{id}")
|
19
19
|
end
|
20
20
|
|
21
|
-
def find_all(limit: nil, offset: nil, filters: nil)
|
21
|
+
def find_all(limit: nil, offset: nil, q: nil, filters: nil)
|
22
22
|
encoded_filters = Moip2::Util::FiltersEncoder.encode(filters)
|
23
23
|
|
24
24
|
# `URI.encode...` will accept nil params, but they will pollute the URI
|
25
25
|
params = {
|
26
26
|
limit: limit,
|
27
27
|
offset: offset,
|
28
|
+
q: q,
|
28
29
|
filters: encoded_filters,
|
29
30
|
}.reject { |_, value| value.nil? }
|
30
31
|
|
data/lib/moip2/version.rb
CHANGED
data/lib/moip2/webhooks_api.rb
CHANGED
@@ -6,12 +6,28 @@ module Moip2
|
|
6
6
|
@client = client
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
|
9
|
+
def find_all(limit: nil, offset: nil, resource_id: nil, event: nil)
|
10
|
+
# `URI.encode...` will accept nil params, but they will pollute the URI
|
11
|
+
params = {
|
12
|
+
limit: limit,
|
13
|
+
offset: offset,
|
14
|
+
resourceId: resource_id,
|
15
|
+
event: event,
|
16
|
+
}.reject { |_, value| value.nil? }
|
17
|
+
|
18
|
+
query_string = URI.encode_www_form(params)
|
19
|
+
path = "#{base_path}?#{query_string}"
|
20
|
+
response = client.get(path)
|
21
|
+
|
22
|
+
# We need to transform raw JSON in Webhooks objects
|
23
|
+
response.webhooks.map! { |webhooks| Resource::Webhooks.new client, webhooks }
|
24
|
+
Resource::Webhooks.new client, response
|
11
25
|
end
|
12
26
|
|
13
|
-
|
14
|
-
|
27
|
+
private
|
28
|
+
|
29
|
+
def base_path
|
30
|
+
"/v2/webhooks"
|
15
31
|
end
|
16
32
|
end
|
17
33
|
end
|
data/lib/moip2.rb
CHANGED
@@ -9,6 +9,7 @@ require "moip2/auth/oauth"
|
|
9
9
|
|
10
10
|
require "moip2/resource/account"
|
11
11
|
require "moip2/resource/order"
|
12
|
+
require "moip2/resource/entry"
|
12
13
|
require "moip2/resource/payment"
|
13
14
|
require "moip2/resource/multi_order"
|
14
15
|
require "moip2/resource/multi_payment"
|
@@ -20,10 +21,14 @@ require "moip2/resource/webhooks"
|
|
20
21
|
require "moip2/resource/connect"
|
21
22
|
require "moip2/resource/credit_card"
|
22
23
|
require "moip2/resource/notification"
|
24
|
+
require "moip2/resource/balances"
|
25
|
+
require "moip2/resource/bank_account"
|
23
26
|
|
24
27
|
require "moip2/response"
|
25
28
|
require "moip2/client"
|
29
|
+
require "moip2/connect_client"
|
26
30
|
require "moip2/order_api"
|
31
|
+
require "moip2/entry_api"
|
27
32
|
require "moip2/multi_order_api"
|
28
33
|
require "moip2/payment_api"
|
29
34
|
require "moip2/multi_payment_api"
|
@@ -36,6 +41,8 @@ require "moip2/webhooks_api"
|
|
36
41
|
require "moip2/accounts_api"
|
37
42
|
require "moip2/connect_api"
|
38
43
|
require "moip2/notifications_api"
|
44
|
+
require "moip2/balances_api"
|
45
|
+
require "moip2/bank_accounts_api"
|
39
46
|
|
40
47
|
require "moip2/exceptions/invalid_enviroment_error"
|
41
48
|
|
data/moip2.gemspec
CHANGED
@@ -13,6 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
"Caio Gama",
|
14
14
|
"João Lucas Lucchetta",
|
15
15
|
"Caio Gaspar",
|
16
|
+
"Jair Bressani Junior",
|
16
17
|
]
|
17
18
|
spec.email = [
|
18
19
|
"rodrigo.saito@moip.com.br",
|
@@ -20,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
20
21
|
"caio.gama@moip.com.br",
|
21
22
|
"joao.lucchetta@moip.com.br",
|
22
23
|
"caio.gaspar@moip.com.br",
|
24
|
+
"jair.bressani@moip.com.br",
|
23
25
|
]
|
24
26
|
spec.summary = "Ruby client for moip v2 api"
|
25
27
|
spec.description = "Ruby client for moip v2 api"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
describe Moip2::BalancesApi do
|
2
|
+
let(:balances_api) { described_class.new sandbox_oauth_client }
|
3
|
+
|
4
|
+
describe "#show" do
|
5
|
+
let(:balances) do
|
6
|
+
VCR.use_cassette("get_balances") do
|
7
|
+
balances_api.show
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it {
|
12
|
+
expect(balances).to have_attributes(
|
13
|
+
unavailable: be_an(Array),
|
14
|
+
future: be_an(Array),
|
15
|
+
current: be_an(Array),
|
16
|
+
)
|
17
|
+
}
|
18
|
+
it { expect(balances.unavailable.first).to have_attributes(amount: be_a(Numeric), currency: be_a(String)) }
|
19
|
+
it { expect(balances.future.first).to have_attributes(amount: be_a(Numeric), currency: be_a(String)) }
|
20
|
+
it { expect(balances.current.first).to have_attributes(amount: be_a(Numeric), currency: be_a(String)) }
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
describe Moip2::BankAccountsApi do
|
2
|
+
let(:bank_accounts_api) { described_class.new sandbox_client }
|
3
|
+
|
4
|
+
describe "#create" do
|
5
|
+
context "when given an existent moip account" do
|
6
|
+
let(:bank_account) do
|
7
|
+
{
|
8
|
+
bank_number: "237",
|
9
|
+
agency_number: "12345",
|
10
|
+
agency_check_number: "0",
|
11
|
+
account_number: "12345678",
|
12
|
+
account_check_number: "7",
|
13
|
+
type: "CHECKING",
|
14
|
+
holder: {
|
15
|
+
tax_document: {
|
16
|
+
type: "CPF",
|
17
|
+
number: "255.328.259-12",
|
18
|
+
},
|
19
|
+
fullname: "Jose Silva dos Santos",
|
20
|
+
},
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:created_bank_account) do
|
25
|
+
VCR.use_cassette("bank_account_create_sucess") do
|
26
|
+
bank_accounts_api.create("MPA-CULBBYHD11", bank_account)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "creates an bank_account accordingly" do
|
31
|
+
expect(created_bank_account.id).to_not be_nil
|
32
|
+
expect(created_bank_account.agency_number).to eq("12345")
|
33
|
+
expect(created_bank_account.holder.tax_document.number).to eq("255.328.259-12")
|
34
|
+
expect(created_bank_account.holder.tax_document.type).to eq("CPF")
|
35
|
+
expect(created_bank_account.holder.fullname).to eq("Jose Silva dos Santos")
|
36
|
+
expect(created_bank_account.account_number).to eq("12345678")
|
37
|
+
expect(created_bank_account.account_check_number).to eq("7")
|
38
|
+
expect(created_bank_account.bank_name).to_not be_nil
|
39
|
+
expect(created_bank_account.agency_check_number).to eq("0")
|
40
|
+
expect(created_bank_account.bank_number).to eq("237")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when given a nonexistent moip account" do
|
45
|
+
let(:non_created_bank_account) do
|
46
|
+
{
|
47
|
+
bank_number: "237",
|
48
|
+
agency_number: "12345",
|
49
|
+
agency_check_number: "0",
|
50
|
+
account_number: "12345678",
|
51
|
+
account_check_number: "7",
|
52
|
+
type: "CHECKING",
|
53
|
+
holder: {
|
54
|
+
tax_document: {
|
55
|
+
type: "CPF",
|
56
|
+
number: "255.328.259-12",
|
57
|
+
},
|
58
|
+
fullname: "Jose Silva dos Santos",
|
59
|
+
},
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
let(:bank_account) do
|
64
|
+
VCR.use_cassette("bank_account_create_fail") do
|
65
|
+
bank_accounts_api.create("MPA-F00B4R123456", non_created_bank_account)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it { expect(bank_account.response.code).to eq("401") }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#show" do
|
74
|
+
context "when given an existent bank_account" do
|
75
|
+
let(:bank_account) do
|
76
|
+
VCR.use_cassette("bank_account_show_existent") do
|
77
|
+
bank_accounts_api.show("BKA-YBG1D8FKXXMT")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it "shows an the bank_account accordingly" do
|
82
|
+
expect(bank_account.id).to_not be_nil
|
83
|
+
expect(bank_account.agency_number).to eq("12345")
|
84
|
+
expect(bank_account.holder.tax_document.number).to eq("255.328.259-12")
|
85
|
+
expect(bank_account.holder.tax_document.type).to eq("CPF")
|
86
|
+
expect(bank_account.holder.fullname).to eq("Jose Silva dos Santos")
|
87
|
+
expect(bank_account.account_number).to eq("12345678")
|
88
|
+
expect(bank_account.account_check_number).to eq("7")
|
89
|
+
expect(bank_account.bank_name).to_not be_nil
|
90
|
+
expect(bank_account.agency_check_number).to eq("0")
|
91
|
+
expect(bank_account.bank_number).to eq("237")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "when given a nonexistent account" do
|
96
|
+
let(:bank_account) do
|
97
|
+
VCR.use_cassette("bank_account_show_nonexistent") do
|
98
|
+
bank_accounts_api.show("BKA-F00B4R123456")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it { expect { bank_account }.to raise_error(Moip2::NotFoundError) }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#find_all" do
|
107
|
+
let(:bank_account) do
|
108
|
+
VCR.use_cassette("bank_account_find_all") do
|
109
|
+
bank_accounts_api.find_all("MPA-CULBBYHD11")
|
110
|
+
end
|
111
|
+
end
|
112
|
+
it { expect(bank_account.first["id"]).to eq("BKA-EQW51MWMAO22") }
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "#update" do
|
116
|
+
let(:bank_account) do
|
117
|
+
{
|
118
|
+
bank_number: "237",
|
119
|
+
agency_number: "54321",
|
120
|
+
agency_check_number: "0",
|
121
|
+
account_number: "12345678",
|
122
|
+
account_check_number: "7",
|
123
|
+
type: "CHECKING",
|
124
|
+
holder: {
|
125
|
+
tax_document: {
|
126
|
+
type: "CPF",
|
127
|
+
number: "255.328.259-12",
|
128
|
+
},
|
129
|
+
fullname: "Jose Silva dos Santos",
|
130
|
+
},
|
131
|
+
}
|
132
|
+
end
|
133
|
+
|
134
|
+
let(:updated_bank_account) do
|
135
|
+
VCR.use_cassette("bank_account_update") do
|
136
|
+
bank_accounts_api.update("BKA-QQSVKMC06A6I", bank_account)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
it "returns an bank_account accordingly to the update" do
|
141
|
+
expect(updated_bank_account.id).to_not be_nil
|
142
|
+
expect(updated_bank_account.agency_number).to eq("54321")
|
143
|
+
expect(updated_bank_account.holder.tax_document.number).to eq("255.328.259-12")
|
144
|
+
expect(updated_bank_account.holder.tax_document.type).to eq("CPF")
|
145
|
+
expect(updated_bank_account.holder.fullname).to eq("Jose Silva dos Santos")
|
146
|
+
expect(updated_bank_account.account_number).to eq("12345678")
|
147
|
+
expect(updated_bank_account.account_check_number).to eq("7")
|
148
|
+
expect(updated_bank_account.bank_name).to_not be_nil
|
149
|
+
expect(updated_bank_account.agency_check_number).to eq("0")
|
150
|
+
expect(updated_bank_account.bank_number).to eq("237")
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "#delete" do
|
155
|
+
context "when given an existent bank account" do
|
156
|
+
let(:bank_account) do
|
157
|
+
VCR.use_cassette("bank_account_deleted_existent") do
|
158
|
+
bank_accounts_api.delete("BKA-YBG1D8FKXXMT")
|
159
|
+
end
|
160
|
+
end
|
161
|
+
it { expect(bank_account.response.code).to eq("200") }
|
162
|
+
end
|
163
|
+
|
164
|
+
context "when given a nonexistent bank account" do
|
165
|
+
let(:bank_account) do
|
166
|
+
VCR.use_cassette("bank_account_deleted_nonexistent") do
|
167
|
+
bank_accounts_api.delete("BKA-F00B4R123456")
|
168
|
+
end
|
169
|
+
end
|
170
|
+
it { expect { bank_account }.to raise_error(Moip2::NotFoundError) }
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
data/spec/moip2/client_spec.rb
CHANGED
@@ -16,105 +16,42 @@ describe Moip2::Client do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "initialize on sandbox with OAuth" do
|
19
|
-
let(:client) do
|
20
|
-
described_class.new :sandbox, auth
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:client) { described_class.new :sandbox, oauth }
|
24
|
-
it { expect(client.uri).to eq ENV["sandbox_url"] }
|
25
|
-
it { expect(client.env).to eq :sandbox }
|
26
|
-
it {
|
27
|
-
expect(client.opts[:headers]["Authorization"]).to eq "OAuth 9fdc242631454d4c95d82e27b4127394_v2"
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "initialize on production" do
|
32
|
-
let(:client) do
|
33
|
-
described_class.new :production, oauth
|
34
|
-
end
|
35
|
-
|
36
|
-
it { expect(client.uri).to eq "https://api.moip.com.br" }
|
37
|
-
it { expect(client.env).to eq :production }
|
38
|
-
it {
|
39
|
-
expect(client.opts[:headers]["Authorization"]).to eq "OAuth 9fdc242631454d4c95d82e27b4127394_v2"
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "initialize on sandbox with base_uri and OAuth" do
|
44
|
-
before do
|
45
|
-
ENV["base_uri"] = "http://localhost:5000"
|
46
|
-
end
|
47
|
-
|
48
19
|
let(:client) do
|
49
20
|
described_class.new :sandbox, oauth
|
50
21
|
end
|
51
22
|
|
52
|
-
it { expect(client.uri).to eq "
|
23
|
+
it { expect(client.uri).to eq "https://sandbox.moip.com.br" }
|
53
24
|
it { expect(client.env).to eq :sandbox }
|
54
|
-
it
|
55
|
-
expect(client.opts[:headers]["Authorization"]).
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "initialize on production with base_uri and OAuth" do
|
60
|
-
before do
|
61
|
-
ENV["base_uri"] = "http://localhost:5000"
|
25
|
+
it do
|
26
|
+
expect(client.opts[:headers]["Authorization"]).
|
27
|
+
to eq "OAuth 9fdc242631454d4c95d82e27b4127394_v2"
|
62
28
|
end
|
29
|
+
end
|
63
30
|
|
31
|
+
describe "initialize on production with OAuth" do
|
64
32
|
let(:client) do
|
65
33
|
described_class.new :production, oauth
|
66
34
|
end
|
67
35
|
|
68
|
-
it { expect(client.uri).to eq "
|
36
|
+
it { expect(client.uri).to eq "https://api.moip.com.br" }
|
69
37
|
it { expect(client.env).to eq :production }
|
70
|
-
it
|
71
|
-
expect(client.opts[:headers]["Authorization"]).
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
describe "initialize on sandbox with base_uri" do
|
76
|
-
before do
|
77
|
-
ENV["base_uri"] = "http://localhost:5000"
|
78
|
-
end
|
79
|
-
|
80
|
-
let(:client) do
|
81
|
-
described_class.new :sandbox, auth
|
38
|
+
it do
|
39
|
+
expect(client.opts[:headers]["Authorization"]).
|
40
|
+
to eq "OAuth 9fdc242631454d4c95d82e27b4127394_v2"
|
82
41
|
end
|
83
|
-
|
84
|
-
it { expect(client.uri).to eq "http://localhost:5000" }
|
85
|
-
it { expect(client.env).to eq :sandbox }
|
86
|
-
it { expect(client.opts[:headers]["Authorization"]).to eq "Basic VE9LRU46U0VDUkVU" }
|
87
42
|
end
|
88
43
|
|
89
|
-
describe "initialize on
|
90
|
-
before do
|
91
|
-
ENV["base_uri"] = "http://localhost:5000"
|
92
|
-
end
|
93
|
-
|
94
|
-
let(:client) do
|
95
|
-
described_class.new :production, auth
|
96
|
-
end
|
97
|
-
|
98
|
-
it { expect(client.uri).to eq "http://localhost:5000" }
|
99
|
-
it { expect(client.env).to eq :production }
|
100
|
-
it { expect(client.opts[:headers]["Authorization"]).to eq "Basic VE9LRU46U0VDUkVU" }
|
101
|
-
end
|
102
|
-
|
103
|
-
describe "initialize on sandbox" do
|
104
|
-
before do
|
105
|
-
ENV["base_uri"] = nil
|
106
|
-
end
|
107
|
-
|
44
|
+
describe "initialize on sandbox with Basic authentication" do
|
108
45
|
let(:client) do
|
109
46
|
described_class.new :sandbox, auth
|
110
47
|
end
|
111
48
|
|
112
|
-
it { expect(client.uri).to eq
|
49
|
+
it { expect(client.uri).to eq "https://sandbox.moip.com.br" }
|
113
50
|
it { expect(client.env).to eq :sandbox }
|
114
51
|
it { expect(client.opts[:headers]["Authorization"]).to eq "Basic VE9LRU46U0VDUkVU" }
|
115
52
|
end
|
116
53
|
|
117
|
-
describe "initialize on production" do
|
54
|
+
describe "initialize on production with Basic authentication" do
|
118
55
|
let(:client) do
|
119
56
|
described_class.new :production, auth
|
120
57
|
end
|