catarse_pagarme 2.8.5 → 2.8.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f159f3d2a054bdd5836655a9c763fb3c6e6ef8f9
4
- data.tar.gz: 52a927a4fd2eb822c042e5cd1f057a7a589be0a2
3
+ metadata.gz: 26db4840bcee5eb2022afcb48281573e17c0de16
4
+ data.tar.gz: 2272b857389fe2035707d0de97db553344f10f57
5
5
  SHA512:
6
- metadata.gz: 184991715e15d6d9109a35e888152699aa95c0c9dc208012c301ab65e734d7194608b027eb1c4edbcd0f13556185c3b9b5b8bd76febb9ef61b18cba8f67276e8
7
- data.tar.gz: 19ce011fec619af4b6f169b9797a178934ff7166a8ef651dda53af4959bf5e7e8bf8247eb558147463c5fce75fa70b810c27183f95bc2fe679c7aa28909762ac
6
+ metadata.gz: 7845edbad5266a3f09668c2a16c2a3e0e1a9aa9a64f4c0a7363e1ec9deee57773f27cbe8f66c5df62cd95cb546549f662cb538c42091d3e3b04b6840a315d97d
7
+ data.tar.gz: 6583532ef3e7b6797ec751b3ee526e332fb7f308623272ce4c2e87475c1c5da13b2803657d065cdb32abc39f09594cf0a1867dbc2f978a0f2b708d08f5aa3495
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- catarse_pagarme (2.8.5)
4
+ catarse_pagarme (2.8.6)
5
5
  pagarme (= 1.10.0)
6
6
  rails (~> 4.0)
7
7
  sidekiq
@@ -48,7 +48,7 @@ GEM
48
48
  arel (6.0.3)
49
49
  builder (3.2.2)
50
50
  coderay (1.1.0)
51
- concurrent-ruby (1.0.0)
51
+ concurrent-ruby (1.0.1)
52
52
  connection_pool (2.2.0)
53
53
  database_cleaner (1.5.0)
54
54
  diff-lcs (1.2.5)
@@ -71,7 +71,7 @@ GEM
71
71
  mail (2.6.3)
72
72
  mime-types (>= 1.16, < 3)
73
73
  method_source (0.8.2)
74
- mime-types (2.99)
74
+ mime-types (2.99.1)
75
75
  mini_portile (0.6.2)
76
76
  minitest (5.8.1)
77
77
  multi_json (1.11.2)
@@ -141,12 +141,13 @@ GEM
141
141
  connection_pool (~> 2.2, >= 2.2.0)
142
142
  redis (~> 3.2, >= 3.2.1)
143
143
  slop (3.6.0)
144
- sprockets (3.4.0)
144
+ sprockets (3.5.2)
145
+ concurrent-ruby (~> 1.0)
145
146
  rack (> 1, < 3)
146
- sprockets-rails (2.3.3)
147
- actionpack (>= 3.0)
148
- activesupport (>= 3.0)
149
- sprockets (>= 2.8, < 4.0)
147
+ sprockets-rails (3.0.4)
148
+ actionpack (>= 4.0)
149
+ activesupport (>= 4.0)
150
+ sprockets (>= 3.0.0)
150
151
  thor (0.19.1)
151
152
  thread_safe (0.3.5)
152
153
  tzinfo (1.2.2)
@@ -24,8 +24,20 @@ module CatarsePagarme
24
24
  soft_descriptor: payment.project.permalink.gsub(/[\W\_]/, ' ')[0, MAX_SOFT_DESCRIPTOR_LENGTH],
25
25
  installments: get_installment,
26
26
  customer: {
27
- email: payment.user.email,
28
- name: payment.user.name
27
+ email: contribution.payer_email,
28
+ name: contribution.payer_name,
29
+ document_number: document_number,
30
+ address: {
31
+ street: contribution.address_street,
32
+ neighborhood: contribution.address_neighbourhood,
33
+ zipcode: zip_code,
34
+ street_number: contribution.address_number,
35
+ complementary: contribution.address_complement
36
+ },
37
+ phone: {
38
+ ddd: phone_matches.try(:[], 1),
39
+ number: phone_matches.try(:[], 2)
40
+ }
29
41
  },
30
42
  metadata: metadata_attributes
31
43
  }
@@ -36,13 +48,27 @@ module CatarsePagarme
36
48
  hash[:card_id] = params[:card_id]
37
49
  end
38
50
 
