moip-assinaturas 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +180 -0
- data/Rakefile +1 -0
- data/lib/moip-assinaturas/client.rb +99 -0
- data/lib/moip-assinaturas/customer.rb +59 -0
- data/lib/moip-assinaturas/invoice.rb +38 -0
- data/lib/moip-assinaturas/payment.rb +38 -0
- data/lib/moip-assinaturas/plan.rb +59 -0
- data/lib/moip-assinaturas/subscription.rb +84 -0
- data/lib/moip-assinaturas/version.rb +5 -0
- data/lib/moip-assinaturas.rb +33 -0
- data/lib/rails/generators/moip_assinaturas/install_generator.rb +14 -0
- data/lib/rails/generators/templates/moip_assinaturas.rb +5 -0
- data/moip-assinaturas.gemspec +28 -0
- data/spec/fixtures/create_customer.json +3 -0
- data/spec/fixtures/create_plan.json +12 -0
- data/spec/fixtures/create_subscription.json +36 -0
- data/spec/fixtures/details_customer.json +34 -0
- data/spec/fixtures/details_invoice.json +36 -0
- data/spec/fixtures/details_payment.json +34 -0
- data/spec/fixtures/details_plan.json +14 -0
- data/spec/fixtures/details_subscription.json +32 -0
- data/spec/fixtures/list_customers.json +15 -0
- data/spec/fixtures/list_invoices.json +23 -0
- data/spec/fixtures/list_payments.json +32 -0
- data/spec/fixtures/list_plans.json +18 -0
- data/spec/fixtures/list_subscriptions.json +35 -0
- data/spec/moip-assinaturas/customer_spec.rb +76 -0
- data/spec/moip-assinaturas/invoice_spec.rb +35 -0
- data/spec/moip-assinaturas/payment_spec.rb +36 -0
- data/spec/moip-assinaturas/plan_spec.rb +61 -0
- data/spec/moip-assinaturas/subscription_spec.rb +83 -0
- data/spec/moip_assinaturas_spec.rb +15 -0
- data/spec/spec_helper.rb +18 -0
- metadata +230 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'moip-assinaturas/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "moip-assinaturas"
|
8
|
+
gem.version = Moip::Assinaturas::VERSION
|
9
|
+
gem.authors = ["Warlley"]
|
10
|
+
gem.email = ["warlleyrezende@gmail.com"]
|
11
|
+
gem.description = %q{Ruby Gem para uso do serviço de assinaturas do Moip}
|
12
|
+
gem.summary = %q{Ruby Gem para uso do serviço de assinaturas do Moip}
|
13
|
+
gem.homepage = "https://github.com/ibody/moip-assinaturas"
|
14
|
+
|
15
|
+
gem.add_development_dependency 'rspec', '~> 2.13'
|
16
|
+
gem.add_development_dependency 'guard-rspec', '~> 2.5.4'
|
17
|
+
gem.add_development_dependency 'growl', '~> 1.0.3'
|
18
|
+
gem.add_development_dependency 'fakeweb', '~> 1.3.0'
|
19
|
+
gem.add_development_dependency 'pry', '~> 0.9'
|
20
|
+
gem.add_dependency 'httparty', '~> 0.11.0'
|
21
|
+
gem.add_dependency 'activesupport', '>= 2.3.2'
|
22
|
+
gem.add_dependency 'json', '>= 1.7'
|
23
|
+
|
24
|
+
gem.files = `git ls-files`.split($/)
|
25
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
26
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
27
|
+
gem.require_paths = ["lib"]
|
28
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
{
|
2
|
+
"code": "ass_homolog_72",
|
3
|
+
"amount": "100",
|
4
|
+
"next_invoice_date": {
|
5
|
+
"day": "05",
|
6
|
+
"month": "01",
|
7
|
+
"year": "2013"
|
8
|
+
},
|
9
|
+
"status": "ACTIVE",
|
10
|
+
"plan": {
|
11
|
+
"name": "Plano de homologação",
|
12
|
+
"code": "homolog1"
|
13
|
+
},
|
14
|
+
"customer": {
|
15
|
+
"email": "fulano@homolog.com",
|
16
|
+
"code": "homolog2",
|
17
|
+
"fullname": "Fulano Homologador"
|
18
|
+
},
|
19
|
+
"invoice": { //dados da primeira cobrança (se houver)
|
20
|
+
"id": 134,
|
21
|
+
"moip_id": "14000000",
|
22
|
+
"amount": 110,
|
23
|
+
"status": {
|
24
|
+
"description": "Em análise",
|
25
|
+
"code": 2
|
26
|
+
}
|
27
|
+
},
|
28
|
+
"message": "Assinatura criada com Sucesso",
|
29
|
+
"errors": [],
|
30
|
+
"alerts": [
|
31
|
+
{
|
32
|
+
"code": "MA90",
|
33
|
+
"description": "O nome do portador do cartão deve ter no máximo 45 caracteres. Os demais caracteres foram ignorados"
|
34
|
+
}
|
35
|
+
]
|
36
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"code": "18",
|
3
|
+
"fullname": "Nome Sobrenome",
|
4
|
+
"email": "nome@exemplo.com",
|
5
|
+
"cpf": "22222222222",
|
6
|
+
"phone_area_code": "11",
|
7
|
+
"phone_number": "990909090",
|
8
|
+
"birthdate_day": 29,
|
9
|
+
"birthdate_month": 3,
|
10
|
+
"birthdate_year": 1980,
|
11
|
+
"address": {
|
12
|
+
"street": "Rua Nome da Rua",
|
13
|
+
"number": "1000",
|
14
|
+
"complement": "Apto 4 - bloco A",
|
15
|
+
"district": "Bairro",
|
16
|
+
"city": "São Paulo",
|
17
|
+
"state": "SP",
|
18
|
+
"country": "BRA",
|
19
|
+
"zipcode": "00000000"
|
20
|
+
},
|
21
|
+
"billing_info": {
|
22
|
+
"credit_cards": [
|
23
|
+
{
|
24
|
+
"vault": "00b21555-296a-4e70-94cd-3e96fef62e5b",
|
25
|
+
"brand": "VISA",
|
26
|
+
"first_six_digits": "411111",
|
27
|
+
"last_four_digits": "1111",
|
28
|
+
"expiration_month": "04",
|
29
|
+
"expiration_year": "15",
|
30
|
+
"holder_name": "Nome Sobrenome"
|
31
|
+
}
|
32
|
+
]
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
{
|
2
|
+
"id": 13,
|
3
|
+
"amount": 101,
|
4
|
+
"subscription_code": "assinatura7",
|
5
|
+
"occurrence": 1,
|
6
|
+
"status": {
|
7
|
+
"code": 2,
|
8
|
+
"description": "Aguardando confirmação"
|
9
|
+
},
|
10
|
+
"items": [
|
11
|
+
{
|
12
|
+
"amount": 100,
|
13
|
+
"type": "Valor da assinatura"
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"amount": 1,
|
17
|
+
"type": "Taxa de contratação"
|
18
|
+
}
|
19
|
+
],
|
20
|
+
"plan": {
|
21
|
+
"code": "plano1",
|
22
|
+
"name": "Plano 1 real"
|
23
|
+
},
|
24
|
+
"customer": {
|
25
|
+
"code": "cliente1",
|
26
|
+
"fullname": "Fulano Testador"
|
27
|
+
},
|
28
|
+
"creation_date": {
|
29
|
+
"day": 28,
|
30
|
+
"month": 12,
|
31
|
+
"year": 2012,
|
32
|
+
"hour": 15,
|
33
|
+
"minute": 38,
|
34
|
+
"second": 41
|
35
|
+
}
|
36
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"id": 6,
|
3
|
+
"moip_id": 7205895,
|
4
|
+
"status": {
|
5
|
+
"code": 6,
|
6
|
+
"description": "Em análise"
|
7
|
+
},
|
8
|
+
"subscription_code": "assinatura7",
|
9
|
+
"customer_code": "cliente1",
|
10
|
+
"invoice": {
|
11
|
+
"id": 13,
|
12
|
+
"amount": 101
|
13
|
+
},
|
14
|
+
"payment_method": {
|
15
|
+
"code": 1,
|
16
|
+
"description": "Cartão de Crédito",
|
17
|
+
"credit_card": {
|
18
|
+
"brand": "VISA",
|
19
|
+
"holder_name": "Fulano Testador",
|
20
|
+
"first_six_digits": "411111",
|
21
|
+
"last_four_digits": "1111",
|
22
|
+
"expiration_month": "03",
|
23
|
+
"expiration_year": "16"
|
24
|
+
}
|
25
|
+
},
|
26
|
+
"creation_date": {
|
27
|
+
"day": 28,
|
28
|
+
"month": 12,
|
29
|
+
"year": 2012,
|
30
|
+
"hour": 15,
|
31
|
+
"minute": 38,
|
32
|
+
"second": 41
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"code": "plano01",
|
3
|
+
"name": "Plano Ouro Ilimitado",
|
4
|
+
"description": "Plano com todas as vantagens",
|
5
|
+
"status": "ACTIVE",
|
6
|
+
"amount": 2990,
|
7
|
+
"max_qty": 50,
|
8
|
+
"setup_fee": 1000,
|
9
|
+
"interval": {
|
10
|
+
"length": 1,
|
11
|
+
"unit": "MONTH"
|
12
|
+
},
|
13
|
+
"billing_cycles": 1
|
14
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
{
|
2
|
+
"code": "assinatura1",
|
3
|
+
"amount": "100",
|
4
|
+
"status": "ACTIVE",
|
5
|
+
"creation_date": {
|
6
|
+
"day": "20",
|
7
|
+
"month": "10",
|
8
|
+
"year": "2012",
|
9
|
+
"hour": "20",
|
10
|
+
"minute": "00",
|
11
|
+
"second": "00"
|
12
|
+
},
|
13
|
+
"next_invoice_date": {
|
14
|
+
"day": "20",
|
15
|
+
"month": "11",
|
16
|
+
"year": "2012"
|
17
|
+
},
|
18
|
+
"expiration_date": {
|
19
|
+
"day": "20",
|
20
|
+
"month": "10",
|
21
|
+
"year": "2013"
|
22
|
+
},
|
23
|
+
"plan": {
|
24
|
+
"name": "Plano Ouro Ilimitado",
|
25
|
+
"code": "plano1"
|
26
|
+
},
|
27
|
+
"customer": {
|
28
|
+
"code": "cliente1",
|
29
|
+
"fullname": "Nome e Sobrenome",
|
30
|
+
"email": "assinaturas@moip.com.br"
|
31
|
+
}
|
32
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"customers": [
|
3
|
+
{
|
4
|
+
"code": "cliente1",
|
5
|
+
"fullname": "Nome Sobrenome",
|
6
|
+
"email": "nome@exemplo.com",
|
7
|
+
"cpf": "22222222222",
|
8
|
+
"phone_area_code": "11",
|
9
|
+
"phone_number": "990909090",
|
10
|
+
"birthdate_day": "29",
|
11
|
+
"birthdate_month": "04",
|
12
|
+
"birthdate_year": "1980"
|
13
|
+
}
|
14
|
+
]
|
15
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
{
|
2
|
+
"invoices": [
|
3
|
+
{
|
4
|
+
"id": 13,
|
5
|
+
"amount": 101,
|
6
|
+
"subscription_code": "assinatura7",
|
7
|
+
|
8
|
+
"occurrence": 1,
|
9
|
+
"status": {
|
10
|
+
"code": 2,
|
11
|
+
"description": "Aguardando confirmação"
|
12
|
+
},
|
13
|
+
"creation_date": {
|
14
|
+
"day": 28,
|
15
|
+
"month": 12,
|
16
|
+
"year": 2012,
|
17
|
+
"hour": 15,
|
18
|
+
"minute": 38,
|
19
|
+
"second": 41
|
20
|
+
}
|
21
|
+
}
|
22
|
+
]
|
23
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
{
|
2
|
+
"payments": [
|
3
|
+
{
|
4
|
+
"id": 6,
|
5
|
+
"moip_id": 7205895,
|
6
|
+
"status": {
|
7
|
+
"code": 6,
|
8
|
+
"description": "Em análise"
|
9
|
+
},
|
10
|
+
"payment_method": {
|
11
|
+
"code": 1,
|
12
|
+
"description": "Cartão de Crédito",
|
13
|
+
"credit_card": {
|
14
|
+
"brand": "VISA",
|
15
|
+
"holder_name": "Fulano Testador",
|
16
|
+
"first_six_digits": "411111",
|
17
|
+
"last_four_digits": "1111",
|
18
|
+
"expiration_month": "03",
|
19
|
+
"expiration_year": "16"
|
20
|
+
}
|
21
|
+
},
|
22
|
+
"creation_date": {
|
23
|
+
"day": 28,
|
24
|
+
"month": 12,
|
25
|
+
"year": 2012,
|
26
|
+
"hour": 15,
|
27
|
+
"minute": 38,
|
28
|
+
"second": 41
|
29
|
+
}
|
30
|
+
}
|
31
|
+
]
|
32
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"plans": [
|
3
|
+
{
|
4
|
+
"code": "plano1",
|
5
|
+
"name": "Plano Exemplo",
|
6
|
+
"description": "Descrição exemplo do Plano",
|
7
|
+
"status": "ACTIVE",
|
8
|
+
"amount": 2990,
|
9
|
+
"max_qty": 50,
|
10
|
+
"setup_fee": 1000,
|
11
|
+
"interval": {
|
12
|
+
"length": 1,
|
13
|
+
"unit": "MONTH"
|
14
|
+
},
|
15
|
+
"billing_cycles": 1
|
16
|
+
}
|
17
|
+
]
|
18
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
{
|
2
|
+
"subscriptions": [
|
3
|
+
{
|
4
|
+
"code": "assinatura1",
|
5
|
+
"amount": "100",
|
6
|
+
"status": "ACTIVE",
|
7
|
+
"creation_date": {
|
8
|
+
"day": "20",
|
9
|
+
"month": "10",
|
10
|
+
"year": "2012",
|
11
|
+
"hour": "20",
|
12
|
+
"minute": "00",
|
13
|
+
"second": "00"
|
14
|
+
},
|
15
|
+
"next_invoice_date": {
|
16
|
+
"day": "20",
|
17
|
+
"month": "11",
|
18
|
+
"year": "2012"
|
19
|
+
},
|
20
|
+
"expiration_date": {
|
21
|
+
"day": "20",
|
22
|
+
"month": "10",
|
23
|
+
"year": "2013"
|
24
|
+
},
|
25
|
+
"plan": {
|
26
|
+
"name": "Plano Ouro Ilimitado",
|
27
|
+
"code": "plano1"
|
28
|
+
},
|
29
|
+
"customer": {
|
30
|
+
"code": "cliente1",
|
31
|
+
"fullname": "Nome e sobrenome"
|
32
|
+
}
|
33
|
+
}
|
34
|
+
]
|
35
|
+
}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Moip::Assinaturas::Customer do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@customer = {
|
8
|
+
code: "18",
|
9
|
+
email: "nome@exemplo.com.br",
|
10
|
+
fullname: "Nome Sobrenome",
|
11
|
+
cpf: "22222222222",
|
12
|
+
phone_area_code: "11",
|
13
|
+
phone_number: "34343434",
|
14
|
+
birthdate_day: "26",
|
15
|
+
birthdate_month: "04",
|
16
|
+
birthdate_year: "1980",
|
17
|
+
address: {
|
18
|
+
street: "Rua Nome da Rua",
|
19
|
+
number: "100",
|
20
|
+
complement: "Casa",
|
21
|
+
district: "Nome do Bairro",
|
22
|
+
city: "São Paulo",
|
23
|
+
state: "SP",
|
24
|
+
country: "BRA",
|
25
|
+
zipcode: "05015010"
|
26
|
+
},
|
27
|
+
billing_info: {
|
28
|
+
credit_card: {
|
29
|
+
holder_name: "Nome Completo",
|
30
|
+
number: "4111111111111111",
|
31
|
+
expiration_month: "04",
|
32
|
+
expiration_year: "15"
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
FakeWeb.register_uri(
|
38
|
+
:post,
|
39
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/customers?new_vault=true",
|
40
|
+
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'create_customer.json'),
|
41
|
+
status: [201, 'CREATED']
|
42
|
+
)
|
43
|
+
|
44
|
+
FakeWeb.register_uri(
|
45
|
+
:get,
|
46
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/customers",
|
47
|
+
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'list_customers.json'),
|
48
|
+
status: [200, 'OK']
|
49
|
+
)
|
50
|
+
|
51
|
+
FakeWeb.register_uri(
|
52
|
+
:get,
|
53
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/customers/18",
|
54
|
+
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'details_customer.json'),
|
55
|
+
status: [200, 'OK']
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should create a new customer" do
|
60
|
+
request = Moip::Assinaturas::Customer.create(@customer)
|
61
|
+
request[:success].should be_true
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should list all customers" do
|
65
|
+
request = Moip::Assinaturas::Customer.list
|
66
|
+
request[:success].should be_true
|
67
|
+
request[:customers].size.should == 1
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should get the customer details" do
|
71
|
+
request = Moip::Assinaturas::Customer.details('18')
|
72
|
+
request[:success].should be_true
|
73
|
+
request[:customer][:code].should == '18'
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Moip::Assinaturas::Invoice do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
|
8
|
+
FakeWeb.register_uri(
|
9
|
+
:get,
|
10
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/subscriptions/assinatura1/invoices",
|
11
|
+
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'list_invoices.json'),
|
12
|
+
status: [200, 'OK']
|
13
|
+
)
|
14
|
+
|
15
|
+
FakeWeb.register_uri(
|
16
|
+
:get,
|
17
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/invoices/13",
|
18
|
+
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'details_invoice.json'),
|
19
|
+
status: [200, 'OK']
|
20
|
+
)
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should list all invoices from a subscription" do
|
25
|
+
request = Moip::Assinaturas::Invoice.list('assinatura1')
|
26
|
+
request[:success].should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should get the invoice details" do
|
30
|
+
request = Moip::Assinaturas::Invoice.details(13)
|
31
|
+
request[:success].should be_true
|
32
|
+
request[:invoice][:id].should == 13
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Moip::Assinaturas::Payment do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
|
8
|
+
FakeWeb.register_uri(
|
9
|
+
:get,
|
10
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/invoices/13/payments",
|
11
|
+
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'list_payments.json'),
|
12
|
+
status: [200, 'OK']
|
13
|
+
)
|
14
|
+
|
15
|
+
FakeWeb.register_uri(
|
16
|
+
:get,
|
17
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/payments/6",
|
18
|
+
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'details_payment.json'),
|
19
|
+
status: [200, 'OK']
|
20
|
+
)
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should get all payments from a invoice" do
|
25
|
+
request = Moip::Assinaturas::Payment.list(13)
|
26
|
+
request[:success].should be_true
|
27
|
+
request[:payments].size.should == 1
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should get details of a payment" do
|
31
|
+
request = Moip::Assinaturas::Payment.details(6)
|
32
|
+
request[:success].should be_true
|
33
|
+
request[:payment][:id].should == 6
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Moip::Assinaturas::Plan do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@plan = {
|
8
|
+
code: "plano01",
|
9
|
+
name: "Plano Especial",
|
10
|
+
description: "Descrição do Plano Especial",
|
11
|
+
amount: 990,
|
12
|
+
setup_fee: 500,
|
13
|
+
max_qty: 1,
|
14
|
+
interval: {
|
15
|
+
length: 1,
|
16
|
+
unit: "MONTH"
|
17
|
+
},
|
18
|
+
billing_cycles: 12
|
19
|
+
}
|
20
|
+
|
21
|
+
FakeWeb.register_uri(
|
22
|
+
:post,
|
23
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/plans",
|
24
|
+
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'create_plan.json'),
|
25
|
+
status: [201, 'OK']
|
26
|
+
)
|
27
|
+
|
28
|
+
FakeWeb.register_uri(
|
29
|
+
:get,
|
30
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/plans",
|
31
|
+
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'list_plans.json'),
|
32
|
+
status: [200, 'OK']
|
33
|
+
)
|
34
|
+
|
35
|
+
FakeWeb.register_uri(
|
36
|
+
:get,
|
37
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/plans/plano01",
|
38
|
+
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'details_plan.json'),
|
39
|
+
status: [200, 'OK']
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should can create a new plan" do
|
44
|
+
request = Moip::Assinaturas::Plan.create(@plan)
|
45
|
+
request[:success].should be_true
|
46
|
+
request[:plan][:code].should == 'plano01'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should list all plans" do
|
50
|
+
request = Moip::Assinaturas::Plan.list
|
51
|
+
request[:success].should be_true
|
52
|
+
request[:plans].size.should == 1
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should get details from a plan" do
|
56
|
+
request = Moip::Assinaturas::Plan.details('plano01')
|
57
|
+
request[:success].should be_true
|
58
|
+
request[:plan][:code].should == 'plano01'
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Moip::Assinaturas::Subscription do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@subscription = {
|
8
|
+
code: "assinatura1",
|
9
|
+
amount: "100",
|
10
|
+
plan: {
|
11
|
+
code: "plano1"
|
12
|
+
},
|
13
|
+
customer: {
|
14
|
+
code: "18"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
FakeWeb.register_uri(
|
19
|
+
:post,
|
20
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/subscriptions?new_customer=false",
|
21
|
+
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'create_subscription.json'),
|
22
|
+
status: [201, 'CREATED']
|
23
|
+
)
|
24
|
+
|
25
|
+
FakeWeb.register_uri(
|
26
|
+
:get,
|
27
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/subscriptions",
|
28
|
+
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'list_subscriptions.json'),
|
29
|
+
status: [200, 'OK']
|
30
|
+
)
|
31
|
+
|
32
|
+
FakeWeb.register_uri(
|
33
|
+
:get,
|
34
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/subscriptions/assinatura1",
|
35
|
+
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'details_subscription.json'),
|
36
|
+
status: [200, 'OK']
|
37
|
+
)
|
38
|
+
|
39
|
+
FakeWeb.register_uri(
|
40
|
+
:put,
|
41
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/subscriptions/assinatura1/activate",
|
42
|
+
body: 'CREATED',
|
43
|
+
status: [201, 'OK']
|
44
|
+
)
|
45
|
+
|
46
|
+
FakeWeb.register_uri(
|
47
|
+
:put,
|
48
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/subscriptions/assinatura1/suspend",
|
49
|
+
body: 'CREATED',
|
50
|
+
status: [201, 'OK']
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should create a new subscription" do
|
55
|
+
request = Moip::Assinaturas::Subscription.create(@subscription)
|
56
|
+
request[:success].should be_true
|
57
|
+
request[:subscription][:code].should == 'ass_homolog_72'
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should list all subscriptions" do
|
61
|
+
request = Moip::Assinaturas::Subscription.list
|
62
|
+
request[:success].should be_true
|
63
|
+
request[:subscriptions].size.should == 1
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should get the subscription details" do
|
67
|
+
request = Moip::Assinaturas::Subscription.details('assinatura1')
|
68
|
+
request[:success].should be_true
|
69
|
+
request[:subscription][:code].should == 'assinatura1'
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should suspend a subscription" do
|
73
|
+
request = Moip::Assinaturas::Subscription.suspend('assinatura1')
|
74
|
+
request[:success].should be_true
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should reactive a subscription" do
|
78
|
+
request = Moip::Assinaturas::Subscription.activate('assinatura1')
|
79
|
+
request[:success].should be_true
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Moip::Assinaturas do
|
4
|
+
|
5
|
+
it "should can use the config method to configure the core class" do
|
6
|
+
Moip::Assinaturas.config do |config|
|
7
|
+
config.token = "YSV8NRJLQVS9JNFURG"
|
8
|
+
config.key = "ZP33V52G90EBISZMONKBSA5TT18KC33"
|
9
|
+
end
|
10
|
+
|
11
|
+
Moip::Assinaturas.token.should == "YSV8NRJLQVS9JNFURG"
|
12
|
+
Moip::Assinaturas.key.should == "ZP33V52G90EBISZMONKBSA5TT18KC33"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|