catarse_moip 2.2.1 → 2.3.0
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.
- data/Gemfile.lock +1 -1
- data/app/assets/javascripts/catarse_moip/moip_form.js +3 -3
- data/app/assets/javascripts/catarse_moip/user_document.js +2 -2
- data/app/controllers/catarse_moip/moip_controller.rb +35 -35
- data/app/views/catarse_moip/moip/review.html.slim +13 -13
- data/config/initializers/register.rb +1 -1
- data/config/locales/en.yml +1 -1
- data/config/locales/pt.yml +1 -1
- data/lib/catarse_moip/version.rb +1 -1
- data/spec/controllers/catarse_moip/moip_controller_spec.rb +74 -74
- metadata +36 -22
- checksums.yaml +0 -7
data/Gemfile.lock
CHANGED
@@ -8,7 +8,7 @@ App.addChild('MoipForm', {
|
|
8
8
|
onSuccess();
|
9
9
|
}
|
10
10
|
} else {
|
11
|
-
$.post('/payment/moip/' + this.
|
11
|
+
$.post('/payment/moip/' + this.contributionId + '/get_moip_token').success(function(response, textStatus){
|
12
12
|
that.paymentChoice.$('input').attr('disabled', 'disabled');
|
13
13
|
if(response.get_token_response.status == 'fail'){
|
14
14
|
that.checkoutFailure({Code: 0, Mensagem: response.get_token_response.message});
|
@@ -47,7 +47,7 @@ App.addChild('MoipForm', {
|
|
47
47
|
|
48
48
|
checkoutSuccessful: function(data) {
|
49
49
|
var that = this;
|
50
|
-
$.post('/payment/moip/' + this.
|
50
|
+
$.post('/payment/moip/' + this.contributionId + '/moip_response', {response: data}).success(function(){
|
51
51
|
that.loader.hide();
|
52
52
|
// Bail out when get an error from MoIP
|
53
53
|
if(data.Status == 'Cancelado'){
|
@@ -75,7 +75,7 @@ App.addChild('MoipForm', {
|
|
75
75
|
|
76
76
|
activate: function(){
|
77
77
|
this.message = this.$('.next_step_after_valid_document .alert-danger');
|
78
|
-
this.
|
78
|
+
this.contributionId = $('input#contribution_id').val();
|
79
79
|
this.projectId = $('input#project_id').val();
|
80
80
|
|
81
81
|
this.loader = this.$('.loader');
|
@@ -24,9 +24,9 @@ App.views.MoipForm.UserDocument = {
|
|
24
24
|
$documentField.addClass('ok').removeClass('error');
|
25
25
|
|
26
26
|
$.ajax({
|
27
|
-
url: '/projects/' + this.moipForm.projectId + '/
|
27
|
+
url: '/projects/' + this.moipForm.projectId + '/contributions/' + this.moipForm.contributionId,
|
28
28
|
type: 'PUT',
|
29
|
-
data: {
|
29
|
+
data: { contribution: { payer_document: documentNumber } }
|
30
30
|
});
|
31
31
|
|
32
32
|
} else {
|
@@ -3,7 +3,7 @@ require 'moip_transparente'
|
|
3
3
|
|
4
4
|
module CatarseMoip
|
5
5
|
class MoipController < ApplicationController
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :contribution
|
7
7
|
|
8
8
|
class TransactionStatus < ::EnumerateIt::Base
|
9
9
|
associate_values(
|
@@ -22,8 +22,8 @@ module CatarseMoip
|
|
22
22
|
layout :false
|
23
23
|
|
24
24
|
def create_notification
|
25
|
-
@
|
26
|
-
process_moip_message if @
|
25
|
+
@contribution = PaymentEngines.find_payment key: params[:id_transacao]
|
26
|
+
process_moip_message if @contribution.payment_method == 'MoIP' || @contribution.payment_method.nil?
|
27
27
|
return render :nothing => true, :status => 200
|
28
28
|
rescue Exception => e
|
29
29
|
return render :text => "#{e.inspect}: #{e.message} recebemos: #{params}", :status => 422
|
@@ -46,13 +46,13 @@ module CatarseMoip
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def moip_response
|
49
|
-
@
|
50
|
-
|
49
|
+
@contribution = PaymentEngines.find_payment id: params[:id], user_id: current_user.id
|
50
|
+
first_update_contribution unless params[:response]['StatusPagamento'] == 'Falha'
|
51
51
|
render nothing: true, status: 200
|
52
52
|
end
|
53
53
|
|
54
54
|
def get_moip_token
|
55
|
-
@
|
55
|
+
@contribution = PaymentEngines.find_payment id: params[:id], user_id: current_user.id
|
56
56
|
|
57
57
|
::MoipTransparente::Config.test = (PaymentEngines.configuration[:moip_test] == 'true')
|
58
58
|
::MoipTransparente::Config.access_token = PaymentEngines.configuration[:moip_token]
|
@@ -61,30 +61,30 @@ module CatarseMoip
|
|
61
61
|
@moip = ::MoipTransparente::Checkout.new
|
62
62
|
|
63
63
|
invoice = {
|
64
|
-
razao: "Apoio para o projeto '#{
|
65
|
-
id:
|
66
|
-
total:
|
64
|
+
razao: "Apoio para o projeto '#{contribution.project.name}'",
|
65
|
+
id: contribution.key,
|
66
|
+
total: contribution.value.to_s,
|
67
67
|
acrescimo: '0.00',
|
68
68
|
desconto: '0.00',
|
69
69
|
cliente: {
|
70
|
-
id:
|
71
|
-
nome:
|
72
|
-
email:
|
73
|
-
logradouro: "#{
|
74
|
-
complemento:
|
75
|
-
bairro:
|
76
|
-
cidade:
|
77
|
-
uf:
|
78
|
-
cep:
|
79
|
-
telefone:
|
70
|
+
id: contribution.user.id,
|
71
|
+
nome: contribution.payer_name,
|
72
|
+
email: contribution.payer_email,
|
73
|
+
logradouro: "#{contribution.address_street}, #{contribution.address_number}",
|
74
|
+
complemento: contribution.address_complement,
|
75
|
+
bairro: contribution.address_neighbourhood,
|
76
|
+
cidade: contribution.address_city,
|
77
|
+
uf: contribution.address_state,
|
78
|
+
cep: contribution.address_zip_code,
|
79
|
+
telefone: contribution.address_phone_number
|
80
80
|
}
|
81
81
|
}
|
82
82
|
|
83
83
|
response = @moip.get_token(invoice)
|
84
84
|
|
85
|
-
session[:thank_you_id] =
|
85
|
+
session[:thank_you_id] = contribution.project.id
|
86
86
|
|
87
|
-
|
87
|
+
contribution.update_column :payment_token, response[:token] if response and response[:token]
|
88
88
|
|
89
89
|
render json: {
|
90
90
|
get_token_response: response,
|
@@ -98,20 +98,20 @@ module CatarseMoip
|
|
98
98
|
}
|
99
99
|
end
|
100
100
|
|
101
|
-
def
|
102
|
-
response = ::MoIP.query(
|
101
|
+
def first_update_contribution
|
102
|
+
response = ::MoIP.query(contribution.payment_token)
|
103
103
|
if response && response["Autorizacao"]
|
104
104
|
params = response["Autorizacao"]["Pagamento"]
|
105
105
|
params = params.first unless params.respond_to?(:key)
|
106
106
|
|
107
|
-
|
107
|
+
contribution.with_lock do
|
108
108
|
if params["Status"] == "Autorizado"
|
109
|
-
|
110
|
-
elsif
|
111
|
-
|
109
|
+
contribution.confirm!
|
110
|
+
elsif contribution.pending?
|
111
|
+
contribution.waiting!
|
112
112
|
end
|
113
113
|
|
114
|
-
|
114
|
+
contribution.update_attributes({
|
115
115
|
:payment_id => params["CodigoMoIP"],
|
116
116
|
:payment_choice => params["FormaPagamento"],
|
117
117
|
:payment_method => 'MoIP',
|
@@ -122,20 +122,20 @@ module CatarseMoip
|
|
122
122
|
end
|
123
123
|
|
124
124
|
def process_moip_message
|
125
|
-
|
126
|
-
PaymentEngines.create_payment_notification
|
127
|
-
payment_id = (
|
125
|
+
contribution.with_lock do
|
126
|
+
PaymentEngines.create_payment_notification contribution_id: contribution.id, extra_data: JSON.parse(params.to_json.force_encoding('iso-8859-1').encode('utf-8'))
|
127
|
+
payment_id = (contribution.payment_id.gsub(".", "").to_i rescue 0)
|
128
128
|
|
129
129
|
if payment_id <= params[:cod_moip].to_i
|
130
|
-
|
130
|
+
contribution.update_attributes payment_id: params[:cod_moip]
|
131
131
|
|
132
132
|
case params[:status_pagamento].to_i
|
133
133
|
when TransactionStatus::AUTHORIZED
|
134
|
-
|
134
|
+
contribution.confirm! unless contribution.confirmed?
|
135
135
|
when TransactionStatus::WRITTEN_BACK, TransactionStatus::REFUNDED
|
136
|
-
|
136
|
+
contribution.refund! unless contribution.refunded?
|
137
137
|
when TransactionStatus::CANCELED
|
138
|
-
|
138
|
+
contribution.cancel! unless contribution.canceled?
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end
|
@@ -17,7 +17,7 @@
|
|
17
17
|
= label_tag :payment_type_account, 'Débito em Conta', :class => "account"
|
18
18
|
|
19
19
|
#payment_type_cards_section.payment_section
|
20
|
-
h3= t('projects.
|
20
|
+
h3= t('projects.contributions.review.form.labels.payment_card')
|
21
21
|
|
22
22
|
.clearfix
|
23
23
|
|
@@ -30,7 +30,7 @@
|
|
30
30
|
|
31
31
|
.choose_card
|
32
32
|
.div
|
33
|
-
span= t('projects.
|
33
|
+
span= t('projects.contributions.review.form.labels.owner_card')
|
34
34
|
.owner_outside
|
35
35
|
.owner
|
36
36
|
ol.inputs
|
@@ -47,7 +47,7 @@
|
|
47
47
|
= label_tag :payment_card_birth, "Data de Nascimento"
|
48
48
|
= text_field_tag :payment_card_birth, nil
|
49
49
|
.div
|
50
|
-
span= t('projects.
|
50
|
+
span= t('projects.contributions.review.form.labels.number_card')
|
51
51
|
.infocard_outside
|
52
52
|
.infocard
|
53
53
|
ol.inputs
|
@@ -67,39 +67,39 @@
|
|
67
67
|
.clearfix
|
68
68
|
.bootstrap-twitter
|
69
69
|
.loader.hide= image_tag('loading.gif')
|
70
|
-
= submit_tag t('projects.
|
70
|
+
= submit_tag t('projects.contributions.review.form.labels.submit'), :disabled => true, :class => 'btn btn-primary btn-large', :id => "credit_card_submit"
|
71
71
|
#payment_type_boleto_section.hide.payment_section
|
72
|
-
h3= t('projects.
|
72
|
+
h3= t('projects.contributions.review.form.labels.payment_boleto')
|
73
73
|
.clearfix
|
74
74
|
.bootstrap-twitter style="float: none;"
|
75
75
|
.alert.alert-danger.hide
|
76
76
|
p.error_msg
|
77
77
|
.clearfix
|
78
78
|
.bootstrap-twitter
|
79
|
-
= label_tag 'user_document_payment_slip', t('projects.
|
79
|
+
= label_tag 'user_document_payment_slip', t('projects.contributions.review.form.labels.document')
|
80
80
|
= text_field_tag 'user_document_payment_slip', nil, { autocomplete: 'off' }
|
81
81
|
.loader.hide= image_tag('loading.gif')
|
82
|
-
= submit_tag t('projects.
|
82
|
+
= submit_tag t('projects.contributions.review.form.labels.build_boleto'), :class => 'btn btn-primary btn-large', :id => "build_boleto", :disabled => true
|
83
83
|
.clearfix
|
84
|
-
p.subtitle.hide= t('projects.
|
84
|
+
p.subtitle.hide= t('projects.contributions.review.form.labels.payment_boleto_subtitle')
|
85
85
|
.link_content
|
86
86
|
|
87
87
|
/
|
88
88
|
#payment_type_account_section.hide.payment_section
|
89
|
-
h3= t('projects.
|
89
|
+
h3= t('projects.contributions.review.form.labels.payment_account')
|
90
90
|
.clearfix
|
91
91
|
.bootstrap-twitter style="float: none;"
|
92
92
|
.alert.alert-danger.hide
|
93
93
|
p.error_msg
|
94
94
|
.clearfix
|
95
95
|
.bootstrap-twitter
|
96
|
-
= label_tag 'user_document_account', t('projects.
|
96
|
+
= label_tag 'user_document_account', t('projects.contributions.review.form.labels.document')
|
97
97
|
= text_field_tag 'user_document_account', nil, { autocomplete: 'off' }
|
98
|
-
= label_tag :account, t('projects.
|
98
|
+
= label_tag :account, t('projects.contributions.review.form.labels.select_account')
|
99
99
|
= select_tag :account, options_for_select([['Banco do Brasil', 'BancoDoBrasil'], ['Bradesco'], ['Banrisul'], ['Itaú', 'Itau'] ]), :include_blank => true
|
100
100
|
.loader.hide= image_tag('loading.gif')
|
101
|
-
= submit_tag t('projects.
|
102
|
-
p.subtitle.hide= t('projects.
|
101
|
+
= submit_tag t('projects.contributions.review.form.labels.submit'), :class => 'btn btn-primary btn-large', :id => "build_account_link", :disabled => true
|
102
|
+
p.subtitle.hide= t('projects.contributions.review.form.labels.select_account')
|
103
103
|
.link_content
|
104
104
|
|
105
105
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
begin
|
2
|
-
PaymentEngines.register({name: 'moip', review_path: ->(
|
2
|
+
PaymentEngines.register({name: 'moip', review_path: ->(contribution){ CatarseMoip::Engine.routes.url_helpers.review_moip_path(contribution) }, locale: 'pt'})
|
3
3
|
rescue Exception => e
|
4
4
|
puts "Error while registering payment engine: #{e}"
|
5
5
|
end
|
data/config/locales/en.yml
CHANGED
data/config/locales/pt.yml
CHANGED
data/lib/catarse_moip/version.rb
CHANGED
@@ -5,9 +5,9 @@ describe CatarseMoip::MoipController do
|
|
5
5
|
subject{ response }
|
6
6
|
|
7
7
|
let(:get_token_response){{:status=>:fail, :code=>"171", :message=>"TelefoneFixo do endereço deverá ser enviado obrigatorio", :id=>"201210192052439150000024698931"}}
|
8
|
-
let(:
|
8
|
+
let(:contribution){ double('contribution', {
|
9
9
|
id: 1,
|
10
|
-
key: '
|
10
|
+
key: 'contribution key',
|
11
11
|
payment_id: 'payment id',
|
12
12
|
project: project,
|
13
13
|
pending?: false,
|
@@ -34,7 +34,7 @@ describe CatarseMoip::MoipController do
|
|
34
34
|
|
35
35
|
let(:user){ double('user', id: 1) }
|
36
36
|
let(:project){ double('project', id: 1, name: 'test project') }
|
37
|
-
let(:extra_data){ {"id_transacao"=>
|
37
|
+
let(:extra_data){ {"id_transacao"=>contribution.key, "valor"=>"2190", "cod_moip"=>"12345123", "forma_pagamento"=>"1", "tipo_pagamento"=>"CartaoDeCredito", "email_consumidor"=>"some@email.com", "controller"=>"catarse_moip/payment/notifications", "action"=>"create"} }
|
38
38
|
|
39
39
|
before do
|
40
40
|
controller.stub(:current_user).and_return(user)
|
@@ -42,107 +42,107 @@ describe CatarseMoip::MoipController do
|
|
42
42
|
::MoipTransparente::Checkout.any_instance.stub(:moip_widget_tag).and_return('<div>')
|
43
43
|
::MoipTransparente::Checkout.any_instance.stub(:moip_javascript_tag).and_return('<script>')
|
44
44
|
::MoipTransparente::Checkout.any_instance.stub(:as_json).and_return('{}')
|
45
|
-
PaymentEngines.stub(:find_payment).and_return(
|
45
|
+
PaymentEngines.stub(:find_payment).and_return(contribution)
|
46
46
|
PaymentEngines.stub(:create_payment_notification)
|
47
|
-
|
47
|
+
contribution.stub(:with_lock).and_yield
|
48
48
|
end
|
49
49
|
|
50
50
|
describe "POST create_notification" do
|
51
|
-
context "when we search for a non-existant
|
51
|
+
context "when we search for a non-existant contribution" do
|
52
52
|
before do
|
53
|
-
PaymentEngines.should_receive(:find_payment).with(key: "non-existant
|
54
|
-
post :create_notification, {:id_transacao => "non-existant
|
53
|
+
PaymentEngines.should_receive(:find_payment).with(key: "non-existant contribution key").and_raise('error')
|
54
|
+
post :create_notification, {:id_transacao => "non-existant contribution key", :use_route => 'catarse_moip'}
|
55
55
|
end
|
56
56
|
|
57
57
|
its(:status){ should == 422 }
|
58
|
-
its(:body){ should == "#<RuntimeError: error>: error recebemos: {\"id_transacao\"=>\"non-existant
|
58
|
+
its(:body){ should == "#<RuntimeError: error>: error recebemos: {\"id_transacao\"=>\"non-existant contribution key\", \"controller\"=>\"catarse_moip/moip\", \"action\"=>\"create_notification\"}" }
|
59
59
|
end
|
60
60
|
|
61
|
-
context "when we seach for an existing
|
61
|
+
context "when we seach for an existing contribution" do
|
62
62
|
before do
|
63
|
-
controller.stub(:params).and_return({:id_transacao =>
|
64
|
-
PaymentEngines.should_receive(:find_payment).with(key:
|
63
|
+
controller.stub(:params).and_return({:id_transacao =>contribution.key, :controller => "catarse_moip/moip", :action => "create_notification"})
|
64
|
+
PaymentEngines.should_receive(:find_payment).with(key: contribution.key).and_return(contribution)
|
65
65
|
controller.should_receive(:process_moip_message)
|
66
|
-
post :create_notification, {:id_transacao =>
|
66
|
+
post :create_notification, {:id_transacao => contribution.key, :use_route => 'catarse_moip'}
|
67
67
|
end
|
68
68
|
|
69
69
|
its(:body){ should == ' ' }
|
70
70
|
its(:status){ should == 200 }
|
71
|
-
it("should assign
|
71
|
+
it("should assign contribution"){ assigns(:contribution).should == contribution }
|
72
72
|
end
|
73
73
|
|
74
|
-
context "when receive ordered notification for
|
74
|
+
context "when receive ordered notification for contribution" do
|
75
75
|
before do
|
76
|
-
controller.stub(:params).and_return({:cod_moip => 125, :id_transacao =>
|
77
|
-
|
76
|
+
controller.stub(:params).and_return({:cod_moip => 125, :id_transacao =>contribution.key, :controller => "catarse_moip/moip", :action => "create_notification", :status_pagamento => 5})
|
77
|
+
contribution.stub(:payment_id).and_return('123')
|
78
78
|
|
79
79
|
controller.should_receive(:process_moip_message).and_call_original
|
80
|
-
|
81
|
-
post :create_notification, {:id_transacao =>
|
80
|
+
contribution.should_receive(:update_attributes).with(payment_id: 125)
|
81
|
+
post :create_notification, {:id_transacao => contribution.key, :use_route => 'catarse_moip'}
|
82
82
|
end
|
83
83
|
|
84
84
|
its(:body){ should == ' ' }
|
85
85
|
its(:status){ should == 200 }
|
86
|
-
it("should assign
|
86
|
+
it("should assign contribution"){ assigns(:contribution).should == contribution }
|
87
87
|
end
|
88
88
|
|
89
89
|
context "when we receive a notification with the same payment id but with another status" do
|
90
90
|
before do
|
91
|
-
controller.stub(:params).and_return({:cod_moip => 123, :id_transacao =>
|
92
|
-
|
91
|
+
controller.stub(:params).and_return({:cod_moip => 123, :id_transacao =>contribution.key, :controller => "catarse_moip/moip", :action => "create_notification", :status_pagamento => 1})
|
92
|
+
contribution.stub(:payment_id).and_return('123')
|
93
93
|
|
94
94
|
controller.should_receive(:process_moip_message).and_call_original
|
95
|
-
|
96
|
-
post :create_notification, {:id_transacao =>
|
95
|
+
contribution.should_receive(:update_attributes).with(payment_id: 123)
|
96
|
+
post :create_notification, {:id_transacao => contribution.key, :use_route => 'catarse_moip'}
|
97
97
|
end
|
98
98
|
|
99
99
|
its(:body){ should == ' ' }
|
100
100
|
its(:status){ should == 200 }
|
101
|
-
it("should assign
|
101
|
+
it("should assign contribution"){ assigns(:contribution).should == contribution }
|
102
102
|
end
|
103
103
|
|
104
|
-
context "when receive a unordered notification for
|
104
|
+
context "when receive a unordered notification for contribution" do
|
105
105
|
before do
|
106
|
-
controller.stub(:params).and_return({:cod_moip => 122, :id_transacao =>
|
107
|
-
|
106
|
+
controller.stub(:params).and_return({:cod_moip => 122, :id_transacao =>contribution.key, :controller => "catarse_moip/moip", :action => "create_notification", :status_pagamento => 5})
|
107
|
+
contribution.stub(:payment_id).and_return('123')
|
108
108
|
|
109
109
|
controller.should_receive(:process_moip_message).and_call_original
|
110
|
-
|
111
|
-
post :create_notification, {:id_transacao =>
|
110
|
+
contribution.should_not_receive(:update_attributes).with(payment_id: 122)
|
111
|
+
post :create_notification, {:id_transacao => contribution.key, :use_route => 'catarse_moip'}
|
112
112
|
end
|
113
113
|
|
114
114
|
its(:body){ should == ' ' }
|
115
115
|
its(:status){ should == 200 }
|
116
|
-
it("should assign
|
116
|
+
it("should assign contribution"){ assigns(:contribution).should == contribution }
|
117
117
|
end
|
118
118
|
|
119
|
-
context "when
|
119
|
+
context "when contribution payment_method is PayPal" do
|
120
120
|
before do
|
121
|
-
controller.stub(:params).and_return({:cod_moip => 125, :id_transacao =>
|
122
|
-
|
121
|
+
controller.stub(:params).and_return({:cod_moip => 125, :id_transacao =>contribution.key, :controller => "catarse_moip/moip", :action => "create_notification", :status_pagamento => 5})
|
122
|
+
contribution.stub(:payment_method).and_return('PayPal')
|
123
123
|
|
124
124
|
controller.should_not_receive(:process_moip_message)
|
125
|
-
post :create_notification, {:id_transacao =>
|
125
|
+
post :create_notification, {:id_transacao => contribution.key, :use_route => 'catarse_moip'}
|
126
126
|
end
|
127
127
|
|
128
128
|
its(:body){ should == ' ' }
|
129
129
|
its(:status){ should == 200 }
|
130
|
-
it("should assign
|
130
|
+
it("should assign contribution"){ assigns(:contribution).should == contribution }
|
131
131
|
end
|
132
132
|
|
133
|
-
context "when
|
133
|
+
context "when contribution payment_id is null" do
|
134
134
|
before do
|
135
|
-
controller.stub(:params).and_return({:cod_moip => 122, :id_transacao =>
|
136
|
-
|
135
|
+
controller.stub(:params).and_return({:cod_moip => 122, :id_transacao =>contribution.key, :controller => "catarse_moip/moip", :action => "create_notification", :status_pagamento => 5})
|
136
|
+
contribution.stub(:payment_id).and_return(nil)
|
137
137
|
|
138
138
|
controller.should_receive(:process_moip_message).and_call_original
|
139
|
-
|
140
|
-
post :create_notification, {:id_transacao =>
|
139
|
+
contribution.should_receive(:update_attributes).with(payment_id: 122)
|
140
|
+
post :create_notification, {:id_transacao => contribution.key, :use_route => 'catarse_moip'}
|
141
141
|
end
|
142
142
|
|
143
143
|
its(:body){ should == ' ' }
|
144
144
|
its(:status){ should == 200 }
|
145
|
-
it("should assign
|
145
|
+
it("should assign contribution"){ assigns(:contribution).should == contribution }
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
@@ -175,8 +175,8 @@ describe CatarseMoip::MoipController do
|
|
175
175
|
describe "POST moip_response" do
|
176
176
|
let(:processor){ double('moip processor') }
|
177
177
|
before do
|
178
|
-
controller.should_receive(:
|
179
|
-
post :moip_response, id:
|
178
|
+
controller.should_receive(:first_update_contribution)
|
179
|
+
post :moip_response, id: contribution.id, response: {StatusPagamento: 'Sucesso'}, use_route: 'catarse_moip'
|
180
180
|
end
|
181
181
|
|
182
182
|
its(:status){ should == 200 }
|
@@ -184,26 +184,26 @@ describe CatarseMoip::MoipController do
|
|
184
184
|
|
185
185
|
describe "POST get_moip_token" do
|
186
186
|
before do
|
187
|
-
post :get_moip_token, :id =>
|
187
|
+
post :get_moip_token, :id => contribution.id, :use_route => 'catarse_moip'
|
188
188
|
end
|
189
189
|
|
190
190
|
its(:status){ should == 200 }
|
191
191
|
its(:body){ should == "{\"get_token_response\":{\"status\":\"fail\",\"code\":\"171\",\"message\":\"TelefoneFixo do endereço deverá ser enviado obrigatorio\",\"id\":\"201210192052439150000024698931\"},\"moip\":\"{}\",\"widget_tag\":{\"tag_id\":\"MoipWidget\",\"token\":null,\"callback_success\":\"checkoutSuccessful\",\"callback_error\":\"checkoutFailure\"}}" }
|
192
192
|
end
|
193
193
|
|
194
|
-
describe "#
|
194
|
+
describe "#first_update_contribution" do
|
195
195
|
before do
|
196
|
-
controller.stub(:
|
197
|
-
|
196
|
+
controller.stub(:contribution).and_return(contribution)
|
197
|
+
contribution.stub(:payment_token).and_return('token')
|
198
198
|
end
|
199
199
|
|
200
200
|
context "with no response from moip" do
|
201
201
|
let(:moip_query_response) { nil }
|
202
202
|
before do
|
203
|
-
MoIP.should_receive(:query).with(
|
204
|
-
|
203
|
+
MoIP.should_receive(:query).with(contribution.payment_token).and_return(moip_query_response)
|
204
|
+
contribution.should_not_receive(:update_attributes)
|
205
205
|
end
|
206
|
-
it("should never call update attributes"){ controller.
|
206
|
+
it("should never call update attributes"){ controller.first_update_contribution }
|
207
207
|
end
|
208
208
|
|
209
209
|
context "with an incomplete transaction" do
|
@@ -211,10 +211,10 @@ describe CatarseMoip::MoipController do
|
|
211
211
|
{"ID"=>"201210191926185570000024694351", "Status"=>"Sucesso"}
|
212
212
|
end
|
213
213
|
before do
|
214
|
-
MoIP.should_receive(:query).with(
|
215
|
-
|
214
|
+
MoIP.should_receive(:query).with(contribution.payment_token).and_return(moip_query_response)
|
215
|
+
contribution.should_not_receive(:update_attributes)
|
216
216
|
end
|
217
|
-
it("should never call update attributes"){ controller.
|
217
|
+
it("should never call update attributes"){ controller.first_update_contribution }
|
218
218
|
end
|
219
219
|
|
220
220
|
context "with a real data set that works for some cases" do
|
@@ -222,34 +222,34 @@ describe CatarseMoip::MoipController do
|
|
222
222
|
{"ID"=>"201210191926185570000024694351", "Status"=>"Sucesso", "Autorizacao"=>{"Pagador"=>{"Nome"=>"juliana.giopato@hotmail.com", "Email"=>"juliana.giopato@hotmail.com"}, "EnderecoCobranca"=>{"Logradouro"=>"Rua sócrates abraão ", "Numero"=>"16.0", "Complemento"=>"casa 19", "Bairro"=>"Campo Limpo", "CEP"=>"05782-470", "Cidade"=>"São Paulo", "Estado"=>"SP", "Pais"=>"BRA", "TelefoneFixo"=>"1184719963"}, "Recebedor"=>{"Nome"=>"Catarse", "Email"=>"financeiro@catarse.me"}, "Pagamento"=>[{"Data"=>"2012-10-17T13:06:07.000-03:00", "DataCredito"=>"2012-10-19T00:00:00.000-03:00", "TotalPago"=>"50.00", "TaxaParaPagador"=>"0.00", "TaxaMoIP"=>"1.34", "ValorLiquido"=>"48.66", "FormaPagamento"=>"BoletoBancario", "InstituicaoPagamento"=>"Bradesco", "Status"=>"Autorizado", "Parcela"=>{"TotalParcelas"=>"1"}, "CodigoMoIP"=>"0000.1325.5258"}, {"Data"=>"2012-10-17T13:05:49.000-03:00", "TotalPago"=>"50.00", "TaxaParaPagador"=>"0.00", "TaxaMoIP"=>"3.09", "ValorLiquido"=>"46.91", "FormaPagamento"=>"CartaoDebito", "InstituicaoPagamento"=>"Visa", "Status"=>"Iniciado", "Parcela"=>{"TotalParcelas"=>"1"}, "CodigoMoIP"=>"0000.1325.5248"}]}}
|
223
223
|
end
|
224
224
|
before do
|
225
|
-
MoIP.should_receive(:query).with(
|
225
|
+
MoIP.should_receive(:query).with(contribution.payment_token).and_return(moip_query_response)
|
226
226
|
payment = moip_query_response["Autorizacao"]["Pagamento"].first
|
227
|
-
|
228
|
-
|
227
|
+
contribution.should_receive(:confirm!)
|
228
|
+
contribution.should_receive(:update_attributes).with({
|
229
229
|
payment_id: payment["CodigoMoIP"],
|
230
230
|
payment_choice: payment["FormaPagamento"],
|
231
231
|
payment_method: 'MoIP',
|
232
232
|
payment_service_fee: payment["TaxaMoIP"]
|
233
233
|
})
|
234
234
|
end
|
235
|
-
it("should call update attributes"){ controller.
|
235
|
+
it("should call update attributes"){ controller.first_update_contribution }
|
236
236
|
end
|
237
237
|
end
|
238
238
|
|
239
239
|
describe "#process_moip_message" do
|
240
240
|
before do
|
241
|
-
controller.stub(:
|
242
|
-
|
243
|
-
|
244
|
-
controller.stub(:
|
241
|
+
controller.stub(:contribution).and_return(contribution)
|
242
|
+
contribution.stub(:confirmed?).and_return(false)
|
243
|
+
contribution.stub(:confirm!)
|
244
|
+
controller.stub(:update_contribution)
|
245
245
|
end
|
246
246
|
|
247
|
-
context "when there is a written back request and
|
247
|
+
context "when there is a written back request and contribution is not refunded" do
|
248
248
|
before do
|
249
|
-
controller.stub(:params).and_return(post_moip_params.merge!({:id_transacao =>
|
250
|
-
|
251
|
-
|
252
|
-
|
249
|
+
controller.stub(:params).and_return(post_moip_params.merge!({:id_transacao => contribution.key, :status_pagamento => CatarseMoip::MoipController::TransactionStatus::WRITTEN_BACK}))
|
250
|
+
contribution.stub(:refunded?).and_return(false)
|
251
|
+
contribution.should_receive(:refund!)
|
252
|
+
contribution.should_receive(:update_attributes)
|
253
253
|
end
|
254
254
|
|
255
255
|
it 'should call refund!' do
|
@@ -259,9 +259,9 @@ describe CatarseMoip::MoipController do
|
|
259
259
|
|
260
260
|
context "when there is an authorized request" do
|
261
261
|
before do
|
262
|
-
controller.stub(:params).and_return(post_moip_params.merge!({:id_transacao =>
|
263
|
-
|
264
|
-
|
262
|
+
controller.stub(:params).and_return(post_moip_params.merge!({:id_transacao => contribution.key, :status_pagamento => CatarseMoip::MoipController::TransactionStatus::AUTHORIZED}))
|
263
|
+
contribution.should_receive(:confirm!)
|
264
|
+
contribution.should_receive(:update_attributes)
|
265
265
|
end
|
266
266
|
|
267
267
|
it 'should call confirm!' do
|
@@ -271,10 +271,10 @@ describe CatarseMoip::MoipController do
|
|
271
271
|
|
272
272
|
context "when there is a refund request" do
|
273
273
|
before do
|
274
|
-
controller.stub(:params).and_return(post_moip_params.merge!({:id_transacao =>
|
275
|
-
|
276
|
-
|
277
|
-
|
274
|
+
controller.stub(:params).and_return(post_moip_params.merge!({:id_transacao => contribution.key, :status_pagamento => CatarseMoip::MoipController::TransactionStatus::REFUNDED}))
|
275
|
+
contribution.stub(:refunded?).and_return(false)
|
276
|
+
contribution.should_receive(:refund!)
|
277
|
+
contribution.should_receive(:update_attributes)
|
278
278
|
end
|
279
279
|
|
280
280
|
it 'should mark refunded to true' do
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: catarse_moip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Antônio Roberto Silva
|
@@ -10,90 +11,102 @@ authors:
|
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2014-01-
|
14
|
+
date: 2014-01-23 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: rails
|
17
18
|
requirement: !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
18
20
|
requirements:
|
19
|
-
- -
|
21
|
+
- - ~>
|
20
22
|
- !ruby/object:Gem::Version
|
21
23
|
version: '4.0'
|
22
24
|
type: :runtime
|
23
25
|
prerelease: false
|
24
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
25
28
|
requirements:
|
26
|
-
- -
|
29
|
+
- - ~>
|
27
30
|
- !ruby/object:Gem::Version
|
28
31
|
version: '4.0'
|
29
32
|
- !ruby/object:Gem::Dependency
|
30
33
|
name: libxml-ruby
|
31
34
|
requirement: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
32
36
|
requirements:
|
33
|
-
- -
|
37
|
+
- - ~>
|
34
38
|
- !ruby/object:Gem::Version
|
35
39
|
version: 2.6.0
|
36
40
|
type: :runtime
|
37
41
|
prerelease: false
|
38
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
39
44
|
requirements:
|
40
|
-
- -
|
45
|
+
- - ~>
|
41
46
|
- !ruby/object:Gem::Version
|
42
47
|
version: 2.6.0
|
43
48
|
- !ruby/object:Gem::Dependency
|
44
49
|
name: enumerate_it
|
45
50
|
requirement: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
46
52
|
requirements:
|
47
|
-
- -
|
53
|
+
- - ! '>='
|
48
54
|
- !ruby/object:Gem::Version
|
49
55
|
version: '0'
|
50
56
|
type: :runtime
|
51
57
|
prerelease: false
|
52
58
|
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
53
60
|
requirements:
|
54
|
-
- -
|
61
|
+
- - ! '>='
|
55
62
|
- !ruby/object:Gem::Version
|
56
63
|
version: '0'
|
57
64
|
- !ruby/object:Gem::Dependency
|
58
65
|
name: rspec-rails
|
59
66
|
requirement: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
60
68
|
requirements:
|
61
|
-
- -
|
69
|
+
- - ~>
|
62
70
|
- !ruby/object:Gem::Version
|
63
71
|
version: 2.14.0
|
64
72
|
type: :development
|
65
73
|
prerelease: false
|
66
74
|
version_requirements: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
67
76
|
requirements:
|
68
|
-
- -
|
77
|
+
- - ~>
|
69
78
|
- !ruby/object:Gem::Version
|
70
79
|
version: 2.14.0
|
71
80
|
- !ruby/object:Gem::Dependency
|
72
81
|
name: factory_girl_rails
|
73
82
|
requirement: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
74
84
|
requirements:
|
75
|
-
- -
|
85
|
+
- - ! '>='
|
76
86
|
- !ruby/object:Gem::Version
|
77
87
|
version: '0'
|
78
88
|
type: :development
|
79
89
|
prerelease: false
|
80
90
|
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
81
92
|
requirements:
|
82
|
-
- -
|
93
|
+
- - ! '>='
|
83
94
|
- !ruby/object:Gem::Version
|
84
95
|
version: '0'
|
85
96
|
- !ruby/object:Gem::Dependency
|
86
97
|
name: database_cleaner
|
87
98
|
requirement: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
88
100
|
requirements:
|
89
|
-
- -
|
101
|
+
- - ! '>='
|
90
102
|
- !ruby/object:Gem::Version
|
91
103
|
version: '0'
|
92
104
|
type: :development
|
93
105
|
prerelease: false
|
94
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
95
108
|
requirements:
|
96
|
-
- -
|
109
|
+
- - ! '>='
|
97
110
|
- !ruby/object:Gem::Version
|
98
111
|
version: '0'
|
99
112
|
description: MoIP integration with Catarse crowdfunding platform
|
@@ -105,9 +118,9 @@ executables: []
|
|
105
118
|
extensions: []
|
106
119
|
extra_rdoc_files: []
|
107
120
|
files:
|
108
|
-
-
|
109
|
-
-
|
110
|
-
-
|
121
|
+
- .gitignore
|
122
|
+
- .rspec
|
123
|
+
- .travis.yml
|
111
124
|
- Gemfile
|
112
125
|
- Gemfile.lock
|
113
126
|
- MIT-LICENSE
|
@@ -181,26 +194,27 @@ files:
|
|
181
194
|
- test/dummy/script/rails
|
182
195
|
homepage: http://github.com/catarse/catarse_moip
|
183
196
|
licenses: []
|
184
|
-
metadata: {}
|
185
197
|
post_install_message:
|
186
198
|
rdoc_options: []
|
187
199
|
require_paths:
|
188
200
|
- lib
|
189
201
|
required_ruby_version: !ruby/object:Gem::Requirement
|
202
|
+
none: false
|
190
203
|
requirements:
|
191
|
-
- -
|
204
|
+
- - ! '>='
|
192
205
|
- !ruby/object:Gem::Version
|
193
206
|
version: '0'
|
194
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
|
+
none: false
|
195
209
|
requirements:
|
196
|
-
- -
|
210
|
+
- - ! '>='
|
197
211
|
- !ruby/object:Gem::Version
|
198
212
|
version: '0'
|
199
213
|
requirements: []
|
200
214
|
rubyforge_project:
|
201
|
-
rubygems_version:
|
215
|
+
rubygems_version: 1.8.25
|
202
216
|
signing_key:
|
203
|
-
specification_version:
|
217
|
+
specification_version: 3
|
204
218
|
summary: MoIP integration with Catarse
|
205
219
|
test_files:
|
206
220
|
- spec/controllers/catarse_moip/moip_controller_spec.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: bf2d975f99e194636ca2089fca03c7aa785baf0a
|
4
|
-
data.tar.gz: d966f3cedfcb618b6d1d518fd33a69a86fc64d03
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 7b7dd1e59ac69a094de99ce6bbc1b9d6b098b471991046fad4d8f5cba2014feb22f8b509e1dd357f65d0ba24c95f2f8fa355358368e1e9a06ac83708e4859d53
|
7
|
-
data.tar.gz: 3b9049ca91ab1c5ff034f6cfa127979e529c81776a050657b332d72f5f643edaba488c5d79a7bfa10e380271aa2a9e9afef6222c6c9bbd1fd3093c92afc2dd7c
|