39
- if params[:save_card] === "true"
40
- hash[:save_card] = true
41
- end
51
+ hash[:save_card] = (params[:save_card] == 'true')
42
52
 
43
53
  hash
44
54
  end
45
55
 
56
+ def document_number
57
+ (international? || contribution.payer_document.present?) ? '00000000000' : contribution.payer_document.gsub(/[-.\/_\s]/,'')
58
+ end
59
+
60
+ def phone_matches
61
+ international? ? ['33', '33335555'] : contribution.address_phone_number.gsub(/[\s,-]/, '').match(/\((.*)\)(\d+)/)
62
+ end
63
+
64
+ def zip_code
65
+ international? ? '00000000' : contribution.address_zip_code.gsub(/[-.]/, '')
66
+ end
67
+
68
+ def international?
69
+ contribution.international?
70
+ end
71
+
46
72
  def get_installment
47
73
  if payment.value.to_f < CatarsePagarme.configuration.minimum_value_for_installment.to_f
48
74
  1
@@ -1,3 +1,3 @@
1
1
  module CatarsePagarme
2
- VERSION = "2.8.5"
2
+ VERSION = "2.8.6"
3
3
  end
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe CatarsePagarme::CreditCardsController, type: :controller do
4
4
  before do
5
+ @routes = CatarsePagarme::Engine.routes
5
6
  controller.stub(:current_user).and_return(user)
6
7
  end
7
8
 
@@ -15,7 +16,7 @@ describe CatarsePagarme::CreditCardsController, type: :controller do
15
16
 
16
17
  it 'should raise a error' do
17
18
  expect {
18
- post :create, { locale: :pt, id: contribution.id, use_route: 'catarse_pagarme' }
19
+ post :create, { locale: :pt, id: contribution.id }
19
20
  }.to raise_error('invalid user')
20
21
  end
21
22
  end
@@ -26,7 +27,7 @@ describe CatarsePagarme::CreditCardsController, type: :controller do
26
27
  before do
27
28
  allow(CatarsePagarme::CreditCardTransaction).to receive(:new).and_call_original
28
29
  post :create, {
29
- locale: :pt, id: contribution.id, use_route: 'catarse_pagarme',
30
+ locale: :pt, id: contribution.id,
30
31
  card_hash: sample_card_hash }
31
32
  end
32
33
 
@@ -42,7 +43,7 @@ describe CatarsePagarme::CreditCardsController, type: :controller do
42
43
  context 'with invalid card data' do
43
44
  before do
44
45
  post :create, {
45
- locale: :pt, id: contribution.id, use_route: 'catarse_pagarme', card_hash: "abcd" }
46
+ locale: :pt, id: contribution.id, card_hash: "abcd" }
46
47
  end
47
48
 
48
49
  it 'payment_status should be failed' do
@@ -54,7 +55,7 @@ describe CatarsePagarme::CreditCardsController, type: :controller do
54
55
  before do
55
56
  allow_any_instance_of(PagarMe::Transaction).to receive(:charge).and_raise(PagarMe::PagarMeError)
56
57
  post :create, {
57
- locale: :pt, id: contribution.id, use_route: 'catarse_pagarme',
58
+ locale: :pt, id: contribution.id,
58
59
  card_hash: sample_card_hash }
59
60
  end
60
61
 
@@ -4,6 +4,7 @@ describe CatarsePagarme::NotificationsController, type: :controller do
4
4
  let(:fake_transaction) { double("fake transaction", id: payment.gateway_id, card_brand: 'visa', acquirer_name: 'stone', tid: '404040404', installments: 2) }
5
5
 
6
6
  before do
7
+ @routes = CatarsePagarme::Engine.routes
7
8
  PagarMe.stub(:validate_fingerprint).and_return(true)
8
9
  PagarMe::Transaction.stub(:find_by_id).and_return(fake_transaction)
9
10
  end
@@ -21,7 +22,7 @@ describe CatarsePagarme::NotificationsController, type: :controller do
21
22
  context "with invalid payment" do
22
23
  before do
23
24
  PaymentEngines.stub(:find_payment).and_return(nil)
24
- post :create, { locale: :pt, id: 'abcdfg', use_route: 'catarse_pagarme' }
25
+ post :create, { locale: :pt, id: 'abcdfg'}
25
26
  end
26
27
 
27
28
  it "should not found the payment" do
@@ -32,7 +33,7 @@ describe CatarsePagarme::NotificationsController, type: :controller do
32
33
  context "with valid payment" do
33
34
  before do
