e4commerce 0.6.1 → 0.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32bbfad0c1b247da62e15952ff121bf6d226850f
4
- data.tar.gz: 48f139894aa93fa7d93f7a25e5372913d7477b20
3
+ metadata.gz: 1d481d0d482c49be0ae8cb4317d1d330d9327751
4
+ data.tar.gz: 2aece2d4aaa951367884c83f6b65b152ac28fd17
5
5
  SHA512:
6
- metadata.gz: 13275a3fd3163bd1d54c9a6a833a7457c4b26b44b64f507afa2318b0096650f1472af1d6adaad28ea23507a92b507d99827573c819f66d6f6a7ca37d8311d9c7
7
- data.tar.gz: f71127fbbcea878837adae1dbf6ec8187ffcd157052c0ddbecb2b97cfa33b6ce70aded5b384650a2d74f93c8be2e6791e2285b9b6c7d89efa1034d8a72182c05
6
+ metadata.gz: 1ea3acd7e101b2b47d37e8a526926cfe8358b93dcc19ba72dbeb4ef51d9021a9b2e245f337b2c95070df1c5a480c15543e8366e2ae72f909b4cb65ccddd338a0
7
+ data.tar.gz: 036e48b291f8837050227cc61d8572353c68f0782e53dfa3a7d57cbe7fada5367eeefc2732d80c23c7619815084a9ca675b89d1581c5816c7b3350ee6531d5b4
@@ -0,0 +1,17 @@
1
+ sudo: true
2
+ language: ruby
3
+
4
+ branches:
5
+ only:
6
+ - master
7
+ - devel
8
+ - travis
9
+
10
+ rvm:
11
+ - "2.3.1"
12
+
13
+ before_script:
14
+ - gem install bundler
15
+ - gem install rspec simplecov
16
+ - bundle install
17
+
data/Gemfile CHANGED
@@ -8,5 +8,6 @@ gem 'dalli'
8
8
  gem "pagseguro-oficial"
9
9
  gem 'abstraction'
10
10
  gem "activerecord"
11
+ gem 'rspec', '~> 3.6'
12
+ gem 'simplecov', :require => false
11
13
 
