activemerchant 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Binary file
data/CHANGELOG CHANGED
@@ -1,5 +1,11 @@
1
1
  = ActiveMerchant CHANGELOG
2
2
 
3
+ == Version 1.7.0 (July 9, 2010)
4
+
5
+ * Add support for new Braintree Blue Gateway (using the braintree gem) [Braintree]
6
+
7
+ == Version 1.6.0 (July 6, 2010)
8
+
3
9
  * Add a task rake gateways:hosts to get a list of all outbound hosts and ports [cody]
4
10
  * Fix test failure in chronopay helper in Ruby 1.9.1 [cody]
5
11
  * Fix timezone issue in credit card test. [cody]
@@ -135,4 +135,8 @@ SallieMae (October 2, 2009)
135
135
 
136
136
  Garanti (May 05, 2010)
137
137
 
138
- * Selem Delul (moon@mac.home)
138
+ * Selem Delul (moon@mac.home)
139
+
140
+ Braintree Blue Gateway (May 19th, 2010)
141
+
142
+ * Braintree (code@getbraintree.com)
@@ -30,6 +30,7 @@ require 'rexml/document'
30
30
 
31
31
  require 'active_merchant/common'
32
32
  require 'active_merchant/billing'
33
+ require 'active_merchant/version'
33
34
 
34
35
  module ActiveMerchant #:nodoc:
35
36
  module Billing #:nodoc:
@@ -1,17 +1,17 @@
1
- require File.join(File.dirname(__FILE__),'smart_ps.rb')
1
+ require File.dirname(__FILE__) + '/braintree/braintree_common'
2
+
2
3
  module ActiveMerchant #:nodoc:
3
4
  module Billing #:nodoc:
4
- class BraintreeGateway < SmartPs
5
- def api_url
6
- 'https://secure.braintreepaymentgateway.com/api/transact.php'
5
+ class BraintreeGateway < Gateway
6
+ include BraintreeCommon
7
+
8
+ def self.new(options={})
9
+ if options.has_key?(:login)
10
+ BraintreeOrangeGateway.new(options)
11
+ else
12
+ BraintreeBlueGateway.new(options)
13
+ end
7
14
  end
8
-
9
- self.supported_countries = ['US']
10
- self.supported_cardtypes = [:visa, :master, :american_express, :discover]
11
- self.homepage_url = 'http://www.braintreepaymentsolutions.com'
12
- self.display_name = 'Braintree'
13
- self.default_currency = 'USD'
14
15
  end
15
16
  end
16
17
  end
