active_merchant_first_data 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Edgars Beigarts
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ First Data gateway for Active Merchant
2
+ ======================================
3
+
4
+ [![Continuous Integration status](https://secure.travis-ci.org/ebeigarts/active_merchant_first_data.png)](http://travis-ci.org/ebeigarts/active_merchant_first_data)
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ $ gem install active_merchant_first_data
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```ruby
15
+ require "active_merchant_first_data"
16
+ @gateway = ActiveMerchant::Billing::FirstDataGateway.new(
17
+ :pem => "1234567_keystore.pem"
18
+ :pem_password => "5x64jq8n234c"
19
+ )
20
+ ```
21
+
22
+ ## First Data test environment setup
23
+
24
+ 1. Generate a new certificate
25
+
26
+ ```bash
27
+ $ openssl req -newkey rsa:1024 -keyout spec/certs/1234567_key.pem -out spec/certs/1234567_req.pem -subj "/C=lv/O=example.com/CN=1234567" -outform PEM
28
+ Enter PEM pass phrase: 81f174259v45
29
+ ```
30
+
31
+ 2. [Request your certificate using `1234567_req.pem`](https://secureshop-test.firstdata.lv/report/keystore_.do)
32
+
33
+ 3. Copy the 3 files you received in e-mail to `spec/certs/`:
34
+
35
+ * 1234567.pem
36
+ * 1234567_certificate_chain.p7.pem
37
+ * ECOMM.pem
38
+
39
+ 4. Convert the certificates and keys to `1234567_keystore.pem`
40
+
41
+ ```bash
42
+ $ openssl pkcs12 -export -in 1234567.pem -out spec/certs/1234567_keystore.p12 -certfile spec/certs/ECOMM.pem -inkey spec/certs/1234567_key.pem
43
+ Enter pass phrase for 1234567_key.pem: 81f174259v45
44
+ Enter Export Password: <empty>
45
+ ```
46
+
47
+ ```bash
48
+ $ openssl pkcs12 -in spec/certs/1234567_keystore.p12 > spec/certs/1234567_keystore.pem
49
+ Enter Import Password: <empty>
50
+ Enter PEM pass phrase: 5x64jq8n234c
51
+ ```
52
+
53
+ 5. [Set your WAN IP address](https://secureshop-test.firstdata.lv/report/merchantlist.do)
@@ -0,0 +1,171 @@
1
+ require "active_merchant"
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class FirstDataGateway < Gateway
6
+ class_attribute :test_url, :live_url, :test_redirect_url, :live_redirect_url, :pem_file, :pem_password
7
+
8
+ self.test_redirect_url = 'https://secureshop-test.firstdata.lv/ecomm/ClientHandler'
9
+ self.live_redirect_url = 'https://secureshop.firstdata.lv/ecomm/ClientHandler'
10
+
11
+ self.test_url = 'https://secureshop-test.firstdata.lv:8443/ecomm/MerchantHandler'
12
+ self.live_url = 'https://secureshop.firstdata.lv:8443/ecomm/MerchantHandler'
13
+
14
+ self.homepage_url = 'http://www.firstdata.lv/'
15
+ self.display_name = 'First Data'
16
+
17
+ self.ssl_strict = false
18
+ self.default_currency = '428' # LVL (http://en.wikipedia.org/wiki/ISO_4217)
19
+ self.money_format = :cents
20
+
21
+ # Creates a new FirstDataGateway
22
+ #
23
+ # The gateway requires that a valid pem and password be passed
24
+ # in the +options+ hash.
25
+ #
26
+ # Options:
27
+ #
28
+ # * <tt>:pem</tt> -- The First Data cert/key (REQUIRED)
29
+ # * <tt>:pem_password</tt> -- The First Data password. (REQUIRED)
30
+ #
31
+ def initialize(options = {})
32
+ requires!(options, :pem, :pem_password)
33
+ @options = options
34
+ super
35
+ end
36
+
37
+ # Perform a purchase, which is essentially an authorization and capture in a single operation.
38
+ #
39
+ # Registering of SMS transaction
40
+ # @param int $amount transaction amount in minor units, mandatory
41
+ # @param int $currency transaction currency code, mandatory
42
+ # @param string $ip clientís IP address, mandatory
43
+ # @param string $desc description of transaction, optional
44
+ # @param string $language authorization language identificator, optional
45
+ # @return string TRANSACTION_ID
46
+ #
47
+ def purchase(amount, params = {})
48
+ params = params.reverse_merge(
49
+ :command => :v,
50
+ :amount => amount,
51
+ :currency => default_currency
52
+ )
53
+ requires!(params, :amount, :currency, :client_ip_addr)
54
+ commit(params)
55
+ end
56
+
57
+ # Performs an authorization, which reserves the funds on the customer's credit card, but does not
58
+ # charge the card.
59
+ #
60
+ # Registering of DMS authorisation
61
+ # @param int $amount transaction amount in minor units, mandatory
62
+ # @param int $currency transaction currency code, mandatory
63
+ # @param string $ip clientís IP address, mandatory
64
+ # @param string $desc description of transaction, optional
65
+ # @param string $language authorization language identificator, optional
66
+ # @return string TRANSACTION_ID
67
+ #
68
+ def authorize(amount, params = {})
69
+ params = params.reverse_merge(
70
+ :command => :a,
71
+ :msg_type => 'DMS',
72
+ :amount => amount,
73
+ :currency => default_currency
74
+ )
75
+ requires!(params, :amount, :currency, :client_ip_addr, :msg_type)
76
+ commit(params)
77
+ end
78
+
79
+ # Captures the funds from an authorized transaction.
80
+ #
81
+ # Making of DMS transaction
82
+ # @param int $auth_id id of previously made successeful authorisation
83
+ # @param int $amount transaction amount in minor units, mandatory
84
+ # @param int $currency transaction currency code, mandatory
85
+ # @param string $ip clientís IP address, mandatory
86
+ # @param string $desc description of transaction, optional
87
+ # @return string RESULT, RESULT_CODE, RRN, APPROVAL_CODE
88
+ #
89
+ def capture(amount, trans_id, params = {})
90
+ params = params.reverse_merge(
91
+ :command => :t,
92
+ :msg_type => 'DMS',
93
+ :trans_id => trans_id,
94
+ :amount => amount,
95
+ :currency => default_currency
96
+ )
97
+ requires!(params, :trans_id, :amount, :currency, :client_ip_addr)
98
+ commit(params)
99
+ end
100
+
101
+ # Transaction result
102
+ #
103
+ # @param int $trans_id transaction identifier, mandatory
104
+ # @param string $ip clientís IP address, mandatory
105
+ # @return string RESULT, RESULT_CODE, 3DSECURE, AAV, RRN, APPROVAL_CODE
106
+ #
107
+ def result(trans_id, params = {})
108
+ params = params.reverse_merge(
109
+ :command => :c,
110
+ :trans_id => trans_id
111
+ )
112
+ requires!(params, :trans_id, :client_ip_addr)
113
+ commit(params)
114
+ end
115
+
116
+ # credit() allows you to return money to a card that was previously billed.
117
+ #
118
+ # Transaction reversal
119
+ # @param int $trans_id transaction identifier, mandatory
120
+ # @param int $amount transaction amount in minor units, mandatory
121
+ # @return string RESULT, RESULT_CODE
122
+ #
123
+ def credit(amount, trans_id = nil)
124
+ params = {
125
+ :command => :r,
126
+ :trans_id => trans_id,
127
+ :amount => amount
128
+ }
129
+ requires!(params, :command, :trans_id, :amount)
130
+ commit(params)
131
+ end
132
+
133
+ # Close business day.
134
+ def close_day
135
+ commit({ :command => :b })
136
+ end
137
+
138
+ def endpoint_url
139
+ test? ? test_url : live_url
140
+ end
141
+
142
+ def redirect_url
143
+ test? ? test_redirect_url : live_redirect_url
144
+ end
145
+
146
+ private
147
+
148
+ # Convert HTTP response body to a Ruby Hash.
149
+ def parse(body)
150
+ results = ActiveSupport::HashWithIndifferentAccess.new
151
+ body.split(/[\r\n]+/).each do |pair|
152
+ key, val = pair.split(": ")
153
+ results[key.downcase] = val
154
+ end
155
+ results
156
+ end
157
+
158
+ def commit(params = {})
159
+ response = parse(ssl_post(endpoint_url, post_data(params)))
160
+ raise response[:error] unless response[:error].blank?
161
+ response
162
+ end
163
+
164
+ def post_data(params)
165
+ post = PostData.new
166
+ params.each { |k, v| post[k] = v }
167
+ post.to_s
168
+ end
169
+ end
170
+ end
171
+ end
@@ -0,0 +1 @@
1
+ require "active_merchant/billing/first_data_gateway"
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_merchant_first_data
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Edgars Beigarts
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-07-08 00:00:00.000000000 +03:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activemerchant
17
+ requirement: &2152366380 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 1.15.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2152366380
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: &2152366000 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *2152366000
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ requirement: &2152365440 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 2.6.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *2152365440
48
+ - !ruby/object:Gem::Dependency
49
+ name: vcr
50
+ requirement: &2152365020 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *2152365020
59
+ - !ruby/object:Gem::Dependency
60
+ name: fakeweb
61
+ requirement: &2152364560 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *2152364560
70
+ description: First Data gateway for Active Merchant
71
+ email:
72
+ - edgars.beigarts@makit.lv
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - lib/active_merchant/billing/first_data_gateway.rb
78
+ - lib/active_merchant_first_data.rb
79
+ - README.md
80
+ - LICENSE
81
+ has_rdoc: true
82
+ homepage: https://github.com/ebeigarts/active_merchant_first_data
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 1.6.2
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: First Data gateway for Active Merchant
106
+ test_files: []