catarse_pagarme 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +120 -0
- data/MIT-LICENSE +20 -0
- data/README.md +35 -0
- data/Rakefile +34 -0
- data/app/assets/images/catarse_pagarme/.keep +0 -0
- data/app/assets/javascripts/catarse_pagarme.js +5 -0
- data/app/assets/javascripts/catarse_pagarme/application.js +12 -0
- data/app/assets/javascripts/catarse_pagarme/credit_card.js +142 -0
- data/app/assets/javascripts/catarse_pagarme/payment_choice.js +22 -0
- data/app/assets/javascripts/catarse_pagarme/payment_slip.js +63 -0
- data/app/assets/stylesheets/catarse_pagarme/application.css +15 -0
- data/app/controllers/catarse_pagarme/application_controller.rb +51 -0
- data/app/controllers/catarse_pagarme/credit_card_base_controller.rb +48 -0
- data/app/controllers/catarse_pagarme/credit_cards_controller.rb +8 -0
- data/app/controllers/catarse_pagarme/notifications_controller.rb +20 -0
- data/app/controllers/catarse_pagarme/pagarme_controller.rb +10 -0
- data/app/controllers/catarse_pagarme/slip_controller.rb +43 -0
- data/app/controllers/catarse_pagarme/subscriptions_controller.rb +27 -0
- data/app/helpers/catarse_pagarme/application_helper.rb +23 -0
- data/app/models/catarse_pagarme/contribution_concern.rb +9 -0
- data/app/models/catarse_pagarme/contribution_delegator.rb +94 -0
- data/app/models/catarse_pagarme/credit_card_concern.rb +9 -0
- data/app/models/catarse_pagarme/credit_card_delegator.rb +26 -0
- data/app/models/catarse_pagarme/credit_card_transaction.rb +11 -0
- data/app/models/catarse_pagarme/payment_type.rb +6 -0
- data/app/models/catarse_pagarme/save_credit_card_transaction.rb +33 -0
- data/app/models/catarse_pagarme/slip_transaction.rb +37 -0
- data/app/models/catarse_pagarme/subscription_transaction.rb +21 -0
- data/app/models/catarse_pagarme/transaction_base.rb +36 -0
- data/app/views/catarse_pagarme/pagarme/review.html.slim +112 -0
- data/app/views/layouts/catarse_pagarme/application.html.erb +14 -0
- data/bin/rails +12 -0
- data/catarse_pagarme.gemspec +26 -0
- data/config/initializers/register.rb +5 -0
- data/config/routes.rb +15 -0
- data/lib/catarse_pagarme.rb +19 -0
- data/lib/catarse_pagarme/configuration.rb +16 -0
- data/lib/catarse_pagarme/engine.rb +10 -0
- data/lib/catarse_pagarme/payment_engine.rb +37 -0
- data/lib/catarse_pagarme/version.rb +3 -0
- data/lib/tasks/catarse_pagarme_tasks.rake +4 -0
- data/spec/controllers/catarse_pagarme/credit_cards_controller_spec.rb +62 -0
- data/spec/controllers/catarse_pagarme/notifications_controller_spec.rb +41 -0
- data/spec/controllers/catarse_pagarme/pagarme_controller_spec.rb +5 -0
- data/spec/controllers/catarse_pagarme/slip_controller_spec.rb +68 -0
- data/spec/controllers/catarse_pagarme/subscriptions_controller_spec.rb +95 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/bank_account.rb +5 -0
- data/spec/dummy/app/models/category.rb +2 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/contribution.rb +29 -0
- data/spec/dummy/app/models/credit_card.rb +3 -0
- data/spec/dummy/app/models/payment_engines.rb +2 -0
- data/spec/dummy/app/models/payment_notification.rb +3 -0
- data/spec/dummy/app/models/project.rb +5 -0
- data/spec/dummy/app/models/user.rb +13 -0
- data/spec/dummy/app/models/user_total.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +23 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +55 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +82 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/pagarme.rb +6 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/helpers/catarse_pagarme/application_helper_spec.rb +23 -0
- data/spec/models/catarse_pagarme/contribution_delegator_spec.rb +146 -0
- data/spec/models/catarse_pagarme/credit_card_transaction_spec.rb +70 -0
- data/spec/models/catarse_pagarme/slip_transaction_spec.rb +102 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/support/factories.rb +70 -0
- metadata +280 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CatarsePagarme::NotificationsController do
|
4
|
+
before do
|
5
|
+
PagarMe.stub(:validate_fingerprint).and_return(true)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:project) { create(:project, goal: 10_000, state: 'online') }
|
9
|
+
let(:contribution) { create(:contribution, value: 10, project: project) }
|
10
|
+
let(:credit_card) { create(:credit_card, subscription_id: '1542')}
|
11
|
+
|
12
|
+
describe 'CREATE' do
|
13
|
+
context "with invalid contribution" do
|
14
|
+
before do
|
15
|
+
PaymentEngines.stub(:find_payment).and_return(nil)
|
16
|
+
post :create, { locale: :pt, id: 'abcdfg', use_route: 'catarse_pagarme' }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not found the contribution" do
|
20
|
+
expect(response.code.to_i).to eq(404)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with valid contribution" do
|
25
|
+
before do
|
26
|
+
PaymentEngines.stub(:find_payment).and_return(contribution)
|
27
|
+
post :create, { locale: :pt, id: contribution.id, use_route: 'catarse_pagarme' }
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should save an extra_data into payment_notifications" do
|
31
|
+
expect(contribution.payment_notifications.size).to eq(1)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return 200 status" do
|
35
|
+
expect(response.code.to_i).to eq(200)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CatarsePagarme::SlipController do
|
4
|
+
before do
|
5
|
+
PaymentEngines.stub(:find_payment).and_return(contribution)
|
6
|
+
controller.stub(:current_user).and_return(user)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:project) { create(:project, goal: 10_000, state: 'online') }
|
10
|
+
let(:contribution) { create(:contribution, value: 10, project: project) }
|
11
|
+
let(:credit_card) { create(:credit_card, subscription_id: '1542')}
|
12
|
+
|
13
|
+
describe 'pay with slip' do
|
14
|
+
context 'without an user' do
|
15
|
+
let(:user) { nil }
|
16
|
+
|
17
|
+
it 'should raise a error' do
|
18
|
+
expect {
|
19
|
+
post :create, { locale: :pt, project_id: project.id, contribution_id: contribution.id, use_route: 'catarse_pagarme' }
|
20
|
+
}.to raise_error('invalid user')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'with an user' do
|
25
|
+
let(:user) { contribution.user }
|
26
|
+
|
27
|
+
context 'with valid bank account data' do
|
28
|
+
before do
|
29
|
+
post :create, {
|
30
|
+
locale: :pt, project_id: project.id, contribution_id: contribution.id, use_route: 'catarse_pagarme',
|
31
|
+
user: { bank_account_attributes: {
|
32
|
+
name: 'bank', agency: '1', agency_digit: '1', account: '1', account_digit: '1', owner_name: 'foo', owner_document: '1'
|
33
|
+
} } }
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'boleto_url should be filled' do
|
37
|
+
expect(ActiveSupport::JSON.decode(response.body)['boleto_url']).not_to be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'payment_status should be waiting_payment' do
|
41
|
+
expect(ActiveSupport::JSON.decode(response.body)['payment_status']).to eq 'waiting_payment'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'with invalid bank account data' do
|
46
|
+
let(:user) { contribution.user }
|
47
|
+
|
48
|
+
before do
|
49
|
+
post :create, { locale: :pt, project_id: project.id, contribution_id: contribution.id, use_route: 'catarse_pagarme', user: { bank_account_attributes: { name: '' } } }
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'boleto_url should be nil' do
|
53
|
+
expect(ActiveSupport::JSON.decode(response.body)['boleto_url']).to be_nil
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'payment_status should be failed' do
|
57
|
+
expect(ActiveSupport::JSON.decode(response.body)['payment_status']).to eq 'failed'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'message should be filled' do
|
61
|
+
expect(ActiveSupport::JSON.decode(response.body)['message']).not_to be_nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CatarsePagarme::SubscriptionsController do
|
4
|
+
before do
|
5
|
+
PaymentEngines.stub(:find_payment).and_return(contribution)
|
6
|
+
controller.stub(:current_user).and_return(user)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:project) { create(:project, goal: 10_000, state: 'online') }
|
10
|
+
let(:contribution) { create(:contribution, value: 10, project: project) }
|
11
|
+
let(:credit_card) { create(:credit_card, subscription_id: '1542')}
|
12
|
+
|
13
|
+
describe "pay with a saved credit card" do
|
14
|
+
context 'without an user' do
|
15
|
+
let(:user) { nil }
|
16
|
+
|
17
|
+
it 'should raise a error' do
|
18
|
+
expect {
|
19
|
+
post :create, { locale: :pt, project_id: project.id, contribution_id: contribution.id, use_route: 'catarse_pagarme' }
|
20
|
+
}.to raise_error('invalid user')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'with an user' do
|
25
|
+
let(:user) { contribution.user }
|
26
|
+
context 'when subscription_id not associated with contribution user' do
|
27
|
+
before do
|
28
|
+
put :update, { locale: :pt, subscription_id: '1542', project_id: project.id, contribution_id: contribution.id, use_route: 'catarse_pagarme' }
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'payment_status should be failed' do
|
32
|
+
expect(ActiveSupport::JSON.decode(response.body)['payment_status']).to eq('failed')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'message should be filled' do
|
36
|
+
expect(ActiveSupport::JSON.decode(response.body)['message']).to eq('invalid subscription')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'pay and save credit card' do
|
43
|
+
context 'without an user' do
|
44
|
+
let(:user) { nil }
|
45
|
+
|
46
|
+
it 'should raise a error' do
|
47
|
+
expect {
|
48
|
+
post :create, { locale: :pt, project_id: project.id, contribution_id: contribution.id, use_route: 'catarse_pagarme' }
|
49
|
+
}.to raise_error('invalid user')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with an user" do
|
54
|
+
let(:user) { contribution.user }
|
55
|
+
|
56
|
+
context 'with invalid card data' do
|
57
|
+
before do
|
58
|
+
post :create, {
|
59
|
+
locale: :pt, project_id: project.id, contribution_id: contribution.id, use_route: 'catarse_pagarme',
|
60
|
+
payment_card_date: '', payment_card_name: '',
|
61
|
+
payment_card_source: '143', payment_card_installments: '1' }
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'payment_status should be failed' do
|
65
|
+
expect(ActiveSupport::JSON.decode(response.body)['payment_status']).to eq('failed')
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'message should be filled' do
|
69
|
+
expect(ActiveSupport::JSON.decode(response.body)['message']).not_to be_nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "with valid card data" do
|
74
|
+
before do
|
75
|
+
post :create, {
|
76
|
+
locale: :pt, project_id: project.id, contribution_id: contribution.id, use_route: 'catarse_pagarme',
|
77
|
+
payment_card_date: '10/17', payment_card_number: '4901720080344448', payment_card_name: 'Foo bar',
|
78
|
+
payment_card_source: '143', payment_card_installments: '1' }
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should save card data into user" do
|
82
|
+
expect(user.credit_cards.count).to eq(1)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'payment_status should be filled and not failed' do
|
86
|
+
expect(ActiveSupport::JSON.decode(response.body)['payment_status']).not_to be_nil
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'and payment_status is not failed' do
|
90
|
+
expect(ActiveSupport::JSON.decode(response.body)['payment_status']).not_to eq('failed')
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Contribution < ActiveRecord::Base
|
2
|
+
belongs_to :user
|
3
|
+
belongs_to :project
|
4
|
+
has_many :payment_notifications
|
5
|
+
|
6
|
+
def confirmed?
|
7
|
+
false
|
8
|
+
end
|
9
|
+
|
10
|
+
def update_current_billing_info
|
11
|
+
end
|
12
|
+
|
13
|
+
def confirm!
|
14
|
+
true
|
15
|
+
end
|
16
|
+
alias :confirm :confirm!
|
17
|
+
|
18
|
+
def waiting_confirmation?
|
19
|
+
end
|
20
|
+
|
21
|
+
def waiting
|
22
|
+
end
|
23
|
+
|
24
|
+
def cancel
|
25
|
+
end
|
26
|
+
|
27
|
+
def canceled?
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
has_many :projects
|
3
|
+
has_many :contributions
|
4
|
+
has_many :credit_cards
|
5
|
+
has_one :user_total
|
6
|
+
has_one :bank_account
|
7
|
+
|
8
|
+
accepts_nested_attributes_for :bank_account
|
9
|
+
|
10
|
+
def credits
|
11
|
+
user_total.present? ? user_total.credits : 0
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/spec/dummy/bin/rake
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require(*Rails.groups)
|
6
|
+
require "catarse_pagarme"
|
7
|
+
|
8
|
+
module Dummy
|
9
|
+
class Application < Rails::Application
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
11
|
+
# Application configuration should go into files in config/initializers
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
13
|
+
|
14
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
15
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
16
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
17
|
+
|
18
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
19
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
20
|
+
# config.i18n.default_locale = :de
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|