spree_ifmb 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -4,6 +4,23 @@ SpreeIfmb
4
4
  Spree extension to add IfMB payment gateway
5
5
 
6
6
 
7
+ Install
8
+ =======
9
+
10
+ add in your Gemfile
11
+
12
+
13
+ gem 'spree_ifmb'
14
+
15
+ The run the install command. This will place necessary migrations in your app. Then you have to do rake db:migrate.
16
+
17
+ bundle exec rails g spree_ifmb:install
18
+
19
+ rake db:migrate
20
+
21
+ So now what you have to do is create a payment method, choose `PaymentMethod::Ifmband` as the provider, save and then set the configurations: Entity, Sub entity and chave. Chave is just needed if you want to have real-time updates on payment status. If you do you have to send the url for your app wich will be something like `http://example.com/ifmb?chave=your_chave`, you have to send the request to the IFthen company.
22
+
23
+
7
24
  Example
8
25
  =======
9
26
 
@@ -13,8 +13,11 @@ class IfmbCallbackController < Spree::BaseController
13
13
  payment_date = params[:data]
14
14
  terminal = params[:terminal]
15
15
 
16
+ # TODO: save payment details?
16
17
 
17
- payment = Spree::Payment.where(ifmb_reference: reference).first
18
+
19
+ # payment = Spree::Payment.where(ifmb_reference: reference).first
20
+ payment = IfmbReference.where(reference: reference).first.payment
18
21
 
19
22
  if !payment || payment.payment_method.preferences[:chave] != chave
20
23
  render nothing: true, status: 500
@@ -0,0 +1,3 @@
1
+ class IfmbReference < ActiveRecord::Base
2
+ belongs_to :payment, class_name: 'Spree::Payment'
3
+ end
@@ -1,3 +1,4 @@
1
+ require 'ifmb'
1
2
  class PaymentMethod::Ifmb < Spree::PaymentMethod
2
3
 
3
4
  attr_accessible :preferred_entity, :preferred_sub_entity, :preferred_chave
@@ -51,37 +52,16 @@ class PaymentMethod::Ifmb < Spree::PaymentMethod
51
52
  generator = Ifmb::Generator.new opts
52
53
  reference = generator.generate
53
54
 
54
- if 0 == Spree::Payment.where(ifmb_reference: reference).count
55
+ if 0 == IfmbReference.where(reference: reference).count
55
56
  unique = true
56
57
  else
57
58
  order_id += 1
58
59
  end
59
60
  end
60
- reference
61
- end
62
-
63
- def generate_ref payment
64
- configuration = payment.payment_method.preferences
65
- order = payment.order
66
- order_id = order.id
67
- unique = nil
68
- while !unique
69
- opts = {
70
- entidade: configuration[:entity],
71
- sub_entidade: configuration[:sub_entity],
72
- order_id: order_id,
73
- order_value: order.total
74
- }
75
- generator = Ifmb::Generator.new opts
76
- reference = generator.generate
77
-
78
- if 0 == Spree::Payment.where(ifmb_reference: reference).count
79
- unique = true
80
- else
81
- order_id += 1
82
- end
83
- end
84
- payment.update_attribute :ifmb_reference, reference
61
+ # payment.update_attribute :ifmb_reference, reference
62
+ ifmb_reference = IfmbReference.find_or_initialize_by_payment_id payment.id
63
+ ifmb_reference.reference = reference
64
+ ifmb_reference.save
85
65
  reference
86
66
  end
87
67
 
@@ -90,11 +70,14 @@ class PaymentMethod::Ifmb < Spree::PaymentMethod
90
70
  configs = payment.payment_method.preferences
91
71
  ref.entidade = configs[:entity]
92
72
  ref.order_value = payment.amount
93
- if payment.ifmb_reference.present?
94
- ref.referencia = payment.ifmb_reference
73
+ reference = IfmbReference.where(payment_id: payment.id).first.try(:reference)
74
+
75
+ ref.referencia= if reference
76
+ reference
95
77
  else
96
- ref.referencia = generate_ref(payment)
78
+ generate_ref(payment)
97
79
  end
80
+
98
81
  if size == :small
99
82
  Ifmb::HtmlFormatter.new(ref).small_html
100
83
  else
@@ -3,8 +3,8 @@
3
3
  </h3>
4
4
 
5
5
  <% # TODO: Place this in a proper place %>
6
- <% if @payment.ifmb_reference.blank? %>
7
- <% @payment.payment_method.generate_ref @payment %>
8
- <% end %>
6
+ <%# if @payment.ifmb_reference.blank? %>
7
+ <%# @payment.payment_method.generate_ref @payment %>
8
+ <%# end %>
9
9
  <% # ----------------------------- %>
10
10
  <%= raw @payment.payment_method.html_reference @payment, :big %>
@@ -0,0 +1,13 @@
1
+ class AddIfmbReferenceTable < ActiveRecord::Migration
2
+ def up
3
+ create_table :ifmb_references do |t|
4
+ t.string :reference
5
+ t.integer :payment_id
6
+ end
7
+ add_index :ifmb_references, :reference
8
+ end
9
+
10
+ def down
11
+ drop_table :ifmb_references
12
+ end
13
+ end
@@ -16,13 +16,10 @@ module SpreeIfmb
16
16
  Rails.configuration.cache_classes ? require(c) : load(c)
17
17
  end
18
18
 
19
- # Dir.glob(File.join(File.dirname(__FILE__), "../../app/overrides/*.rb")) do |c|
20
- # Rails.application.config.cache_classes ? require(c) : load(c)
21
- # end
22
19
 
23
20
  Rails.application.config.spree.payment_methods.push(PaymentMethod::Ifmb)
24
21
  end
25
22
 
26
23
  config.to_prepare &method(:activate).to_proc
27
24
  end
28
- end
25
+ end
data/spree_ifmb.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.platform = Gem::Platform::RUBY
3
3
  s.name = 'spree_ifmb'
4
- s.version = '0.0.1'
4
+ s.version = '0.0.2'
5
5
  s.summary = 'IFMB payments for spree'
6
6
  # s.description = 'TODO: Add (optional) gem description here'
7
7
  s.required_ruby_version = '>= 1.9.2'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_ifmb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-23 00:00:00.000000000 Z
12
+ date: 2012-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spree_core
@@ -159,7 +159,7 @@ files:
159
159
  - app/controllers/ifmb_callback_controller.rb
160
160
  - app/controllers/ifmb_controller.rb
161
161
  - app/controllers/spree/checkout_controller_decorator.rb
162
- - app/models/order_decorator.rb
162
+ - app/models/ifmb_reference.rb
163
163
  - app/models/payment_method/ifmb.rb
164
164
  - app/overrides/ifmb_admin_override.rb
165
165
  - app/overrides/spree/shared/_order_details/add_ifmb_details.html.erb.deface
@@ -169,7 +169,7 @@ files:
169
169
  - app/views/spree/checkout/payment/_ifmb.html.erb
170
170
  - config/locales/en.yml
171
171
  - config/routes.rb
172
- - db/migrate/20121122152848_add_ifmb_reference_to_payments.rb
172
+ - db/migrate/20121122152848_add_ifmb_reference_table.rb
173
173
  - lib/generators/spree_ifmb/install/install_generator.rb
174
174
  - lib/spree_ifmb.rb
175
175
  - lib/spree_ifmb/engine.rb
@@ -194,6 +194,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  - - ! '>='
195
195
  - !ruby/object:Gem::Version
196
196
  version: '0'
197
+ segments:
198
+ - 0
199
+ hash: -3159424096221970679
197
200
  requirements:
198
201
  - none
199
202
  rubyforge_project:
@@ -203,4 +206,3 @@ specification_version: 3
203
206
  summary: IFMB payments for spree
204
207
  test_files:
205
208
  - spec/spec_helper.rb
206
- has_rdoc:
@@ -1,42 +0,0 @@
1
- Spree::Order.class_eval do
2
-
3
- # def ifmb_reference payment_method_id
4
- # ifmb_generator(payment_method_id).generate
5
- # end
6
-
7
- # def ifmb_html payment_method_id
8
- # ifmb_generator(payment_method_id).in_html
9
- # end
10
-
11
- # private
12
-
13
- # def ifmb_generator payment_method_id
14
- # @generator ||= Hash.new
15
- # return @generator[payment_method_id] if @generator[payment_method_id]
16
-
17
- # payment_method = PaymentMethod::Ifmb.find(payment_method_id)
18
- # configuration = payment_method.preferences
19
-
20
- # order_id = self.id
21
- # unique = nil
22
- # while !unique
23
- # opts = {
24
- # entidade: configuration[:entity],
25
- # sub_entidade: configuration[:sub_entity],
26
- # order_id: order_id,
27
- # order_value: self.total
28
- # }
29
- # @generator[payment_method_id] = Ifmb::Generator.new opts
30
- # reference = @generator[payment_method_id].generate
31
-
32
- # if 0 == Spree::Payment.where(ifmb_reference: reference).count
33
- # unique = true
34
- # else
35
- # order_id += 1
36
- # end
37
- # end
38
-
39
- # @generator[payment_method_id]
40
- # end
41
-
42
- end
@@ -1,10 +0,0 @@
1
- class AddIfmbReferenceToPayments < ActiveRecord::Migration
2
- def up
3
- add_column :spree_payments, :ifmb_reference, :string
4
- add_index :spree_payments, :ifmb_reference
5
- end
6
-
7
- def down
8
- remove_column :spree_payments, :ifmb_reference, :string
9
- end
10
- end