pagarme 1.9.2 → 1.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.2'
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}
@@ -3,27 +3,27 @@ require_relative '../test_helper'
3
3
 
4
4
  module PagarMe
5
5
  class ObjectTest < Test::Unit::TestCase
6
- should 'be able to create object and add any attribute' do
7
- object = PagarMe::PagarMeObject.new({
8
- :attr1 => 2
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
- assert object.attr1 == 2
11
+ assert object.attr1 == 2
12
12
 
13
- object = PagarMe::PagarMeObject.new
14
- object.attr1 = 2
13
+ object = PagarMe::PagarMeObject.new
14
+ object.attr1 = 2
15
15
 
16
- assert object.attr1 == 2
17
- end
16
+ assert object.attr1 == 2
17
+ end
18
18
 
19
- should 'be able to add nested attributes' do
20
- object = PagarMe::PagarMeObject.new({
21
- :nested => {
22
- :attr => 2
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
- assert object.nested.attr = 2
27
- end
26
+ assert object.nested.attr = 2
27
+ end
28
28
  end
29
29
  end
@@ -17,17 +17,17 @@ module PagarMe
17
17
  assert plan.name == 'plano silver'
18
18
  end
19
19
 
20
- should 'be able to search by anything' do
21
- plan = test_plan
22
- plan.create
20
+ should 'be able to search by anything' do
21
+ plan = test_plan
22
+ plan.create
23
23
 
24
- plans = PagarMe::Plan.find_by({:trial_days => 5})
24
+ plans = PagarMe::Plan.find_by({:trial_days => 5})
25
25
 
26
- assert plans.size
27
- plans.each do |p|
28
- assert p.trial_days == 5
29
- end
30
- end
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
- 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
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
- 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
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
- should 'be able to search by anything' do
26
- subscription = test_subscription_with_customer
27
- subscription.create
25
+ should 'be able to search by anything' do
26
+ subscription = test_subscription_with_customer
27
+ subscription.create
28
28
 
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
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
- should 'be able to update subscription' do
38
- subscription = test_subscription
39
- subscription.create
40
- subscription.payment_method = 'boleto'
41
- subscription.save
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
- subscription2 = PagarMe::Subscription.find_by_id(subscription.id)
44
- assert subscription2.payment_method == 'boleto'
45
- end
43
+ subscription2 = PagarMe::Subscription.find_by_id(subscription.id)
44
+ assert subscription2.payment_method == 'boleto'
45
+ end
46
46
 
47
- should 'be able to change plans' do
48
- subscription = test_subscription
49
- plan = test_plan
50
- plan.create
47
+ should 'be able to change plans' do
48
+ subscription = test_subscription
49
+ plan = test_plan
50
+ plan.create
51
51
 
52
- plan2 = PagarMe::Plan.new({
53
- :name => "Plano Silver",
54
- :days => 30,
55
- :amount => 3000
56
- });
57
- plan2.create
52
+ plan2 = PagarMe::Plan.new({
53
+ :name => "Plano Silver",
54
+ :days => 30,
55
+ :amount => 3000
56
+ });
57
+ plan2.create
58
58
 
59
- subscription.plan = plan
60
- subscription.create
59
+ subscription.plan = plan
60
+ subscription.create
61
61
 
62
- assert subscription.plan.id == plan.id
63
- subscription.plan = plan2
64
- subscription.save
62
+ assert subscription.plan.id == plan.id
63
+ subscription.plan = plan2
64
+ subscription.save
65
65
 
66
- assert subscription.plan.id == plan2.id
67
- end
66
+ assert subscription.plan.id == plan2.id
67
+ end
68
68
 
69
- should 'be able to cancel a subscription' do
70
- subscription = test_subscription
71
- plan = test_plan
72
- plan.create
69
+ should 'be able to cancel a subscription' do
70
+ subscription = test_subscription
71
+ plan = test_plan
72
+ plan.create
73
73
 
74
- subscription.plan = plan
75
- subscription.create
74
+ subscription.plan = plan
75
+ subscription.create
76
76
 
77
- subscription.cancel
77
+ subscription.cancel
78
78
 
79
- assert subscription.status == 'canceled'
80
- end
79
+ assert subscription.status == 'canceled'
80
+ end
81
81
  end
82
82
  end
@@ -3,152 +3,162 @@ require_relative '../test_helper'
3
3
 
4
4
  module PagarMe
5
5
  class TransactionTest < Test::Unit::TestCase
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
- end
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