e4commerce 0.2.0 → 0.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.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/Gemfile.lock +9 -1
  4. data/e4commerce/.gitignore +21 -0
  5. data/e4commerce/Gemfile +53 -0
  6. data/e4commerce/README.md +24 -0
  7. data/e4commerce/Rakefile +6 -0
  8. data/e4commerce/app/assets/config/manifest.js +3 -0
  9. data/e4commerce/app/assets/images/.keep +0 -0
  10. data/e4commerce/app/assets/javascripts/application.js +16 -0
  11. data/e4commerce/app/assets/javascripts/cable.js +13 -0
  12. data/e4commerce/app/assets/javascripts/channels/.keep +0 -0
  13. data/e4commerce/app/assets/stylesheets/application.css +15 -0
  14. data/e4commerce/app/channels/application_cable/channel.rb +4 -0
  15. data/e4commerce/app/channels/application_cable/connection.rb +4 -0
  16. data/e4commerce/app/controllers/application_controller.rb +3 -0
  17. data/e4commerce/app/controllers/concerns/.keep +0 -0
  18. data/e4commerce/app/helpers/application_helper.rb +2 -0
  19. data/e4commerce/app/jobs/application_job.rb +2 -0
  20. data/e4commerce/app/mailers/application_mailer.rb +4 -0
  21. data/e4commerce/app/models/application_record.rb +3 -0
  22. data/e4commerce/app/models/concerns/.keep +0 -0
  23. data/e4commerce/app/views/layouts/application.html.erb +14 -0
  24. data/e4commerce/app/views/layouts/mailer.html.erb +13 -0
  25. data/e4commerce/app/views/layouts/mailer.text.erb +1 -0
  26. data/e4commerce/bin/bundle +3 -0
  27. data/e4commerce/bin/rails +4 -0
  28. data/e4commerce/bin/rake +4 -0
  29. data/e4commerce/bin/setup +34 -0
  30. data/e4commerce/bin/update +29 -0
  31. data/e4commerce/config/application.rb +15 -0
  32. data/e4commerce/config/boot.rb +3 -0
  33. data/e4commerce/config/cable.yml +9 -0
  34. data/e4commerce/config/database.yml +25 -0
  35. data/e4commerce/config/environment.rb +5 -0
  36. data/e4commerce/config/environments/development.rb +54 -0
  37. data/e4commerce/config/environments/production.rb +86 -0
  38. data/e4commerce/config/environments/test.rb +42 -0
  39. data/e4commerce/config/initializers/application_controller_renderer.rb +6 -0
  40. data/e4commerce/config/initializers/assets.rb +11 -0
  41. data/e4commerce/config/initializers/backtrace_silencers.rb +7 -0
  42. data/e4commerce/config/initializers/cookies_serializer.rb +5 -0
  43. data/e4commerce/config/initializers/filter_parameter_logging.rb +4 -0
  44. data/e4commerce/config/initializers/inflections.rb +16 -0
  45. data/e4commerce/config/initializers/mime_types.rb +4 -0
  46. data/e4commerce/config/initializers/new_framework_defaults.rb +26 -0
  47. data/e4commerce/config/initializers/session_store.rb +3 -0
  48. data/e4commerce/config/initializers/wrap_parameters.rb +14 -0
  49. data/e4commerce/config/locales/en.yml +23 -0
  50. data/e4commerce/config/puma.rb +47 -0
  51. data/e4commerce/config/routes.rb +3 -0
  52. data/e4commerce/config/secrets.yml +22 -0
  53. data/e4commerce/config/spring.rb +6 -0
  54. data/e4commerce/config.ru +5 -0
  55. data/e4commerce/db/seeds.rb +7 -0
  56. data/e4commerce/lib/assets/.keep +0 -0
  57. data/e4commerce/lib/tasks/.keep +0 -0
  58. data/e4commerce/log/.keep +0 -0
  59. data/e4commerce/public/404.html +67 -0
  60. data/e4commerce/public/422.html +67 -0
  61. data/e4commerce/public/500.html +66 -0
  62. data/e4commerce/public/apple-touch-icon-precomposed.png +0 -0
  63. data/e4commerce/public/apple-touch-icon.png +0 -0
  64. data/e4commerce/public/favicon.ico +0 -0
  65. data/e4commerce/public/robots.txt +5 -0
  66. data/e4commerce/test/controllers/.keep +0 -0
  67. data/e4commerce/test/fixtures/.keep +0 -0
  68. data/e4commerce/test/fixtures/files/.keep +0 -0
  69. data/e4commerce/test/helpers/.keep +0 -0
  70. data/e4commerce/test/integration/.keep +0 -0
  71. data/e4commerce/test/mailers/.keep +0 -0
  72. data/e4commerce/test/models/.keep +0 -0
  73. data/e4commerce/test/test_helper.rb +10 -0
  74. data/e4commerce/tmp/.keep +0 -0
  75. data/e4commerce/vendor/assets/javascripts/.keep +0 -0
  76. data/e4commerce/vendor/assets/stylesheets/.keep +0 -0
  77. data/lib/e4commerce/notifications_controller.rb +15 -0
  78. data/lib/e4commerce/payment.rb +23 -0
  79. data/lib/e4commerce/product.rb +20 -0
  80. data/lib/e4commerce/ps_checkout_template.rb +48 -0
  81. data/lib/e4commerce/version.rb +1 -1
  82. data/lib/pagseguro/checkout_controller.rb +48 -0
  83. data/lib/pagseguro/notifications_controller.rb +15 -0
  84. data/lib/tasks/pagseguro.rake +17 -0
  85. metadata +81 -6
  86. data/lib/builder.rb +0 -12
  87. data/lib/e4commerce/app/controllers/application_controller.rb +0 -6
  88. data/lib/e4commerce/app/controllers/pagseguro_controller.rb +0 -32
  89. data/lib/e4commerce/config/initializers.rb +0 -19
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Specify a serializer for the signed and encrypted cookie jars.
4
+ # Valid options are :json, :marshal, and :hybrid.
5
+ Rails.application.config.action_dispatch.cookies_serializer = :json
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Configure sensitive parameters which will be filtered from the log file.
4
+ Rails.application.config.filter_parameters += [:password]
@@ -0,0 +1,16 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format. Inflections
4
+ # are locale specific, and you may define rules for as many different
5
+ # locales as you wish. All of these examples are active by default:
6
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
7
+ # inflect.plural /^(ox)$/i, '\1en'
8
+ # inflect.singular /^(ox)en/i, '\1'
9
+ # inflect.irregular 'person', 'people'
10
+ # inflect.uncountable %w( fish sheep )
11
+ # end
12
+
13
+ # These inflection rules are supported but not enabled by default:
14
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
15
+ # inflect.acronym 'RESTful'
16
+ # end
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
@@ -0,0 +1,26 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains migration options to ease your Rails 5.0 upgrade.
4
+ #
5
+ # Read the Guide for Upgrading Ruby on Rails for more info on each option.
6
+
7
+ Rails.application.config.raise_on_unfiltered_parameters = true
8
+
9
+ # Enable per-form CSRF tokens. Previous versions had false.
10
+ Rails.application.config.action_controller.per_form_csrf_tokens = true
11
+
12
+ # Enable origin-checking CSRF mitigation. Previous versions had false.
13
+ Rails.application.config.action_controller.forgery_protection_origin_check = true
14
+
15
+ # Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`.
16
+ # Previous versions had false.
17
+ ActiveSupport.to_time_preserves_timezone = true
18
+
19
+ # Require `belongs_to` associations by default. Previous versions had false.
20
+ Rails.application.config.active_record.belongs_to_required_by_default = true
21
+
22
+ # Do not halt callback chains when a callback returns false. Previous versions had true.
23
+ ActiveSupport.halt_callback_chains_on_return_false = false
24
+
25
+ # Configure SSL options to enable HSTS with subdomains. Previous versions had false.
26
+ Rails.application.config.ssl_options = { hsts: { subdomains: true } }
@@ -0,0 +1,3 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Rails.application.config.session_store :cookie_store, key: '_e4commerce_session'
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json]
9
+ end
10
+
11
+ # To enable root element in JSON for ActiveRecord objects.
12
+ # ActiveSupport.on_load(:active_record) do
13
+ # self.include_root_in_json = true
14
+ # end
@@ -0,0 +1,23 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en:
23
+ hello: "Hello world"
@@ -0,0 +1,47 @@
1
+ # Puma can serve each request in a thread from an internal thread pool.
2
+ # The `threads` method setting takes two numbers a minimum and maximum.
3
+ # Any libraries that use thread pools should be configured to match
4
+ # the maximum value specified for Puma. Default is set to 5 threads for minimum
5
+ # and maximum, this matches the default thread size of Active Record.
6
+ #
7
+ threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
8
+ threads threads_count, threads_count
9
+
10
+ # Specifies the `port` that Puma will listen on to receive requests, default is 3000.
11
+ #
12
+ port ENV.fetch("PORT") { 3000 }
13
+
14
+ # Specifies the `environment` that Puma will run in.
15
+ #
16
+ environment ENV.fetch("RAILS_ENV") { "development" }
17
+
18
+ # Specifies the number of `workers` to boot in clustered mode.
19
+ # Workers are forked webserver processes. If using threads and workers together
20
+ # the concurrency of the application would be max `threads` * `workers`.
21
+ # Workers do not work on JRuby or Windows (both of which do not support
22
+ # processes).
23
+ #
24
+ # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
25
+
26
+ # Use the `preload_app!` method when specifying a `workers` number.
27
+ # This directive tells Puma to first boot the application and load code
28
+ # before forking the application. This takes advantage of Copy On Write
29
+ # process behavior so workers use less memory. If you use this option
30
+ # you need to make sure to reconnect any threads in the `on_worker_boot`
31
+ # block.
32
+ #
33
+ # preload_app!
34
+
35
+ # The code in the `on_worker_boot` will be called if you are using
36
+ # clustered mode by specifying a number of `workers`. After each worker
37
+ # process is booted this block will be run, if you are using `preload_app!`
38
+ # option you will want to use this block to reconnect to any threads
39
+ # or connections that may have been created at application boot, Ruby
40
+ # cannot share connections between processes.
41
+ #
42
+ # on_worker_boot do
43
+ # ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
44
+ # end
45
+
46
+ # Allow puma to be restarted by `rails restart` command.
47
+ plugin :tmp_restart
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
3
+ end
@@ -0,0 +1,22 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rails secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ development:
14
+ secret_key_base: 3765d38a12926da31ced1dcdcf26eae958c865c191dc04940ed65aa5ad3aa463d972e08d87c18862d3c32926d9609cb9d9dbf4aacd8bf4528260f3f3b69fa57f
15
+
16
+ test:
17
+ secret_key_base: bf5d782a342d899e321779c340b4aeb658f7982e0cbc5177168b9ce8545eb28f2d3dcff6311df778c50062f8f67ccae229a4274a6ebfd9a214c592c28b2de6e7
18
+
19
+ # Do not keep production secrets in the repository,
20
+ # instead read values from the environment.
21
+ production:
22
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@@ -0,0 +1,6 @@
1
+ %w(
2
+ .ruby-version
3
+ .rbenv-vars
4
+ tmp/restart.txt
5
+ tmp/caching-dev.txt
6
+ ).each { |path| Spring.watch(path) }
@@ -0,0 +1,5 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative 'config/environment'
4
+
5
+ run Rails.application
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
7
+ # Character.create(name: 'Luke', movie: movies.first)
File without changes
File without changes
File without changes
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-agent: *
5
+ # Disallow: /
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,10 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
7
+ fixtures :all
8
+
9
+ # Add more helper methods to be used by all tests here...
10
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,15 @@
1
+ class NotificationsController < ApplicationController
2
+ skip_before_filter :verify_authenticity_token, only: :create
3
+
4
+ def create
5
+ transaction = PagSeguro::Transaction.find_by_notification_code(params[:notificationCode])
6
+
7
+ if transaction.errors.empty?
8
+ # Processa a notificação. A melhor maneira de se fazer isso é realizar
9
+ # o processamento em background. Uma boa alternativa para isso é a
10
+ # biblioteca Sidekiq.
11
+ end
12
+
13
+ render nothing: true, status: 200
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ require "abstraction"
2
+ require "active_record"
3
+
4
+ #class E4CPayment < ActiveRecord::Base ~> Rails project, need database
5
+ class E4CPayment
6
+ abstract
7
+
8
+ attr_accessor :product_list
9
+ attr_accessor :total
10
+
11
+ def calculate_total(products)
12
+ raise NotImplementedError, "Child must implement method"
13
+ end
14
+
15
+ def create_payment
16
+ raise NotImplementedError, "Child must implement method"
17
+ end
18
+
19
+ def add_product(product)
20
+ raise NotImplementedError, "Child must implement method"
21
+ end
22
+
23
+ end
@@ -0,0 +1,20 @@
1
+ require "abstraction"
2
+ require "active_record"
3
+
4
+ # class E4CProduct < ActiveRecord::Base -> Rails project, need database
5
+ class E4CProduct
6
+ abstract
7
+
8
+ attr_accessor :title
9
+ attr_accessor :serial_number
10
+ attr_accessor :brand
11
+ attr_accessor :unit_price
12
+
13
+ def initialize(title, serial_number, brand, unit_price)
14
+ @title = title
15
+ @serial_number = serial_number
16
+ @brand = brand
17
+ @unit_price = unit_price
18
+ end
19
+
20
+ end
@@ -0,0 +1,48 @@
1
+ class CheckoutController < ApplicationController
2
+ def create
3
+ # O modo como você irá armazenar os produtos que estão sendo comprados
4
+ # depende de você. Neste caso, temos um modelo Order que referência os
5
+ # produtos que estão sendo comprados.
6
+ order = Order.find(params[:id])
7
+
8
+ payment = PagSeguro::PaymentRequest.new
9
+
10
+ # Você também pode fazer o request de pagamento usando credenciais
11
+ # diferentes, como no exemplo abaixo
12
+
13
+ payment = PagSeguro::PaymentRequest.new(email: 'abc@email', token: 'token')
14
+
15
+ payment.reference = order.id
16
+ payment.notification_url = notifications_url
17
+ payment.redirect_url = processing_url
18
+
19
+ order.products.each do |product|
20
+ payment.items << {
21
+ id: product.id,
22
+ description: product.title,
23
+ amount: product.price,
24
+ weight: product.weight
25
+ }
26
+ end
27
+
28
+ # Caso você precise passar parâmetros para a api que ainda não foram
29
+ # mapeados na gem, você pode fazer de maneira dinâmica utilizando um
30
+ # simples hash.
31
+ payment.extra_params << { paramName: 'paramValue' }
32
+ payment.extra_params << { senderBirthDate: '07/05/1981' }
33
+ payment.extra_params << { extraAmount: '-15.00' }
34
+
35
+ response = payment.register
36
+
37
+ # Caso o processo de checkout tenha dado errado, lança uma exceção.
38
+ # Assim, um serviço de rastreamento de exceções ou até mesmo a gem
39
+ # exception_notification poderá notificar sobre o ocorrido.
40
+ #
41
+ # Se estiver tudo certo, redireciona o comprador para o PagSeguro.
42
+ if response.errors.any?
43
+ raise response.errors.join("\n")
44
+ else
45
+ redirect_to response.url
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module E4commerce
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,48 @@
1
+ class CheckoutController < ApplicationController
2
+ def create
3
+ # O modo como você irá armazenar os produtos que estão sendo comprados
4
+ # depende de você. Neste caso, temos um modelo Order que referência os
5
+ # produtos que estão sendo comprados.
6
+ order = Order.find(params[:id])
7
+
8
+ payment = PagSeguro::PaymentRequest.new
9
+
10
+ # Você também pode fazer o request de pagamento usando credenciais
11
+ # diferentes, como no exemplo abaixo
12
+
13
+ payment = PagSeguro::PaymentRequest.new(email: 'abc@email', token: 'token')
14
+
15
+ payment.reference = order.id
16
+ payment.notification_url = notifications_url
17
+ payment.redirect_url = processing_url
18
+
19
+ order.products.each do |product|
20
+ payment.items << {
21
+ id: product.id,
22
+ description: product.title,
23
+ amount: product.price,
24
+ weight: product.weight
25
+ }
26
+ end
27
+
28
+ # Caso você precise passar parâmetros para a api que ainda não foram
29
+ # mapeados na gem, você pode fazer de maneira dinâmica utilizando um
30
+ # simples hash.
31
+ payment.extra_params << { paramName: 'paramValue' }
32
+ payment.extra_params << { senderBirthDate: '07/05/1981' }
33
+ payment.extra_params << { extraAmount: '-15.00' }
34
+
35
+ response = payment.register
36
+
37
+ # Caso o processo de checkout tenha dado errado, lança uma exceção.
38
+ # Assim, um serviço de rastreamento de exceções ou até mesmo a gem
39
+ # exception_notification poderá notificar sobre o ocorrido.
40
+ #
41
+ # Se estiver tudo certo, redireciona o comprador para o PagSeguro.
42
+ if response.errors.any?
43
+ raise response.errors.join("\n")
44
+ else
45
+ redirect_to response.url
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,15 @@
1
+ class NotificationsController < ApplicationController
2
+ skip_before_filter :verify_authenticity_token, only: :create
3
+
4
+ def create
5
+ transaction = PagSeguro::Transaction.find_by_notification_code(params[:notificationCode])
6
+
7
+ if transaction.errors.empty?
8
+ # Processa a notificação. A melhor maneira de se fazer isso é realizar
9
+ # o processamento em background. Uma boa alternativa para isso é a
10
+ # biblioteca Sidekiq.
11
+ end
12
+
13
+ render nothing: true, status: 200
14
+ end
15
+ end