From 820c4903a8757d040fb99c307c9dbcd2e84df244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Roberto?= Date: Thu, 11 Dec 2014 11:09:39 -0200 Subject: [PATCH 01/16] adjust best_in_place and postgres-copy versions --- Gemfile | 5 +++-- Gemfile.lock | 32 ++++++++++---------------------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/Gemfile b/Gemfile index 339f0707..d542f55a 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,8 @@ gem 'sidekiq', '~> 2.13.0' gem 'sinatra', require: false # required by sidekiq web interface mounted on /sidekiq # Turns every field on a editable one -gem 'best_in_place', github: 'bernat/best_in_place', branch: 'rails-4' +#gem 'best_in_place', github: 'bernat/best_in_place', branch: 'rails-4' +gem 'best_in_place' # State machine for attributes on models gem 'state_machine', require: 'state_machine/core' @@ -22,7 +23,7 @@ gem 'paper_trail', github: 'airblade/paper_trail', branch: 'rails4' # Database and data related gem 'pg' -gem 'postgres-copy', github: 'josemarluedke/postgres-copy', branch: 'rails4' +gem 'postgres-copy'#, github: 'josemarluedke/postgres-copy', branch: 'rails4' gem 'pg_search' gem 'schema_plus', '~> 1.2.0' gem 'schema_associations', '~> 1.2.0' diff --git a/Gemfile.lock b/Gemfile.lock index 458815d5..bc79f384 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,15 +7,6 @@ GIT activerecord (~> 4.0) railties (~> 4.0) -GIT - remote: git://github.com/bernat/best_in_place.git - revision: 366413be357d65cdf47031e928aea969f72e3659 - branch: rails-4 - specs: - best_in_place (2.0.3) - jquery-rails - rails (~> 4) - GIT remote: git://github.com/catarse/catarse_mailchimp revision: 2ed4f3931dfa292e5c1c62619772f04e41c68629 @@ -34,17 +25,6 @@ GIT httparty (~> 0.6.1) nokogiri (~> 1.5.0) -GIT - remote: git://github.com/josemarluedke/postgres-copy.git - revision: 41afec70f5c6b2431f045388b14a80d194329a20 - branch: rails4 - specs: - postgres-copy (0.6.0) - activerecord (>= 3.0.0) - pg - rails (>= 3.0.0) - responders - GIT remote: git://github.com/ryanb/cancan.git revision: f1cebde51a87be149b4970a3287826bb63c0ac0b @@ -101,6 +81,9 @@ GEM rinku tag_helper bcrypt-ruby (3.1.1) + best_in_place (3.0.0) + actionpack (>= 3.2) + railties (>= 3.2) better_errors (0.9.0) coderay (>= 1.0.0) erubis (>= 2.6.6) @@ -301,6 +284,11 @@ GEM faye-websocket (>= 0.4.4, < 0.5.0) http_parser.rb (~> 0.5.3) polyglot (0.3.3) + postgres-copy (0.9.0) + activerecord (>= 4.0) + pg (>= 0.17) + rails (>= 4.0) + responders protected_attributes (1.0.3) activemodel (>= 4.0.0, < 5.0) pry (0.9.12.2) @@ -464,7 +452,7 @@ PLATFORMS DEPENDENCIES RedCloth auto_html (= 1.4.2) - best_in_place! + best_in_place better_errors binding_of_caller cancan! @@ -510,7 +498,7 @@ DEPENDENCIES pg pg_search poltergeist - postgres-copy! + postgres-copy protected_attributes (~> 1.0.3) pry rack-timeout From 869d4d3fec95399745c0f7aee07770cc802002ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Roberto?= Date: Thu, 11 Dec 2014 11:09:47 -0200 Subject: [PATCH 02/16] added bank / bank_accounts --- app/models/bank.rb | 20 +++++++++++++ app/models/bank_account.rb | 13 +++++++++ .../20141211124556_create_bank_accounts.rb | 17 +++++++++++ db/migrate/20141211125209_create_banks.rb | 11 ++++++++ ...41211125359_add_bank_into_bank_accounts.rb | 5 ++++ ...0_change_remove_name_from_bank_accounts.rb | 5 ++++ spec/factories.rb | 15 ++++++++++ spec/models/bank_account_spec.rb | 17 +++++++++++ spec/models/bank_spec.rb | 28 +++++++++++++++++++ 9 files changed, 131 insertions(+) create mode 100644 app/models/bank.rb create mode 100644 app/models/bank_account.rb create mode 100644 db/migrate/20141211124556_create_bank_accounts.rb create mode 100644 db/migrate/20141211125209_create_banks.rb create mode 100644 db/migrate/20141211125359_add_bank_into_bank_accounts.rb create mode 100644 db/migrate/20141211130230_change_remove_name_from_bank_accounts.rb create mode 100644 spec/models/bank_account_spec.rb create mode 100644 spec/models/bank_spec.rb diff --git a/app/models/bank.rb b/app/models/bank.rb new file mode 100644 index 00000000..de36a007 --- /dev/null +++ b/app/models/bank.rb @@ -0,0 +1,20 @@ +class Bank < ActiveRecord::Base + has_many :bank_accounts + + validates :name, :code, presence: true + scope :order_popular, ->{ + select('banks.code, banks.id, banks.name, count(bank_accounts.bank_id) as total'). + joins('left join bank_accounts on bank_accounts.bank_id = banks.id'). + group('banks.id, bank_accounts.bank_id').order('total DESC') + } + + def self.to_collection + order_popular.map do |bank| + [bank.to_s, bank.id] + end + end + + def to_s + [code, name].join(' . ') + end +end diff --git a/app/models/bank_account.rb b/app/models/bank_account.rb new file mode 100644 index 00000000..34a0d0ff --- /dev/null +++ b/app/models/bank_account.rb @@ -0,0 +1,13 @@ +class BankAccount < ActiveRecord::Base + #include CatarsePagarme::BankAccountConcern + + belongs_to :user + belongs_to :bank + + validates :bank_id, :agency, :account, :owner_name, :owner_document, :account_digit, presence: true + + def bank_code + self.bank.code + end +end + diff --git a/db/migrate/20141211124556_create_bank_accounts.rb b/db/migrate/20141211124556_create_bank_accounts.rb new file mode 100644 index 00000000..58e81226 --- /dev/null +++ b/db/migrate/20141211124556_create_bank_accounts.rb @@ -0,0 +1,17 @@ +class CreateBankAccounts < ActiveRecord::Migration + def change + create_table :bank_accounts do |t| + t.references :user, index: true + t.text :name, null: false + t.text :account, null: false + t.text :account_digit + t.text :agency, null: false + t.text :agency_digit + t.text :owner_name, null: false + t.text :owner_document, null: false + + t.timestamps + t.timestamps + end + end +end diff --git a/db/migrate/20141211125209_create_banks.rb b/db/migrate/20141211125209_create_banks.rb new file mode 100644 index 00000000..645c496c --- /dev/null +++ b/db/migrate/20141211125209_create_banks.rb @@ -0,0 +1,11 @@ +class CreateBanks < ActiveRecord::Migration + def change + create_table :banks do |t| + t.text :name, null: false + t.text :code, null: false + + t.timestamps + end + add_index :banks, :code, unique: true + end +end diff --git a/db/migrate/20141211125359_add_bank_into_bank_accounts.rb b/db/migrate/20141211125359_add_bank_into_bank_accounts.rb new file mode 100644 index 00000000..9e0ed39a --- /dev/null +++ b/db/migrate/20141211125359_add_bank_into_bank_accounts.rb @@ -0,0 +1,5 @@ +class AddBankIntoBankAccounts < ActiveRecord::Migration + def change + add_column :bank_accounts, :bank_id, :integer, index: true + end +end diff --git a/db/migrate/20141211130230_change_remove_name_from_bank_accounts.rb b/db/migrate/20141211130230_change_remove_name_from_bank_accounts.rb new file mode 100644 index 00000000..3658991f --- /dev/null +++ b/db/migrate/20141211130230_change_remove_name_from_bank_accounts.rb @@ -0,0 +1,5 @@ +class ChangeRemoveNameFromBankAccounts < ActiveRecord::Migration + def change + remove_column :bank_accounts, :name + end +end diff --git a/spec/factories.rb b/spec/factories.rb index c55d3982..845823fa 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -15,6 +15,21 @@ "foo_page_#{n}" end + factory :bank do + name "Foo" + code "000" + end + + factory :bank_account do |f| + f.association :user, factory: :user + f.association :bank, factory: :bank + owner_name "Foo" + owner_document "000" + account_digit "1" + agency "1" + account "1" + end + factory :user do |f| f.name "Foo bar" f.password "123456" diff --git a/spec/models/bank_account_spec.rb b/spec/models/bank_account_spec.rb new file mode 100644 index 00000000..4b546fb6 --- /dev/null +++ b/spec/models/bank_account_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe BankAccount do + describe "associations" do + it{ should belong_to :user } + end + + describe "Validations" do + it{ should validate_presence_of(:bank_id) } + it{ should validate_presence_of(:agency) } + it{ should validate_presence_of(:account) } + it{ should validate_presence_of(:account_digit) } + it{ should validate_presence_of(:owner_name) } + it{ should validate_presence_of(:owner_document) } + end + +end diff --git a/spec/models/bank_spec.rb b/spec/models/bank_spec.rb new file mode 100644 index 00000000..55a29d2b --- /dev/null +++ b/spec/models/bank_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe Bank do + describe ".order_popular" do + subject { Bank.order_popular } + let(:user_01) { create(:user) } + let(:bank_01) { create(:bank, name: "Foo") } + let(:bank_02) { create(:bank, name: "Foo bar", code: "001") } + + before do + user_01 + bank_01 + bank_02 + end + + context "we have bank accounts" do + before do + @bank_account01 = create(:bank_account, user: user_01, bank: bank_01) + @bank_account02 = create(:bank_account, user: user_01, bank: bank_01) + @bank_account03 = create(:bank_account, user: user_01, bank: bank_02) + end + + it "should return a collection with banks in order of most used" do + should eq([bank_01, bank_02]) + end + end + end +end From dec8737c639e7ae43c289cd3258a706e0589d7be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Roberto?= Date: Thu, 11 Dec 2014 11:38:20 -0200 Subject: [PATCH 03/16] added bank_account form on user settings --- app/assets/stylesheets/miv/_index.sass | 50 ++++++++++++++++++- app/controllers/users_controller.rb | 6 +++ app/models/user.rb | 2 + .../users/_current_user_fields.html.slim | 22 ++++++++ config/locales/pt.yml | 12 +++++ 5 files changed, 90 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/miv/_index.sass b/app/assets/stylesheets/miv/_index.sass index 6cb8872d..8ef65baf 100644 --- a/app/assets/stylesheets/miv/_index.sass +++ b/app/assets/stylesheets/miv/_index.sass @@ -34,7 +34,7 @@ +box-shadow(rgba(black,0.75) 0px 0px 5px inset !important) &:active +box-shadow(rgba(black, 1) 0px 0px 15px inset !important) - + #announcement display: block padding: 10px @@ -148,4 +148,50 @@ span.on_the_spot_editing .avatar_wrapper overflow: hidden - +.brbanks-banks + margin: 0 !important + padding: 5px !important + position: absolute + width: 260px + max-height: 200px + overflow: auto + background: white + border: #dfdfdf 1px solid + border-radius: 4px + ul + padding: 0 !important + margin: 0 !important + list-style-position: inside + list-style-type: none + li + margin: 0 !important + font-size: 12px !important + padding: 5px 0 + &:hover + background: #ededed +.bank_accounts + .input, .inputs + float: left + width: 160px + #user_bank_account_attributes_agency_input, .user_bank_account_agency + width: 60px + input[type='text'] + width: 40px + #user_bank_account_attributes_agency_digit_input, .user_bank_account_agency_digit + width: 60px + input[type='text'] + width: 40px + #user_bank_account_attributes_name_input, .user_bank_account_name + width: 220px + input[type='text'] + width: 200px + #user_bank_account_attributes_account_input, .user_bank_account_account + width: 150px + input[type='text'] + width: 130px + #user_bank_account_attributes_account_digit_input, .user_bank_account_account_digit + width: 60px + input[type='text'] + width: 40px + input[type='text'] + width: 140px diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e9289049..0bef8ab0 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -20,6 +20,7 @@ def show @credits = @user.backs.can_refund @subscribed_to_updates = @user.updates_subscription @unsubscribes = @user.project_unsubscribes + build_bank_account } end @@ -74,4 +75,9 @@ def credits @credits = @user.backs.can_refund.order(:id).all render json: @credits end + + private + def build_bank_account + @user.build_bank_account unless @user.bank_account + end end diff --git a/app/models/user.rb b/app/models/user.rb index 589c3bd7..286d5443 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -70,6 +70,7 @@ class User < ActiveRecord::Base has_many :oauth_providers, through: :authorizations has_many :backs, class_name: "Backer" has_one :user_total + has_one :bank_account has_and_belongs_to_many :recommended_projects, join_table: :recommendations, class_name: 'Project' @@ -80,6 +81,7 @@ class User < ActiveRecord::Base has_many :channels_subscribers accepts_nested_attributes_for :unsubscribes, allow_destroy: true rescue puts "No association found for name 'unsubscribes'. Has it been defined yet?" + accepts_nested_attributes_for :bank_account, allow_destroy: true scope :backers, -> { where("id IN ( diff --git a/app/views/users/_current_user_fields.html.slim b/app/views/users/_current_user_fields.html.slim index bee3ca3b..d709312e 100644 --- a/app/views/users/_current_user_fields.html.slim +++ b/app/views/users/_current_user_fields.html.slim @@ -1,3 +1,25 @@ +#bank_account.user_data + h1= t('.bank_account_title') + br/ + ul + li + .bootstrap-form + = semantic_form_for @user, html: {method: :put, id: 'user_form'} do |f| + .bank_accounts + = f.semantic_fields_for :bank_account do |bank_form| + = bank_form.input :bank_id, as: :select, collection: Bank.to_collection + .clearfix + = bank_form.input :agency, as: :string + = bank_form.input :agency_digit, as: :string + .clearfix + = bank_form.input :account, as: :string + = bank_form.input :account_digit, as: :string + .clearfix + = bank_form.input :owner_name, as: :string, input_html: { value: bank_form.object.owner_name || @user.full_name } + = bank_form.input :owner_document, as: :string, input_html: { value: bank_form.object.owner_document || @user.cpf } + .clearfix + .bootstrap-twitter + p= f.submit t('.update_social_info'), class: 'btn' #my_avatar h1 = t('.local_avatar') ul diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 7a3727de..1c837553 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -177,11 +177,21 @@ pt: password: Senha password_confirmation: "Confirmação de senha" phone_number: "Telefone (fixo ou celular)" + bank_account: + bank: 'Banco' + bank_id: 'Banco' + owner_name: 'Nome do titular' + owner_document: 'CPF / CNPJ do titular' + agency: 'Agência' + agency_digit: 'Dígito' + account: 'Número da conta' + account_digit: 'Dígito' models: backer: Apoiador category: Categoria project: Projeto reward: Recompensa + bank_account: Dados bancários backer: display_confirmed_at: "Há %{time_ago}" reward_must_be_from_project: "deve ser do mesmo projeto" @@ -838,6 +848,8 @@ pt: title: "Escolha de quais projetos você deseja receber notificações:" updates: "Eu quero receber atualizações dos projetos" current_user_fields: + bank_account_title: "Dados bancários" + bank_account_hint: "Seus dados bancários serão utilizados para realizar o reembolso integral do seu apoio, caso o projeto não atinja 100% da meta estabelecida." my_facebook: 'Integração com o facebook' bio_limit: 'até 140 caracteres' updated: "As suas informações foram atualizadas" From fcd38910370f31f4f68f2b60ee538719589f9879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Roberto?= Date: Thu, 11 Dec 2014 12:00:39 -0200 Subject: [PATCH 04/16] insert bank data --- db/migrate/20141211134156_insert_banks.rb | 148 ++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 db/migrate/20141211134156_insert_banks.rb diff --git a/db/migrate/20141211134156_insert_banks.rb b/db/migrate/20141211134156_insert_banks.rb new file mode 100644 index 00000000..e7c244d0 --- /dev/null +++ b/db/migrate/20141211134156_insert_banks.rb @@ -0,0 +1,148 @@ +class InsertBanks < ActiveRecord::Migration + def up + execute < Date: Thu, 11 Dec 2014 12:01:26 -0200 Subject: [PATCH 05/16] fix permission to update bank_account --- app/models/user.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 286d5443..581e5cab 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -52,7 +52,8 @@ class User < ActiveRecord::Base :twitter, :facebook_link, :other_link, - :moip_login + :moip_login, + :bank_account_attributes mount_uploader :uploaded_image, UserUploader From 77b43323729499b44dac1f574b311b3fcab2ab89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Roberto?= Date: Fri, 12 Dec 2014 12:56:03 -0200 Subject: [PATCH 06/16] added credit cards struct --- app/decorators/credit_card_decorator.rb | 8 ++++++++ app/models/credit_card.rb | 17 +++++++++++++++++ app/models/user.rb | 1 + .../20141212144955_create_credit_cards.rb | 13 +++++++++++++ spec/models/credit_card_spec.rb | 14 ++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 app/decorators/credit_card_decorator.rb create mode 100644 app/models/credit_card.rb create mode 100644 db/migrate/20141212144955_create_credit_cards.rb create mode 100644 spec/models/credit_card_spec.rb diff --git a/app/decorators/credit_card_decorator.rb b/app/decorators/credit_card_decorator.rb new file mode 100644 index 00000000..527c9c4b --- /dev/null +++ b/app/decorators/credit_card_decorator.rb @@ -0,0 +1,8 @@ +class CreditCardDecorator < Draper::Decorator + decorates :credit_card + include Draper::LazyHelpers + + def display_digits + "XXXX-XXXX-XXXX-#{source.last_digits}" + end +end diff --git a/app/models/credit_card.rb b/app/models/credit_card.rb new file mode 100644 index 00000000..8459eec4 --- /dev/null +++ b/app/models/credit_card.rb @@ -0,0 +1,17 @@ +class CreditCard < ActiveRecord::Base + belongs_to :user + + validates :user, :last_digits, :card_brand, :subscription_id, presence: true + delegate :display_digits, to: :decorator + + def decorator + CreditCardDecorator.new(self) + end + + def cancel_subscription + if defined?(CatarsePagarme) + self.pagarme_delegator.cancel_subscription + end + end +end + diff --git a/app/models/user.rb b/app/models/user.rb index 581e5cab..1ae54be4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -70,6 +70,7 @@ class User < ActiveRecord::Base schema_associations has_many :oauth_providers, through: :authorizations has_many :backs, class_name: "Backer" + has_many :credit_cards has_one :user_total has_one :bank_account has_and_belongs_to_many :recommended_projects, join_table: :recommendations, class_name: 'Project' diff --git a/db/migrate/20141212144955_create_credit_cards.rb b/db/migrate/20141212144955_create_credit_cards.rb new file mode 100644 index 00000000..982e1f1c --- /dev/null +++ b/db/migrate/20141212144955_create_credit_cards.rb @@ -0,0 +1,13 @@ +class CreateCreditCards < ActiveRecord::Migration + def change + create_table :credit_cards do |t| + t.references :user, index: true + t.text :last_digits, null: false + t.text :card_brand, null: false + t.text :subscription_id, foreign_key: false, null: false + + t.timestamps + end + end +end + diff --git a/spec/models/credit_card_spec.rb b/spec/models/credit_card_spec.rb new file mode 100644 index 00000000..0e4fce68 --- /dev/null +++ b/spec/models/credit_card_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' + +describe CreditCard do + describe "Associations" do + it{ should belong_to :user } + end + + describe "Validations" do + it{ should validate_presence_of(:user) } + it{ should validate_presence_of(:last_digits) } + it{ should validate_presence_of(:card_brand) } + it{ should validate_presence_of(:subscription_id) } + end +end From 2296f5dd0f480ce86ab3b71cae38d7e6521faa44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Roberto?= Date: Fri, 12 Dec 2014 13:12:17 -0200 Subject: [PATCH 07/16] added credit_cards view and permissions --- app/assets/javascripts/app/user.js | 1 + app/controllers/users/credit_cards_controller.rb | 11 +++++++++++ app/controllers/users_controller.rb | 1 + app/models/ability.rb | 5 +++++ app/views/users/_credit_cards.html.slim | 13 +++++++++++++ app/views/users/show.html.slim | 7 +++++++ config/locales/pt.yml | 7 +++++++ config/routes.rb | 1 + 8 files changed, 46 insertions(+) create mode 100644 app/controllers/users/credit_cards_controller.rb create mode 100644 app/views/users/_credit_cards.html.slim diff --git a/app/assets/javascripts/app/user.js b/app/assets/javascripts/app/user.js index 815a4220..e185210a 100644 --- a/app/assets/javascripts/app/user.js +++ b/app/assets/javascripts/app/user.js @@ -12,6 +12,7 @@ App.addChild('User', _.extend({ this.makeRoute('credits'); this.makeRoute('settings'); this.makeRoute('unsubscribes'); + this.makeRoute('credit_cards'); }, makeRoute: function(name){ diff --git a/app/controllers/users/credit_cards_controller.rb b/app/controllers/users/credit_cards_controller.rb new file mode 100644 index 00000000..c8bffd2a --- /dev/null +++ b/app/controllers/users/credit_cards_controller.rb @@ -0,0 +1,11 @@ +class Users::CreditCardsController < ApplicationController + load_and_authorize_resource + inherit_resources + actions :destroy + belongs_to :user + + def destroy + resource.cancel_subscription + destroy! { user_path(parent, anchor: 'credit_cards') } + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0bef8ab0..945112c3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -20,6 +20,7 @@ def show @credits = @user.backs.can_refund @subscribed_to_updates = @user.updates_subscription @unsubscribes = @user.project_unsubscribes + @credit_cards = @user.credit_cards build_bank_account } end diff --git a/app/models/ability.rb b/app/models/ability.rb index 302427d1..51aee2ee 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -26,6 +26,11 @@ def initialize(current_user, options = {}) project.user == current_user && ( project.draft? || project.rejected? ) end + # NOTE: Credit card authorizations + can :access, :credit_cards do |credit_card| + credit_card.user == current_user + end + # NOTE: Reward authorizations can :create, :rewards do |reward| diff --git a/app/views/users/_credit_cards.html.slim b/app/views/users/_credit_cards.html.slim new file mode 100644 index 00000000..e248e616 --- /dev/null +++ b/app/views/users/_credit_cards.html.slim @@ -0,0 +1,13 @@ +.table_content + table.table.table-striped + thead + th= t('.index.last_digits') + th= t('.index.brand') + th + - @credit_cards.each do |card| + tr + td.card_name= card.display_digits + td.brand= card.card_brand + td.actions + .bootstrap-twitter + = link_to t('.index.remove'), user_credit_card_path(@user, card), class: 'btn btn-danger', method: :delete, data: { confirm: 'você tem certeza?' } diff --git a/app/views/users/show.html.slim b/app/views/users/show.html.slim index 5873108c..95d067ea 100644 --- a/app/views/users/show.html.slim +++ b/app/views/users/show.html.slim @@ -41,6 +41,8 @@ = link_to t('.tabs.credits'), '#credits', id: 'credits_link', data: { target: '#user_credits' } = link_to t('.tabs.settings'), '#settings', id: 'settings_link', data: { target: '#user_settings' } = link_to t('.tabs.unsubscribes'), '#unsubscribes', id: 'unsubscribes_link', data: { target: '#user_unsubscribes' } + - if @credit_cards.present? + = link_to t('.tabs.credit_cards'), '#credit_cards', id: 'credit_cards_link', data: { target: '#user_credit_cards' } .clearfix #user_profile_content #user_backed_projects.content[data-path=user_backers_path(@user)] @@ -68,5 +70,10 @@ = render 'current_user_fields' #user_credits.content.hide = render 'credits' + - if @credit_cards.present? + #user_credit_cards.content.hide + = render 'credit_cards' + + .clearfix .clearfix diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 1c837553..6c3e0185 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -823,9 +823,16 @@ pt: site_title: 'Defina um email de contato' title: 'Defina um email de contato' submit: 'Gravar o email e prosseguir' + credit_cards: + index: + last_digits: 'Cartão' + brand: 'Operadora' + title: 'Cartões de credito' + remove: 'Remover' show: attention: "Atenção" tabs: + credit_cards: "Cartões de credito" backed_projects: "Projetos apoiados" created_projects: "Projetos criados" comments: Comentários diff --git a/config/routes.rb b/config/routes.rb index 7f22f2fe..fb1838de 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -102,6 +102,7 @@ end resources :users do resources :projects, controller: 'users/projects', only: [ :index ] + resources :credit_cards, controller: 'users/credit_cards', only: [ :destroy ] collection do get :uservoice_gadget end From b21f50d7ab1b188c5f2478c7733a77fbd3ee69c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Roberto?= Date: Fri, 12 Dec 2014 13:26:12 -0200 Subject: [PATCH 08/16] adjust payment_engines --- lib/payment_engines.rb | 7 +++++++ lib/payment_engines/interface.rb | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 lib/payment_engines/interface.rb diff --git a/lib/payment_engines.rb b/lib/payment_engines.rb index 724025c6..d198757b 100644 --- a/lib/payment_engines.rb +++ b/lib/payment_engines.rb @@ -1,6 +1,13 @@ class PaymentEngines @@engines = [] + def self.find_engine name + # if name is nil we should return nil + name && @@engines.find do |engine| + engine.name.downcase == name.downcase + end + end + def self.register options @@engines.push(options) end diff --git a/lib/payment_engines/interface.rb b/lib/payment_engines/interface.rb new file mode 100644 index 00000000..27656cb4 --- /dev/null +++ b/lib/payment_engines/interface.rb @@ -0,0 +1,19 @@ +class PaymentEngines + class Interface + + def name; end + + def locale; end + + def review_path(contribution); end + + def can_do_refund?; end + + def direct_refund(contribution); end + + def can_generate_second_slip?; end + + def second_slip_path(contribution); end + + end +end From b5bd41c21fd5e0a27d13955a1c21c70fc52a516d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Roberto?= Date: Fri, 12 Dec 2014 13:26:26 -0200 Subject: [PATCH 09/16] basic config for pagar.me --- Gemfile | 5 +++-- Gemfile.lock | 28 ++++++---------------------- config/initializers/pagarme.rb | 12 ++++++++++++ 3 files changed, 21 insertions(+), 24 deletions(-) create mode 100644 config/initializers/pagarme.rb diff --git a/Gemfile b/Gemfile index d542f55a..55fdbef4 100644 --- a/Gemfile +++ b/Gemfile @@ -30,8 +30,9 @@ gem 'schema_associations', '~> 1.2.0' gem 'chartkick' # Payment engines -gem 'catarse_paypal_express', '~> 2.0.0' -gem 'catarse_moip', '~> 2.0.0' +#gem 'catarse_paypal_express', '~> 2.0.0' +#gem 'catarse_moip', '~> 2.0.0' +gem 'catarse_pagarme', '1.4.8' # # Decorators gem 'draper' diff --git a/Gemfile.lock b/Gemfile.lock index bc79f384..f64dbb37 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,17 +46,6 @@ GEM erubis (~> 2.7.0) rack (~> 1.5.2) rack-test (~> 0.6.2) - active_utils (2.0.0) - activesupport (>= 2.3.11) - i18n - activemerchant (1.36.0) - active_utils (>= 1.0.2) - activesupport (>= 2.3.14) - builder (>= 2.0.0) - i18n - json (>= 1.5.1) - money - nokogiri (< 1.6.0) activemodel (4.0.0) activesupport (= 4.0.0) builder (~> 3.1.0) @@ -99,13 +88,9 @@ GEM carrierwave (0.8.0) activemodel (>= 3.2.0) activesupport (>= 3.2.0) - catarse_moip (2.0.0) - libxml-ruby (~> 2.6.0) + catarse_pagarme (1.4.8) + pagarme (~> 1.9.8) rails (~> 4.0) - catarse_paypal_express (2.0.0) - activemerchant (>= 1.34.0) - rails (~> 4.0) - slim-rails celluloid (0.14.1) timers (>= 1.0.0) chartkick (1.2.0) @@ -231,7 +216,6 @@ GEM addressable (~> 2.3) letter_opener (1.1.2) launchy (~> 2.2) - libxml-ruby (2.6.0) loofah (1.2.1) nokogiri (>= 1.4.4) mail (2.5.3) @@ -243,8 +227,6 @@ GEM method_source (0.8.2) mime-types (1.24) minitest (4.7.5) - money (5.1.1) - i18n (~> 0.6.0) multi_json (1.7.9) multipart-post (1.2.0) net-scp (1.1.2) @@ -274,6 +256,9 @@ GEM multi_json (~> 1.3) omniauth-oauth (~> 1.0) orm_adapter (0.4.0) + pagarme (1.9.8) + multi_json + rest-client pg (0.17.0) pg_search (0.7.0) activerecord (>= 3.1) @@ -459,8 +444,7 @@ DEPENDENCIES capybara (~> 2.1.0) carrierwave (~> 0.8.0) catarse_mailchimp! - catarse_moip (~> 2.0.0) - catarse_paypal_express (~> 2.0.0) + catarse_pagarme (= 1.4.8) chartkick coffee-rails (~> 4.0.0) compass-960-plugin diff --git a/config/initializers/pagarme.rb b/config/initializers/pagarme.rb new file mode 100644 index 00000000..e5f6051a --- /dev/null +++ b/config/initializers/pagarme.rb @@ -0,0 +1,12 @@ +CatarsePagarme.configure do |config| + config.api_key = Configuration[:pagarme_api_key] + config.slip_tax = Configuration[:pagarme_slip_tax] + config.credit_card_tax = Configuration[:pagarme_credit_card_tax] + config.interest_rate = Configuration[:pagarme_interest_rate] + config.credit_card_cents_fee = Configuration[:pagarme_cents_fee] + config.host = Configuration[:host] + config.subdomain = 'www' + config.protocol = 'http' + config.max_installments = Configuration[:pagarme_max_installments] + config.minimum_value_for_installment = Configuration[:pagarme_minimum_value_for_installment] +end From 7fd5851647bd60811e27bb1f9cdc038d5f0cb3ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Roberto?= Date: Fri, 12 Dec 2014 13:26:41 -0200 Subject: [PATCH 10/16] added pagar.me route and removed moip / paypal --- config/routes.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index fb1838de..bf8f802c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,8 +24,9 @@ mount Sidekiq::Web => '/sidekiq' end - mount CatarsePaypalExpress::Engine => "/", as: :catarse_paypal_express - mount CatarseMoip::Engine => "/", as: :catarse_moip + #mount CatarsePaypalExpress::Engine => "/", as: :catarse_paypal_express + #mount CatarseMoip::Engine => "/", as: :catarse_moip + mount CatarsePagarme::Engine => "/", as: :catarse_pagarme # Non production routes if Rails.env.development? From 81d513323ed3a7fba16cf5c384f9780c2ec2fdb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Roberto?= Date: Mon, 15 Dec 2014 12:27:13 -0200 Subject: [PATCH 11/16] added some pagarme columns into backers --- .../20141215134125_add_pagarme_columns_to_backers.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 db/migrate/20141215134125_add_pagarme_columns_to_backers.rb diff --git a/db/migrate/20141215134125_add_pagarme_columns_to_backers.rb b/db/migrate/20141215134125_add_pagarme_columns_to_backers.rb new file mode 100644 index 00000000..fbf3185c --- /dev/null +++ b/db/migrate/20141215134125_add_pagarme_columns_to_backers.rb @@ -0,0 +1,9 @@ +class AddPagarmeColumnsToBackers < ActiveRecord::Migration + def change + add_column :backers, :slip_url, :text + add_column :backers, :installments, :integer + add_column :backers, :installment_value, :decimal + add_column :backers, :acquirer_name, :text + add_column :backers, :acquirer_tid, :text + end +end From 30b48f4fb6bede204770ca434dd2394b10b10c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Roberto?= Date: Mon, 15 Dec 2014 12:27:22 -0200 Subject: [PATCH 12/16] fixed best_in_place --- Gemfile | 8 +++++--- Gemfile.lock | 44 ++++++++++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/Gemfile b/Gemfile index 55fdbef4..c98100ed 100644 --- a/Gemfile +++ b/Gemfile @@ -12,8 +12,9 @@ gem 'sidekiq', '~> 2.13.0' gem 'sinatra', require: false # required by sidekiq web interface mounted on /sidekiq # Turns every field on a editable one -#gem 'best_in_place', github: 'bernat/best_in_place', branch: 'rails-4' -gem 'best_in_place' +gem 'best_in_place', github: 'widernet/best_in_place', branch: 'rails-4' +#gem 'best_in_place', github: 'bernat/best_in_place', ref: '769ba1887feafb2b46693fe52c2953230d61c5e1' +#gem 'best_in_place', '2.1.3' # State machine for attributes on models gem 'state_machine', require: 'state_machine/core' @@ -32,7 +33,7 @@ gem 'chartkick' # Payment engines #gem 'catarse_paypal_express', '~> 2.0.0' #gem 'catarse_moip', '~> 2.0.0' -gem 'catarse_pagarme', '1.4.8' +gem 'catarse_pagarme', path: '~/code/soudoesporte_pagarme' # # Decorators gem 'draper' @@ -57,6 +58,7 @@ gem 'catarse_mailchimp', git: 'git://github.com/catarse/catarse_mailchimp', ref: # HTML manipulation and formatting gem 'formtastic', '~> 2.2.1' +gem 'simple_form' gem "auto_html", '= 1.4.2' gem 'kaminari' diff --git a/Gemfile.lock b/Gemfile.lock index f64dbb37..c59301f0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -33,6 +33,22 @@ GIT specs: cancan (2.0.0.alpha) +GIT + remote: git://github.com/widernet/best_in_place.git + revision: 964f3f36fe24cd7cd304b44f4ffac2ee1de3cd1e + branch: rails-4 + specs: + best_in_place (2.0.3) + jquery-rails + rails (~> 4) + +PATH + remote: ~/code/soudoesporte_pagarme + specs: + catarse_pagarme (2.3.9) + pagarme (~> 1.9.8) + rails (~> 4.0) + GEM remote: https://rubygems.org/ specs: @@ -63,16 +79,12 @@ GEM tzinfo (~> 0.3.37) addressable (2.3.5) arel (4.0.0) - atomic (1.1.13) auto_html (1.4.2) RedCloth redcarpet rinku tag_helper bcrypt-ruby (3.1.1) - best_in_place (3.0.0) - actionpack (>= 3.2) - railties (>= 3.2) better_errors (0.9.0) coderay (>= 1.0.0) erubis (>= 2.6.6) @@ -88,9 +100,6 @@ GEM carrierwave (0.8.0) activemodel (>= 3.2.0) activesupport (>= 3.2.0) - catarse_pagarme (1.4.8) - pagarme (~> 1.9.8) - rails (~> 4.0) celluloid (0.14.1) timers (>= 1.0.0) chartkick (1.2.0) @@ -192,7 +201,7 @@ GEM crack (= 0.1.8) httpauth (0.2.0) httpclient (2.3.4.1) - i18n (0.6.5) + i18n (0.6.11) inherited_resources (1.4.1) has_scope (~> 0.6.0.rc) responders (~> 1.0.0.rc) @@ -227,7 +236,7 @@ GEM method_source (0.8.2) mime-types (1.24) minitest (4.7.5) - multi_json (1.7.9) + multi_json (1.10.1) multipart-post (1.2.0) net-scp (1.1.2) net-ssh (>= 2.6.5) @@ -309,7 +318,7 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) raindrops (0.11.0) - rake (10.1.0) + rake (10.4.2) ranked-model (0.3) activerecord (>= 3.1.12) redcarpet (3.0.0) @@ -371,6 +380,9 @@ GEM json redis (>= 3.0) redis-namespace + simple_form (3.0.0) + actionpack (>= 4.0.0, < 4.1) + activemodel (>= 4.0.0, < 4.1) simplecov (0.7.1) multi_json (~> 1.0) simplecov-html (~> 0.7.1) @@ -404,15 +416,14 @@ GEM activemodel (>= 3.0.0.beta) tag_helper (0.0.3) temple (0.6.6) - thor (0.18.1) - thread_safe (0.1.2) - atomic + thor (0.19.1) + thread_safe (0.3.4) tilt (1.4.1) timers (1.1.0) treetop (1.4.14) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.37) + tzinfo (0.3.42) uglifier (2.1.2) execjs (>= 0.3.0) multi_json (~> 1.0, >= 1.0.2) @@ -437,14 +448,14 @@ PLATFORMS DEPENDENCIES RedCloth auto_html (= 1.4.2) - best_in_place + best_in_place! better_errors binding_of_caller cancan! capybara (~> 2.1.0) carrierwave (~> 0.8.0) catarse_mailchimp! - catarse_pagarme (= 1.4.8) + catarse_pagarme! chartkick coffee-rails (~> 4.0.0) compass-960-plugin @@ -500,6 +511,7 @@ DEPENDENCIES selenium-webdriver (~> 2.34.0) shoulda sidekiq (~> 2.13.0) + simple_form sinatra slim-rails (~> 1.1.1) spectator-validates_email From b56b63a1560c8d8476ca742ffc6e41ea65d22a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Roberto?= Date: Mon, 15 Dec 2014 12:27:40 -0200 Subject: [PATCH 13/16] payment engine now is a object and not anymore a hash --- app/views/projects/backers/create.html.slim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/projects/backers/create.html.slim b/app/views/projects/backers/create.html.slim index 2f9a973a..59ff4ca5 100644 --- a/app/views/projects/backers/create.html.slim +++ b/app/views/projects/backers/create.html.slim @@ -65,10 +65,10 @@ .tab_container nav#payment_menu - PaymentEngines.engines.each do |engine| - - unless engine[:name] == 'moip' - = link_to "##{engine[:name]}_payment", id: engine[:name], class: 'selected enabled' , data: {target: "##{engine[:name]}_payment"} do - = t("projects.backers.review.#{engine[:name]}") + - unless engine.name == 'moip' + = link_to "##{engine.name}_payment", id: engine.name, class: 'selected enabled' , data: {target: "##{engine.name}_payment"} do + = t("projects.backers.review.#{engine.name}") .tab_content_container - PaymentEngines.engines.each do |engine| - div[id="#{engine[:name]}_payment" class="payments_type hide" data-path=engine[:review_path].call(@backer) ] + div[id="#{engine.name}_payment" class="payments_type hide" data-path=engine.review_path(@backer) ] .clearfix From 0e3f8cf7730225bdfcc94a91bb0f43a9621133f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Roberto?= Date: Thu, 18 Dec 2014 08:24:21 -0200 Subject: [PATCH 14/16] fix sprockets version --- Gemfile | 1 + Gemfile.lock | 178 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 172 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index c98100ed..a6d59d3b 100644 --- a/Gemfile +++ b/Gemfile @@ -139,6 +139,7 @@ end gem 'sass-rails', '~> 4.0.0' gem 'coffee-rails', '~> 4.0.0' gem "compass-rails", '~> 1.1.0' +gem 'sprockets', '2.10.0' gem 'uglifier' gem 'compass-960-plugin' diff --git a/Gemfile.lock b/Gemfile.lock index c59301f0..07c72e54 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,7 +45,7 @@ GIT PATH remote: ~/code/soudoesporte_pagarme specs: - catarse_pagarme (2.3.9) + catarse_pagarme (1.4.8) pagarme (~> 1.9.8) rails (~> 4.0) @@ -78,7 +78,7 @@ GEM thread_safe (~> 0.1) tzinfo (~> 0.3.37) addressable (2.3.5) - arel (4.0.0) + arel (4.0.2) auto_html (1.4.2) RedCloth redcarpet @@ -234,13 +234,14 @@ GEM mailchimp (0.0.9) httparty method_source (0.8.2) - mime-types (1.24) + mime-types (1.25.1) minitest (4.7.5) multi_json (1.10.1) multipart-post (1.2.0) net-scp (1.1.2) net-ssh (>= 2.6.5) net-ssh (2.6.8) + netrc (0.10.2) newrelic_rpm (3.6.6.147) nokogiri (1.5.10) oauth (0.4.7) @@ -277,7 +278,7 @@ GEM capybara (~> 2.1.0) faye-websocket (>= 0.4.4, < 0.5.0) http_parser.rb (~> 0.5.3) - polyglot (0.3.3) + polyglot (0.3.5) postgres-copy (0.9.0) activerecord (>= 4.0) pg (>= 0.17) @@ -328,8 +329,9 @@ GEM request_store (1.0.5) responders (1.0.0.rc) railties (>= 3.2, < 5) - rest-client (1.6.7) - mime-types (>= 1.16) + rest-client (1.7.2) + mime-types (>= 1.16, < 3.0) + netrc (~> 0.7) rinku (1.7.3) rmagick (2.13.2) routing-filter (0.4.0.pre) @@ -420,8 +422,170 @@ GEM thread_safe (0.3.4) tilt (1.4.1) timers (1.1.0) - treetop (1.4.14) + treetop (1.4.15) + polyglot + polyglot + polyglot + polyglot + polyglot + polyglot + polyglot + polyglot + polyglot + polyglot polyglot + polyglot + polyglot + polyglot + polyglot + polyglot + polyglot + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) polyglot (>= 0.3.1) tzinfo (0.3.42) uglifier (2.1.2) From fb40daf39dda01788af213868f4524a841fed5b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Roberto?= Date: Sun, 21 Dec 2014 18:57:51 -0200 Subject: [PATCH 15/16] pagarme finish --- Gemfile.lock | 1 + app/assets/javascripts/lib/jquery.brbanks.js | 103 ++++++++++++++++++ .../resources/backers/_create.sass | 31 ++++++ app/views/projects/backers/create.html.slim | 2 + config/locales/pt.yml | 54 +++++++++ 5 files changed, 191 insertions(+) create mode 100644 app/assets/javascripts/lib/jquery.brbanks.js diff --git a/Gemfile.lock b/Gemfile.lock index 07c72e54..6eeb0d01 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -679,6 +679,7 @@ DEPENDENCIES sinatra slim-rails (~> 1.1.1) spectator-validates_email + sprockets (= 2.10.0) state_machine uglifier unicorn diff --git a/app/assets/javascripts/lib/jquery.brbanks.js b/app/assets/javascripts/lib/jquery.brbanks.js new file mode 100644 index 00000000..45bfcc8f --- /dev/null +++ b/app/assets/javascripts/lib/jquery.brbanks.js @@ -0,0 +1,103 @@ +(function($){ + $.fn.extend({ + brbanks: function(options) { + var root = this; + + local = { + selector: this, + bankDivSelector: '.brbanks-banks', + banks: [], + + parseToList: function(banks_data) { + that = this; + $.each(banks_data, function(i,item){ + that.banks.push(item.id + ' - ' + item.name) + }); + + that.inserListOnData(); + }, + + inserListOnData: function() { + this.selector.data('banks', this.banks); + }, + + loadBanksOnSelector: function(callback) { + var that = this; + $.getJSON("http://brbanks.herokuapp.com", function(data){ + that.parseToList(data); + callback(that); + }); + }, + + buildBankDiv: function() { + var div = $("") + var ul = $("
    ") + + $.each(this.selector.data('banks'), function(i, item){ + ul.append($('
  • '+item+'
  • ')); + }); + + div.prepend(ul); + return div; + } + } + + showUpBanks = function(that) { + that.selector.focusin(function(){ + if($(that.bankDivSelector).length <= 0) { + var div = that.buildBankDiv(); + that.selector.parent().append(div); + div.show(); + } else { + $(that.bankDivSelector).show(); + }; + + $('ul li', that.bankDivSelector).click(function(element){ + root.val($(element.currentTarget).text()); + $(that.bankDivSelector).hide(); + }) + }); + + $(document).mouseup(function(e){ + if(!$(that.bankDivSelector).is(e.target) && !that.selector.is(e.target)) { + $(that.bankDivSelector).hide(); + $('ul li', that.bankDivSelector).css({display: 'block'}); + + if($.inArray($(that.selector).val(), that.banks) < 0) { + $(that.selector).val(''); + }; + } + }); + }; + + enableFilterOnBanks = function(that) { + that.selector.keyup(function(){ + var value = that.selector.val(); + var regexPattern = new RegExp(value, 'i'); + + $('ul li', that.bankDivSelector).filter(function(){ + if(regexPattern.test($(this).text())) { + $(this).fadeIn(); + } else { + $(this).css({'display':'none'}); + $(this).fadeOut(); + } + }); + //$.each($('ul li', that.bankDivSelector), function(i, item){ + // if(regexPattern.test($(item).text())){ + // $(item).css({'display':'block'}) + // } else { + // $(item).css({'display':'none'}) + // } + //}); + }); + }; + + local.loadBanksOnSelector(function(that) { + showUpBanks(that); + enableFilterOnBanks(that); + }); + } + }); +})(jQuery); + diff --git a/app/assets/stylesheets/resources/backers/_create.sass b/app/assets/stylesheets/resources/backers/_create.sass index 931c080a..8155844f 100644 --- a/app/assets/stylesheets/resources/backers/_create.sass +++ b/app/assets/stylesheets/resources/backers/_create.sass @@ -430,3 +430,34 @@ text-decoration: none &:hover text-decoration: underline + .save_card + input[type='checkbox'] + float: left + margin-right: 10px + label + float: left + ul.my_credit_cards + list-style-position: none + list-style-type: none + width: 100% + li + width: 90% + display: block + padding: 10px 10px 5px + border: 1px solid #DFDFDF + background: #F4F4F4 + .radio_button + float: left + width: 5% + .select_installments + float: left + width: 30% + select + width: 90% + .card_info + float: left + width: 40% + margin-left: 10px + .card_brand + float: left + width: 10% diff --git a/app/views/projects/backers/create.html.slim b/app/views/projects/backers/create.html.slim index 59ff4ca5..182e9c69 100644 --- a/app/views/projects/backers/create.html.slim +++ b/app/views/projects/backers/create.html.slim @@ -1,6 +1,8 @@ #page_content .container #project_review data-thank-you-path=project_backer_path(project_id: @project.id, id: @backer.id) + = hidden_field_tag :contribution_id, @backer.id + = hidden_field_tag :project_id, @project.id .project_info = image_tag @project.display_image, id: 'project_image', alt: @project.name, width: '250px' h1= t('.you_are_about_html', link: link_to(@project.name, project_by_slug_path(permalink: @project.permalink))) diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 6c3e0185..2e17b7e0 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -406,6 +406,60 @@ pt: draft: "Esse projeto é apenas um rascunho e ainda não está aberto para receber apoios." reached_of: "Atingidos de" submit: "Apoiar este projeto" + contributions: + review: + Credits: 'Créditos' + error: Ooops. Ocorreu um erro ao registrar seu apoio. Por favor, tente novamente. + form: + labels: + payment_boleto: Pagamento com Boleto + payment_card: Pagamento com Cartão + submit: Efetuar pagamento + build_boleto: Gerar boleto + payment_boleto_subtitle: "Clique no link abaixo para ver o boleto:" + edit: + form_labels: + payment_card_number: 'Número do cartão de crédito' + payment_card_flag: 'Bandeira' + payment_card_source: 'Código de Segurança' + payment_card_date: 'Data de Expiração' + payment_card_name: 'Nome impresso no cartão de crédito' + payment_card_installments: 'Parcelas' + installment_with_tax: 'sem juros' + transaction_error: 'Transação recusada, por favor verifique novamente seus dados ou entre em contato com o banco/emissor do cartão para maiores informações.' + pagarme_warning_html: "O Catarse está em fase de teste de um novo meio de pagamento que facilitará o apoio financeiro e o eventual reembolso dos valores aos apoiadores. Dessa forma, alertamos que poderão ser exigidos dados extras, além daqueles mencionados nos Termos de Uso para apoiar este projeto. Qualquer dúvida ou dificuldade, entre em contato conosco pelo e-mail %{mailto} . Obrigado." + payment_save_card: 'Quero salvar meu cartão de crédito para facilitar apoios futuros.' + reward_sold_out: Essa recompensa está esgotada. Inicie um novo apoio. + credits_preview_html: "Você possui %{credits} em créditos para realizar esse apoio até o dia 10/11, conforme novas regras divulgadas pelo Catarse." + credits_submit: 'Efetuar pagamento' + credits_title: 'Pagamento com créditos' + insufficient_credits: "Você possui %{credits} em créditos. Esse valor não é suficiente para realizar o apoio, por favor escolha outro meio de pagamento." + choose_payment: Como você quer pagar? + choose_payment_subtitle: Selecione abaixo uma forma de pagamento + cpf: 'Para prosseguir, por favor informe:' + credits_notice_html: Este apoio será pago com seus créditos. Após a confirmação, + você ficará com um saldo de %{credits} em créditos para + apoiar outros projetos. + live_in_brazil: Moro no Brasil. ( Desmarque caso o seu apoio seja internacional + ) + number_card: Dados do cartão + owner_card: Dados do titular do cartão + payment_account: Pagamento com Débito em Conta + payment_boleto: Pagamento com Boleto + payment_card: Pagamento com Cartão + review_with_reward_html: 'Você irá apoiar com %{value} e + ganhará a seguinte recompensa:' + review_without_reward_html: Você irá apoiar com %{value} + e não quer nenhuma recompensa por seu apoio. + select_account: 'Você será redirecionado para o site do seu banco:' + select_boleto: 'Para prosseguir, por favor selecione:' + submit: + credits: Confirmar + moip: Efetuar pagamento pelo MoIP + subtitle: Estes dados serão informados ao organizador do projeto. + title: Preencha e revise os dados para pagamento + you_are_about_html: Você está prestes a fazer parte do grupo que faz de tudo + para o %{link} acontecer. backers: backer: anonymous_backer: "Apoiador anônimo" From 57abb1440ecff09b0712d715eb4d8df6adac4e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Roberto?= Date: Sun, 21 Dec 2014 19:00:38 -0200 Subject: [PATCH 16/16] use engageis/catarse_pagarme --- Gemfile | 2 +- Gemfile.lock | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index a6d59d3b..fd188057 100644 --- a/Gemfile +++ b/Gemfile @@ -33,7 +33,7 @@ gem 'chartkick' # Payment engines #gem 'catarse_paypal_express', '~> 2.0.0' #gem 'catarse_moip', '~> 2.0.0' -gem 'catarse_pagarme', path: '~/code/soudoesporte_pagarme' +gem 'catarse_pagarme', github: 'engageis/catarse_pagarme', branch: 'v1' # # Decorators gem 'draper' diff --git a/Gemfile.lock b/Gemfile.lock index 6eeb0d01..3faed772 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -25,6 +25,15 @@ GIT httparty (~> 0.6.1) nokogiri (~> 1.5.0) +GIT + remote: git://github.com/engageis/catarse_pagarme.git + revision: ff69884bbcca44795091af8b7d51218a2a66da97 + branch: v1 + specs: + catarse_pagarme (1.4.8) + pagarme (~> 1.9.8) + rails (~> 4.0) + GIT remote: git://github.com/ryanb/cancan.git revision: f1cebde51a87be149b4970a3287826bb63c0ac0b @@ -42,13 +51,6 @@ GIT jquery-rails rails (~> 4) -PATH - remote: ~/code/soudoesporte_pagarme - specs: - catarse_pagarme (1.4.8) - pagarme (~> 1.9.8) - rails (~> 4.0) - GEM remote: https://rubygems.org/ specs: