d4_pagamento 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bed9f2143e54f94e51e1e91b61e3968f07c6c3b1
4
+ data.tar.gz: ed6057a427bb1c07be694f80650ca2034c8f96e7
5
+ SHA512:
6
+ metadata.gz: 207174c14bea9a5b00ce8c8556f3d97c949bf0e5f6cac47f56c479d0771c732e4e5c17fc45224a5995ee7831ee974b0524df34eea684df03fea340fc75d26ae0
7
+ data.tar.gz: 4b0e63136fb8a1e6caf9d04187ae6134a27dd07249d4e92f05af480edf864e66123a20127ce3ad093d4e56a6ced581c8528f491b33259e7c9739633b95244da7
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Maurilio Campos
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # D4Pagamento
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'd4_pagamento'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install d4_pagamento
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'D4Pagamento'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'test'
31
+ t.pattern = 'test/**/*_test.rb'
32
+ t.verbose = false
33
+ end
34
+
35
+
36
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/d4_pagamento .js
2
+ //= link_directory ../stylesheets/d4_pagamento .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,5 @@
1
+ module D4Pagamento
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ require_dependency "d4_pagamento/application_controller"
2
+
3
+ module D4Pagamento
4
+
5
+ class ProcessarController < ApplicationController
6
+
7
+ def pagamento
8
+ render json: { error: false }
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,11 @@
1
+ require_dependency "d4_pagamento/application_controller"
2
+
3
+ module D4Pagamento
4
+
5
+ class MoipPagamentoController < ApplicationController
6
+ def index
7
+ render json: { error: false }
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,4 @@
1
+ module D4Pagamento
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module D4Pagamento
2
+ module ProcessarHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module D4Pagamento
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module D4Pagamento
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module D4Pagamento
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,101 @@
1
+ module Moip
2
+ module Pagamento
3
+
4
+ def Moip::Pagamento::criar_pagamento(pacote, cobranca)
5
+ auth = Moip2::Auth::Basic.new(MOIP_TOKEN, MOIP_KEY)
6
+ client = Moip2::Client.new(:development, auth)
7
+ api = Moip2::Api.new(client)
8
+
9
+ #pp api.notifications.find_all
10
+ #api.notifications.delete("NPR-YYLCEM7GX4KD")
11
+ # api.notifications.create(
12
+ # events: ["ORDER.*", "PAYMENT.*"],
13
+ # target: "http://webhook.site/5ebb1acd-11c5-4f43-8222-837523e11ee8",
14
+ # media: "WEBHOOK"
15
+ # )
16
+
17
+ moip_cliente = Pagamento::criar_ou_buscar_cliente(api, pacote.usuario)
18
+ moip_pedido = Pagamento::criar_pedido(api, pacote)
19
+ moip_pagamento = Pagamento::pagar(api, moip_pedido, pacote, cobranca)
20
+
21
+ pp moip_cliente
22
+ end
23
+
24
+ def Moip::Pagamento::criar_ou_buscar_cliente(api, usuario)
25
+ if usuario.codigo_moip != nil
26
+ customer = api.customer.show(usuario.codigo_moip)
27
+ else
28
+ options = {
29
+ ownId: usuario.id,
30
+ fullname: usuario.nome,
31
+ email: usuario.email,
32
+ birthDate: usuario.data_nascimento,
33
+ taxDocument: {
34
+ type: 'CPF',
35
+ number: usuario.cpf
36
+ },
37
+ shippingAddress: {
38
+ city: usuario.cidade.nome,
39
+ complement: usuario.endereco_complemento,
40
+ district: usuario.endereco_bairro,
41
+ street: usuario.endereco,
42
+ streetNumber: usuario.endereco_numero,
43
+ zipCode: usuario.endereco_cep,
44
+ state: usuario.cidade.estado.uf,
45
+ country: "BRA"
46
+ }
47
+ }
48
+
49
+ customer = api.customer.create(options)
50
+ usuario.codigo_moip = customer["id"]
51
+ usuario.save!
52
+ end
53
+ customer
54
+ end
55
+
56
+ def Moip::Pagamento::criar_pedido(api, pacote)
57
+ order = api.order.create({
58
+ own_id: pacote.id,
59
+ items: [
60
+ {
61
+ product: "Pacote PESK",
62
+ quantity: 1,
63
+ detail: "Pacote de pesca via Pesk",
64
+ price: pacote.valor * 100
65
+ }
66
+ ],
67
+ customer: {
68
+ own_id: pacote.usuario.id,
69
+ fullname: pacote.usuario.nome,
70
+ email: pacote.usuario.email,
71
+ }
72
+ })
73
+ order
74
+ end
75
+
76
+ def Moip::Pagamento::pagar(api, order, pacote, cobranca)
77
+ pagamento = api.payment.create(order["id"], {
78
+ installment_count: cobranca[:parcelas],
79
+ funding_instrument: {
80
+ method: "CREDIT_CARD",
81
+ credit_card: {
82
+ expirationMonth: "10",
83
+ expirationYear: "18",
84
+ number: "4485360893426969",
85
+ cvc: "311",
86
+ holder: {
87
+ fullname: cobranca[:nome],
88
+ birthdate: cobranca[:nascimento],
89
+ tax_document: {
90
+ type: "CPF",
91
+ number: cobranca[:cpf]
92
+ }
93
+ }
94
+ }
95
+ }
96
+ })
97
+ pagamento
98
+ end
99
+
100
+ end
101
+ end
@@ -0,0 +1,2 @@
1
+ <h1>Processar#index</h1>
2
+ <p>Find me in app/views/d4_pagamento/processar/index.html.erb</p>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>D4 pagamento</title>
5
+ <%= stylesheet_link_tag "d4_pagamento/application", media: "all" %>
6
+ <%= javascript_include_tag "d4_pagamento/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,8 @@
1
+ D4Pagamento::Engine.routes.draw do
2
+ get 'processar'
3
+
4
+ scope 'moip' do
5
+ post '/', to: 'moip_pagamento#pagamento', as: 'moip_pagamento_novo'
6
+ end
7
+
8
+ end
@@ -0,0 +1,4 @@
1
+ require "d4_pagamento/engine"
2
+
3
+ module D4Pagamento
4
+ end
@@ -0,0 +1,7 @@
1
+ module D4Pagamento
2
+
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace D4Pagamento
5
+ end
6
+
7
+ end
@@ -0,0 +1,3 @@
1
+ module D4Pagamento
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,44 @@
1
+ namespace :d4_pagamento do
2
+ task :install do
3
+ initializer_path = Rails.root.join('config', 'initializers', 'd4_pagamento.rb')
4
+ routes_content = "mount D4Pagamento::Engine => '/pagamento'"
5
+
6
+ initializer_content = %{
7
+ ###############################################
8
+ # #
9
+ # Modulo de pagamento da dev4web #
10
+ # Modulos suportados: MOIP / IUGU #
11
+ # #
12
+ # Descomentar as chaves que for utilizar #
13
+ # #
14
+ ################################################
15
+
16
+ # MOIP
17
+ # D4_MOIP_TOKEN = 'TOKEN MOIP'
18
+ # D4_MOIP_PUBLIC_KEY = 'CHAVE PUBLICA DO MOIP'
19
+
20
+
21
+ # IUGU
22
+ # D4_IUGU_TOKEN = 'TOKEN MOIP'
23
+ # D4_IUGU_PUBLIC_KEY = 'CHAVE PUBLICA DO MOIP'
24
+ }
25
+
26
+
27
+ begin
28
+ initializer_file = File.open(initializer_path, 'w')
29
+ initializer_file << initializer_content
30
+ initializer_file.close
31
+
32
+
33
+ puts '[*] Instalação do modulo D4Pagamento finalizada.'
34
+ puts '[*] Configure as chaves no initializer chamado d4_pagamento'
35
+ puts '[*] Adicione o código abaixo em seu arquivo de rotas: '
36
+ puts "[*] #{routes_content}"
37
+
38
+ rescue exception
39
+ puts "[*] Erro: #{exception.message}"
40
+ puts "[*] Finalizado com erros."
41
+ end
42
+
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: d4_pagamento
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Maurilio Campos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: moip2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Modulo de pagamento criado pela dev4web.
56
+ email:
57
+ - mauriliohrc@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - MIT-LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - app/assets/config/d4_pagamento_manifest.js
66
+ - app/assets/javascripts/d4_pagamento/application.js
67
+ - app/assets/javascripts/d4_pagamento/processar.js
68
+ - app/assets/stylesheets/d4_pagamento/application.css
69
+ - app/assets/stylesheets/d4_pagamento/processar.css
70
+ - app/controllers/d4_pagamento/application_controller.rb
71
+ - app/controllers/d4_pagamento/moip_pagamento_controller.rb
72
+ - app/controllers/d4_pagamento/processar_controller.rb
73
+ - app/helpers/d4_pagamento/application_helper.rb
74
+ - app/helpers/d4_pagamento/processar_helper.rb
75
+ - app/jobs/d4_pagamento/application_job.rb
76
+ - app/mailers/d4_pagamento/application_mailer.rb
77
+ - app/models/d4_pagamento/application_record.rb
78
+ - app/models/d4_pagamento/pagamento_moip.rb
79
+ - app/views/d4_pagamento/processar/index.html.erb
80
+ - app/views/layouts/d4_pagamento/application.html.erb
81
+ - config/routes.rb
82
+ - lib/d4_pagamento.rb
83
+ - lib/d4_pagamento/engine.rb
84
+ - lib/d4_pagamento/version.rb
85
+ - lib/tasks/d4_pagamento.rake
86
+ homepage: http://www.dev4web.com.br
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.6.14
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Modulo de pagamento criado pela dev4web.
110
+ test_files: []