17
-
@@ -0,0 +1,9 @@
1
+ module BraintreeCommon
2
+ def self.included(base)
3
+ base.supported_countries = ['US']
4
+ base.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb]
5
+ base.homepage_url = 'http://www.braintreepaymentsolutions.com'
6
+ base.display_name = 'Braintree'
7
+ base.default_currency = 'USD'
8
+ end
9
+ end
@@ -0,0 +1,210 @@
1
+ require File.dirname(__FILE__) + '/braintree/braintree_common'
2
+
3
+ begin
4
+ require "braintree"
5
+ rescue LoadError
6
+ raise "Could not load the braintree gem. Use `gem install braintree` to install it."
7
+ end
8
+
9
+ raise "Need braintree gem 2.x.y. Run `gem install braintree --version '~>2.0'` to get the correct version." unless Braintree::Version::Major == 2
10
+
11
+ module ActiveMerchant #:nodoc:
12
+ module Billing #:nodoc:
13
+ class BraintreeBlueGateway < Gateway
14
+ include BraintreeCommon
15
+
16
+ self.display_name = 'Braintree (Blue Platform)'
17
+
18
+ def initialize(options = {})
19
+ requires!(options, :merchant_id, :public_key, :private_key)
20
+ @options = options
21
+ Braintree::Configuration.merchant_id = options[:merchant_id]
22
+ Braintree::Configuration.public_key = options[:public_key]
23
+ Braintree::Configuration.private_key = options[:private_key]
24
+ Braintree::Configuration.environment = test? ? :sandbox : :production
25
+ Braintree::Configuration.logger.level = Logger::ERROR#DEBUG
26
+ Braintree::Configuration.custom_user_agent = "ActiveMerchant #{ActiveMerchant::VERSION}"
27
+ super
28
+ end
29
+
30
+ def authorize(money, credit_card_or_vault_id, options = {})
31
+ create_transaction(:sale, money, credit_card_or_vault_id, options)
32
+ end
33
+
34
+ def capture(money, authorization, options = {})
35
+ commit do
36
+ result = Braintree::Transaction.submit_for_settlement(authorization, amount(money).to_s)
37
+ Response.new(result.success?, message_from_result(result))
38
+ end
39
+ end
40
+
41
+ def purchase(money, credit_card_or_vault_id, options = {})
42
+ authorize(money, credit_card_or_vault_id, options.merge(:submit_for_settlement => true))
43
+ end
44
+
45
+ def credit(money, credit_card_or_vault_id, options = {})
46
+ create_transaction(:credit, money, credit_card_or_vault_id, options)
47
+ end
48
+
49
+ def refund(transaction_id, options = {})
50
+ commit do
51
+ result = Braintree::Transaction.find(transaction_id).refund
52
+ Response.new(result.success?, message_from_result(result))
53
+ end
54
+ end
55
+
56
+ def void(authorization, options = {})
57
+ commit do
58
+ result = Braintree::Transaction.void(authorization)
59
+ Response.new(result.success?, message_from_result(result),
60
+ :braintree_transaction => (result.transaction if result.success?)
61
+ )
62
+ end
63
+ end
64
+
65
+ def store(creditcard, options = {})
66
+ commit do
67
+ result = Braintree::Customer.create(
68
+ :first_name => creditcard.first_name,
69
+ :last_name => creditcard.last_name,
70
+ :email => options[:email],
71
+ :credit_card => {
72
+ :number => creditcard.number,
73
+ :cvv => creditcard.verification_value,
74
+ :expiration_month => creditcard.month.to_s.rjust(2, "0"),
75
+ :expiration_year => creditcard.year.to_s
76
+ }
77
+ )
78
+ Response.new(result.success?, message_from_result(result),
79
+ {
80
+ :braintree_customer => (result.customer if result.success?),
81
+ :customer_vault_id => (result.customer.id if result.success?)
82
+ }
83
+ )
84
+ end
85
+ end
86
+
87
+ def update(vault_id, creditcard, options = {})
88
+ braintree_credit_card = nil
89
+ customer_update_result = commit do
90
+ braintree_credit_card = Braintree::Customer.find(vault_id).credit_cards.detect { |cc| cc.default? }
91
+ return Response.new(false, 'Braintree::NotFoundError') if braintree_credit_card.nil?
92
+ result = Braintree::Customer.update(vault_id,
93
+ :first_name => creditcard.first_name,
94
+ :last_name => creditcard.last_name,
95
+ :email => options[:email]
96
+ )
97
+ Response.new(result.success?, message_from_result(result),
98
+ :braintree_customer => (Braintree::Customer.find(vault_id) if result.success?)
99
+ )
100
+ end
101
+ return customer_update_result unless customer_update_result.success?
102
+ credit_card_update_result = commit do
103
+ result = Braintree::CreditCard.update(braintree_credit_card.token,
104
+ :number => creditcard.number,
105
+ :expiration_month => creditcard.month.to_s.rjust(2, "0"),
106
+ :expiration_year => creditcard.year.to_s
107
+ )
108
+ Response.new(result.success?, message_from_result(result),
109
+ :braintree_customer => (Braintree::Customer.find(vault_id) if result.success?)
110
+ )
111
+ end
112
+ end
113
+
114
+ def unstore(customer_vault_id)
115
+ commit do
116
+ Braintree::Customer.delete(customer_vault_id)
117
+ Response.new(true, "OK")
118
+ end
119
+ end
120
+ alias_method :delete, :unstore
121
+
122
+ private
123
+
124
+ def map_address(address)
125
+ return {} if address.nil?
126
+ {
127
+ :street_address => address[:address1],
128
+ :extended_address => address[:address2],
129
+ :company => address[:company],
130
+ :locality => address[:city],
131
+ :region => address[:state],
132
+ :postal_code => address[:zip],
133
+ :country_name => address[:country]
134
+ }
135
+ end
136
+
137
+ def commit(&block)
138
+ yield
139
+ rescue Braintree::BraintreeError => ex
140
+ Response.new(false, ex.class.to_s)
141
+ end
142
+
143
+ def message_from_result(result)
144
+ if result.success?
145
+ "OK"
146
+ else
147
+ result.errors.map { |e| "#{e.message} (#{e.code})" }.join(" ")
148
+ end
149
+ end
150
+
151
+ def create_transaction(transaction_type, money, credit_card_or_vault_id, options)
152
+ parameters = {
153
+ :amount => amount(money).to_s,
154
+ :order_id => options[:order_id],
155
+ :customer => {
156
+ :id => options[:store] == true ? "" : options[:store],
157
+ :email => options[:email]
158
+ },
159
+ :options => {
160
+ :store_in_vault => options[:store] ? true : false,
161
+ :submit_for_settlement => options[:submit_for_settlement]
162
+ }
163
+ }
164
+ if credit_card_or_vault_id.is_a?(String) || credit_card_or_vault_id.is_a?(Integer)
165
+ parameters[:customer_id] = credit_card_or_vault_id
166
+ else
167
+ parameters[:customer].merge!(
168
+ :first_name => credit_card_or_vault_id.first_name,
169
+ :last_name => credit_card_or_vault_id.last_name
170
+ )
171
+ parameters[:credit_card] = {
172
+ :number => credit_card_or_vault_id.number,
173
+ :cvv => credit_card_or_vault_id.verification_value,
174
+ :expiration_month => credit_card_or_vault_id.month.to_s.rjust(2, "0"),
175
+ :expiration_year => credit_card_or_vault_id.year.to_s
176
+ }
177
+ end
178
+ parameters[:billing] = map_address(options[:billing_address]) if options[:billing_address]
179
+ parameters[:shipping] = map_address(options[:shipping_address]) if options[:shipping_address]
180
+ commit do
181
+ result = Braintree::Transaction.send(transaction_type, parameters)
182
+ response_params, response_options, avs_result, cvv_result = {}, {}, {}, {}
183
+ if result.success?
184
+ response_params[:braintree_transaction] = result.transaction
185
+ response_params[:customer_vault_id] = result.transaction.customer_details.id
186
+ response_options[:authorization] = result.transaction.id
187
+ end
188
+ if result.transaction
189
+ avs_result = {
190
+ 'code' => '', 'message' => '',
191
+ 'street_match' => result.transaction.avs_street_address_response_code == 'M',
192
+ 'postal_match' => result.transaction.avs_postal_code_response_code == 'M'
193
+ }
194
+ cvv_result = {
195
+ 'code' => result.transaction.cvv_response_code, 'message' => ''
196
+ }
197
+ message = result.transaction.processor_response_code + " " + result.transaction.processor_response_text
198
+ else
199
+ message = message_from_result(result)
200
+ end
201
+ response = Response.new(result.success?, message, response_params, response_options)
202
+ response.instance_variable_set("@avs_result", avs_result)
203
+ response.instance_variable_set("@cvv_result", cvv_result)
204
+ response
205
+ end
206
+ end
207
+ end
208
+ end
209
+ end
210
+
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/smart_ps.rb'
2
+ require File.dirname(__FILE__) + '/braintree/braintree_common'
3
+
4
+ module ActiveMerchant #:nodoc:
5
+ module Billing #:nodoc:
6
+ class BraintreeOrangeGateway < SmartPs
7
+ include BraintreeCommon
8
+
9
+ self.display_name = 'Braintree (Orange Platform)'
10
+
11
+ def api_url
12
+ 'https://secure.braintreepaymentgateway.com/api/transact.php'
13
+ end
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,3 @@
1
+ module ActiveMerchant
2
+ VERSION = "1.7.0"
3
+ end
metadata CHANGED
@@ -1,21 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemerchant
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 6
8
+ - 7
9
9
  - 0
