catarse_moip 0.1.1 → 1.0.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.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -6
  3. data/.rspec +2 -0
  4. data/.travis.yml +17 -0
  5. data/Gemfile +2 -109
  6. data/Gemfile.lock +73 -476
  7. data/README.md +2 -26
  8. data/Rakefile +7 -2
  9. data/app/assets/javascripts/catarse_moip/moip_form.js +80 -0
  10. data/app/assets/javascripts/catarse_moip/payment_account.js +37 -0
  11. data/app/assets/javascripts/catarse_moip/payment_card.js +89 -0
  12. data/app/assets/javascripts/catarse_moip/payment_choice.js +19 -0
  13. data/app/assets/javascripts/catarse_moip/payment_slip.js +35 -0
  14. data/app/assets/javascripts/catarse_moip/user_document.js +111 -0
  15. data/app/assets/javascripts/catarse_moip.js +7 -0
  16. data/app/controllers/catarse_moip/moip_controller.rb +126 -0
  17. data/app/views/catarse_moip/moip/review.html.slim +105 -0
  18. data/catarse_moip.gemspec +5 -5
  19. data/config/initializers/moip.rb +4 -7
  20. data/config/initializers/register.rb +5 -0
  21. data/config/locales/en.yml +2 -0
  22. data/config/locales/pt.yml +19 -0
  23. data/config/routes.rb +9 -5
  24. data/lib/catarse_moip/engine.rb +7 -0
  25. data/lib/catarse_moip/version.rb +1 -1
  26. data/lib/catarse_moip.rb +1 -1
  27. data/lib/moip_transparente/checkout.rb +218 -0
  28. data/lib/moip_transparente/version.rb +3 -0
  29. data/lib/moip_transparente.rb +32 -0
  30. data/spec/controllers/catarse_moip/moip_controller_spec.rb +230 -0
  31. data/spec/fixtures/ipn_data.txt +1 -0
  32. data/spec/javascripts/moip_form_spec.js +25 -0
  33. data/spec/javascripts/support/app.js +1 -0
  34. data/spec/javascripts/support/backbone.js +1571 -0
  35. data/spec/javascripts/support/jquery.js +8829 -0
  36. data/spec/javascripts/support/skull.js +64 -0
  37. data/spec/javascripts/support/underscore.js +1227 -0
  38. data/spec/spec_helper.rb +2 -23
  39. data/spec/support/payment_engines.rb +3 -0
  40. data/test/dummy/README.rdoc +261 -0
  41. data/test/dummy/Rakefile +7 -0
  42. data/test/dummy/app/assets/javascripts/application.js +15 -0
  43. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  44. data/test/dummy/app/controllers/application_controller.rb +3 -0
  45. data/test/dummy/app/helpers/application_helper.rb +2 -0
  46. data/test/dummy/app/mailers/.gitkeep +0 -0
  47. data/test/dummy/app/models/.gitkeep +0 -0
  48. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  49. data/test/dummy/config/application.rb +59 -0
  50. data/test/dummy/config/boot.rb +10 -0
  51. data/test/dummy/config/database.yml +50 -0
  52. data/test/dummy/config/environment.rb +5 -0
  53. data/test/dummy/config/environments/development.rb +37 -0
  54. data/test/dummy/config/environments/production.rb +67 -0
  55. data/test/dummy/config/environments/test.rb +37 -0
  56. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  57. data/test/dummy/config/initializers/inflections.rb +15 -0
  58. data/test/dummy/config/initializers/mime_types.rb +5 -0
  59. data/test/dummy/config/initializers/secret_token.rb +7 -0
  60. data/test/dummy/config/initializers/session_store.rb +8 -0
  61. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  62. data/test/dummy/config/locales/en.yml +5 -0
  63. data/test/dummy/config/routes.rb +4 -0
  64. data/test/dummy/config.ru +4 -0
  65. data/test/dummy/lib/assets/.gitkeep +0 -0
  66. data/test/dummy/log/.gitkeep +0 -0
  67. data/test/dummy/public/404.html +26 -0
  68. data/test/dummy/public/422.html +26 -0
  69. data/test/dummy/public/500.html +25 -0
  70. data/test/dummy/public/favicon.ico +0 -0
  71. data/test/dummy/script/rails +6 -0
  72. metadata +120 -35
  73. data/.gitmodules +0 -3
  74. data/app/controllers/catarse_moip/payment/moip_controller.rb +0 -49
  75. data/spec/controllers/catarse_moip/payment/moip_controller_spec.rb +0 -81
