pagarme 1.9.2 → 1.9.3
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/.travis.yml +1 -0
- data/Gemfile.lock +1 -1
- data/lib/pagarme.rb +11 -4
- data/lib/pagarme/errors.rb +23 -23
- data/lib/pagarme/model.rb +50 -50
- data/lib/pagarme/object.rb +135 -135
- data/lib/pagarme/plan.rb +4 -4
- data/lib/pagarme/request.rb +58 -58
- data/lib/pagarme/subscription.rb +34 -34
- data/lib/pagarme/transaction.rb +15 -8
- data/lib/pagarme/transaction_common.rb +81 -81
- data/lib/pagarme/util.rb +12 -9
- data/pagarme.gemspec +1 -1
- data/test/pagarme/object.rb +17 -17
- data/test/pagarme/plan.rb +9 -9
- data/test/pagarme/subscription.rb +61 -61
- data/test/pagarme/transaction.rb +158 -148
- data/test/test_helper.rb +76 -76
- metadata +2 -2
data/pagarme.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "pagarme"
|
7
|
-
spec.version = '1.9.
|
7
|
+
spec.version = '1.9.3'
|
8
8
|
spec.authors = ["Pedro Franceschi", "Henrique Dubugras"]
|
9
9
|
spec.email = ["pedrohfranceschi@gmail.com", "henrique@pagar.me"]
|
10
10
|
spec.description = %q{Pagar.me's ruby gem}
|
data/test/pagarme/object.rb
CHANGED
@@ -3,27 +3,27 @@ require_relative '../test_helper'
|
|
3
3
|
|
4
4
|
module PagarMe
|
5
5
|
class ObjectTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
should 'be able to create object and add any attribute' do
|
7
|
+
object = PagarMe::PagarMeObject.new({
|
8
|
+
:attr1 => 2
|
9
|
+
})
|
10
10
|
|
11
|
-
|
11
|
+
assert object.attr1 == 2
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
object = PagarMe::PagarMeObject.new
|
14
|
+
object.attr1 = 2
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
assert object.attr1 == 2
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
should 'be able to add nested attributes' do
|
20
|
+
object = PagarMe::PagarMeObject.new({
|
21
|
+
:nested => {
|
22
|
+
:attr => 2
|
23
|
+
}
|
24
|
+
})
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
assert object.nested.attr = 2
|
27
|
+
end
|
28
28
|
end
|
29
29
|
end
|
data/test/pagarme/plan.rb
CHANGED
@@ -17,17 +17,17 @@ module PagarMe
|
|
17
17
|
assert plan.name == 'plano silver'
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
should 'be able to search by anything' do
|
21
|
+
plan = test_plan
|
22
|
+
plan.create
|
23
23
|
|
24
|
-
|
24
|
+
plans = PagarMe::Plan.find_by({:trial_days => 5})
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
assert plans.size
|
27
|
+
plans.each do |p|
|
28
|
+
assert p.trial_days == 5
|
29
|
+
end
|
30
|
+
end
|
31
31
|
|
32
32
|
should 'be able to create with unformatted amount' do
|
33
33
|
plan = test_plan
|
@@ -3,80 +3,80 @@ require_relative '../test_helper'
|
|
3
3
|
|
4
4
|
module PagarMe
|
5
5
|
class SubscriptionTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
should 'be able to create subscription with plan' do
|
7
|
+
plan = test_plan
|
8
|
+
plan.create
|
9
|
+
subscription = test_subscription
|
10
|
+
subscription.plan = plan
|
11
|
+
subscription.create
|
12
|
+
test_plan_response(subscription.plan)
|
13
|
+
test_transaction_with_customer(subscription)
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
should 'be able to create subscription without plan' do
|
17
|
+
subscription = test_subscription({:amount => 2000})
|
18
|
+
subscription.create
|
19
|
+
assert subscription.current_transaction.amount == 2000
|
20
|
+
subscription.charge(2000)
|
21
|
+
assert subscription.current_transaction.kind_of?(PagarMe::Transaction)
|
22
|
+
test_subscription_transaction_response(subscription.current_transaction)
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
should 'be able to search by anything' do
|
26
|
+
subscription = test_subscription_with_customer
|
27
|
+
subscription.create
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
subscriptions = PagarMe::Subscription.find_by({'customer[name]' => 'Jose da Silva'})
|
30
|
+
assert subscriptions.size
|
31
|
+
subscriptions.each do |s|
|
32
|
+
# puts s.inspect unless s.customer.name == 'Jose da Silva'
|
33
|
+
# assert s.customer.name == 'Jose da Silva'
|
34
|
+
end
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
should 'be able to update subscription' do
|
38
|
+
subscription = test_subscription
|
39
|
+
subscription.create
|
40
|
+
subscription.payment_method = 'boleto'
|
41
|
+
subscription.save
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
subscription2 = PagarMe::Subscription.find_by_id(subscription.id)
|
44
|
+
assert subscription2.payment_method == 'boleto'
|
45
|
+
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
should 'be able to change plans' do
|
48
|
+
subscription = test_subscription
|
49
|
+
plan = test_plan
|
50
|
+
plan.create
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
plan2 = PagarMe::Plan.new({
|
53
|
+
:name => "Plano Silver",
|
54
|
+
:days => 30,
|
55
|
+
:amount => 3000
|
56
|
+
});
|
57
|
+
plan2.create
|
58
58
|
|
59
|
-
|
60
|
-
|
59
|
+
subscription.plan = plan
|
60
|
+
subscription.create
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
assert subscription.plan.id == plan.id
|
63
|
+
subscription.plan = plan2
|
64
|
+
subscription.save
|
65
65
|
|
66
|
-
|
67
|
-
|
66
|
+
assert subscription.plan.id == plan2.id
|
67
|
+
end
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
should 'be able to cancel a subscription' do
|
70
|
+
subscription = test_subscription
|
71
|
+
plan = test_plan
|
72
|
+
plan.create
|
73
73
|
|
74
|
-
|
75
|
-
|
74
|
+
subscription.plan = plan
|
75
|
+
subscription.create
|
76
76
|
|
77
|
-
|
77
|
+
subscription.cancel
|
78
78
|
|
79
|
-
|
80
|
-
|
79
|
+
assert subscription.status == 'canceled'
|
80
|
+
end
|
81
81
|
end
|
82
82
|
end
|
data/test/pagarme/transaction.rb
CHANGED
@@ -3,152 +3,162 @@ require_relative '../test_helper'
|
|
3
3
|
|
4
4
|
module PagarMe
|
5
5
|
class TransactionTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
6
|
+
should 'be able to charge' do
|
7
|
+
transaction = test_transaction
|
8
|
+
assert transaction.status == 'local'
|
9
|
+
transaction.charge
|
10
|
+
assert transaction.status == 'paid'
|
11
|
+
test_transaction_response(transaction)
|
12
|
+
end
|
13
|
+
|
14
|
+
should 'be able to refund' do
|
15
|
+
transaction = test_transaction
|
16
|
+
transaction.charge
|
17
|
+
test_transaction_response(transaction)
|
18
|
+
transaction.refund
|
19
|
+
assert transaction.status == 'refunded'
|
20
|
+
end
|
21
|
+
|
22
|
+
should 'be able to search by anything' do
|
23
|
+
transaction = test_transaction_with_customer
|
24
|
+
transaction.charge
|
25
|
+
transactions = PagarMe::Transaction.find_by({'customer[document_number]' => 36433809847}, 2, 10)
|
26
|
+
assert transactions.size == 10
|
27
|
+
transactions.each do |t|
|
28
|
+
assert t.customer.document_number == '36433809847'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'be able to create transaciton with boleto' do
|
33
|
+
transaction = PagarMe::Transaction.new({
|
34
|
+
:payment_method => "boleto",
|
35
|
+
:amount => "1000"
|
36
|
+
})
|
37
|
+
transaction.charge
|
38
|
+
|
39
|
+
assert transaction.payment_method == 'boleto'
|
40
|
+
assert transaction.status == 'waiting_payment'
|
41
|
+
assert transaction.amount.to_s == '1000'
|
42
|
+
end
|
43
|
+
|
44
|
+
should 'be able to send metadata' do
|
45
|
+
transaction = test_transaction
|
46
|
+
transaction.metadata = {event: {:name => "Evento foda", :id => 335}}
|
47
|
+
transaction.charge
|
48
|
+
assert transaction.metadata
|
49
|
+
|
50
|
+
transaction2 = PagarMe::Transaction.find_by_id(transaction.id)
|
51
|
+
assert transaction2.metadata.event.id.to_i == 335
|
52
|
+
assert transaction2.metadata.event.name == "Evento foda"
|
53
|
+
end
|
54
|
+
|
55
|
+
should 'be able to find a transaction' do
|
56
|
+
transaction = test_transaction
|
57
|
+
transaction.charge
|
58
|
+
test_transaction_response(transaction)
|
59
|
+
|
60
|
+
transaction_2 = PagarMe::Transaction.find_by_id(transaction.id)
|
61
|
+
assert transaction_2.id == transaction.id
|
62
|
+
end
|
63
|
+
|
64
|
+
should 'be able to create transaction with customer' do
|
65
|
+
transaction = test_transaction_with_customer
|
66
|
+
transaction.charge
|
67
|
+
test_transaction_response(transaction)
|
68
|
+
assert transaction.address.class == Address
|
69
|
+
assert transaction.address.street== 'Av. Brigadeiro Faria Lima'
|
70
|
+
assert transaction.customer.class == Customer
|
71
|
+
test_customer_response(transaction.customer)
|
72
|
+
end
|
73
|
+
|
74
|
+
should 'be able to refund transaction with customer' do
|
75
|
+
transaction = test_transaction_with_customer
|
76
|
+
transaction.charge
|
77
|
+
test_transaction_response(transaction)
|
78
|
+
assert transaction.customer.class == Customer
|
79
|
+
test_customer_response(transaction.customer)
|
80
|
+
transaction.refund
|
81
|
+
|
82
|
+
assert transaction.status == 'refunded'
|
83
|
+
end
|
84
|
+
|
85
|
+
should 'should allow transactions with R$ amount' do
|
86
|
+
transaction = test_transaction
|
87
|
+
transaction.amount = 'R$ 10.00'
|
88
|
+
transaction.charge
|
89
|
+
assert transaction.amount == 1000
|
90
|
+
end
|
91
|
+
|
92
|
+
should 'validate invalid transaction' do
|
93
|
+
|
94
|
+
#Test invalid card_number
|
95
|
+
exception = assert_raises PagarMeError do
|
96
|
+
transaction = PagarMe::Transaction.new({
|
97
|
+
:amount => "1000",
|
98
|
+
:card_number => '123456',
|
99
|
+
:card_holder_name => "Jose da Silva",
|
100
|
+
})
|
101
|
+
transaction.charge
|
102
|
+
end
|
103
|
+
assert exception.errors.first.parameter_name == 'card_number'
|
104
|
+
|
105
|
+
#Test missing card_holder_name
|
106
|
+
exception = assert_raises PagarMeError do
|
107
|
+
transaction = PagarMe::Transaction.new({
|
108
|
+
:card_number => '4111111111111111',
|
109
|
+
:amount => "1000",
|
110
|
+
})
|
111
|
+
transaction.charge
|
112
|
+
end
|
113
|
+
assert exception.errors.first.parameter_name == 'card_holder_name'
|
114
|
+
|
115
|
+
#Test invalid expiracy month
|
116
|
+
exception = assert_raises PagarMeError do
|
117
|
+
transaction = PagarMe::Transaction.new({
|
118
|
+
:card_number => '4111111111111111',
|
119
|
+
:card_holder_name => "Jose da Silva",
|
120
|
+
:amount => "1000",
|
121
|
+
:card_expiracy_month => 15
|
122
|
+
})
|
123
|
+
transaction.charge
|
124
|
+
end
|
125
|
+
assert exception.errors.first.parameter_name == 'card_expiration_date'
|
126
|
+
|
127
|
+
#Test invalid expiracy year
|
128
|
+
exception = assert_raises PagarMeError do
|
129
|
+
transaction = PagarMe::Transaction.new({
|
130
|
+
:card_number => '4111111111111111',
|
131
|
+
:card_holder_name => "Jose da Silva",
|
132
|
+
:amount => "1000",
|
133
|
+
:card_expiration_month => 12,
|
134
|
+
:card_expiration_year => -1,
|
135
|
+
})
|
136
|
+
transaction.charge
|
137
|
+
end
|
138
|
+
assert exception.errors.first.parameter_name == 'card_expiration_date'
|
139
|
+
|
140
|
+
#Test invalid expiracy year
|
141
|
+
exception = assert_raises PagarMeError do
|
142
|
+
transaction = PagarMe::Transaction.new({
|
143
|
+
:card_number => '4111111111111111',
|
144
|
+
:card_holder_name => "Jose da Silva",
|
145
|
+
:amount => "1000",
|
146
|
+
:card_expiration_month => 12,
|
147
|
+
:card_expiration_year => 16,
|
148
|
+
})
|
149
|
+
transaction.charge
|
150
|
+
end
|
151
|
+
assert exception.errors.first.parameter_name == 'card_cvv'
|
152
|
+
end
|
153
|
+
|
154
|
+
should 'calculate installments' do
|
155
|
+
installments_result = PagarMe::Transaction.calculate_installments({
|
156
|
+
amount: 10000,
|
157
|
+
interest_rate: 0
|
158
|
+
})
|
159
|
+
|
160
|
+
assert installments_result['installments'].size == 12
|
161
|
+
assert installments_result['installments']['2']['installment_amount'] == 5000
|
162
|
+
end
|
154
163
|
end
|
164
|
+
end
|