spree_gateway 2.0.0 → 2.0.1
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 +4 -4
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/.travis.yml +22 -0
- data/Gemfile +14 -0
- data/LICENSE +26 -0
- data/README.md +68 -0
- data/Rakefile +14 -0
- data/Versionfile +12 -0
- data/app/controllers/spree/checkout_controller_decorator.rb +51 -0
- data/app/controllers/spree/skrill_status_controller.rb +39 -0
- data/app/models/spree/billing_integration/skrill/quick_checkout.rb +52 -0
- data/app/models/spree/gateway/authorize_net.rb +18 -0
- data/app/models/spree/gateway/authorize_net_cim.rb +134 -0
- data/app/models/spree/gateway/balanced_gateway.rb +68 -0
- data/app/models/spree/gateway/banwire.rb +16 -0
- data/app/models/spree/gateway/beanstream.rb +195 -0
- data/app/models/spree/gateway/braintree_gateway.rb +143 -0
- data/app/models/spree/gateway/card_save.rb +12 -0
- data/app/models/spree/gateway/data_cash.rb +12 -0
- data/app/models/spree/gateway/eway.rb +22 -0
- data/app/models/spree/gateway/fatzebra.rb +17 -0
- data/app/models/spree/gateway/klarna.rb +0 -0
- data/app/models/spree/gateway/linkpoint.rb +30 -0
- data/app/models/spree/gateway/moneris.rb +13 -0
- data/app/models/spree/gateway/pay_junction.rb +18 -0
- data/app/models/spree/gateway/pay_pal_gateway.rb +14 -0
- data/app/models/spree/gateway/payflow_pro.rb +19 -0
- data/app/models/spree/gateway/paymill.rb +15 -0
- data/app/models/spree/gateway/pin_gateway.rb +18 -0
- data/app/models/spree/gateway/sage_pay.rb +13 -0
- data/app/models/spree/gateway/samurai.rb +65 -0
- data/app/models/spree/gateway/secure_pay_au.rb +10 -0
- data/app/models/spree/gateway/stripe_gateway.rb +94 -0
- data/app/models/spree/gateway/usa_epay.rb +11 -0
- data/app/models/spree/gateway/worldpay.rb +96 -0
- data/app/models/spree/payment_decorator.rb +3 -0
- data/app/models/spree/skrill_transaction.rb +21 -0
- data/app/views/spree/admin/payments/source_forms/_quickcheckout.html.erb +8 -0
- data/app/views/spree/admin/payments/source_views/_quickcheckout.html.erb +39 -0
- data/app/views/spree/checkout/payment/_quickcheckout.html.erb +26 -0
- data/config/locales/bg.yml +11 -0
- data/config/locales/de.yml +11 -0
- data/config/locales/en.yml +11 -0
- data/config/locales/sv.yml +11 -0
- data/config/routes.rb +13 -0
- data/db/migrate/20111118164631_create_skrill_transactions.rb +14 -0
- data/db/migrate/20121017004102_update_braintree_payment_method_type.rb +9 -0
- data/db/migrate/20130213222555_update_stripe_payment_method_type.rb +9 -0
- data/db/migrate/20130415222802_update_balanced_payment_method_type.rb +9 -0
- data/db/migrate/20131008221012_update_paypal_payment_method_type.rb +9 -0
- data/lib/active_merchant/billing/skrill.rb +18 -0
- data/lib/generators/spree_gateway/install/install_generator.rb +28 -0
- data/lib/spree_gateway.rb +3 -0
- data/lib/spree_gateway/engine.rb +41 -0
- data/script/rails +5 -0
- data/spec/factories/payment_method_factory.rb +4 -0
- data/spec/models/gateway/authorize_net_cim_spec.rb +17 -0
- data/spec/models/gateway/authorize_net_spec.rb +17 -0
- data/spec/models/gateway/balanced_gateway_spec.rb +9 -0
- data/spec/models/gateway/banwire_spec.rb +9 -0
- data/spec/models/gateway/braintree_gateway_spec.rb +284 -0
- data/spec/models/gateway/eway_spec.rb +17 -0
- data/spec/models/gateway/fatzebra_spec.rb +47 -0
- data/spec/models/gateway/linkpoint_spec.rb +60 -0
- data/spec/models/gateway/pay_junction_spec.rb +17 -0
- data/spec/models/gateway/payflow_pro_spec.rb +17 -0
- data/spec/models/gateway/pin_gateway_spec.rb +57 -0
- data/spec/models/gateway/stripe_gateway_spec.rb +122 -0
- data/spec/models/gateway/usa_epay_spec.rb +38 -0
- data/spec/spec_helper.rb +34 -0
- data/spree_gateway.gemspec +26 -0
- metadata +91 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bafe8ca30672c3d4623c11485ee16f9f7f811f9a
|
4
|
+
data.tar.gz: 1d688f69623c2094ae6acb19625c794cf709fa46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dd05a7bfd1573344b099e458a4b1192cd049477c24ea7f8df5385cc7a363ae77dec23ff73684c85cd4077540409654344964d547df2be96509553b86cd75513
|
7
|
+
data.tar.gz: 67c9b0f0a3282139cb31cbee7cbbb24ae9340d0dc5b99fd0b05ffbe3355b044454fa8505319c71c3337193e1dbb377afb76e252073809ba92dd7badc53623a1f
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/.travis.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
language: ruby
|
2
|
+
before_script:
|
3
|
+
- sh -e /etc/init.d/xvfb start
|
4
|
+
- export DISPLAY=:99.0
|
5
|
+
- bundle exec rake test_app
|
6
|
+
env:
|
7
|
+
- DB=sqlite
|
8
|
+
- DB=mysql
|
9
|
+
- DB=postgres
|
10
|
+
script:
|
11
|
+
- bundle exec rspec spec
|
12
|
+
notifications:
|
13
|
+
email:
|
14
|
+
- ryan@spreecommerce.com
|
15
|
+
irc:
|
16
|
+
use_notice: true
|
17
|
+
skip_join: true
|
18
|
+
channels:
|
19
|
+
- "irc.freenode.org#spree"
|
20
|
+
rvm:
|
21
|
+
- 1.9.3
|
22
|
+
- 2.0.0
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2013 Spree Commerce
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
5
|
+
are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
* Neither the name Spree nor the names of its contributors may be used to
|
13
|
+
endorse or promote products derived from this software without specific
|
14
|
+
prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
20
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
21
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
22
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
23
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
24
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Spree Gateway
|
2
|
+
|
3
|
+
[](http://travis-ci.org/spree/spree_gateway)
|
4
|
+
|
5
|
+
Community supported Spree Payment Method Gateways.
|
6
|
+
|
7
|
+
These can be used with Spree >= 1.0.x (but see note below for necessary changes)
|
8
|
+
|
9
|
+
http://guides.spreecommerce.com/developer/payments.html
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
In your Gemfile:
|
14
|
+
|
15
|
+
**Spree edge**
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'spree'
|
19
|
+
gem 'spree_gateway', github: 'spree/spree_gateway'
|
20
|
+
```
|
21
|
+
|
22
|
+
**Spree 1.3**
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
gem 'spree', '~> 1.3'
|
26
|
+
gem 'spree_gateway', github: 'spree/spree_gateway', branch: '1-3-stable'
|
27
|
+
```
|
28
|
+
|
29
|
+
**Note:** *Please consult the Versionfile at the root of the repository to determine which branch to use.*
|
30
|
+
|
31
|
+
Then run from the command line:
|
32
|
+
|
33
|
+
$ bundle install
|
34
|
+
$ rails g spree_gateway:install
|
35
|
+
|
36
|
+
Finally, make sure to **restart your app**. Navigate to *Configuration > Payment Methods > New Payment Method* in the admin panel and you should see that a bunch of additional gateways have been added to the list.
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
In the spirit of [free software][1], **everyone** is encouraged to help improve this project.
|
41
|
+
|
42
|
+
Here are some ways *you* can contribute:
|
43
|
+
|
44
|
+
* by using prerelease versions
|
45
|
+
* by reporting [bugs][2]
|
46
|
+
* by suggesting new features
|
47
|
+
* by writing or editing documentation
|
48
|
+
* by writing specifications
|
49
|
+
* by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
|
50
|
+
* by refactoring code
|
51
|
+
* by resolving [issues][2]
|
52
|
+
* by reviewing patches
|
53
|
+
|
54
|
+
Starting point:
|
55
|
+
|
56
|
+
* Fork the repo
|
57
|
+
* Clone your repo
|
58
|
+
* Run `bundle`
|
59
|
+
* Run `bundle exec rake test_app` to create the test application in `spec/test_app`
|
60
|
+
* Make your changes
|
61
|
+
* Ensure specs pass by running `bundle exec rspec spec`
|
62
|
+
* Submit your pull request
|
63
|
+
|
64
|
+
Copyright (c) 2013 Spree Commerce, released under the [New BSD License][3]
|
65
|
+
|
66
|
+
[1]: http://www.fsf.org/licensing/essays/free-sw.html
|
67
|
+
[2]: https://github.com/futhr/spree-dibs/issues
|
68
|
+
[3]: https://github.com/spree/spree_gateway/tree/master/LICENSE
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'spree/testing_support/common_rake'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new
|
7
|
+
|
8
|
+
task :default => [:spec]
|
9
|
+
|
10
|
+
desc "Generates a dummy app for testing"
|
11
|
+
task :test_app do
|
12
|
+
ENV['LIB_NAME'] = 'spree_gateway'
|
13
|
+
Rake::Task['common:test_app'].invoke
|
14
|
+
end
|
data/Versionfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file is used to designate compatibilty with different versions of Spree
|
2
|
+
# Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details
|
3
|
+
|
4
|
+
# Examples
|
5
|
+
#
|
6
|
+
|
7
|
+
"2.1.x" => { :branch => "master" }
|
8
|
+
"2.0.x" => { :branch => "2-0-stable" }
|
9
|
+
"1.3.x" => { :branch => "1-3-stable" }
|
10
|
+
"1.2.x" => { :branch => "1-2-stable" }
|
11
|
+
"1.1.x" => { :branch => "1-1-stable" }
|
12
|
+
"1.0.x" => { :branch => "1-0-stable" }
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Spree
|
2
|
+
CheckoutController.class_eval do
|
3
|
+
before_filter :confirm_skrill, :only => [:update]
|
4
|
+
|
5
|
+
def skrill_return
|
6
|
+
|
7
|
+
unless @order.payments.where(:source_type => 'Spree::SkrillTransaction').present?
|
8
|
+
payment_method = PaymentMethod.find(params[:payment_method_id])
|
9
|
+
skrill_transaction = SkrillTransaction.new
|
10
|
+
|
11
|
+
payment = @order.payments.create({:amount => @order.total,
|
12
|
+
:source => skrill_transaction,
|
13
|
+
:payment_method => payment_method},
|
14
|
+
:without_protection => true)
|
15
|
+
payment.started_processing!
|
16
|
+
payment.pend!
|
17
|
+
end
|
18
|
+
|
19
|
+
@order.update_attributes({:state => "complete", :completed_at => Time.now}, :without_protection => true)
|
20
|
+
|
21
|
+
until @order.state == "complete"
|
22
|
+
if @order.next!
|
23
|
+
@order.update!
|
24
|
+
state_callback(:after)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
@order.finalize!
|
29
|
+
|
30
|
+
flash.notice = Spree.t(:order_processed_successfully)
|
31
|
+
redirect_to completion_route
|
32
|
+
end
|
33
|
+
|
34
|
+
def skrill_cancel
|
35
|
+
flash[:error] = Spree.t(:payment_has_been_cancelled)
|
36
|
+
redirect_to edit_order_path(@order)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def confirm_skrill
|
41
|
+
return unless (params[:state] == "payment") && params[:order][:payments_attributes]
|
42
|
+
|
43
|
+
payment_method = PaymentMethod.find(params[:order][:payments_attributes].first[:payment_method_id])
|
44
|
+
if payment_method.kind_of?(BillingIntegration::Skrill::QuickCheckout)
|
45
|
+
#TODO confirming payment method
|
46
|
+
redirect_to edit_order_checkout_url(@order, :state => 'payment'),
|
47
|
+
:notice => Spree.t(:complete_skrill_checkout)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Spree
|
2
|
+
class SkrillStatusController < ApplicationController
|
3
|
+
def update
|
4
|
+
@order = Order.find_by_number!(params[:order_id])
|
5
|
+
payment_method = PaymentMethod.find(params[:payment_method_id])
|
6
|
+
skrill_transaction = SkrillTransaction.create_from_postback params
|
7
|
+
|
8
|
+
payment = @order.payments.where(:state => "pending",
|
9
|
+
:payment_method_id => payment_method).first
|
10
|
+
|
11
|
+
if payment
|
12
|
+
payment.source = skrill_transaction
|
13
|
+
payment.save
|
14
|
+
else
|
15
|
+
payment = @order.payments.create(:amount => @order.total,
|
16
|
+
:source => skrill_transaction,
|
17
|
+
:payment_method => payment_method)
|
18
|
+
end
|
19
|
+
|
20
|
+
payment.started_processing!
|
21
|
+
|
22
|
+
unless payment.completed?
|
23
|
+
case params[:status]
|
24
|
+
when "0"
|
25
|
+
payment.pend #may already be pending
|
26
|
+
when "2" #processed / captured
|
27
|
+
payment.complete!
|
28
|
+
when "-1", "-2"
|
29
|
+
payment.failure!
|
30
|
+
else
|
31
|
+
raise "Unexpected payment status"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
render :text => ""
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Spree
|
2
|
+
class BillingIntegration::Skrill::QuickCheckout < BillingIntegration
|
3
|
+
preference :merchant_id, :string
|
4
|
+
preference :language, :string, :default => 'EN'
|
5
|
+
preference :currency, :string, :default => 'EUR'
|
6
|
+
preference :payment_options, :string, :default => 'ACC'
|
7
|
+
preference :pay_to_email, :string , :default => 'your@merchant.email_here'
|
8
|
+
|
9
|
+
attr_accessible :preferred_merchant_id, :preferred_language, :preferred_currency,
|
10
|
+
:preferred_payment_options, :preferred_server, :preferred_test_mode,
|
11
|
+
:preferred_pay_to_email
|
12
|
+
|
13
|
+
def provider_class
|
14
|
+
ActiveMerchant::Billing::Skrill
|
15
|
+
end
|
16
|
+
|
17
|
+
def redirect_url(order, opts = {})
|
18
|
+
opts.merge! self.preferences
|
19
|
+
|
20
|
+
set_global_options(opts)
|
21
|
+
|
22
|
+
opts[:detail1_text] = order.number
|
23
|
+
opts[:detail1_description] = "Order:"
|
24
|
+
|
25
|
+
opts[:pay_from_email] = order.email
|
26
|
+
opts[:firstname] = order.bill_address.firstname
|
27
|
+
opts[:lastname] = order.bill_address.lastname
|
28
|
+
opts[:address] = order.bill_address.address1
|
29
|
+
opts[:address2] = order.bill_address.address2
|
30
|
+
opts[:phone_number] = order.bill_address.phone.gsub(/\D/,'') if order.bill_address.phone
|
31
|
+
opts[:city] = order.bill_address.city
|
32
|
+
opts[:postal_code] = order.bill_address.zipcode
|
33
|
+
opts[:state] = order.bill_address.state.nil? ? order.bill_address.state_name.to_s : order.bill_address.state.abbr
|
34
|
+
opts[:country] = order.bill_address.country.name
|
35
|
+
opts[:pay_to_email] = self.preferred_pay_to_email
|
36
|
+
opts[:hide_login] = 1
|
37
|
+
opts[:merchant_fields] = 'platform,order_id,payment_method_id'
|
38
|
+
opts[:platform] = 'Spree'
|
39
|
+
opts[:order_id] = order.number
|
40
|
+
|
41
|
+
skrill = self.provider
|
42
|
+
skrill.payment_url(opts)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def set_global_options(opts)
|
47
|
+
opts[:recipient_description] = Spree::Config[:site_name]
|
48
|
+
opts[:payment_methods] = self.preferred_payment_options
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::AuthorizeNet < Gateway
|
3
|
+
preference :login, :string
|
4
|
+
preference :password, :string
|
5
|
+
|
6
|
+
attr_accessible :preferred_login, :preferred_password
|
7
|
+
|
8
|
+
def provider_class
|
9
|
+
ActiveMerchant::Billing::AuthorizeNetGateway
|
10
|
+
end
|
11
|
+
|
12
|
+
def options_with_test_preference
|
13
|
+
options_without_test_preference.merge(:test => self.preferred_test_mode)
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method_chain :options, :test_preference
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::AuthorizeNetCim < Gateway
|
3
|
+
preference :login, :string
|
4
|
+
preference :password, :string
|
5
|
+
preference :test_mode, :boolean, :default => false
|
6
|
+
preference :validate_on_profile_create, :boolean, :default => false
|
7
|
+
|
8
|
+
attr_accessible :preferred_login, :preferred_password, :preferred_test_mode, :preferred_validate_on_profile_create
|
9
|
+
|
10
|
+
ActiveMerchant::Billing::Response.class_eval do
|
11
|
+
attr_writer :authorization
|
12
|
+
end
|
13
|
+
|
14
|
+
def provider_class
|
15
|
+
self.class
|
16
|
+
end
|
17
|
+
|
18
|
+
def options
|
19
|
+
# add :test key in the options hash, as that is what the ActiveMerchant::Billing::AuthorizeNetGateway expects
|
20
|
+
if self.preferred_test_mode
|
21
|
+
self.class.preference :test, :boolean, :default => true
|
22
|
+
else
|
23
|
+
self.class.remove_preference :test
|
24
|
+
end
|
25
|
+
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
def authorize(amount, creditcard, gateway_options)
|
30
|
+
t_options = { :order => {:invoice_number => gateway_options[:order_id] } }
|
31
|
+
create_transaction( amount, creditcard, :auth_only, t_options )
|
32
|
+
end
|
33
|
+
|
34
|
+
def purchase(amount, creditcard, gateway_options)
|
35
|
+
create_transaction(amount, creditcard, :auth_capture)
|
36
|
+
end
|
37
|
+
|
38
|
+
def capture(authorization, creditcard, gateway_options)
|
39
|
+
create_transaction((authorization.amount * 100).round, creditcard, :prior_auth_capture, :trans_id => authorization.response_code)
|
40
|
+
end
|
41
|
+
|
42
|
+
def credit(amount, creditcard, response_code, gateway_options)
|
43
|
+
create_transaction(amount, creditcard, :refund, :trans_id => response_code)
|
44
|
+
end
|
45
|
+
|
46
|
+
def void(response_code, creditcard, gateway_options)
|
47
|
+
create_transaction(nil, creditcard, :void, :trans_id => response_code)
|
48
|
+
end
|
49
|
+
|
50
|
+
def payment_profiles_supported?
|
51
|
+
true
|
52
|
+
end
|
53
|
+
|
54
|
+
# Create a new CIM customer profile ready to accept a payment
|
55
|
+
def create_profile(payment)
|
56
|
+
if payment.source.gateway_customer_profile_id.nil?
|
57
|
+
profile_hash = create_customer_profile(payment)
|
58
|
+
payment.source.update_attributes(:gateway_customer_profile_id => profile_hash[:customer_profile_id], :gateway_payment_profile_id => profile_hash[:customer_payment_profile_id])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# simpler form
|
63
|
+
def create_profile_from_card(card)
|
64
|
+
if card.gateway_customer_profile_id.nil?
|
65
|
+
profile_hash = create_customer_profile(card)
|
66
|
+
card.update_attributes(:gateway_customer_profile_id => profile_hash[:customer_profile_id], :gateway_payment_profile_id => profile_hash[:customer_payment_profile_id])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
# Create a transaction on a creditcard
|
72
|
+
# Set up a CIM profile for the card if one doesn't exist
|
73
|
+
# Valid transaction_types are :auth_only, :capture_only and :auth_capture
|
74
|
+
def create_transaction(amount, creditcard, transaction_type, options = {})
|
75
|
+
#create_profile(creditcard, creditcard.gateway_options)
|
76
|
+
creditcard.save
|
77
|
+
if amount
|
78
|
+
amount = "%.2f" % (amount / 100.0) # This gateway requires formated decimal, not cents
|
79
|
+
end
|
80
|
+
transaction_options = {
|
81
|
+
:type => transaction_type,
|
82
|
+
:amount => amount,
|
83
|
+
:customer_profile_id => creditcard.gateway_customer_profile_id,
|
84
|
+
:customer_payment_profile_id => creditcard.gateway_payment_profile_id,
|
85
|
+
}.update(options)
|
86
|
+
t = cim_gateway.create_customer_profile_transaction(:transaction => transaction_options)
|
87
|
+
logger.debug("\nAuthorize Net CIM Transaction")
|
88
|
+
logger.debug(" transaction_options: #{transaction_options.inspect}")
|
89
|
+
logger.debug(" response: #{t.inspect}\n")
|
90
|
+
t
|
91
|
+
end
|
92
|
+
|
93
|
+
# Create a new CIM customer profile ready to accept a payment
|
94
|
+
def create_customer_profile(payment)
|
95
|
+
options = options_for_create_customer_profile(payment)
|
96
|
+
response = cim_gateway.create_customer_profile(options)
|
97
|
+
if response.success?
|
98
|
+
{ :customer_profile_id => response.params['customer_profile_id'],
|
99
|
+
:customer_payment_profile_id => response.params['customer_payment_profile_id_list'].values.first }
|
100
|
+
else
|
101
|
+
payment.send(:gateway_error, response)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def options_for_create_customer_profile(payment)
|
106
|
+
if payment.is_a? CreditCard
|
107
|
+
info = { :bill_to => generate_address_hash(payment.address), :payment => { :credit_card => payment } }
|
108
|
+
else
|
109
|
+
info = { :bill_to => generate_address_hash(payment.order.bill_address),
|
110
|
+
:payment => { :credit_card => payment.source } }
|
111
|
+
end
|
112
|
+
validation_mode = preferred_validate_on_profile_create ? preferred_server.to_sym : :none
|
113
|
+
|
114
|
+
{ :profile => { :merchant_customer_id => "#{Time.now.to_f}",
|
115
|
+
#:ship_to_list => generate_address_hash(creditcard.checkout.ship_address),
|
116
|
+
:email => payment.order.email,
|
117
|
+
:payment_profiles => info },
|
118
|
+
:validation_mode => validation_mode }
|
119
|
+
end
|
120
|
+
|
121
|
+
# As in PaymentGateway but with separate name fields
|
122
|
+
def generate_address_hash(address)
|
123
|
+
return {} if address.nil?
|
124
|
+
{:first_name => address.firstname, :last_name => address.lastname, :address1 => address.address1, :address2 => address.address2, :city => address.city,
|
125
|
+
:state => address.state_text, :zip => address.zipcode, :country => address.country.iso, :phone_number => address.phone}
|
126
|
+
end
|
127
|
+
|
128
|
+
def cim_gateway
|
129
|
+
ActiveMerchant::Billing::Base.gateway_mode = preferred_server.to_sym
|
130
|
+
gateway_options = options
|
131
|
+
ActiveMerchant::Billing::AuthorizeNetCimGateway.new(gateway_options)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|