@@ -0,0 +1,80 @@
1
+ App.addChild('MoipForm', {
2
+ el: 'form.moip',
3
+
4
+ getMoipToken: function(onSuccess){
5
+ var that = this;
6
+ if($('#MoipWidget').length > 0) {
7
+ if(_.isFunction(onSuccess)){
8
+ onSuccess();
9
+ }
10
+ } else {
11
+ $.post('/payment/moip/' + this.backerId + '/get_moip_token').success(function(response, textStatus){
12
+ that.paymentChoice.$('input').attr('disabled', 'disabled');
13
+ if(response.get_token_response.status == 'fail'){
14
+ that.checkoutFailure({Code: 0, Mensagem: response.get_token_response.message});
15
+ }
16
+ else{
17
+ $('#catarse_moip_form').prepend(response.widget_tag);
18
+ if(_.isFunction(onSuccess)){
19
+ onSuccess(response);
20
+ }
21
+ }
22
+ });
23
+ }
24
+ },
25
+
26
+ checkoutFailure: function(data) {
27
+ this.loader.hide();
28
+ var response_data = (data.length > 0 ? data[0] : data);
29
+ if(response_data.Codigo == 914){
30
+ response_data.Mensagem += '. Tente <a href="javascript:window.location.reload();">recarregar a página</a> e repetir a operação de pagamento.';
31
+ }
32
+ this.message.find('p').html(response_data.Mensagem);
33
+ this.message.fadeIn('fast');
34
+ $('input[type="submit"]').removeAttr('disabled').show();
35
+ },
36
+
37
+ checkoutSuccessful: function(data) {
38
+ var that = this;
39
+ $.post('/payment/moip/' + this.backerId + '/moip_response', {response: data}).success(function(){
40
+ that.loader.hide();
41
+ // Bail out when get an error from MoIP
42
+ if(data.Status == 'Cancelado'){
43
+ return that.checkoutFailure({Codigo: 0, Mensagem: data.Classificacao.Descricao + '. Verifique os dados de pagamento e tente novamente.'})
44
+ }
45
+
46
+ // Go on otherwise
47
+ if(data.url && $('#payment_type_cards_section').css('display') != 'block') {
48
+ var link = $('<a target="__blank">'+data.url+'</a>')
49
+ link.attr('href', data.url);
50
+ $('.link_content:visible').empty().html(link);
51
+ $('.payment_section:visible .subtitle').fadeIn('fast');
52
+ }
53
+ else {
54
+ var thank_you = $('#project_review').data('thank-you-path');
55
+ if(thank_you){
56
+ location.href = thank_you;
57
+ }
58
+ else {
59
+ location.href = '/';
60
+ }
61
+ }
62
+ });
63
+ },
64
+
65
+ activate: function(){
66
+ this.message = this.$('.next_step_after_valid_document .alert-danger');
67
+ this.backerId = $('input#backer_id').val();
68
+ this.projectId = $('input#project_id').val();
69
+
70
+ this.loader = this.$('.loader');
71
+
72
+ //this.paymentChoice = new CATARSE.PaymentChoice();
73
+ //this.paymentCard = new CATARSE.PaymentCard({moipForm: this});
74
+ //this.paymentSlip = new CATARSE.PaymentSlip({moipForm: this});
75
+ //this.paymentAccount = new CATARSE.PaymentAccount({moipForm: this});
76
+ window.checkoutSuccessful = _.bind(this.checkoutSuccessful, this);
77
+ window.checkoutFailure = _.bind(this.checkoutFailure, this);
78
+ }
79
+ });
80
+
@@ -0,0 +1,37 @@
1
+ App.views.MoipForm.addChild('PaymentAccount', _.extend({
2
+ el: '#payment_type_account_section',
3
+
4
+ events: {
5
+ 'change select#account' : 'onChangeAccount',
6
+ 'click input#build_account_link' : 'onBuildAccountClick',
7
+ 'keyup #user_document_account' : 'onUserDocumentKeyup',
8
+ 'click .link_content a' : 'onContentClick',
9
+ },
10
+
11
+ activate: function(){
12
+ this.moipForm = this.parent;
13
+ this.$('input#user_document_account').mask("999.999.999-99");
14
+ },
15
+
16
+ onChangeAccount: function(e){
17
+ var value = $(e.currentTarget).val();
18
+ this.$('input#build_account_link').attr('disabled', !(value != "" && value != undefined));
19
+ },
20
+
21
+ onBuildAccountClick: function(e) {
22
+ var that = this;
23
+ e.preventDefault();
24
+ $(e.currentTarget).hide();
25
+ that.moipForm.loader.show();
26
+
27
+ // Get token and send payment
28
+ that.moipForm.getMoipToken(function(){
29
+ var settings = {
30
+ "Instituicao": $('select#account').val(),
31
+ "Forma": "DebitoBancario"
32
+ }
33
+ MoipWidget(settings);
34
+ });
35
+ }
36
+ }, App.views.MoipForm.UserDocument));
37
+
@@ -0,0 +1,89 @@
1
+ App.views.MoipForm.addChild('PaymentCard', _.extend({
2
+ el: '#payment_type_cards_section',
3
+
4
+ events: {
5
+ 'keyup input[type="text"]' : 'creditCardInputValidator',
6
+ 'keyup #payment_card_number' : 'onKeyupPaymentCardNumber',
7
+ 'click input#credit_card_submit' : 'onSubmit',
8
+ 'keyup #payment_card_cpf' : 'onUserDocumentKeyup'
9
+ },
10
+
11
+ activate: function(options){
12
+ // Set credit card fields masks
13
+ this.moipForm = this.parent;
14
+ this.$('input#payment_card_date').mask('99/99');
15
+ this.$('input#payment_card_birth').mask('99/99/9999');
16
+ this.$('input#payment_card_cpf').mask("999.999.999-99");
17
+ this.$('input#payment_card_phone').mask("(99) 9999-9999?9");
18
+ },
19
+
20
+ onKeyupPaymentCardNumber: function(e){
21
+ this.$('input#payment_card_flag').val(this.getCardFlag($(e.currentTarget).val()))
22
+ },
23
+
24
+ onSubmit: function(e) {
25
+ var that = this;
26
+ e.preventDefault();
27
+ $(e.currentTarget).hide();
28
+ that.moipForm.loader.show();
29
+
30
+ // Get token and send payment
31
+ that.moipForm.getMoipToken(function(){
32
+ var settings = {
33
+ "Forma": "CartaoCredito",
34
+ "Instituicao": that.$('input#payment_card_flag').val(),
35
+ "Parcelas": "1",
36
+ "Recebimento": "AVista",
37
+ "CartaoCredito": {
38
+ "Numero": that.$('input#payment_card_number').val(),
39
+ "Expiracao": that.$('input#payment_card_date').val(),
40
+ "CodigoSeguranca": that.$('input#payment_card_source').val(),
41
+ "Portador": {
42
+ "Nome": that.$('input#payment_card_name').val(),
43
+ "DataNascimento": that.$('input#payment_card_birth').val(),
44
+ "Telefone": that.$('input#payment_card_phone').val(),
45
+ "Identidade": that.$('input#payment_card_cpf').val()
46
+ }
47
+ }
48
+ };
49
+ MoipWidget(settings);
50
+ });
51
+ },
52
+
53
+ hasContent: function(element) {
54
+ var value = $(element).val().replace(/[\-\.\_\/\s]/g, '');
55
+ if(value && value.length > 0){
56
+ $(element).addClass("ok").removeClass("error")
57
+ return true
58
+ } else {
59
+ $(element).addClass("error").removeClass("ok")
60
+ return false
61
+ }
62
+ },
63
+
64
+ creditCardInputValidator: function() {
65
+ var that = this;
66
+ var all_ok = true;
67
+ $.each($('#payment_type_cards_section input[type="text"]'), function(i, item){
68
+ all_ok = that.hasContent(item);
69
+ });
70
+ $('input#credit_card_submit').attr('disabled', !all_ok);
71
+ },
72
+
73
+ getCardFlag: function(number) {
74
+ var cc = (number + '').replace(/\s/g, ''); //remove space
75
+
76
+ if ((/^(34|37)/).test(cc) && cc.length == 15) {
77
+ return 'AmericanExpress'; //AMEX begins with 34 or 37, and length is 15.
78
+ } else if ((/^(51|52|53|54|55)/).test(cc) && cc.length == 16) {
79
+ return 'Mastercard'; //MasterCard beigins with 51-55, and length is 16.
80
+ } else if ((/^(4)/).test(cc) && (cc.length == 13 || cc.length == 16)) {
81
+ return 'Visa'; //VISA begins with 4, and length is 13 or 16.
82
+ } else if ((/^(300|301|302|303|304|305|36|38)/).test(cc) && cc.length == 14) {
83
+ return 'Diners'; //Diners Club begins with 300-305 or 36 or 38, and length is 14.
84
+ } else if ((/^(38)/).test(cc) && cc.length == 19) {
85
+ return 'Hipercard';
86
+ }
87
+ return 'Desconhecido';
88
+ }
89
+ }, App.views.MoipForm.UserDocument));
@@ -0,0 +1,19 @@
1
+ App.views.MoipForm.addChild('PaymentChoice', {
2
+ el: '.list_payment',
3
+
4
+ events: {
5
+ 'change input[type="radio"]' : 'onListPaymentChange'
6
+ },
7
+
8
+ onListPaymentChange: function(e){
9
+ $('.payment_section').fadeOut('fast', function(){
10
+ var currentElementId = $(e.currentTarget).attr('id');
11
+ $('#'+currentElementId+'_section').fadeIn('fast');
12
+ });
13
+ },
14
+
15
+ activate: function(){
16
+ this.$('input#payment_type_cards').click();
17
+ }
18
+ });
19
+
@@ -0,0 +1,35 @@
1
+ App.views.MoipForm.addChild('PaymentSlip', _.extend({
2
+ el: '#payment_type_boleto_section',
3
+
4
+ events: {
5
+ 'click input#build_boleto' : 'onBuildBoletoClick',
6
+ 'click .link_content a' : 'onContentClick',
7
+ 'keyup #user_document_payment_slip' : 'onUserDocumentPaymentSlipKeyup'
8
+ },
9
+
10
+ onUserDocumentPaymentSlipKeyup: function(e){
11
+ var $documentField = $(e.currentTarget);
12
+ this.onUserDocumentKeyup(e);
13
+ $('input#build_boleto').attr('disabled', !$documentField.hasClass('ok'));
14
+ },
15
+
16
+ activate: function(options){
17
+ this.moipForm = this.parent;
18
+ this.$('input#user_document_payment_slip').mask("999.999.999-99");
19
+ },
20
+
21
+ onBuildBoletoClick: function(e){
22
+ var that = this;
23
+ e.preventDefault();
24
+ $(e.currentTarget).hide();
25
+ that.moipForm.loader.show();
26
+
27
+ // Get token and send payment
28
+ that.moipForm.getMoipToken(function(){
29
+ var settings = {
30
+ "Forma":"BoletoBancario"
31
+ }
32
+ MoipWidget(settings);
33
+ });
34
+ }
35
+ }, App.views.MoipForm.UserDocument));
@@ -0,0 +1,111 @@
1
+ App.views.MoipForm.UserDocument = {
2
+ onContentClick: function(e){
3
+ window.setTimeout(function(){
4
+ this.moipForm.checkoutSuccessful({'StatusPagamento': 'Success'});
5
+ }, 2000);
6
+ },
7
+
8
+ onUserDocumentKeyup: function(e){
9
+ var $documentField = $(e.currentTarget);
10
+
11
+ var documentNumber = $documentField.val();
12
+ $documentField.prop('maxlength', 18);
13
+ var resultCpf = this.validateCpf(documentNumber);
14
+ var resultCnpj = this.validateCnpj(documentNumber.replace(/[\/.\-\_ ]/g, ''));
15
+ var numberLength = documentNumber.replace(/[.\-\_ ]/g, '').length
16
+ if(numberLength > 10) {
17
+ if($documentField.attr('id') != 'payment_card_cpf'){
18
+ if(numberLength == 11) {$documentField.mask('999.999.999-99?999'); }//CPF
19
+ else if(numberLength == 14 ){$documentField.mask('99.999.999/9999-99');}//CNPJ
20
+ if(numberLength != 14 || numberLength != 11){ $documentField.unmask()}
21
+ }
22
+
23
+ if(resultCpf || resultCnpj) {
24
+ $documentField.addClass('ok').removeClass('error');
25
+
26
+ $.post('/projects/' + this.moipForm.projectId + '/backers/' + this.moipForm.backerId + '/update_info', {
27
+ backer: { payer_document: documentNumber }
28
+ });
29
+
30
+ } else {
31
+ $documentField.addClass('error').removeClass('ok');
32
+ }
33
+ }
34
+ else{
35
+ $documentField.addClass('error').removeClass('ok');
36
+ }
37
+
38
+ },
39
+
40
+ validateCpf: function(cpfString){
41
+ var product = 0, i, digit;
42
+ cpfString = cpfString.replace(/[.\-\_ ]/g, '');
43
+ var aux = Math.floor(parseFloat(cpfString) / 100);
44
+ var cpf = aux * 100;
45
+ var quotient;
46
+
47
+ for(i=0; i<=8; i++){
48
+ product += (aux % 10) * (i+2);
49
+ aux = Math.floor(aux / 10);
50
+ }
51
+ digit = product % 11 < 2 ? 0 : 11 - (product % 11);
52
+ cpf += (digit * 10);
53
+ product = 0;
54
+ aux = Math.floor(cpf / 10);
55
+ for(i=0; i<=9; i++){
56
+ product += (aux % 10) * (i+2);
57
+ aux = Math.floor(aux / 10);
58
+ }
59
+ digit = product % 11 < 2 ? 0 : 11 - (product % 11);
60
+ cpf += digit;
61
+ return parseFloat(cpfString) === cpf;
62
+ },
63
+
64
+ validateCnpj: function(cnpj) {
65
+ var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
66
+ digitos_iguais = 1;
67
+ if (cnpj.length < 14 && cnpj.length < 15)
68
+ return false;
69
+ for (i = 0; i < cnpj.length - 1; i++)
70
+ if (cnpj.charAt(i) != cnpj.charAt(i + 1))
71
+ {
72
+ digitos_iguais = 0;
73
+ break;
74
+ }
75
+ if (!digitos_iguais)
76
+ {
77
+ tamanho = cnpj.length - 2
78
+ numeros = cnpj.substring(0,tamanho);
79
+ digitos = cnpj.substring(tamanho);
80
+ soma = 0;
81
+ pos = tamanho - 7;
82
+ for (i = tamanho; i >= 1; i--)
83
+ {
84
+ soma += numeros.charAt(tamanho - i) * pos--;
85
+ if (pos < 2)
86
+ pos = 9;
87
+ }
88
+ resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
89
+ if (resultado != digitos.charAt(0))
90
+ return false;
91
+ tamanho = tamanho + 1;
92
+ numeros = cnpj.substring(0,tamanho);
93
+ soma = 0;
94
+ pos = tamanho - 7;
95
+ for (i = tamanho; i >= 1; i--)
96
+ {
97
+ soma += numeros.charAt(tamanho - i) * pos--;
98
+ if (pos < 2)
99
+ pos = 9;
100
+ }
101
+ resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
102
+ if (resultado != digitos.charAt(1))
103
+ return false;
104
+ return true;
105
+ }
106
+ else
107
+ return false;
108
+ }
109
+ };
110
+
111
+
@@ -0,0 +1,7 @@
1
+ //= require ./catarse_moip/moip_form
2
+ //= require ./catarse_moip/user_document
3
+ //= require_tree ./catarse_moip
4
+
5
+ $(function(){
6
+ app.createViewGetters();
7
+ });
@@ -0,0 +1,126 @@
1
+ require 'moip_transparente'
2
+
3
+ module CatarseMoip
4
+ class MoipController < ApplicationController
5
+ attr_accessor :backer
6
+
7
+ class TransactionStatus < ::EnumerateIt::Base
8
+ associate_values(
9
+ :authorized => 1,
10
+ :started => 2,
11
+ :printed_boleto => 3,
12
+ :finished => 4,
13
+ :canceled => 5,
14
+ :process => 6,
15
+ :written_back => 7,
16
+ :refunded => 9
17
+ )
18
+ end
19
+
20
+ skip_before_filter :force_http
21
+ layout :false
22
+
23
+ def create_notification
24
+ @backer = PaymentEngines.find_payment key: params[:id_transacao]
25
+ process_moip_message(params)
26
+ return render :nothing => true, :status => 200
27
+ rescue Exception => e
28
+ return render :text => "#{e.inspect}: #{e.message} recebemos: #{params}", :status => 422
29
+ end
30
+
31
+ def js
32
+ tries = 0
33
+ begin
34
+ @moip = ::MoipTransparente::Checkout.new
35
+ render :text => open(@moip.get_javascript_url).set_encoding('ISO-8859-1').read.encode('utf-8')
36
+ rescue Exception => e
37
+ tries += 1
38
+ retry unless tries > 3
39
+ raise e
40
+ end
41
+ end
42
+
43
+ def review
44
+ @moip = ::MoipTransparente::Checkout.new
45
+ end
46
+
47
+ def moip_response
48
+ @backer = PaymentEngines.find_payment id: params[:id], user_id: current_user.id
49
+ process_moip_message params[:response] unless params[:response]['StatusPagamento'] == 'Falha'
50
+ render nothing: true, status: 200
51
+ end
52
+
53
+ def get_moip_token
54
+ @backer = PaymentEngines.find_payment id: params[:id], user_id: current_user.id
55
+
56
+ ::MoipTransparente::Config.test = (PaymentEngines.configuration[:moip_test] == 'true')
57
+ ::MoipTransparente::Config.access_token = PaymentEngines.configuration[:moip_token]
58
+ ::MoipTransparente::Config.access_key = PaymentEngines.configuration[:moip_key]
59
+
60
+ @moip = ::MoipTransparente::Checkout.new
61
+
62
+ invoice = {
63
+ razao: "Apoio para o projeto '#{backer.project.name}'",
64
+ id: backer.key,
65
+ total: backer.value.to_s,
66
+ acrescimo: '0.00',
67
+ desconto: '0.00',
68
+ cliente: {
69
+ id: backer.user.id,
70
+ nome: backer.payer_name,
71
+ email: backer.payer_email,
72
+ logradouro: "#{backer.address_street}, #{backer.address_number}",
73
+ complemento: backer.address_complement,
74
+ bairro: backer.address_neighbourhood,
75
+ cidade: backer.address_city,
76
+ uf: backer.address_state,
77
+ cep: backer.address_zip_code,
78
+ telefone: backer.address_phone_number
79
+ }
80
+ }
81
+
82
+ response = @moip.get_token(invoice)
83
+
84
+ session[:thank_you_id] = backer.project.id
85
+
86
+ backer.update_column :payment_token, response[:token] if response and response[:token]
87
+
88
+ render json: { get_token_response: response, moip: @moip, widget_tag: @moip.widget_tag('checkoutSuccessful', 'checkoutFailure'), javascript_tag: @moip.javascript_tag }
89
+ end
90
+
91
+ def update_backer params = nil
92
+ unless params && params["CodigoMoIP"] && params["TaxaMoIP"]
93
+ response = ::MoIP.query(backer.payment_token)
94
+ if response && response["Autorizacao"]
95
+ params = response["Autorizacao"]["Pagamento"]
96
+ params = params.first unless params.respond_to?(:key)
97
+ end
98
+ end
99
+
100
+ if params
101
+ backer.update_attributes({
102
+ :payment_id => params["CodigoMoIP"],
103
+ :payment_choice => params["FormaPagamento"],
104
+ :payment_service_fee => params["TaxaMoIP"]
105
+ })
106
+ end
107
+ end
108
+
109
+ def process_moip_message params
110
+ PaymentEngines.create_payment_notification backer_id: backer.id, extra_data: JSON.parse(params.to_json.force_encoding('iso-8859-1').encode('utf-8'))
111
+ backer.with_lock do
112
+ update_backer if backer.payment_id.nil?
113
+ case params[:status_pagamento].to_i
114
+ when TransactionStatus::AUTHORIZED
115
+ backer.confirm! unless backer.confirmed?
116
+ when TransactionStatus::WRITTEN_BACK, TransactionStatus::REFUNDED
117
+ backer.refund! unless backer.refunded?
118
+ when TransactionStatus::CANCELED
119
+ backer.cancel! unless backer.canceled?
120
+ else
121
+ backer.waiting! if backer.pending?
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,105 @@
1
+ = javascript_include_tag 'catarse_moip'
2
+ #catarse_moip_form
3
+ = form_tag 'javascript:void(0);', :class => 'moip' do
4
+
5
+ .next_step_after_valid_document
6
+
7
+ .list_payment
8
+ .input
9
+ = radio_button_tag 'payment_type', "cards"
10
+ = label_tag :payment_type_cards, nil, :class => "cards"
11
+
12
+ = radio_button_tag 'payment_type', "boleto"
13
+ = label_tag :payment_type_boleto, 'Boleto', :class => "boleto"
14
+
15
+ = radio_button_tag 'payment_type', "account"
16
+ = label_tag :payment_type_account, 'Débito em Conta', :class => "account"
17
+
18
+ #payment_type_cards_section.payment_section
19
+ h3= t('projects.backers.review.form.labels.payment_card')
20
+
21
+ .clearfix
22
+
23
+ .bootstrap-twitter style="float: none;"
24
+ .alert.alert-danger.hide
25
+ p.error_msg
26
+ .clearfix
27
+
28
+ .clearfix
29
+
30
+ .choose_card
31
+ .div
32
+ span= t('projects.backers.review.form.labels.owner_card')
33
+ .owner_outside
34
+ .owner
35
+ ol.inputs
36
+ li.name
37
+ = label_tag :payment_card_name, "Nome do titular do cartão"
38
+ = text_field_tag :payment_card_name, nil
39
+ li.cpf
40
+ = label_tag :payment_card_cpf, "CPF"
41
+ = text_field_tag :payment_card_cpf, nil
42
+ li.phone
43
+ = label_tag :payment_card_phone, "Telefone"
44
+ = text_field_tag :payment_card_phone, nil
45
+ li.birth
46
+ = label_tag :payment_card_birth, "Data de Nascimento"
47
+ = text_field_tag :payment_card_birth, nil
48
+ .div
49
+ span= t('projects.backers.review.form.labels.number_card')
50
+ .infocard_outside
51
+ .infocard
52
+ ol.inputs
53
+ li.number
54
+ = label_tag :payment_card_number, 'Número do cartão'
55
+ = text_field_tag :payment_card_number, nil
56
+ li.flag
57
+ = label_tag :payment_card_flag, 'Bandeira'
58
+ = text_field_tag :payment_card_flag, nil, { disabled: true }
59
+ li.source
60
+ = label_tag :payment_card_source, 'Código de Segurança'
61
+ = text_field_tag :payment_card_source, nil
62
+ li.date
63
+ = label_tag :payment_card_date, 'Data de Expiração'
64
+ = text_field_tag :payment_card_date, nil
65
+
66
+ .clearfix
67
+ .bootstrap-twitter
68
+ .loader.hide= image_tag('loading.gif')
69
+ = submit_tag t('projects.backers.review.form.labels.submit'), :disabled => true, :class => 'btn btn-primary btn-large', :id => "credit_card_submit"
70
+ #payment_type_boleto_section.hide.payment_section
71
+ h3= t('projects.backers.review.form.labels.payment_boleto')
72
+ .clearfix
73
+ .bootstrap-twitter style="float: none;"
74
+ .alert.alert-danger.hide
75
+ p.error_msg
76
+ .clearfix
77
+ .bootstrap-twitter
78
+ = label_tag 'user_document_payment_slip', t('projects.backers.review.form.labels.document')
79
+ = text_field_tag 'user_document_payment_slip', nil, { autocomplete: 'off' }
80
+ .loader.hide= image_tag('loading.gif')
81
+ = submit_tag t('projects.backers.review.form.labels.build_boleto'), :class => 'btn btn-primary btn-large', :id => "build_boleto", :disabled => true
82
+ .clearfix
83
+ p.subtitle.hide= t('projects.backers.review.form.labels.payment_boleto_subtitle')
84
+ .link_content
85
+
86
+ #payment_type_account_section.hide.payment_section
87
+ h3= t('projects.backers.review.form.labels.payment_account')
88
+ .clearfix
89
+ .bootstrap-twitter style="float: none;"
90
+ .alert.alert-danger.hide
91
+ p.error_msg
92
+ .clearfix
93
+ .bootstrap-twitter
94
+ = label_tag 'user_document_account', t('projects.backers.review.form.labels.document')
95
+ = text_field_tag 'user_document_account', nil, { autocomplete: 'off' }
96
+ = label_tag :account, t('projects.backers.review.form.labels.select_account')
97
+ = select_tag :account, options_for_select([['Banco do Brasil', 'BancoDoBrasil'], ['Bradesco'], ['Banrisul'], ['Itaú', 'Itau'] ]), :include_blank => true
98
+ .loader.hide= image_tag('loading.gif')
99
+ = submit_tag t('projects.backers.review.form.labels.submit'), :class => 'btn btn-primary btn-large', :id => "build_account_link", :disabled => true
100
+ p.subtitle.hide= t('projects.backers.review.form.labels.select_account')
101
+ .link_content
102
+
103
+
104
+
105
+ == javascript_include_tag js_moip_index_path
data/catarse_moip.gemspec CHANGED
@@ -8,17 +8,17 @@ require "catarse_moip/version"
8
8
  Gem::Specification.new do |s|