34
35
  PaymentEngines.stub(:find_payment).and_return(payment)
35
- post :create, { locale: :pt, id: 'abcd', use_route: 'catarse_pagarme' }
36
+ post :create, { locale: :pt, id: 'abcd'}
36
37
  end
37
38
 
38
39
  it "should save an extra_data into payment_notifications" do
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe CatarsePagarme::SlipController, type: :controller do
4
4
  before do
5
+ @routes = CatarsePagarme::Engine.routes
5
6
  controller.stub(:current_user).and_return(user)
6
7
  Bank.create(name: 'foo', code: '123')
7
8
  end
@@ -17,7 +18,7 @@ describe CatarsePagarme::SlipController, type: :controller do
17
18
 
18
19
  it 'should raise a error' do
19
20
  expect {
20
- get :update, locale: :pt, id: contribution.id, use_route: 'catarse_pagarme'
21
+ get :update, locale: :pt, id: contribution.id
21
22
  }.to raise_error('invalid user')
22
23
  end
23
24
  end
@@ -26,7 +27,7 @@ describe CatarsePagarme::SlipController, type: :controller do
26
27
  let(:user) { payment.user }
27
28
 
28
29
  before do
29
- get :update, locale: :pt, id: contribution.id, use_route: 'catarse_pagarme'
30
+ get :update, locale: :pt, id: contribution.id
30
31
  end
31
32
 
32
33
  it 'boleto_url should be filled' do
@@ -41,7 +42,7 @@ describe CatarsePagarme::SlipController, type: :controller do
41
42
 
42
43
  it 'should raise a error' do
43
44
  expect {
44
- post :create, { locale: :pt, id: contribution.id, use_route: 'catarse_pagarme' }
45
+ post :create, { locale: :pt, id: contribution.id }
45
46
  }.to raise_error('invalid user')
46
47
  end
47
48
  end
@@ -51,7 +52,7 @@ describe CatarsePagarme::SlipController, type: :controller do
51
52
 
52
53
  before do
53
54
  post :create, {
54
- locale: :pt, id: contribution.id, use_route: 'catarse_pagarme',
55
+ locale: :pt, id: contribution.id,
55
56
  user: { bank_account_attributes: {
56
57
  bank_id: Bank.first.id, agency: '1', agency_digit: '1', account: '1', account_digit: '1', owner_name: 'foo', owner_document: '1'
57
58
  } } }
@@ -0,0 +1,7 @@
1
+ class City < ActiveRecord::Base
2
+ belongs_to :state
3
+
4
+ def show_name
5
+ "#{self.name}, #{self.state.acronym}"
6
+ end
7
+ end
@@ -1,6 +1,11 @@
1
1
  class Contribution < ActiveRecord::Base
2
2
  belongs_to :user
3
3
  belongs_to :project
4
+ belongs_to :country
4
5
  has_many :payment_notifications
5
6
  has_many :payments
7
+
8
+ def international?
9
+ false
10
+ end
6
11
  end
@@ -0,0 +1,2 @@
1
+ class Country < ActiveRecord::Base
2
+ end
@@ -2,4 +2,21 @@ class Project < ActiveRecord::Base
2
2
  belongs_to :user
3
3
  belongs_to :category
4
4
  has_many :contributions
5
+ has_many :rewards
6
+ has_many :project_transitions
7
+ belongs_to :city
8
+ has_one :account, class_name: "ProjectAccount", inverse_of: :project
9
+
10
+ def pluck_from_database attribute
11
+ Project.where(id: self.id).pluck("projects.#{attribute}").first
12
+ end
13
+
14
+ %w(
15
+ draft rejected online successful waiting_funds
16
+ deleted in_analysis approved failed
17
+ ).each do |st|
18
+ define_method "#{st}_at" do
19
+ pluck_from_database("#{st}_at")
20
+ end
21
+ end
5
22
  end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ class ProjectAccount < ActiveRecord::Base
3
+ belongs_to :project
4
+ belongs_to :bank
5
+ end
@@ -0,0 +1,3 @@
1
+ class ProjectTransition < ActiveRecord::Base
2
+ belongs_to :project, inverse_of: :project_transitions
3
+ end
@@ -0,0 +1,3 @@
1
+ class Reward < ActiveRecord::Base
2
+ belongs_to :project
3
+ end
@@ -0,0 +1,10 @@
1
+ class State < ActiveRecord::Base
2
+ validates_presence_of :name, :acronym
3
+ validates_uniqueness_of :name, :acronym
4
+
5
+ has_many :cities
6
+
7
+ def self.array
8
+ @array ||= order(:name).pluck(:name, :acronym).push(['Outro / Other', 'outro / other'])
9
+ end
10
+ end
Binary file
@@ -3,6 +3,10 @@ FactoryGirl.define do
3
3
  "Foo bar #{n}"
