spree_aprova_facil 0.0.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/.DS_Store CHANGED
Binary file
@@ -0,0 +1,18 @@
1
+ class Gateway::CobreBemAprovaFacil < Gateway
2
+ preference :login, :string
3
+
4
+ def provider_class
5
+ ActiveMerchant::Billing::AprovaFacilGateway
6
+ end
7
+
8
+ def options
9
+ # add :test key in the options hash, as that is what the ActiveMerchant::Billing::AuthorizeNetGateway expects
10
+ if self.prefers? :test_mode
11
+ self.class.default_preferences[:test] = true
12
+ else
13
+ self.class.default_preferences.delete(:test)
14
+ end
15
+
16
+ super
17
+ end
18
+ end
@@ -1,143 +1,151 @@
1
+ #encoding: utf-8
2
+ begin
3
+ require "aprova_facil"
4
+ rescue LoadError
5
+ raise "Could not load the aprova_facil gem. Use `gem install aprova_facil` to install it."
6
+ end
1
7
  module ActiveMerchant #:nodoc:
2
8
  module Billing #:nodoc:
3
9
  class AprovaFacilGateway < Gateway
4
-
10
+
11
+ # The countries the gateway supports merchants from as 2 digit ISO country codes
5
12
  self.supported_countries = ['BR']
6
- self.supported_cardtypes = [:visa, :master, :american_express, :dinners_club]
7
-
13
+
14
+ # The card types supported by the payment gateway
15
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
16
+
17
+ # The homepage URL of the gateway
18
+ self.homepage_url = 'http://www.cobrebem.com/'
19
+
20
+ # The name of the gateway
21
+ self.display_name = 'Aprova Fácil'
22
+
8
23
  def initialize(options = {})
24
+ requires!(options, :login)
9
25
  @options = options
10
- end
11
-
12
- def authorize(money, creditcard, options = {})
13
- card = add_creditcard(creditcard,options)
14
-
15
- approval_response = gateway.aprovar(card)
26
+ super
16
27
 
17
- if success?(approval_response)
18
- Response.new(
19
- approval_response[:aprovada],
20
- approval_response[:resultado],
21
- { :transaction_id => approval_response[:transacao] },
22
- :authorization => approval_response[:codigo_autorizacao]
23
- )
24
- else
25
- Response.new(
26
- approval_response[:aprovada],
27
- approval_response[:resultado],
28
- { :transaction_id => approval_response[:transacao] },
29
- :authorization => approval_response[:codigo_autorizacao]
30
- )
28
+ AprovaFacil::Config.usuario = @options[:login]
29
+
30
+ if @options[:test]
31
+ AprovaFacil::Config.teste = true
31
32
  end
33
+ end
34
+
35
+ def authorize(money, creditcard, options = {})
36
+ post = {}
37
+ add_invoice(post, options)
38
+ add_creditcard(post, creditcard)
39
+ add_customer_data(post, options)
40
+
41
+ commit('authonly', money, post)
32
42
  end
33
-
43
+
44
+ def purchase(money, creditcard, options = {})
45
+ post = {}
46
+ add_invoice(post, options)
47
+ add_creditcard(post, creditcard)
48
+ add_customer_data(post, options)
49
+
50
+ commit('sale', money, post)
51
+ end
52
+
34
53
  def capture(money, authorization, options = {})
35
- binding.pry
36
- capture_response = gateway.capturar(authorization)
37
- if success?(capture_response)
38
- #response_to_spree(approval_response,capture_response)
39
- else
40
- Response.new false, approval_response[:resultado]
41
- end
42
-
54
+ post = {:transaction => authorization}
55
+ commit('capture', money, post)
43
56
  end
44
57
 
45
- def purchase(money, creditcard, options = {})
46
- approves_transaction(creditcard, options)
58
+ def void(authorization, options = {})
59
+ post = {:transaction => authorization}
60
+ commit('void', nil, post)
47
61
  end
62
+
63
+ private
64
+
65
+ def add_customer_data(post, options)
66
+ if options.has_key? :email
67
+ post[:email] = options[:email]
68
+ post[:email_customer] = false
69
+ end
48
70
 
49
- # testar ainda
50
- def credit(money, creditcard, options = {})
51
- credit_response = gateway.cancelar(creditcard.transacao_anterior)
52
- if credited?(credit_response)
53
- response_to_spree_to_credit(credit_response)
54
- else
55
- response_to_spree_to_credit(credit_response)
71
+ if options.has_key? :ip
72
+ post[:ip_comprador] = options[:ip]
56
73
  end
57
74
  end
58
75
 
