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,37 @@
|
|
1
|
+
module CatarsePagarme
|
2
|
+
class SlipTransaction < TransactionBase
|
3
|
+
def initialize(attributes, contribution)
|
4
|
+
super
|
5
|
+
build_default_bank_account
|
6
|
+
end
|
7
|
+
|
8
|
+
def charge!
|
9
|
+
update_user_bank_account
|
10
|
+
|
11
|
+
self.transaction = PagarMe::Transaction.new(self.attributes)
|
12
|
+
self.transaction.charge
|
13
|
+
|
14
|
+
change_contribution_state
|
15
|
+
|
16
|
+
self.transaction
|
17
|
+
end
|
18
|
+
|
19
|
+
def payment_method
|
20
|
+
PaymentType::SLIP
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def update_user_bank_account
|
26
|
+
self.user.update_attributes(self.attributes.delete(:user))
|
27
|
+
|
28
|
+
if self.user.errors.present?
|
29
|
+
raise ::PagarMe::PagarMeError.new(self.user.errors.full_messages.to_sentence)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_default_bank_account
|
34
|
+
self.user.build_bank_account unless self.user.bank_account
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module CatarsePagarme
|
2
|
+
class SubscriptionTransaction < TransactionBase
|
3
|
+
def charge!
|
4
|
+
validate_subscription_id
|
5
|
+
|
6
|
+
self.subscription = PagarMe::Subscription.find_by_id(self.attributes[:subscription_id])
|
7
|
+
self.subscription.charge(self.attributes[:amount], self.attributes[:installments])
|
8
|
+
self.transaction = subscription.current_transaction
|
9
|
+
|
10
|
+
change_contribution_state
|
11
|
+
|
12
|
+
self.transaction
|
13
|
+
end
|
14
|
+
|
15
|
+
def validate_subscription_id
|
16
|
+
unless self.user.credit_cards.where(subscription_id: self.attributes[:subscription_id]).present?
|
17
|
+
raise PagarMe::PagarMeError.new('invalid subscription')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module CatarsePagarme
|
2
|
+
class TransactionBase
|
3
|
+
attr_accessor :attributes, :contribution,
|
4
|
+
:transaction, :user, :subscription
|
5
|
+
|
6
|
+
def initialize(attributes, contribution)
|
7
|
+
self.attributes = attributes
|
8
|
+
self.contribution = contribution
|
9
|
+
self.user = contribution.user
|
10
|
+
end
|
11
|
+
|
12
|
+
def change_contribution_state
|
13
|
+
self.contribution.update_attributes(attributes_to_contribution)
|
14
|
+
delegator.change_status_by_transaction(self.transaction.status)
|
15
|
+
end
|
16
|
+
|
17
|
+
def payment_method
|
18
|
+
PaymentType::CREDIT_CARD
|
19
|
+
end
|
20
|
+
|
21
|
+
def attributes_to_contribution
|
22
|
+
{
|
23
|
+
payment_choice: payment_method,
|
24
|
+
payment_service_fee: delegator.get_fee(payment_method),
|
25
|
+
payment_id: self.transaction.id,
|
26
|
+
payment_method: 'Pagarme',
|
27
|
+
slip_url: self.transaction.boleto_url,
|
28
|
+
installments: (self.transaction.installments || 1)
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def delegator
|
33
|
+
self.contribution.pagarme_delegator
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
= javascript_include_tag 'catarse_pagarme'
|
2
|
+
#catarse_pagarme_form
|
3
|
+
= form_tag 'javascript:void(0);', :class => 'pagarme' do
|
4
|
+
|
5
|
+
.next_step_after_valid_document
|
6
|
+
|
7
|
+
.list_payment
|
8
|
+
.input
|
9
|
+
= radio_button_tag 'payment_type', "credit_card"
|
10
|
+
= label_tag :payment_type_credit_card, nil, :class => "cards"
|
11
|
+
|
12
|
+
= radio_button_tag 'payment_type', "slip"
|
13
|
+
= label_tag :payment_type_slip, 'Boleto', :class => "boleto"
|
14
|
+
|
15
|
+
#payment_type_credit_card_section.payment_section
|
16
|
+
h3= t('projects.contributions.review.form.labels.payment_card')
|
17
|
+
|
18
|
+
.clearfix
|
19
|
+
|
20
|
+
.bootstrap-twitter style="float: none;"
|
21
|
+
.alert.alert-danger.hide
|
22
|
+
p.error_msg
|
23
|
+
.clearfix
|
24
|
+
|
25
|
+
.clearfix
|
26
|
+
|
27
|
+
.choose_card
|
28
|
+
ul class="my_credit_cards #{(current_user.credit_cards.present? ? '' : 'hide')}"
|
29
|
+
- current_user.credit_cards.each_with_index do |credit_card, i|
|
30
|
+
li.credit_card
|
31
|
+
.radio_button
|
32
|
+
= radio_button_tag :payment_subscription_card, credit_card.subscription_id, { checked: (i == 0) }
|
33
|
+
.select_installments
|
34
|
+
= select_tag :payment_card_installments, options_for_select(installments_for_select(@contribution))
|
35
|
+
.card_info
|
36
|
+
= "XXXX.XXXX.XXXX.#{credit_card.last_digits}"
|
37
|
+
.card_brand
|
38
|
+
= credit_card.card_brand
|
39
|
+
.clearfix
|
40
|
+
|
41
|
+
.bootstrap-twitter
|
42
|
+
a href='javascript:void(0)' class="btn use_another-card #{(current_user.credit_cards.present? ? '' : 'hide')}"
|
43
|
+
| Utilizar outro cartão
|
44
|
+
|
45
|
+
div class="type_card_data #{(current_user.credit_cards.present? ? 'hide' : '')}"
|
46
|
+
.div
|
47
|
+
.owner_outside
|
48
|
+
.owner
|
49
|
+
ol.inputs
|
50
|
+
li.name
|
51
|
+
= label_tag :payment_card_name, t('projects.contributions.edit.form_labels.payment_card_name')
|
52
|
+
= text_field_tag :payment_card_name, nil
|
53
|
+
- if @contribution.value >= CatarsePagarme.configuration.minimum_value_for_installment
|
54
|
+
li.cpf
|
55
|
+
= label_tag :payment_card_installments, t('projects.contributions.edit.form_labels.payment_card_installments')
|
56
|
+
= select_tag :payment_card_installments, options_for_select(installments_for_select(@contribution))
|
57
|
+
.div
|
58
|
+
.infocard_outside
|
59
|
+
.infocard
|
60
|
+
ol.inputs
|
61
|
+
li.number
|
62
|
+
= label_tag :payment_card_number, t('projects.contributions.edit.form_labels.payment_card_number')
|
63
|
+
= text_field_tag :payment_card_number, nil
|
64
|
+
li.flag
|
65
|
+
= label_tag :payment_card_flag, t('projects.contributions.edit.form_labels.payment_card_flag')
|
66
|
+
= text_field_tag :payment_card_flag, nil, { disabled: true }
|
67
|
+
li.source
|
68
|
+
= label_tag :payment_card_source, t('projects.contributions.edit.form_labels.payment_card_source')
|
69
|
+
= text_field_tag :payment_card_source, nil
|
70
|
+
li.date
|
71
|
+
= label_tag :payment_card_date, t('projects.contributions.edit.form_labels.payment_card_date')
|
72
|
+
= text_field_tag :payment_card_date, nil
|
73
|
+
|
74
|
+
.clearfix
|
75
|
+
.bootstrap-twitter
|
76
|
+
div class="save_card #{(current_user.credit_cards.present? ? 'hide' : '')}"
|
77
|
+
= check_box_tag :payment_save_card, 1, false
|
78
|
+
= label_tag :payment_save_card, t('projects.contributions.edit.payment_save_card')
|
79
|
+
.loader.hide= image_tag('loading.gif')
|
80
|
+
.clearfix
|
81
|
+
= submit_tag t('projects.contributions.review.form.labels.submit'), :class => 'btn btn-primary btn-large', :id => "credit_card_submit"
|
82
|
+
|
83
|
+
#payment_type_slip_section.hide.payment_section
|
84
|
+
h3= t('projects.contributions.review.form.labels.payment_boleto')
|
85
|
+
.clearfix
|
86
|
+
.bootstrap-twitter style="float: none;"
|
87
|
+
.alert.alert-danger.hide
|
88
|
+
p.error_msg
|
89
|
+
.clearfix
|
90
|
+
.bootstrap-twitter
|
91
|
+
.bootstrap-form
|
92
|
+
|
93
|
+
.bootstrap-alert
|
94
|
+
.alert.credit_alert
|
95
|
+
= t('users.current_user_fields.bank_account_hint')
|
96
|
+
|
97
|
+
= simple_form_for current_user, url: 'javascript:void(0)' do |f|
|
98
|
+
.bank_accounts
|
99
|
+
= f.simple_fields_for :bank_account do |bank_form|
|
100
|
+
= bank_form.input :name, as: :string, input_html: {autocomplete: 'off'}
|
101
|
+
= bank_form.input :agency, as: :string
|
102
|
+
= bank_form.input :agency_digit, as: :string
|
103
|
+
= bank_form.input :account, as: :string
|
104
|
+
= bank_form.input :account_digit, as: :string
|
105
|
+
= bank_form.input :owner_name, as: :string, input_html: { value: bank_form.object.owner_name || current_user.full_name }
|
106
|
+
= bank_form.input :owner_document, as: :string, input_html: { value: bank_form.object.owner_document || current_user.cpf }
|
107
|
+
.clearfix
|
108
|
+
.loader.hide= image_tag('loading.gif')
|
109
|
+
= submit_tag t('projects.contributions.review.form.labels.build_boleto'), :class => 'btn btn-primary btn-large', :id => "build_boleto"
|
110
|
+
.clearfix
|
111
|
+
p.subtitle.hide= t('projects.contributions.review.form.labels.payment_boleto_subtitle')
|
112
|
+
.link_content
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>CatarsePagarme</title>
|
5
|
+
<%= stylesheet_link_tag "catarse_pagarme/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "catarse_pagarme/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/bin/rails
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
|
3
|
+
|
4
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
5
|
+
ENGINE_PATH = File.expand_path('../../lib/catarse_pagarme/engine', __FILE__)
|
6
|
+
|
7
|
+
# Set up gems listed in the Gemfile.
|
8
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
9
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
10
|
+
|
11
|
+
require 'rails/all'
|
12
|
+
require 'rails/engine/commands'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
# Maintain your gem's version:
|
5
|
+
require "catarse_pagarme/version"
|
6
|
+
|
7
|
+
# Describe your gem and declare its dependencies:
|
8
|
+
Gem::Specification.new do |s|
|
9
|
+
s.name = "catarse_pagarme"
|
10
|
+
s.version = CatarsePagarme::VERSION
|
11
|
+
s.authors = ["Antônio Roberto Silva", "Diogo Biazus"]
|
12
|
+
s.email = ["forevertonny@gmail.com", "diogob@gmail.com"]
|
13
|
+
s.homepage = "http://github.com/catarse/catarse_pagarme"
|
14
|
+
s.summary = "Integration with Pagar.me"
|
15
|
+
s.description = "Pagar.me engine for catarse"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split($\)
|
18
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
19
|
+
|
20
|
+
s.add_dependency "rails", "~> 4.0"
|
21
|
+
s.add_dependency "pagarme", "~> 1.9.5"
|
22
|
+
|
23
|
+
s.add_development_dependency "rspec-rails", "~> 2.14.0"
|
24
|
+
s.add_development_dependency "factory_girl_rails"
|
25
|
+
s.add_development_dependency "pg"
|
26
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
CatarsePagarme::Engine.routes.draw do
|
2
|
+
resources :pagarme, only: [], path: "payment/pagarme" do
|
3
|
+
|
4
|
+
member do
|
5
|
+
get :review
|
6
|
+
put :second_slip, to: 'slip#update'
|
7
|
+
post :ipn, to: 'notifications#create'
|
8
|
+
post :pay_credit_card, to: 'credit_cards#create'
|
9
|
+
post :pay_slip, to: 'slip#create'
|
10
|
+
post :pay_with_subscription, to: 'subscriptions#create'
|
11
|
+
put :pay_with_subscription, to: 'subscriptions#update'
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'pagarme'
|
2
|
+
require "catarse_pagarme/engine"
|
3
|
+
require "catarse_pagarme/configuration"
|
4
|
+
require "catarse_pagarme/payment_engine"
|
5
|
+
|
6
|
+
|
7
|
+
module CatarsePagarme
|
8
|
+
class << self
|
9
|
+
attr_writer :configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configuration
|
13
|
+
@configuration ||= Configuration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.configure
|
17
|
+
yield(configuration)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module CatarsePagarme
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :api_key, :slip_tax, :credit_card_tax, :interest_rate,
|
4
|
+
:max_installments, :minimum_value_for_installment, :credit_card_cents_fee
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
self.api_key = ''
|
8
|
+
self.slip_tax = 0
|
9
|
+
self.credit_card_tax = 0
|
10
|
+
self.interest_rate = 0
|
11
|
+
self.max_installments = 12
|
12
|
+
self.minimum_value_for_installment = 10
|
13
|
+
self.credit_card_cents_fee = 0.39
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module CatarsePagarme
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace CatarsePagarme
|
4
|
+
|
5
|
+
config.to_prepare do
|
6
|
+
::Contribution.send(:include, CatarsePagarme::ContributionConcern)
|
7
|
+
::CreditCard.send(:include, CatarsePagarme::CreditCardConcern)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module CatarsePagarme
|
2
|
+
class PaymentEngine
|
3
|
+
def name
|
4
|
+
'Pagarme'
|
5
|
+
end
|
6
|
+
|
7
|
+
def review_path contribution
|
8
|
+
url_helpers.review_pagarme_path(contribution)
|
9
|
+
end
|
10
|
+
|
11
|
+
def locale
|
12
|
+
'pt'
|
13
|
+
end
|
14
|
+
|
15
|
+
def can_do_refund?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def direct_refund contribution
|
20
|
+
contribution.pagarme_delegator.refund
|
21
|
+
end
|
22
|
+
|
23
|
+
def can_generate_second_slip?
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
def second_slip_path(contribution)
|
28
|
+
url_helpers.second_slip_pagarme_path(contribution)
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def url_helpers
|
34
|
+
CatarsePagarme::Engine.routes.url_helpers
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CatarsePagarme::CreditCardsController 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 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 "with valid card data" do
|
27
|
+
before do
|
28
|
+
post :create, {
|
29
|
+
locale: :pt, project_id: project.id, contribution_id: contribution.id, use_route: 'catarse_pagarme',
|
30
|
+
payment_card_date: '10/17', payment_card_number: '4901720080344448', payment_card_name: 'Foo bar',
|
31
|
+
payment_card_source: '143', payment_card_installments: '1' }
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'payment_status should be filled and not failed' do
|
36
|
+
expect(ActiveSupport::JSON.decode(response.body)['payment_status']).not_to be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'and payment_status is not failed' do
|
40
|
+
expect(ActiveSupport::JSON.decode(response.body)['payment_status']).not_to eq('failed')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with invalid card data' do
|
45
|
+
before do
|
46
|
+
post :create, {
|
47
|
+
locale: :pt, project_id: project.id, contribution_id: contribution.id, use_route: 'catarse_pagarme',
|
48
|
+
payment_card_date: '', payment_card_name: '',
|
49
|
+
payment_card_source: '143', payment_card_installments: '1' }
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'payment_status should be failed' do
|
53
|
+
expect(ActiveSupport::JSON.decode(response.body)['payment_status']).to eq('failed')
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'message should be filled' do
|
57
|
+
expect(ActiveSupport::JSON.decode(response.body)['message']).not_to be_nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|