4
4
  end
5
5
 
6
+ sequence :serial do |n|
7
+ n
8
+ end
9
+
6
10
  sequence :email do |n|
7
11
  "person#{n}@example.com"
8
12
  end
@@ -33,7 +37,7 @@ FactoryGirl.define do
33
37
 
34
38
  factory :bank do |f|
35
39
  f.name { generate(:uid) }
36
- f.code '237'
40
+ f.code { generate(:serial) }
37
41
  end
38
42
 
39
43
  factory :bank_account do |f|
@@ -47,23 +51,99 @@ FactoryGirl.define do
47
51
  end
48
52
 
49
53
  factory :project do |f|
54
+ #after(:create) do |project|
55
+ # create(:reward, project: project)
56
+ # if project.state == 'change_to_online_after_create'
57
+ # project.update_attributes(state: 'online')
58
+ # end
59
+ #end
50
60
  f.name "Foo bar"
51
61
  f.permalink { generate(:permalink) }
52
- f.association :user, factory: :user
53
- f.association :category, factory: :category
62
+ f.association :user
63
+ f.association :category
64
+ f.association :city
54
65
  f.about_html "Foo bar"
55
66
  f.headline "Foo bar"
56
67
  f.goal 10000
57
- f.online_date Time.now
58
68
  f.online_days 5
69
+ f.more_links 'Ipsum dolor'
70
+ f.first_contributions 'Foo bar'
59
71
  f.video_url 'http://vimeo.com/17298435'
60
- f.video_thumbnail 'http://vimeo.com/17298435'
61
72
  f.state 'online'
73
+ f.budget '1000'
74
+ f.uploaded_image File.open("#{Rails.root}/spec/support/testimg.png")
75
+ after :create do |project|
76
+ unless project.project_transitions.where(to_state: project.state).present?
77
+ FactoryGirl.create(:project_transition, to_state: project.state, project: project)
78
+ end
79
+
80
+ # should set expires_at when create a project in these states
81
+ if %w(online waiting_funds failed successful).include?(project.state) && project.online_days.present? && project.online_at.present?
82
+ project.expires_at = (project.online_at + project.online_days.days).end_of_day
83
+ project.save
84
+ end
85
+ end
86
+ after :build do |project|
87
+ project.account = build(:project_account, project: nil)
88
+ project.rewards.build(deliver_at: Time.now, minimum_value: 10, description: 'test')
89
+ end
90
+ end
91
+
92
+ factory :flexible_project do |f|
93
+ f.association :project
94
+ f.state 'draft'
95
+
96
+ after :create do |flex_project|
97
+ FactoryGirl.create(:flexible_project_transition, {
98
+ to_state: flex_project.state,
99
+ flexible_project: flex_project
100
+ })
101
+ end
102
+ end
103
+
104
+ factory :flexible_project_transition do |f|
105
+ f.association :flexible_project
106
+ f.most_recent true
107
+ f.to_state 'online'
108
+ f.sort_key { generate(:serial) }
109
+ end
110
+
111
+ factory :project_transition do |f|
112
+ f.association :project
113
+ f.most_recent true
114
+ f.to_state 'online'
115
+ f.sort_key { generate(:serial) }
116
+ end
117
+
118
+ factory :project_account do |f|
119
+ f.association :project
120
+ f.association :bank
121
+ f.email "foo@bar.com"
122
+ f.address_zip_code "foo"
123
+ f.address_neighbourhood "foo"
124
+ f.address_state "foo"
125
+ f.address_city "foo"
126
+ f.address_number "foo"
127
+ f.address_street "foo"
128
+ f.phone_number "1234"
129
+ f.agency "fooo"
130
+ f.agency_digit "foo"
131
+ f.owner_document "foo"
132
+ f.owner_name "foo"
133
+ f.account "1"
134
+ f.account_digit "1000"
135
+ f.account_type "foo"
62
136
  end
63
137
 
64
138
  factory :contribution do |f|
65
139
  f.association :project, factory: :project
66
140
  f.association :user, factory: :user