59
- #def create_profile(creditcard, gateway_options)
60
- # if creditcard.gateway_customer_profile_id.nil?
61
- # profile_hash = create_customer_profile(creditcard, gateway_options)
62
- # creditcard.update_attributes(:gateway_customer_profile_id => profile_hash[:customer_profile_id], :gateway_payment_profile_id => profile_hash[:customer_payment_profile_id])
63
- # end
64
- #end
76
+ def add_invoice(post, options)
77
+ post[:documento] = options[:order_id]
78
+ end
79
+
80
+ def add_creditcard(post, creditcard)
81
+ post[:numero_cartao] = creditcard.number
82
+ post[:codigo_seguranca] = creditcard.verification_value if creditcard.verification_value?
83
+ post[:ano_validade] = creditcard.year.to_s[-2,2]
84
+ post[:mes_validade] = sprintf("%.2i",creditcard.month).to_s
85
+ post[:nome_portador] = "#{creditcard.first_name} #{creditcard.last_name}"
86
+ post[:bandeira] = code_for_brand_of creditcard
87
+ end
65
88
 
66
89
 
67
- private
90
+
91
+ def commit(action, money, parameters)
68
92
 
69
- def success?(response)
70
- response[:aprovada] || response[:capturado]
71
- end
93
+ parameters[:valor] = format_amount(money.to_f)
72
94
 
73
- def gateway
74
- @gateway ||= AprovaFacil.new
75
- end
95
+ cartao = AprovaFacil::CartaoCredito.new(parameters)
76
96
 
77
- def code_for_brand_of(creditcard)
78
- case CreditCard.type? creditcard.number
79
- when 'visa' then AprovaFacil::CartaoCredito::Bandeira::VISA
80
- when 'master' then AprovaFacil::CartaoCredito::Bandeira::MASTERCARD
81
- when 'american_express' then AprovaFacil::CartaoCredito::Bandeira::AMEX
82
- when 'diners_club' then AprovaFacil::CartaoCredito::Bandeira::DINERS
97
+ case action
98
+ when 'authonly'
99
+ resultado = gateway.aprovar(cartao)
100
+ parameters[:transaction] = resultado[:transacao]
101
+ when 'sale'
102
+ resultado = gateway.aprovar(cartao)
103
+ if resultado[:aprovada]
104
+ resultado = resultado.merge gateway.capturar(resultado[:transacao])
105
+ parameters[:transaction] = resultado[:transacao]
106
+ end
107
+
108
+ when 'capture'
109
+ resultado = gateway.capturar(parameters[:transaction])
110
+ when 'void'
111
+ resultado = gateway.cancelar parameters[:transaction]
83
112
  end
84
- end
85
113
 
86
- def last_digits_from(string)
87
- string[-2,2]
88
- end
89
114
 
90
- def creditcard_month(month)
91
- if month.to_i < 10
92
- "0#{month}"
93
- else
94
- month
95
- end
115
+ Response.new(success?(resultado), resultado[:resultado], {:transaction_id => parameters[:transaction]} ,
116
+ :test => test?,
117
+ :authorization => resultado[:codigo_autorizacao]
118
+ )
96
119
  end
97
120
 
98
- def full_name_from(creditcard)
99
- "#{creditcard[:first_name]} #{creditcard[:last_name]}"
121
+ def message_from(response)
122
+ end
123
+
124
+ def post_data(action, parameters = {})
100
125
  end
101
126
 
102
- def add_creditcard(creditcard, options = {})
103
- AprovaFacil::CartaoCredito.new(
104
- :valor => options[:subtotal].to_f / 100,
105
- :numero_cartao => creditcard.number,
106
- :codigo_seguranca => creditcard.verification_value,
107
- :mes_validade => creditcard_month(creditcard.month),
108
- :ano_validade => last_digits_from(creditcard.year),
109
- :bandeira => code_for_brand_of(creditcard),
110
- :ip_comprador => options[:ip],
111
- :nome_portador => full_name_from(creditcard)
112
- )
127
+ private
128
+
129
+ def gateway
130
+ @gateway ||= AprovaFacil.new
113
131
  end
114
132
 
115
- def response_to_spree(approval_response,capture_response)
116
- Response.new(
117
- capture_response[:capturado],
118
- capture_response[:resultado],
119
- { :transaction_id => approval_response[:transacao] },
120
- :authorization => approval_response[:codigo_autorizacao]
121
- )
133
+ def success?(response)
134
+ response[:aprovada] || response[:capturado] || response[:cancelado]
122
135
  end
123
136
 
124
- def approves_transaction(creditcard, options)
125
- card = add_creditcard(creditcard,options)
137
+ def format_amount(amount)
138
+ amount / 100
139
+ end
126
140
 
127
- approval_response = gateway.aprovar(card)
128
- if success?(approval_response)
129
- capture_response = gateway.capturar(approval_response[:transacao])
130
- if success?(capture_response)
131
- response_to_spree(approval_response,capture_response)
132
- else
133
- response_to_spree(approval_response,capture_response)
134
- end
135
- else
136
- Response.new false, approval_response[:resultado]
141
+ def code_for_brand_of(creditcard)
142
+ case CreditCard.type? creditcard.number
143
+ when 'visa' then AprovaFacil::CartaoCredito::Bandeira::VISA
144
+ when 'master' then AprovaFacil::CartaoCredito::Bandeira::MASTERCARD
145
+ when 'american_express' then AprovaFacil::CartaoCredito::Bandeira::AMEX
146
+ when 'diners_club' then AprovaFacil::CartaoCredito::Bandeira::DINERS
137
147
  end