10
- version: 1.6.0
10
+ version: 1.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tobias Luetke
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain:
17
- - gem-public_cert.pem
18
- date: 2010-07-06 00:00:00 -04:00
17
+ - |
18
+ -----BEGIN CERTIFICATE-----
19
+ MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRMwEQYDVQQDDApjb2R5
20
+ ZmF1c2VyMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZFgNj
21
+ b20wHhcNMDcwMjIyMTcyMTI3WhcNMDgwMjIyMTcyMTI3WjBBMRMwEQYDVQQDDApj
22
+ b2R5ZmF1c2VyMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZ
23
+ FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC6T4Iqt5iWvAlU
24
+ iXI6L8UO0URQhIC65X/gJ9hL/x4lwSl/ckVm/R/bPrJGmifT+YooFv824N3y/TIX
25
+ 25o/lZtRj1TUZJK4OCb0aVzosQVxBHSe6rLmxO8cItNTMOM9wn3thaITFrTa1DOQ
26
+ O3wqEjvW2L6VMozVfK1MfjL9IGgy0rCnl+2g4Gh4jDDpkLfnMG5CWI6cTCf3C1ye
27
+ ytOpWgi0XpOEy8nQWcFmt/KCQ/kFfzBo4QxqJi54b80842EyvzWT9OB7Oew/CXZG
28
+ F2yIHtiYxonz6N09vvSzq4CvEuisoUFLKZnktndxMEBKwJU3XeSHAbuS7ix40OKO
29
+ WKuI54fHAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
30
+ BBR9QQpefI3oDCAxiqJW/3Gg6jI6qjANBgkqhkiG9w0BAQUFAAOCAQEAs0lX26O+
31
+ HpyMp7WL+SgZuM8k76AjfOHuKajl2GEn3S8pWYGpsa0xu07HtehJhKLiavrfUYeE
32
+ qlFtyYMUyOh6/1S2vfkH6VqjX7mWjoi7XKHW/99fkMS40B5SbN+ypAUst+6c5R84
33
+ w390mjtLHpdDE6WQYhS6bFvBN53vK6jG3DLyCJc0K9uMQ7gdHWoxq7RnG92ncQpT
34
+ ThpRA+fky5Xt2Q63YJDnJpkYAz79QIama1enSnd4jslKzSl89JS2luq/zioPe/Us
35
+ hbyalWR1+HrhgPoSPq7nk+s2FQUBJ9UZFK1lgMzho/4fZgzJwbu+cO8SNuaLS/bj
36
+ hPaSTyVU0yCSnw==
37
+ -----END CERTIFICATE-----
38
+
39
+ date: 2010-07-09 00:00:00 -04:00
19
40
  default_executable:
