spree_aprova_facil 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in spree_aprova_facil.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Redistribution and use in source and binary forms, with or without modification,
2
+ are permitted provided that the following conditions are met:
3
+
4
+ * Redistributions of source code must retain the above copyright notice,
5
+ this list of conditions and the following disclaimer.
6
+ * Redistributions in binary form must reproduce the above copyright notice,
7
+ this list of conditions and the following disclaimer in the documentation
8
+ and/or other materials provided with the distribution.
9
+ * Neither the name of the Rails Dog LLC nor the names of its
10
+ contributors may be used to endorse or promote products derived from this
11
+ software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ Spree Aprova Fácil
2
+ =============
3
+
4
+ Introduction goes here.
5
+
6
+
7
+ How to install
8
+ =======
9
+
10
+ Example goes here.
11
+
12
+
13
+ released under the New BSD License
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/app/.DS_Store ADDED
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ class Gateway::ExperiaAprovaFacil < Gateway
2
+ def provider_class
3
+ ActiveMerchant::Billing::AprovaFacilGateway
4
+ end
5
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ # Add your extension routes here
3
+ end
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,143 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class AprovaFacilGateway < Gateway
4
+
5
+ self.supported_countries = ['BR']
6
+ self.supported_cardtypes = [:visa, :master, :american_express, :dinners_club]
7
+
8
+ def initialize(options = {})
9
+ @options = options
10
+ end
11
+
12
+ def authorize(money, creditcard, options = {})
13
+ card = add_creditcard(creditcard,options)
14
+
15
+ approval_response = gateway.aprovar(card)
16
+
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
+ )
31
+ end
32
+ end
33
+
34
+ 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
+
43
+ end
44
+
45
+ def purchase(money, creditcard, options = {})
46
+ approves_transaction(creditcard, options)
47
+ end
48
+
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)
56
+ end
57
+ end
58
+
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
65
+
66
+
67
+ private
68
+
69
+ def success?(response)
70
+ response[:aprovada] || response[:capturado]
71
+ end
72
+
73
+ def gateway
74
+ @gateway ||= AprovaFacil.new
75
+ end
76
+
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
83
+ end
84
+ end
85
+
86
+ def last_digits_from(string)
87
+ string[-2,2]
88
+ end
89
+
90
+ def creditcard_month(month)
91
+ if month.to_i < 10
92
+ "0#{month}"
93
+ else
94
+ month
95
+ end
96
+ end
97
+
98
+ def full_name_from(creditcard)
99
+ "#{creditcard[:first_name]} #{creditcard[:last_name]}"
100
+ end
101
+
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
+ )
113
+ end
114
+
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
+ )
122
+ end
123
+
124
+ def approves_transaction(creditcard, options)
125
+ card = add_creditcard(creditcard,options)
126
+
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]
137
+ end
138
+ end
139
+
140
+ end
141
+ end
142
+ end
143
+
@@ -0,0 +1,3 @@
1
+ module SpreeAprovaFacil
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ require "spree_aprova_facil/version"
2
+ require 'spree_core'
3
+ require 'spree_aprova_facil_hooks'
4
+ require 'active_merchant/billing/gateways/aprova_facil'
5
+ require 'aprova_facil'
6
+
7
+ module SpreeAprovaFacil
8
+ class Engine < Rails::Engine
9
+
10
+ require 'active_merchant'
11
+ ActiveMerchant::Billing::AprovaFacilGateway
12
+
13
+
14
+ def self.activate
15
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
16
+ Rails.env.production? ? require(c) : load(c)
17
+ end
18
+ Gateway::ExperiaAprovaFacil.register
19
+ end
20
+
21
+ config.to_prepare &method(:activate).to_proc
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ class SpreeAprovaFacilHooks < Spree::ThemeSupport::HookListener
2
+ # custom hooks go here
3
+ end
@@ -0,0 +1,25 @@
1
+ namespace :spree_cobre_bem do
2
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ Rake::Task['spree_cobre_bem:install:migrations'].invoke
5
+ Rake::Task['spree_cobre_bem:install:assets'].invoke
6
+ end
7
+
8
+ namespace :install do
9
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
10
+ task :migrations do
11
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
12
+ destination = File.join(Rails.root, 'db')
13
+ Spree::FileUtilz.mirror_files(source, destination)
14
+ end
15
+
16
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
17
+ task :assets do
18
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
19
+ destination = File.join(Rails.root, 'public')
20
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
21
+ Spree::FileUtilz.mirror_files(source, destination)
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1 @@
1
+ # add custom rake tasks here
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "spree_aprova_facil/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "spree_aprova_facil"
7
+ s.version = SpreeAprovaFacil::VERSION
8
+ s.authors = ["Raphael Costa"]
9
+ s.email = ["raphael@experia.com.br"]
10
+ s.homepage = ""
11
+ s.summary = %q{Aprova Fácil Payment Gateway to Spree}
12
+ s.description = %q{Aprova Fácil Payment Gateway to Spree}
13
+
14
+ s.rubyforge_project = "spree_aprova_facil"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency "spree_core", '>= 0.60.1'
22
+ s.add_runtime_dependency "aprova_facil", '>= 1.2.0'
23
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_aprova_facil
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Raphael Costa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-10-31 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: spree_core
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.60.1
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: aprova_facil
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 1.2.0
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ description: "Aprova F\xC3\xA1cil Payment Gateway to Spree"
38
+ email:
39
+ - raphael@experia.com.br
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .DS_Store
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - app/.DS_Store
54
+ - app/models/.DS_Store
55
+ - app/models/gateway/experia_aprova_facil.rb
56
+ - config/routes.rb
57
+ - lib/.DS_Store
58
+ - lib/active_merchant/billing/gateways/aprova_facil.rb
59
+ - lib/spree_aprova_facil.rb
60
+ - lib/spree_aprova_facil/version.rb
61
+ - lib/spree_aprova_facil_hooks.rb
62
+ - lib/tasks/install.rake
63
+ - lib/tasks/spree_aprova_facil.rake
64
+ - spree_aprova_facil.gemspec
65
+ homepage: ""
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options: []
70
+
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project: spree_aprova_facil
88
+ rubygems_version: 1.8.11
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: "Aprova F\xC3\xA1cil Payment Gateway to Spree"
92
+ test_files: []
93
+