138
148
  end
139
-
140
149
  end
141
150
  end
142
151
  end
143
-
@@ -1,23 +1,21 @@
1
1
  require "spree_aprova_facil/version"
2
- require 'spree_core'
3
- require 'spree_aprova_facil_hooks'
4
2
  require 'active_merchant/billing/gateways/aprova_facil'
5
3
  require 'aprova_facil'
6
4
 
7
5
  module SpreeAprovaFacil
8
6
  class Engine < Rails::Engine
9
7
 
10
- require 'active_merchant'
11
- ActiveMerchant::Billing::AprovaFacilGateway
8
+ config.autoload_paths += %W(#{config.root}/lib)
12
9
 
13
10
 
14
11
  def self.activate
15
12
  Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
16
13
  Rails.env.production? ? require(c) : load(c)
17
14
  end
18
- Gateway::ExperiaAprovaFacil.register
15
+ Gateway::CobreBemAprovaFacil.register
19
16
  end
20
17
 
21
18
  config.to_prepare &method(:activate).to_proc
22
19
  end
23
20
  end
21
+
@@ -1,3 +1,3 @@
1
1
  module SpreeAprovaFacil
2
- VERSION = "0.0.1"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.name = "spree_aprova_facil"
7
7
  s.version = SpreeAprovaFacil::VERSION
8
8
  s.authors = ["Raphael Costa"]
9
- s.email = ["raphael@experia.com.br"]
9
+ s.email = ["raphael@raphaelcosta.net"]
10
10
  s.homepage = ""
11
11
  s.summary = %q{Aprova Fácil Payment Gateway to Spree}
12
12
  s.description = %q{Aprova Fácil Payment Gateway to Spree}
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_runtime_dependency "spree_core", '>= 0.60.1'
22
22
  s.add_runtime_dependency "aprova_facil", '>= 1.2.0'
23
+
23
24
  end
metadata CHANGED
@@ -1,49 +1,45 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: spree_aprova_facil
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
4
5
  prerelease:
5
- version: 0.0.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Raphael Costa
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-10-31 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2011-12-27 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: spree_core
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70142140773840 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
23
21
  version: 0.60.1
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: aprova_facil
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70142140773840
25
+ - !ruby/object:Gem::Dependency
26
+ name: aprova_facil
27
+ requirement: &70142140773140 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
34
32
  version: 1.2.0
35
33
  type: :runtime
36
- version_requirements: *id002
37
- description: "Aprova F\xC3\xA1cil Payment Gateway to Spree"
38
- email:
39
- - raphael@experia.com.br
34
+ prerelease: false
35
+ version_requirements: *70142140773140
36
+ description: Aprova Fácil Payment Gateway to Spree
37
+ email:
38
+ - raphael@raphaelcosta.net
40
39
  executables: []
41
-
42
40
  extensions: []
43
-
44
41
  extra_rdoc_files: []
45
-
46
- files:
42
+ files:
47
43
  - .DS_Store
48
44
  - .gitignore
49
45
  - Gemfile
@@ -52,7 +48,7 @@ files:
52
48
  - Rakefile
53
49
  - app/.DS_Store
54
50
  - app/models/.DS_Store
55
- - app/models/gateway/experia_aprova_facil.rb
51
+ - app/models/gateway/cobre_bem_aprova_facil.rb
56
52
  - config/routes.rb
57
53
  - lib/.DS_Store
58
54
  - lib/active_merchant/billing/gateways/aprova_facil.rb
@@ -62,32 +58,28 @@ files:
62
58
  - lib/tasks/install.rake
63
59
  - lib/tasks/spree_aprova_facil.rake
64
60
  - spree_aprova_facil.gemspec
65
- homepage: ""
61
+ homepage: ''
66
62
  licenses: []
67
-
68
63
  post_install_message:
69
64
  rdoc_options: []
70
-
71
- require_paths:
65
+ require_paths:
72
66
  - lib
73
- required_ruby_version: !ruby/object:Gem::Requirement
67
+ required_ruby_version: !ruby/object:Gem::Requirement
74
68
  none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- version: "0"
79
- required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
74
  none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- version: "0"
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
85
79
  requirements: []
86
-
87
80
  rubyforge_project: spree_aprova_facil
88
- rubygems_version: 1.8.11
81
+ rubygems_version: 1.8.10
89
82
  signing_key:
90
83
  specification_version: 3
91
- summary: "Aprova F\xC3\xA1cil Payment Gateway to Spree"
84
+ summary: Aprova Fácil Payment Gateway to Spree
92
85
  test_files: []
93
-
@@ -1,5 +0,0 @@
1
- class Gateway::ExperiaAprovaFacil < Gateway
2
- def provider_class
3
- ActiveMerchant::Billing::AprovaFacilGateway
4
- end
5
- end