12
- #gem "brcobranca", :github => "kivanio/brcobranca"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- e4commerce (0.6.1)
4
+ e4commerce (0.7.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -27,6 +27,8 @@ GEM
27
27
  her (~> 0.8.1)
28
28
  concurrent-ruby (1.0.5)
29
29
  dalli (2.7.6)
30
+ diff-lcs (1.3)
31
+ docile (1.1.5)
30
32
  faraday (0.12.1)
31
33
  multipart-post (>= 1.2, < 3)
32
34
  faraday-http-cache (1.3.1)
@@ -52,6 +54,24 @@ GEM
52
54
  json (~> 1.8)
53
55
  nokogiri (~> 1.6)
54
56
  rake (10.5.0)
57
+ rspec (3.6.0)
58
+ rspec-core (~> 3.6.0)
59
+ rspec-expectations (~> 3.6.0)
60
+ rspec-mocks (~> 3.6.0)
61
+ rspec-core (3.6.0)
62
+ rspec-support (~> 3.6.0)
63
+ rspec-expectations (3.6.0)
64
+ diff-lcs (>= 1.2.0, < 2.0)
65
+ rspec-support (~> 3.6.0)
66
+ rspec-mocks (3.6.0)
67
+ diff-lcs (>= 1.2.0, < 2.0)
68
+ rspec-support (~> 3.6.0)
69
+ rspec-support (3.6.0)
70
+ simplecov (0.14.1)
71
+ docile (~> 1.1.0)
72
+ json (>= 1.8, < 3)
73
+ simplecov-html (~> 0.10.0)
74
+ simplecov-html (0.10.1)
55
75
  thread_safe (0.3.6)
56
76
  tzinfo (1.2.3)
57
77
  thread_safe (~> 0.1)
@@ -68,6 +88,8 @@ DEPENDENCIES
68
88
  e4commerce!
69
89
  pagseguro-oficial
70
90
  rake (~> 10.0)
91
+ rspec (~> 3.6)
92
+ simplecov
71
93
 
72
94
  BUNDLED WITH
73
95
  1.15.1
data/README.md CHANGED
@@ -1,3 +1,8 @@
1
+
2
+ <p align="left">
3
+ <img src="https://travis-ci.org/miguelpimentel/e4commerce.svg?branch=devel"></a>
4
+ </p>
5
+
1
6
  # E4commerce
2
7
 
3
8
  O e4commerce tem como objetivo fornecer uma ferramenta que facilite no desenvolvimento de um commerce. Voltada ao público brasileiro procurar fornecer formas de pagamento de acordo com as normas nacionais.
data/Rakefile CHANGED
@@ -2,10 +2,10 @@
2
2
  Dir.glob('lib/tasks/*.rake').each { |r| load r}
3
3
 
4
4
  require "bundler/gem_tasks"
5
-
5
+ require 'rspec/core/rake_task'
6
6
  task :default => :spec
7
7
 
8
-
8
+ RSpec::Core::RakeTask.new
9
9
 
10
10
 
11
11
 
@@ -0,0 +1,6 @@
1
+ class Product < ApplicationRecord
2
+ validates :title
3
+ validates :description
4
+ validates :price
5
+ validates :weight
6
+ end
@@ -1,7 +1,9 @@
1
1
  require "e4commerce/version"
2
2
  require "e4commerce/payment"
3
3
  require "e4commerce/product"
4
+ require "e4commerce/e4commerce_pagseguro"
4
5
 
5
6
  module E4commerce
6
7
 
7
- end
8
+
9
+ end
@@ -0,0 +1,61 @@
1
+ module E4commerce
2
+
3
+ require "pagseguro"
4
+
5
+ class PagSeguroPayment
6
+
7
+ # Email and token for different profiles to authenticate paymeny
8
+ # e4c_payment, class must inheritate from E4commerce::E4CPayment
9
+ def self.create_payment(e4c_payment, email, token)
10
+
11
+ payment = PagSeguro::PaymentRequest.new
12
+
13
+ payment = PagSeguro::PaymentRequest.new(email: email, token: token)
14
+
15
+ payment.reference = order.id
16
+ payment.notification_url = notifications_url
17
+ payment.redirect_url = processing_url
18
+
19
+ e4c_payment.product_list.each do |product|
20
+ payment.items << {
21
+ description: product.title,
22
+ id: product.serial_number,
23
+ amount: product.unit_price
24
+ }
25
+ end
26
+
27
+ calculate_total(self.product_list)
28
+
29
+ response = payment.register
30
+
31
+ if response.errors.any?
32
+ raise response.errors.join("\n")
33
+ else
34
+ redirect_to response.url
35
+ end
36
+ end
37
+
38
+ def calculate_total(products)
39
+ total = 0
40
+ self.product_list.each do |product|
41
+ total += product.unit_price
42
+ end
43
+
44
+ total
45
+ end
46
+
47
+ def self.create_notification(notification_code_param)
48
+ transaction = PagSeguro::Transaction.find_by_notification_code(params[:notification_code_param])
49
+
50
+ if transaction.errors.empty?
51
+ # Processa a notificação. A melhor maneira de se fazer isso é realizar
52
+ # o processamento em background. Uma boa alternativa para isso é a
53
+ # biblioteca Sidekiq.
54
+ end
55
+
56
+ render nothing: true, status: 200
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -9,7 +9,7 @@ require "active_record"
9
9
  attr_accessor :product_list
10
10
  attr_accessor :total
11
11
 
12
- def calculate_total
12
+ def calculate_total(products)
13
13
  raise NotImplementedError, "Child must implement method"
14
14
  end
15
15
 
@@ -19,6 +19,14 @@ module E4commerce
19
19
  @unit_price = unit_price
20
20
  end
21
21
 
22
+ def search
23
+ raise 'Abstract method'
24
+ end
25
+
26
+ def sale
27
+ raise 'Abstract method'
28
+ end
29
+
22
30
  end
23
31
 
24
32
  end
@@ -1,3 +1,3 @@
1
1
  module E4commerce
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -0,0 +1,51 @@
1
+ class CheckoutController < E4CPayment
2
+
3
+ def abandoned_transactions
4
+ report = PagSeguro::Transaction.find_abandoned
5
+
6
+ while report.next_page?
7
+ report.next_page!
8
+ puts "=> Page #{report.page}"
9
+
10
+ abort "=> Errors: #{report.errors.join("\n")}" unless report.valid?
11
+
12
+ puts "=> Report was created at: #{report.created_at}"
13
+ puts
14
+
15
+ report.transactions.each do |transaction|
16
+ puts "=> Abandoned transaction"
17
+ puts " created at: #{transaction.created_at}"
18
+ puts " code: #{transaction.code}"
19
+ puts " type_id: #{transaction.type_id}"
20
+ puts " gross amount: #{transaction.gross_amount}"
21
+ puts
22
+ end
23
+ end
24
+ end
25
+
26
+ def transaction_history
27
+
28
+ report = PagSeguro::Transaction.find_by_date
29
+
30
+ while report.next_page?
31
+ report.next_page!
32
+ puts "== Page #{report.page}"
33
+ abort "=> Errors: #{report.errors.join("\n")}" unless report.valid?
34
+ puts "Report created on #{report.created_at}"
35
+ puts
36
+
37
+ report.transactions.each do |transaction|
38
+ puts "=> Transaction"
39
+ puts " created_at: #{transaction.created_at}"
40
+ puts " code: #{transaction.code}"
41
+ puts " cancellation_source: #{transaction.cancellation_source}"
42
+ puts " payment method: #{transaction.payment_method.type}"
43
+ puts " gross amount: #{transaction.gross_amount}"
44
+ puts " updated at: #{transaction.updated_at}"
45
+ puts
46
+ end
47
+ end
48
+ end
49
+
50
+
51
+ end
@@ -0,0 +1,31 @@
1
+
2
+ BREAK_LINE = "\n"
3
+
4
+
5
+ namespace :cart do
6
+ task :generate_model do
7
+ touch 'lib/e4commerce/cart.rb'
8
+
9
+ file_path = 'lib/e4commerce/cart.rb'
10
+
11
+ content = "class Cart < ActiveRecord::Base" + BREAK_LINE
12
+
13
+ content += " has_many :products" + BREAK_LINE + "end" + BREAK_LINE
14
+
15
+ write_content(file_path, content)
16
+ end
17
+ end
18
+
19
+ task :CartInitialize do
20
+
21
+ ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: 'database.db'
22
+
23
+ ActiveRecord::Schema.define do
24
+ unless ActiveRecord::Base.connection.tables.include? 'tags'
25
+ create_table :cart do |table|
26
+ table.column :total_price, :float
27
+ table.column :number_items, :integer
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+
2
+ BREAK_LINE = "\n"
3
+
4
+ def self.generate
5
+
6
+ end
7
+
8
+ namespace :order do
9
+ task :generate_model do
10
+ touch 'lib/e4commerce/Order.rb'
11
+
12
+ file_path = 'lib/e4commerce/Order.rb'
13
+
14
+
15
+ content = "class Order < ActiveRecord::Base" + BREAK_LINE
16
+
17
+ content += " has_many :products" + BREAK_LINE + "end" + BREAK_LINE
18
+
19
+ write_content(file_path, content)
20
+ end
21
+ end
22
+
23
+ task :OrderInitialize do
24
+
25
+ ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: 'database.db'
26
+
27
+ ActiveRecord::Schema.define do
28
+ unless ActiveRecord::Base.connection.tables.include? 'tags'
29
+ create_table :order do |table|
30
+ table.column :total_price, :float
31
+ table.column :number_items, :integer
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,6 +1,6 @@
1
1
  module Product
2
2
 
3
- require "active_record"
3
+ #require "active_record"
4
4
 
5
5
  def self.generate
6
6
 
@@ -17,21 +17,20 @@ namespace :product do
17
17
  content = ""
18
18
  tab = " "
19
19
 
20
-
21
20
  desc "Generate a model that heritances from product"
22
- #usage example: rake product:generate_model[Nike,Produto,numero,cor]
21
+ #usage example: rake product:generate_model[Shoes,E4CProduct,color,size,imported_from]
23
22
  task :generate_model do |task, args|
24
23
 
25
24
  file = "lib/e4commerce/#{args.extras[0]}.rb"
26
25
 
27
26
  #Check if first letter of first argument is uppercased
28
27
  if args.extras[0][0].upcase! || args.extras[1][0].upcase! then
29
- abort("First letter of a class must be in uppercase\nUsage: rake product:generate_model[<Model>,<Heritance>,<arg2>,<arg ...>]")
28
+ abort("First letter of a class must be in uppercase\nUsage: rake product:generate_model[<Model>,<Heritance>,<arg2:type>,<arg3:type ...>]")
30
29
  end
31
30
 
32
31
  content = "class #{args.extras[0]} < #{args.extras[1]}" + new_line
33
32
 
34
- #Include validations to each element but first
33
+ #Include validations to each element but first and second argument
35
34
  args.extras.drop(2).each do |params|
36
35
  content += tab + "validates :#{params}, presence: true" + new_line
37
36
  end
@@ -42,10 +41,12 @@ namespace :product do
42
41
 
43
42
  write_content(file,content)
44
43
 
44
+ puts "CREATED " + file + new_line
45
+
45
46
  end
46
47
 
47
48
  def write_content(file,content)
48
- #Writes the file
49
+ #Writes the file for model
49
50
  File.open(file, "w+") { |file| file.write(content) }
50
51
  end
51
52
  desc "All taks related to products"
@@ -68,8 +69,11 @@ task :E4Cinitialize do
68
69
  table.column :serial_number, :string
69
70
  table.column :unit_price, :float
70
71
  table.column :unit_price, :float
72
+ args.extras.drop(2).each do |params|
73
+ str_tmp = "#{params}".split(":")
74
+ table.column (":" + str_tmp[0]).to_sym , (":" + str_tmp[1]).to_sym
75
+ end
71
76
  end
72
77
  end
73
78
  end
74
-
75
79
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: e4commerce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Pimentel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-23 00:00:00.000000000 Z
11
+ date: 2017-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,6 +88,7 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
+ - ".travis.yml"
91
92
  - Gemfile
92
93
  - Gemfile.lock
93
94
  - LICENSE.md
@@ -98,11 +99,13 @@ files:
98
99
  - bin/setup
99
100
  - database.db
100
101
  - e4commerce.gemspec
102
+ - e4commerce/app/models/product.rb
101
103
  - lib/e4commerce.rb
102
104
  - lib/e4commerce/banco_brasil_billet.rb
103
105
  - lib/e4commerce/bank_billet.rb
104
106
  - lib/e4commerce/bradesco_billet.rb
105
107
  - lib/e4commerce/client.rb
108
+ - lib/e4commerce/e4commerce_pagseguro.rb
106
109
  - lib/e4commerce/itau_billet.rb
107
110
  - lib/e4commerce/notifications_controller.rb
108
111
  - lib/e4commerce/payment.rb
@@ -110,7 +113,10 @@ files:
110
113
  - lib/e4commerce/ps_checkout_template.rb
111
114
  - lib/e4commerce/santander_billet.rb
112
115
  - lib/e4commerce/version.rb
116
+ - lib/pagseguro/consults_controller.rb
113
117
  - lib/tasks/boleto.rake
118
+ - lib/tasks/cart.rake
119
+ - lib/tasks/order.rake
114
120
  - lib/tasks/pagseguro.rake
115
121
  - lib/tasks/product.rake
116
122
  homepage: https://github.com/miguelpimentel/e4commerce