moip2 0.1.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +644 -0
- data/.travis.yml +14 -3
- data/CONTRIBUTING.md +42 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +25 -6
- data/Guardfile +1 -2
- data/README.md +373 -74
- data/Rakefile +2 -2
- data/changelog.md +36 -0
- data/lib/moip2/accounts_api.rb +27 -0
- data/lib/moip2/api.rb +25 -2
- data/lib/moip2/auth/basic.rb +2 -5
- data/lib/moip2/auth/oauth.rb +0 -3
- data/lib/moip2/client.rb +45 -31
- data/lib/moip2/connect_api.rb +41 -0
- data/lib/moip2/customer_api.rb +16 -2
- data/lib/moip2/exceptions/invalid_enviroment_error.rb +0 -2
- data/lib/moip2/invoice_api.rb +8 -3
- data/lib/moip2/keys_api.rb +14 -14
- data/lib/moip2/multi_order_api.rb +1 -3
- data/lib/moip2/multi_payment_api.rb +1 -1
- data/lib/moip2/notifications_api.rb +33 -0
- data/lib/moip2/order_api.rb +18 -3
- data/lib/moip2/payment_api.rb +11 -1
- data/lib/moip2/refund_api.rb +5 -4
- data/lib/moip2/resource/account.rb +12 -0
- data/lib/moip2/resource/connect.rb +9 -0
- data/lib/moip2/resource/credit_card.rb +12 -0
- data/lib/moip2/resource/customer.rb +0 -4
- data/lib/moip2/resource/invoice.rb +0 -2
- data/lib/moip2/resource/keys.rb +1 -3
- data/lib/moip2/resource/multi_order.rb +2 -6
- data/lib/moip2/resource/multi_payment.rb +1 -3
- data/lib/moip2/resource/notification.rb +12 -0
- data/lib/moip2/resource/order.rb +0 -4
- data/lib/moip2/resource/payment.rb +0 -4
- data/lib/moip2/resource/refund.rb +1 -2
- data/lib/moip2/resource/webhooks.rb +11 -13
- data/lib/moip2/response.rb +7 -7
- data/lib/moip2/util/filters_encoder.rb +28 -0
- data/lib/moip2/version.rb +1 -1
- data/lib/moip2/webhooks_api.rb +16 -16
- data/lib/moip2.rb +10 -5
- data/moip2.gemspec +21 -7
- data/spec/moip2/accounts_api_spec.rb +189 -0
- data/spec/moip2/api_spec.rb +22 -4
- data/spec/moip2/auth/basic_spec.rb +8 -4
- data/spec/moip2/auth/oauth_spec.rb +4 -4
- data/spec/moip2/client_spec.rb +20 -27
- data/spec/moip2/connect_api_spec.rb +68 -0
- data/spec/moip2/customer_api_spec.rb +147 -72
- data/spec/moip2/invoice_spec.rb +51 -32
- data/spec/moip2/keys_spec.rb +16 -18
- data/spec/moip2/multi_order_api_spec.rb +99 -108
- data/spec/moip2/multi_payment_api_spec.rb +8 -11
- data/spec/moip2/notifications_api_spec.rb +104 -0
- data/spec/moip2/order_api_spec.rb +100 -20
- data/spec/moip2/payment_api_spec.rb +77 -17
- data/spec/moip2/refund_api_spec.rb +2 -4
- data/spec/moip2/resource/order_spec.rb +24 -28
- data/spec/moip2/response_spec.rb +0 -8
- data/spec/moip2/webhooks_spec.rb +18 -21
- data/spec/moip2_spec.rb +6 -13
- data/spec/spec_helper.rb +24 -10
- data/vcr_cassettes/_create_invoice.yml +42 -0
- data/vcr_cassettes/_get_invoice.yml +41 -0
- data/vcr_cassettes/account_doesnt_exist.yml +44 -0
- data/vcr_cassettes/account_exists.yml +46 -0
- data/vcr_cassettes/accounts_show_existent.yml +50 -0
- data/vcr_cassettes/accounts_show_nonexistent.yml +42 -0
- data/vcr_cassettes/cancel_payment.yml +43 -0
- data/vcr_cassettes/capture_payment.yml +42 -0
- data/vcr_cassettes/create_account_success_company.yml +87 -0
- data/vcr_cassettes/create_account_success_standalone.yml +74 -0
- data/vcr_cassettes/create_credit_card_customer.yml +41 -0
- data/vcr_cassettes/create_invoice.yml +10 -16
- data/vcr_cassettes/create_notification.yml +38 -0
- data/vcr_cassettes/create_notification_app.yml +38 -0
- data/vcr_cassettes/delete_credit_card_customer.yml +40 -0
- data/vcr_cassettes/delete_nonexistent_credit_card_customer.yml +40 -0
- data/vcr_cassettes/delete_nonexistent_notification.yml +40 -0
- data/vcr_cassettes/delete_notification.yml +36 -0
- data/vcr_cassettes/find_all_orders_filters.yml +56 -0
- data/vcr_cassettes/find_all_orders_limit.yml +48 -0
- data/vcr_cassettes/find_all_orders_multi_filters.yml +57 -0
- data/vcr_cassettes/find_all_orders_no_filter.yml +56 -0
- data/vcr_cassettes/generate_oauth_token.yml +42 -0
- data/vcr_cassettes/get_invoice.yml +10 -15
- data/vcr_cassettes/get_keys.yml +1 -1
- data/vcr_cassettes/get_notification.yml +38 -0
- data/vcr_cassettes/get_notifications_list.yml +38 -0
- data/vcr_cassettes/get_payment.yml +42 -0
- data/vcr_cassettes/get_payment_not_found.yml +40 -0
- data/vcr_cassettes/get_webhooks.yml +1 -1
- data/vcr_cassettes/list_invoices.yml +2 -2
- data/vcr_cassettes/refresh_oauth_token.yml +40 -0
- data/vcr_cassettes/update_invoice.yml +1 -1
- metadata +69 -7
data/lib/moip2/resource/order.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module Moip2
|
2
2
|
module Resource
|
3
|
-
|
4
3
|
class Order < SimpleDelegator
|
5
|
-
|
6
4
|
attr_reader :client, :payment_api, :external_id
|
7
5
|
|
8
6
|
def initialize(client, response)
|
@@ -18,8 +16,6 @@ module Moip2
|
|
18
16
|
def create_payment(payment)
|
19
17
|
payment_api.create(external_id, payment)
|
20
18
|
end
|
21
|
-
|
22
19
|
end
|
23
|
-
|
24
20
|
end
|
25
21
|
end
|
@@ -1,14 +1,12 @@
|
|
1
1
|
module Moip2
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
2
|
+
module Resource
|
3
|
+
class Webhooks < SimpleDelegator
|
4
|
+
attr_reader :client
|
5
|
+
|
6
|
+
def initialize(client, response)
|
7
|
+
super(response)
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/moip2/response.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
module Moip2
|
2
|
-
|
3
2
|
class Response < SimpleDelegator
|
4
|
-
|
5
3
|
def initialize(resp, json)
|
6
|
-
|
4
|
+
if json.is_a? Hash
|
5
|
+
super(RecursiveOpenStruct.new(json, recurse_over_arrays: true))
|
6
|
+
else
|
7
|
+
super(resp)
|
8
|
+
end
|
7
9
|
@resp = resp
|
8
10
|
end
|
9
11
|
|
10
12
|
def success?
|
11
|
-
(200..299).
|
13
|
+
(200..299).cover? @resp.code.to_i
|
12
14
|
end
|
13
15
|
|
14
16
|
def client_error?
|
15
|
-
(400..499).
|
17
|
+
(400..499).cover? @resp.code.to_i
|
16
18
|
end
|
17
|
-
|
18
19
|
end
|
19
|
-
|
20
20
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Moip2
|
2
|
+
module Util
|
3
|
+
class FiltersEncoder
|
4
|
+
def self.encode(filters)
|
5
|
+
return nil unless filters.is_a? Hash
|
6
|
+
|
7
|
+
encoded_filters = filters.map do |field, value|
|
8
|
+
rules = extract_rules(field, value)
|
9
|
+
rules.join("|")
|
10
|
+
end
|
11
|
+
|
12
|
+
encoded_filters.join("|")
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.extract_rules(field, rules)
|
18
|
+
rules.map do |type, value|
|
19
|
+
return unless %i[gt ge lt le bt in].include?(type)
|
20
|
+
|
21
|
+
content = value.is_a?(Array) ? value.join(",") : value
|
22
|
+
|
23
|
+
"#{field}::#{type}(#{content})"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/moip2/version.rb
CHANGED
data/lib/moip2/webhooks_api.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
module Moip2
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
2
|
+
class WebhooksApi
|
3
|
+
attr_reader :client
|
4
|
+
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
def base_path
|
10
|
+
"/v2/webhooks"
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
Resource::Webhooks.new(client, client.get(base_path.to_s))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/moip2.rb
CHANGED
@@ -7,6 +7,7 @@ require "moip2/version"
|
|
7
7
|
require "moip2/auth/basic"
|
8
8
|
require "moip2/auth/oauth"
|
9
9
|
|
10
|
+
require "moip2/resource/account"
|
10
11
|
require "moip2/resource/order"
|
11
12
|
require "moip2/resource/payment"
|
12
13
|
require "moip2/resource/multi_order"
|
@@ -16,6 +17,9 @@ require "moip2/resource/invoice"
|
|
16
17
|
require "moip2/resource/keys"
|
17
18
|
require "moip2/resource/refund"
|
18
19
|
require "moip2/resource/webhooks"
|
20
|
+
require "moip2/resource/connect"
|
21
|
+
require "moip2/resource/credit_card"
|
22
|
+
require "moip2/resource/notification"
|
19
23
|
|
20
24
|
require "moip2/response"
|
21
25
|
require "moip2/client"
|
@@ -29,14 +33,17 @@ require "moip2/refund_api"
|
|
29
33
|
require "moip2/api"
|
30
34
|
require "moip2/keys_api"
|
31
35
|
require "moip2/webhooks_api"
|
36
|
+
require "moip2/accounts_api"
|
37
|
+
require "moip2/connect_api"
|
38
|
+
require "moip2/notifications_api"
|
32
39
|
|
33
40
|
require "moip2/exceptions/invalid_enviroment_error"
|
34
41
|
|
35
|
-
|
42
|
+
require "moip2/util/filters_encoder"
|
36
43
|
|
44
|
+
module Moip2
|
37
45
|
class << self
|
38
|
-
|
39
|
-
VALID_ENVS = %i(sandbox production)
|
46
|
+
VALID_ENVS = %i(sandbox production).freeze
|
40
47
|
|
41
48
|
def env=(env)
|
42
49
|
raise InvalidEnviromentError unless VALID_ENVS.include?(env.to_sym)
|
@@ -68,10 +75,8 @@ module Moip2
|
|
68
75
|
|
69
76
|
Api.new Client.new(env, auth)
|
70
77
|
end
|
71
|
-
|
72
78
|
end
|
73
79
|
|
74
80
|
class NotFoundError < StandardError
|
75
81
|
end
|
76
|
-
|
77
82
|
end
|
data/moip2.gemspec
CHANGED
@@ -1,15 +1,28 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
5
|
+
require "moip2/version"
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
8
|
spec.name = "moip2"
|
8
9
|
spec.version = Moip2::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
spec.authors = [
|
11
|
+
"Rodrigo Saito",
|
12
|
+
"Danillo Souza",
|
13
|
+
"Caio Gama",
|
14
|
+
"João Lucas Lucchetta",
|
15
|
+
"Caio Gaspar",
|
16
|
+
]
|
17
|
+
spec.email = [
|
18
|
+
"rodrigo.saito@moip.com.br",
|
19
|
+
"danillo.souza@moip.com.br",
|
20
|
+
"caio.gama@moip.com.br",
|
21
|
+
"joao.lucchetta@moip.com.br",
|
22
|
+
"caio.gaspar@moip.com.br",
|
23
|
+
]
|
24
|
+
spec.summary = "Ruby client for moip v2 api"
|
25
|
+
spec.description = "Ruby client for moip v2 api"
|
13
26
|
spec.homepage = ""
|
14
27
|
spec.license = "MIT"
|
15
28
|
|
@@ -21,11 +34,12 @@ Gem::Specification.new do |spec|
|
|
21
34
|
spec.add_dependency "httparty"
|
22
35
|
spec.add_dependency "recursive-open-struct"
|
23
36
|
|
24
|
-
spec.add_development_dependency "bundler"
|
37
|
+
spec.add_development_dependency "bundler"
|
25
38
|
spec.add_development_dependency "rake"
|
26
39
|
spec.add_development_dependency "rspec"
|
27
40
|
spec.add_development_dependency "vcr"
|
28
41
|
spec.add_development_dependency "webmock"
|
29
42
|
spec.add_development_dependency "guard-rspec"
|
30
43
|
spec.add_development_dependency "codeclimate-test-reporter"
|
44
|
+
spec.add_development_dependency "rubocop", "0.49.1"
|
31
45
|
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
describe Moip2::AccountsApi do
|
2
|
+
let(:accounts_api) { described_class.new sandbox_oauth_client }
|
3
|
+
|
4
|
+
describe "#create" do
|
5
|
+
describe "standalone account" do
|
6
|
+
let(:account) do
|
7
|
+
{
|
8
|
+
email: {
|
9
|
+
address: "dev.moip.1503312362@labs.moip.com.br",
|
10
|
+
},
|
11
|
+
person: {
|
12
|
+
name: "Joaquim José",
|
13
|
+
lastName: "Silva Silva",
|
14
|
+
taxDocument: {
|
15
|
+
type: "CPF",
|
16
|
+
number: "572.619.050-54",
|
17
|
+
},
|
18
|
+
identityDocument: {
|
19
|
+
type: "RG",
|
20
|
+
number: "35.868.057-8",
|
21
|
+
issuer: "SSP",
|
22
|
+
issueDate: "2000-12-12",
|
23
|
+
},
|
24
|
+
birthDate: "1990-01-01",
|
25
|
+
phone: {
|
26
|
+
countryCode: "55",
|
27
|
+
areaCode: "11",
|
28
|
+
number: "965213244",
|
29
|
+
},
|
30
|
+
address: {
|
31
|
+
street: "Av. Brigadeiro Faria Lima",
|
32
|
+
streetNumber: "2927",
|
33
|
+
district: "Itaim",
|
34
|
+
zipCode: "01234-000",
|
35
|
+
city: "S\u00E3o Paulo",
|
36
|
+
state: "SP",
|
37
|
+
country: "BRA",
|
38
|
+
},
|
39
|
+
},
|
40
|
+
type: "MERCHANT",
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:created_account) do
|
45
|
+
VCR.use_cassette("create_account_success_standalone") do
|
46
|
+
accounts_api.create(account)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "creates an account accordingly" do
|
51
|
+
expect(created_account.id).to_not be_nil
|
52
|
+
expect(created_account.type).to eq("MERCHANT")
|
53
|
+
expect(created_account.transparent_account).to be false
|
54
|
+
expect(created_account.person.name).to eq("Joaquim José")
|
55
|
+
expect(created_account.person.last_name).to eq("Silva Silva")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "company account" do
|
60
|
+
let(:account) do
|
61
|
+
{
|
62
|
+
email: {
|
63
|
+
address: "dev.moip.1503312536@labs.moip.com.br",
|
64
|
+
},
|
65
|
+
person: {
|
66
|
+
name: "Joaquim José",
|
67
|
+
lastName: "Silva Silva",
|
68
|
+
taxDocument: {
|
69
|
+
type: "CPF",
|
70
|
+
number: "436.130.670-21",
|
71
|
+
},
|
72
|
+
identityDocument: {
|
73
|
+
type: "RG",
|
74
|
+
number: "30.790.138-5",
|
75
|
+
issuer: "SSP",
|
76
|
+
issueDate: "2000-12-12",
|
77
|
+
},
|
78
|
+
birthDate: "1990-01-01",
|
79
|
+
phone: {
|
80
|
+
countryCode: "55",
|
81
|
+
areaCode: "11",
|
82
|
+
number: "965213244",
|
83
|
+
},
|
84
|
+
address: {
|
85
|
+
street: "Av. Brigadeiro Faria Lima",
|
86
|
+
streetNumber: "2927",
|
87
|
+
district: "Itaim",
|
88
|
+
zipCode: "01234-000",
|
89
|
+
city: "S\u00E3o Paulo",
|
90
|
+
state: "SP",
|
91
|
+
country: "BRA",
|
92
|
+
},
|
93
|
+
},
|
94
|
+
company: {
|
95
|
+
name: "ACME Factories",
|
96
|
+
businessName: "ACME Inc.",
|
97
|
+
taxDocument: {
|
98
|
+
type: "CNPJ",
|
99
|
+
number: "88127676000191",
|
100
|
+
},
|
101
|
+
mainActivity: {
|
102
|
+
cnae: "82.91-1/00",
|
103
|
+
description: "Atividades de cobranças e informações cadastrais",
|
104
|
+
},
|
105
|
+
openingDate: "2011-01-01",
|
106
|
+
phone: {
|
107
|
+
countryCode: "55",
|
108
|
+
areaCode: "15",
|
109
|
+
number: "40028922",
|
110
|
+
},
|
111
|
+
address: {
|
112
|
+
street: "Av. Brig Faria Lima",
|
113
|
+
streetNumber: "3064",
|
114
|
+
complement: "12o Andar",
|
115
|
+
district: "Itaim Bibi",
|
116
|
+
zipCode: "01452002",
|
117
|
+
city: "São Paulo",
|
118
|
+
state: "SP",
|
119
|
+
country: "BRA",
|
120
|
+
},
|
121
|
+
},
|
122
|
+
type: "MERCHANT",
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
let(:created_account) do
|
127
|
+
VCR.use_cassette("create_account_success_company") do
|
128
|
+
accounts_api.create(account)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
it "creates an account accordingly" do
|
133
|
+
expect(created_account.id).to_not be_nil
|
134
|
+
expect(created_account.type).to eq("MERCHANT")
|
135
|
+
expect(created_account.transparent_account).to be false
|
136
|
+
expect(created_account.person.name).to eq("Joaquim José")
|
137
|
+
expect(created_account.person.last_name).to eq("Silva Silva")
|
138
|
+
expect(created_account.company.business_name).to eq("ACME Inc.")
|
139
|
+
expect(created_account.company.tax_document.number).to eq("88.127.676/0001-91")
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "#exists" do
|
145
|
+
describe "with a registered tax document" do
|
146
|
+
let(:existence_check) do
|
147
|
+
VCR.use_cassette("account_exists") do
|
148
|
+
accounts_api.exists?("436.130.670-21")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
it { expect(existence_check).to be true }
|
153
|
+
end
|
154
|
+
|
155
|
+
describe "with a non registered tax document" do
|
156
|
+
let(:existence_check) do
|
157
|
+
VCR.use_cassette("account_doesnt_exist") do
|
158
|
+
accounts_api.exists?("555.000.123-40")
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
it { expect(existence_check).to be false }
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "#show" do
|
167
|
+
context "when given an existent account" do
|
168
|
+
let(:retrieved_account) do
|
169
|
+
VCR.use_cassette("accounts_show_existent") do
|
170
|
+
accounts_api.show("MPA-67C15332EB4A")
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
it { expect(retrieved_account.id).to eq("MPA-67C15332EB4A") }
|
175
|
+
it { expect(retrieved_account.person.name).to eq("Joaquim") }
|
176
|
+
it { expect(retrieved_account.person.last_name).to eq("Silva Silva") }
|
177
|
+
end
|
178
|
+
|
179
|
+
context "when given a nonexistent account" do
|
180
|
+
let(:retrieved_account) do
|
181
|
+
VCR.use_cassette("accounts_show_nonexistent") do
|
182
|
+
accounts_api.show("MPA-F00B4R123456")
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
it { expect { retrieved_account }.to raise_error(Moip2::NotFoundError) }
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
data/spec/moip2/api_spec.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
describe Moip2::Api do
|
2
|
-
|
3
|
-
let(:auth) { Moip2::Auth::Basic.new('', '') }
|
2
|
+
let(:auth) { Moip2::Auth::Basic.new("", "") }
|
4
3
|
let(:client) { Moip2::Client.new(:sandbox, auth) }
|
5
4
|
let(:api) { described_class.new client }
|
6
5
|
|
@@ -8,10 +7,9 @@ describe Moip2::Api do
|
|
8
7
|
it "returns an OrderApi" do
|
9
8
|
expect(api.order).to be_a(Moip2::OrderApi)
|
10
9
|
end
|
11
|
-
|
12
10
|
end
|
13
11
|
|
14
|
-
describe
|
12
|
+
describe "#payment" do
|
15
13
|
it "returns a PaymentApi" do
|
16
14
|
expect(api.payment).to be_a(Moip2::PaymentApi)
|
17
15
|
end
|
@@ -29,4 +27,24 @@ describe Moip2::Api do
|
|
29
27
|
it { expect(api.keys).to be_a Moip2::KeysApi }
|
30
28
|
end
|
31
29
|
|
30
|
+
describe "#customer" do
|
31
|
+
it { expect(api.customer).to be_a Moip2::CustomerApi }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#multi_order" do
|
35
|
+
it { expect(api.multi_order).to be_a Moip2::MultiOrderApi }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#multi_payment" do
|
39
|
+
it { expect(api.multi_payment).to be_a Moip2::MultiPaymentApi }
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#accounts" do
|
43
|
+
it { expect(api.accounts).to be_a Moip2::AccountsApi }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#connect" do
|
47
|
+
it { expect(api.connect).to be_a Moip2::ConnectApi }
|
48
|
+
it { expect(api.connect.client.uri).to eq "https://connect-sandbox.moip.com.br" }
|
49
|
+
end
|
32
50
|
end
|
@@ -1,9 +1,13 @@
|
|
1
1
|
describe Moip2::Auth::Basic do
|
2
|
-
|
3
|
-
|
2
|
+
let(:basic) do
|
3
|
+
described_class.new(
|
4
|
+
"01010101010101010101010101010101",
|
5
|
+
"ABABABABABABABABABABABABABABABABABABABAB",
|
6
|
+
)
|
7
|
+
end
|
4
8
|
|
5
9
|
it "builds authorization header" do
|
6
|
-
expect(basic.header).to eq "Basic
|
10
|
+
expect(basic.header).to eq "Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkF"\
|
11
|
+
"CQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg=="
|
7
12
|
end
|
8
|
-
|
9
13
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
describe Moip2::Auth::OAuth do
|
2
|
-
let(:oauth_with_text) { described_class.new "OAuth
|
3
|
-
let(:oauth_without_text) { described_class.new "
|
2
|
+
let(:oauth_with_text) { described_class.new "OAuth 9fdc242631454d4c95d82e27b4127394_v2" }
|
3
|
+
let(:oauth_without_text) { described_class.new "9fdc242631454d4c95d82e27b4127394_v2" }
|
4
4
|
|
5
5
|
describe ".header" do
|
6
|
-
it { expect(oauth_with_text.header).to eq "OAuth
|
7
|
-
it { expect(oauth_without_text.header).to eq "OAuth
|
6
|
+
it { expect(oauth_with_text.header).to eq "OAuth 9fdc242631454d4c95d82e27b4127394_v2" }
|
7
|
+
it { expect(oauth_without_text.header).to eq "OAuth 9fdc242631454d4c95d82e27b4127394_v2" }
|
8
8
|
end
|
9
9
|
end
|
data/spec/moip2/client_spec.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
describe Moip2::Client do
|
2
|
-
|
3
2
|
let(:auth) do
|
4
3
|
Moip2::Auth::Basic.new("TOKEN", "SECRET")
|
5
4
|
end
|
6
5
|
|
7
6
|
let(:oauth) do
|
8
|
-
Moip2::Auth::OAuth.new "
|
7
|
+
Moip2::Auth::OAuth.new "9fdc242631454d4c95d82e27b4127394_v2"
|
9
8
|
end
|
10
9
|
|
11
10
|
describe "initialize env with string" do
|
@@ -17,16 +16,16 @@ describe Moip2::Client do
|
|
17
16
|
end
|
18
17
|
|
19
18
|
describe "initialize on sandbox with OAuth" do
|
20
|
-
|
21
19
|
let(:client) do
|
22
20
|
described_class.new :sandbox, auth
|
23
21
|
end
|
24
22
|
|
25
23
|
let(:client) { described_class.new :sandbox, oauth }
|
26
|
-
it { expect(client.uri).to eq ENV[
|
24
|
+
it { expect(client.uri).to eq ENV["sandbox_url"] }
|
27
25
|
it { expect(client.env).to eq :sandbox }
|
28
|
-
it {
|
29
|
-
|
26
|
+
it {
|
27
|
+
expect(client.opts[:headers]["Authorization"]).to eq "OAuth 9fdc242631454d4c95d82e27b4127394_v2"
|
28
|
+
}
|
30
29
|
end
|
31
30
|
|
32
31
|
describe "initialize on production" do
|
@@ -36,30 +35,30 @@ describe Moip2::Client do
|
|
36
35
|
|
37
36
|
it { expect(client.uri).to eq "https://api.moip.com.br" }
|
38
37
|
it { expect(client.env).to eq :production }
|
39
|
-
it {
|
38
|
+
it {
|
39
|
+
expect(client.opts[:headers]["Authorization"]).to eq "OAuth 9fdc242631454d4c95d82e27b4127394_v2"
|
40
|
+
}
|
40
41
|
end
|
41
42
|
|
42
43
|
describe "initialize on sandbox with base_uri and OAuth" do
|
43
|
-
|
44
44
|
before do
|
45
|
-
ENV[
|
45
|
+
ENV["base_uri"] = "http://localhost:5000"
|
46
46
|
end
|
47
47
|
|
48
48
|
let(:client) do
|
49
49
|
described_class.new :sandbox, oauth
|
50
50
|
end
|
51
51
|
|
52
|
-
|
53
52
|
it { expect(client.uri).to eq "http://localhost:5000" }
|
54
53
|
it { expect(client.env).to eq :sandbox }
|
55
|
-
it {
|
56
|
-
|
54
|
+
it {
|
55
|
+
expect(client.opts[:headers]["Authorization"]).to eq "OAuth 9fdc242631454d4c95d82e27b4127394_v2"
|
56
|
+
}
|
57
57
|
end
|
58
58
|
|
59
59
|
describe "initialize on production with base_uri and OAuth" do
|
60
|
-
|
61
60
|
before do
|
62
|
-
ENV[
|
61
|
+
ENV["base_uri"] = "http://localhost:5000"
|
63
62
|
end
|
64
63
|
|
65
64
|
let(:client) do
|
@@ -68,31 +67,28 @@ describe Moip2::Client do
|
|
68
67
|
|
69
68
|
it { expect(client.uri).to eq "http://localhost:5000" }
|
70
69
|
it { expect(client.env).to eq :production }
|
71
|
-
it {
|
72
|
-
|
70
|
+
it {
|
71
|
+
expect(client.opts[:headers]["Authorization"]).to eq "OAuth 9fdc242631454d4c95d82e27b4127394_v2"
|
72
|
+
}
|
73
73
|
end
|
74
74
|
|
75
75
|
describe "initialize on sandbox with base_uri" do
|
76
|
-
|
77
76
|
before do
|
78
|
-
ENV[
|
77
|
+
ENV["base_uri"] = "http://localhost:5000"
|
79
78
|
end
|
80
79
|
|
81
80
|
let(:client) do
|
82
81
|
described_class.new :sandbox, auth
|
83
82
|
end
|
84
83
|
|
85
|
-
|
86
84
|
it { expect(client.uri).to eq "http://localhost:5000" }
|
87
85
|
it { expect(client.env).to eq :sandbox }
|
88
86
|
it { expect(client.opts[:headers]["Authorization"]).to eq "Basic VE9LRU46U0VDUkVU" }
|
89
|
-
|
90
87
|
end
|
91
88
|
|
92
89
|
describe "initialize on production with base_uri" do
|
93
|
-
|
94
90
|
before do
|
95
|
-
ENV[
|
91
|
+
ENV["base_uri"] = "http://localhost:5000"
|
96
92
|
end
|
97
93
|
|
98
94
|
let(:client) do
|
@@ -102,20 +98,18 @@ describe Moip2::Client do
|
|
102
98
|
it { expect(client.uri).to eq "http://localhost:5000" }
|
103
99
|
it { expect(client.env).to eq :production }
|
104
100
|
it { expect(client.opts[:headers]["Authorization"]).to eq "Basic VE9LRU46U0VDUkVU" }
|
105
|
-
|
106
101
|
end
|
107
102
|
|
108
103
|
describe "initialize on sandbox" do
|
109
|
-
|
110
104
|
before do
|
111
|
-
ENV[
|
105
|
+
ENV["base_uri"] = nil
|
112
106
|
end
|
113
107
|
|
114
108
|
let(:client) do
|
115
109
|
described_class.new :sandbox, auth
|
116
110
|
end
|
117
111
|
|
118
|
-
it { expect(client.uri).to eq ENV[
|
112
|
+
it { expect(client.uri).to eq ENV["sandbox_url"] }
|
119
113
|
it { expect(client.env).to eq :sandbox }
|
120
114
|
it { expect(client.opts[:headers]["Authorization"]).to eq "Basic VE9LRU46U0VDUkVU" }
|
121
115
|
end
|
@@ -129,5 +123,4 @@ describe Moip2::Client do
|
|
129
123
|
it { expect(client.env).to eq :production }
|
130
124
|
it { expect(client.opts[:headers]["Authorization"]).to eq "Basic VE9LRU46U0VDUkVU" }
|
131
125
|
end
|
132
|
-
|
133
126
|
end
|