141
+ f.address_phone_number '(33) 3333-3333'
142
+ f.address_neighbourhood 'lorem'
143
+ f.address_number 'lnumber'
144
+ f.address_street 'lstreet lorem'
145
+ f.address_zip_code '33600-000'
146
+ f.payer_document '872.123.775-11'
67
147
  f.value 10.00
68
148
  f.payer_name 'Foo Bar'
69
149
  f.payer_email 'foo@bar.com'
@@ -84,6 +164,16 @@ FactoryGirl.define do
84
164
  payment.gateway = 'pagarme'
85
165
  end
86
166
  end
167
+
168
+ factory :state do
169
+ name { generate(:name) }
170
+ acronym { generate(:name) }
171
+ end
172
+
173
+ factory :city do |f|
174
+ f.association :state
175
+ f.name "foo"
176
+ end
87
177
  end
88
178
 
89
179
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catarse_pagarme
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.5
4
+ version: 2.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antônio Roberto Silva
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-19 00:00:00.000000000 Z
12
+ date: 2016-03-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -189,14 +189,20 @@ files:
189
189
  - spec/dummy/app/models/bank.rb
190
190
  - spec/dummy/app/models/bank_account.rb
191
191
  - spec/dummy/app/models/category.rb
192
+ - spec/dummy/app/models/city.rb
192
193
  - spec/dummy/app/models/concerns/.keep
193
194
  - spec/dummy/app/models/contribution.rb
195
+ - spec/dummy/app/models/country.rb
194
196
  - spec/dummy/app/models/credit_card.rb
195
197
  - spec/dummy/app/models/payment.rb
196
198
  - spec/dummy/app/models/payment_engines.rb
197
199
  - spec/dummy/app/models/payment_notification.rb
198
200
  - spec/dummy/app/models/payment_transfer.rb
199
201
  - spec/dummy/app/models/project.rb
202
+ - spec/dummy/app/models/project_account.rb
203
+ - spec/dummy/app/models/project_transition.rb
204
+ - spec/dummy/app/models/reward.rb
205
+ - spec/dummy/app/models/state.rb
200
206
  - spec/dummy/app/models/user.rb
201
207
  - spec/dummy/app/models/user_total.rb
202
208
  - spec/dummy/app/views/layouts/application.html.erb
@@ -229,6 +235,7 @@ files:
229
235
  - spec/dummy/public/422.html
230
236
  - spec/dummy/public/500.html
231
237
  - spec/dummy/public/favicon.ico
238
+ - spec/dummy/spec/support/testimg.png
232
239
  - spec/helpers/catarse_pagarme/application_helper_spec.rb
233
240
  - spec/models/catarse_pagarme/bank_account_concern_spec.rb
234
241
  - spec/models/catarse_pagarme/credit_card_transaction_spec.rb
@@ -278,14 +285,20 @@ test_files:
278
285
  - spec/dummy/app/models/bank.rb
279
286
  - spec/dummy/app/models/bank_account.rb
280
287
  - spec/dummy/app/models/category.rb
288
+ - spec/dummy/app/models/city.rb
281
289
  - spec/dummy/app/models/concerns/.keep
282
290
  - spec/dummy/app/models/contribution.rb
291
+ - spec/dummy/app/models/country.rb
283
292
  - spec/dummy/app/models/credit_card.rb
284
293
  - spec/dummy/app/models/payment.rb
285
294
  - spec/dummy/app/models/payment_engines.rb
286
295
  - spec/dummy/app/models/payment_notification.rb
287
296
  - spec/dummy/app/models/payment_transfer.rb
288
297
  - spec/dummy/app/models/project.rb
298
+ - spec/dummy/app/models/project_account.rb
299
+ - spec/dummy/app/models/project_transition.rb
300
+ - spec/dummy/app/models/reward.rb
301
+ - spec/dummy/app/models/state.rb
289
302
  - spec/dummy/app/models/user.rb
290
303
  - spec/dummy/app/models/user_total.rb
291
304
  - spec/dummy/app/views/layouts/application.html.erb
@@ -318,6 +331,7 @@ test_files:
318
331
  - spec/dummy/public/422.html
319
332
  - spec/dummy/public/500.html
320
333
  - spec/dummy/public/favicon.ico
334
+ - spec/dummy/spec/support/testimg.png
321
335
  - spec/helpers/catarse_pagarme/application_helper_spec.rb
322
336
  - spec/models/catarse_pagarme/bank_account_concern_spec.rb
323
337
  - spec/models/catarse_pagarme/credit_card_transaction_spec.rb