9
9
  s.name = "catarse_moip"
10
10
  s.version = CatarseMoip::VERSION
11
- s.authors = ["Antônio Roberto Silva"]
12
- s.email = ["forevertonny@gmail.com"]
13
- s.homepage = "http://github.com/devton/catarse_moip"
11
+ s.authors = ["Antônio Roberto Silva", "Diogo Biazus", "Josemar Davi Luedke"]
12
+ s.email = ["forevertonny@gmail.com", "diogob@gmail.com", "josemarluedke@gmail.com"]
13
+ s.homepage = "http://github.com/catarse/catarse_moip"
14
14
  s.summary = "MoIP integration with Catarse"
15
15
  s.description = "MoIP integration with Catarse crowdfunding platform"
16
16
 
17
17
  s.files = `git ls-files`.split($\)
18
18
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
19
 
20
- s.add_dependency "rails", "~> 3.2.6"
21
- s.add_dependency 'moip_catarse', "~> 1.0.6"
20
+ s.add_dependency "rails", "~> 3.2.12"
21
+ s.add_dependency('libxml-ruby', '~> 2.6.0')
22
22
 
23
23
  s.add_development_dependency "rspec-rails"
24
24
  s.add_development_dependency "factory_girl_rails"
@@ -1,8 +1,5 @@
1
- MoIP.setup do |config|
2
- if Configuration[:moip_uri]
3
- config.uri = ::Configuration[:moip_uri]
4
- end
5
-
6
- config.token = Configuration[:moip_token] or ''
7
- config.key = Configuration[:moip_key] or ''
1
+ ::MoIP.setup do |config|
2
+ config.uri = (PaymentEngines.configuration[:moip_uri] rescue nil) || ''
3
+ config.token = (PaymentEngines.configuration[:moip_token] rescue nil) || ''
4
+ config.key = (PaymentEngines.configuration[:moip_key] rescue nil) || ''
8
5
  end
@@ -0,0 +1,5 @@
1
+ begin
2
+ PaymentEngines.register({name: 'moip', review_path: ->(backer){ CatarseMoip::Engine.routes.url_helpers.review_moip_path(backer) }, locale: 'pt'})
3
+ rescue Exception => e
4
+ puts "Error while registering payment engine: #{e}"
5
+ end
@@ -1,6 +1,8 @@
1
1
  en:
2
2
  projects:
3
3
  backers:
4
+ review:
5
+ moip: 'Payments from Brazil'
4
6
  checkout:
5
7
  moip_error: "Ooops. There was an error while sending your payment to MoIP. Please try again."
6
8
  success: "Your back was successfully made. Thanks a lot!"