20
41
  dependencies:
21
42
  - !ruby/object:Gem::Dependency
@@ -24,7 +45,7 @@ dependencies:
24
45
  requirement: &id001 !ruby/object:Gem::Requirement
25
46
  none: false
26
47
  requirements:
27
- - - ">="
48
+ - - ~>
28
49
  - !ruby/object:Gem::Version
29
50
  hash: 7
30
51
  segments:
@@ -50,6 +71,22 @@ dependencies:
50
71
  version: 2.0.0
51
72
  type: :runtime
52
73
  version_requirements: *id002
74
+ - !ruby/object:Gem::Dependency
75
+ name: braintree
76
+ prerelease: false
77
+ requirement: &id003 !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 15
83
+ segments:
84
+ - 2
85
+ - 0
86
+ - 0
87
+ version: 2.0.0
88
+ type: :runtime
89
+ version_requirements: *id003
53
90
  description: Active Merchant is a simple payment abstraction library used in and sponsored by Shopify. It is written by Tobias Luetke, Cody Fauser, and contributors. The aim of the project is to feel natural to Ruby users and to abstract as many parts as possible away from the user to offer a consistent interface across all supported gateways.
54
91
  email: tobi@leetsoft.com
55
92
  executables: []
@@ -79,7 +116,10 @@ files:
79
116
  - lib/active_merchant/billing/gateways/beanstream.rb
80
117
  - lib/active_merchant/billing/gateways/beanstream_interac.rb
81
118
  - lib/active_merchant/billing/gateways/bogus.rb
119
+ - lib/active_merchant/billing/gateways/braintree/braintree_common.rb
82
120
  - lib/active_merchant/billing/gateways/braintree.rb
121
+ - lib/active_merchant/billing/gateways/braintree_blue.rb
122
+ - lib/active_merchant/billing/gateways/braintree_orange.rb
83
123
  - lib/active_merchant/billing/gateways/card_stream.rb
84
124
  - lib/active_merchant/billing/gateways/cyber_source.rb
85
125
  - lib/active_merchant/billing/gateways/data_cash.rb
@@ -188,6 +228,7 @@ files:
188
228
  - lib/active_merchant/common/utils.rb
189
229
  - lib/active_merchant/common/validateable.rb
190
230
  - lib/active_merchant/common.rb
231
+ - lib/active_merchant/version.rb
191
232
  - lib/active_merchant.rb
192
233
  - lib/activemerchant.rb
193
234
  - lib/certs/cacert.pem
Binary file