active_merchant_tranzila 0.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.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Vitaly Kushner
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.
@@ -0,0 +1,60 @@
1
+ # ActiveMerchantTranzila
2
+
3
+ [Tranzila](http://tranzila.com) gateway support for [ActiveMerchant](http://www.activemerchant.org/).
4
+
5
+ ## Installation
6
+
7
+ ### Requirements
8
+
9
+ First you need the ActiveMerchant gem / rails-plugin installed. More info about
10
+ ActiveMerchant installation can be found in [ActiveMerchant documentation](http://activemerchant.rubyforge.org/).
11
+
12
+ ### As a Rails plugin
13
+
14
+ To install ActiveMerchantTranzila in your rails app you can just do:
15
+
16
+ ./script/plugin install git://github.com/astrails/active_merchant_tranzila
17
+
18
+ ### As a gem
19
+
20
+ To install ActiveMerchantTranzila in your rails app you can just do:
21
+
22
+ config.gem 'active_merchant_tranzila'
23
+
24
+ ## Configuration
25
+
26
+ Signup on [Tranzila site](http://tranzila.com) to obtain your own 'supplier' id.
27
+
28
+ ## Example Usage
29
+
30
+ Once you've configured the Ogone settings you need to set up a leaving page with in your view:
31
+
32
+ gateway = ActiveMerchant::Billing::TranzilaGateway.new(:supplier => 'YOUR_SUPPLIER_ID', :currency => 1)
33
+ creditcard = ActiveMerchant::Billing::CreditCard.new(
34
+ :number => '4444333322221111',
35
+ :month => '09',
36
+ :year => '2015',
37
+ :verification_value => '333'
38
+ )
39
+
40
+ response = gateway.purchase(
41
+ 100, # cents here
42
+ creditcard,
43
+ { :cred_type => '1', :myid => '306122847' }
44
+ )
45
+
46
+ response.inspect
47
+
48
+ ## Note on Patches/Pull Requests
49
+
50
+ * Fork the project.
51
+ * Make your feature addition or bug fix.
52
+ * Add tests for it. This is important so I don't break it in a
53
+ future version unintentionally.
54
+ * Commit, do not mess with rakefile, version, or history.
55
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
56
+ * Send me a pull request. Bonus points for topic branches.
57
+
58
+ ## Copyright
59
+
60
+ Copyright (c) 2010 Astrails Ltd. See LICENSE for details.
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "active_merchant_tranzila"
8
+ gem.summary = %Q{Tranzila gateway support for ActiveMerchant}
9
+ gem.description = %Q{Tranzila gateway support for ActiveMerchant}
10
+ gem.email = "we@astrails.com"
11
+ gem.homepage = "http://github.com/astrails/active_merchant_tranzila"
12
+ gem.authors = ["Astrails Ltd."]
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+ task :test => :check_dependencies
40
+
41
+ task :default => :test
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "active_merchant_tranzila #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,50 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{active_merchant_tranzila}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Astrails Ltd."]
12
+ s.date = %q{2010-08-11}
13
+ s.description = %q{Tranzila gateway support for ActiveMerchant}
14
+ s.email = %q{we@astrails.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ "LICENSE",
21
+ "README.markdown",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "active_merchant_tranzila.gemspec",
25
+ "lib/active_merchant/billing/gateways/tranzila.rb",
26
+ "lib/active_merchant_tranzila.rb",
27
+ "test/helper.rb",
28
+ "test/unit/gateways/tranzila_test.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/astrails/active_merchant_tranzila}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.6}
34
+ s.summary = %q{Tranzila gateway support for ActiveMerchant}
35
+ s.test_files = [
36
+ "test/helper.rb",
37
+ "test/unit/gateways/tranzila_test.rb"
38
+ ]
39
+
40
+ if s.respond_to? :specification_version then
41
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
+ else
46
+ end
47
+ else
48
+ end
49
+ end
50
+
@@ -0,0 +1,438 @@
1
+ require 'active_merchant'
2
+ module ActiveMerchant #:nodoc:
3
+ module Billing #:nodoc:
4
+ # This class implements the Tranzila (http://www.tranzila.com) Israeli payment gateway.
5
+ # Implemented by http://www.astrails.com
6
+ #
7
+ # == Supported transaction types by TranzilaGateway:
8
+ # * - Purchase
9
+ # * - Refund
10
+ # * - Authorize
11
+ # * - Capture
12
+ #
13
+ # == Notes
14
+ # * Recurring billing is not yet implemented.
15
+ # * Adding of order products information is not implemented.
16
+ # * There is no test URL, use tranzila test account
17
+ #
18
+ # Example purchase:
19
+ #
20
+ # gateway = ActiveMerchant::Billing::TranzilaGateway.new(:supplier => 'YOUR_SUPPLIER_ID', :currency => 1)
21
+ # creditcard = ActiveMerchant::Billing::CreditCard.new(
22
+ # :number => '4444333322221111',
23
+ # :month => '09',
24
+ # :year => '2015',
25
+ # :verification_value => '333'
26
+ # )
27
+ #
28
+ # response = gateway.purchase(
29
+ # 100, # cents here
30
+ # creditcard,
31
+ # { :cred_type => '1', :myid => '306122847' }
32
+ # )
33
+ #
34
+ # response.inspect
35
+ class TranzilaGateway < Gateway
36
+
37
+ SHEKEL_DOLLAR_URL = 'https://secure5.tranzila.com/cgi-bin/tranzila31.cgi'
38
+ MULTICURRENCY_URL = 'https://secure5.tranzila.com/cgi-bin/tranzila36a.cgi'
39
+
40
+ RESPONSE_MESSAGES = {
41
+ '000' => 'Transaction approved',
42
+ '001' => 'Blocked confiscate card.',
43
+ '002' => 'Stolen confiscate card.',
44
+ '003' => 'Contact credit company.',
45
+ '004' => 'Refusal.',
46
+ '005' => 'Forged. confiscate card.',
47
+ '006' => 'Identity Number of CVV incorrect.',
48
+ '007' => 'Must contact Credit Card Company',
49
+ '008' => 'Fault in building of access key to blocked cards file.',
50
+ '009' => 'Contact unsuccessful.',
51
+ '010' => 'Program ceased by user instruction (ESC).',
52
+ '011' => 'No confirmation for the ISO currency clearing.',
53
+ '012' => 'No confirmation for the ISO currency type.',
54
+ '013' => 'No confirmation for charge/discharge transaction.',
55
+ '014' => 'Unsupported card',
56
+ '015' => 'Number Entered and Magnetic Strip do not match',
57
+ '017' => 'Last 4 digets not entered',
58
+ '019' => 'Record in INT_IN shorter than 16 characters.',
59
+ '020' => 'Input file (INT_IN) does not exist.',
60
+ '021' => 'Blocked cards file (NEG) non-existent or has not been updated - execute transmission or request authorization for each transaction.',
61
+ '022' => 'One of the parameter files or vectors do not exist.',
62
+ '023' => 'Date file (DATA) does not exist.',
63
+ '024' => 'Format file (START) does not exist.',
64
+ '025' => 'Difference in days in input of blocked cards is too large - execute transmission or request authorization for each transaction.',
65
+ '026' => 'Difference in generations in input of blocked cards is too large - execute transmission or request authorization for each transaction.',
66
+ '027' => 'Where the magnetic strip is not completely entered',
67
+ '028' => 'Central terminal number not entered into terminal defined for work as main supplier.',
68
+ '029' => 'Beneficiary number not entered into terminal defined as main beneficiary.',
69
+ '030' => 'Terminal not updated as main supplier/beneficiary and supplier/beneficiary number entered.',
70
+ '031' => 'Terminal updated as main supplier and beneficiary number entered',
71
+ '032' => 'Old transactions - carry out transmission or request authorization for each transaction.',
72
+ '033' => 'Defective card',
73
+ '034' => 'Card not permitted for this terminal or no authorization for this type of transaction.',
74
+ '035' => 'Card not permitted for transaction or type of credit.',
75
+ '036' => 'Expired.',
76
+ '037' => 'Error in instalments - Amount of transaction needs to be equal to the first instalment + (fixed instalments times no. of instalments)',
77
+ '038' => 'Cannot execute transaction in excess of credit card ceiling for immediate debit.',
78
+ '039' => 'Control number incorrect.',
79
+ '040' => 'Terminal defined as main beneficiary and supplier number entered.',
80
+ '041' => 'Exceeds ceiling where input file contains J1 or J2 or J3 (contact prohibited).',
81
+ '042' => 'Card blocked for supplier where input file contains J1 or J2 or J3 (contact prohibited).',
82
+ '043' => 'Random where input file contains J1 (contact prohibited).',
83
+ '044' => 'Terminal prohibited from requesting authorization without transaction (J5)',
84
+ '045' => 'Terminal prohibited for supplier-initiated authorization request (J6)',
85
+ '046' => 'Terminal must request authorization where input file contains J1 or J2 or J3 (contact prohibited).',
86
+ '047' => 'Secret code must be entered where input file contains J1 or J2 or J3 (contact prohibited).',
87
+ '051' => ' Vehicle number defective.',
88
+ '052' => 'Distance meter not entered.',
89
+ '053' => 'Terminal not defined as gas station. (petrol card passed or incorrect transaction code).',
90
+ '057' => 'Identity Number Not Entered',
91
+ '058' => 'CVV2 Not Entered',
92
+ '059' => 'Identiy Number and CVV2 Not Entered',
93
+ '060' => 'ABS attachment not found at start of input data in memory.',
94
+ '061' => 'Card number not found or found twice',
95
+ '062' => 'Incorrect transaction type',
96
+ '063' => 'Incorrect transaction code.',
97
+ '064' => 'Type of credit incorrect.',
98
+ '065' => 'Incorrect currency.',
99
+ '066' => 'First instalment and/or fixed payment exists for non-instalments type of credit.',
100
+ '067' => 'Number of instalments exists for type of credit not requiring this.',
101
+ '068' => 'Linkage to dollar or index not possible for credit other than instalments.',
102
+ '069' => 'Length of magnetic strip too short.',
103
+ '070' => 'PIN terminal not defined',
104
+ '071' => 'PIN must be enetered',
105
+ '072' => 'Secret code not entered.',
106
+ '073' => 'Incorrect secret code.',
107
+ '074' => 'Incorrect secret code - last try.',
108
+ '079' => 'Currency is not listed in vector 59.',
109
+ '080' => '"Club code" entered for unsuitable credit type',
110
+ '090' => 'Transaction cancelling is not allowed for this card.',
111
+ '091' => 'Transaction cancelling is not allowed for this card.',
112
+ '092' => 'Transaction cancelling is not allowed for this card.',
113
+ '099' => 'Cannot read/write/open TRAN file.',
114
+ '100' => 'No equipment for inputting secret code.',
115
+ '101' => 'No authorization from credit company for work.',
116
+ '107' => 'Transaction amount too large - split into a number of transactions.',
117
+ '108' => 'Terminal not authorized to execute forced actions.',
118
+ '109' => 'Terminal not authorized for card with service code 587.',
119
+ '110' => 'Terminal not authorized for immediate debit card.',
120
+ '111' => 'Terminal not authorized for instalments transaction.',
121
+ '112' => 'Terminal not authorized for telephone/signature only instalments transaction.',
122
+ '113' => 'Terminal not authorized for telephone transaction.',
123
+ '114' => 'Terminal not authorized for "signature only" transaction.',
124
+ '115' => 'Terminal not authorized for dollar transaction.',
125
+ '116' => 'Terminal not authorized for club transaction.',
126
+ '117' => 'Terminal not authorized for stars/points/miles transaction.',
127
+ '118' => 'Terminal not authorized for Isracredit credit.',
128
+ '119' => 'Terminal not authorized for Amex Credit credit.',
129
+ '120' => 'Terminal not authorized for dollar linkage.',
130
+ '121' => 'Terminal not authorized for index linkage.',
131
+ '122' => 'Terminal not authorized for index linkage with foreign cards.',
132
+ '123' => 'Terminal not authorized for stars/points/miles transaction for this type of credit.',
133
+ '124' => 'Terminal not authorized for Isracredit payments.',
134
+ '125' => 'Terminal not authorized for Amex payments.',
135
+ '126' => 'Terminal not authorized for this club code.',
136
+ '127' => 'Terminal not authorized for immediate debit transaction except for immediate debit cards.',
137
+ '128' => 'Terminal not authorized to accept Visa card staring with 3.',
138
+ '129' => 'Terminal not authorized to execute credit transaction above the ceiling.',
139
+ '130' => 'Card not permitted for execution of club transaction.',
140
+ '131' => 'Card not permitted for execution stars/points/miles transaction.',
141
+ '132' => 'Card not permitted for execution of dollar transactions (regular or telephone).',
142
+ '133' => 'Card not valid according Isracard list of valid cards.',
143
+ '134' => 'Defective card according to system definitions (Isracard VECTOR1) - no. of figures on card - error.',
144
+ '135' => 'Card not permitted to execute dollar transactions according to system definition (Isracard VECTOR1).',
145
+ '136' => 'Card belongs to group not permitted to execute transactions according to system definition (Visa VECTOR 20).',
146
+ '137' => 'Card prefix (7 figures) invalid according to system definition (Diners VECTOR21)',
147
+ '138' => 'Card not permitted to carry out instalments transaction according to Isracard list of valid cards.',
148
+ '139' => 'Number of instalments too large according to Isracard list of valid cards.',
149
+ '140' => 'Visa and Diners cards not permitted for club instalments transactions.',
150
+ '141' => 'Series of cards not valid according to system definition (Isracard VECTOR5).',
151
+ '142' => 'Invalid service code according to system definition (Isracard VECTOR6).',
152
+ '143' => 'Card prefix (2 figures) invalid according to system definition (Isracard VECTOR7).',
153
+ '144' => 'Invalid service code according to system definition (Visa VECTOR12).',
154
+ '145' => 'Invalid service code according to system definition (Visa VECTOR13).',
155
+ '146' => 'Immediate debit card prohibited for execution of credit transaction.',
156
+ '147' => 'Card not permitted to execute instalments transaction according to Leumicard vector no. 31.',
157
+ '148' => 'Card not permitted for telephone and signature only transaction according to Leumicard vector no. 31',
158
+ '149' => 'Card not permitted for telephone transaction according to Leumicard vector no. 31',
159
+ '150' => 'Credit not approved for immediate debit cards.',
160
+ '151' => 'Credit not approved for foreign cards.',
161
+ '152' => 'Club code incorrect.',
162
+ '153' => 'Card not permitted to execute flexible credit transactions (Adif/30+) according to system definition (Diners VECTOR21).',
163
+ '154' => 'Card not permitted to execute immediate debit transactions according to system definition (Diners VECTOR21).',
164
+ '155' => 'Amount of payment for credit transaction too small.',
165
+ '156' => 'Incorrect number of instalments for credit transaction',
166
+ '157' => '0 ceiling for this type of card for regular credit or Credit transaction.',
167
+ '158' => '0 ceiling for this type of card for immediate debit credit transaction',
168
+ '159' => '0 ceiling for this type of card for immediate debit in dollars.',
169
+ '160' => '0 ceiling for this type of card for telephone transaction.',
170
+ '161' => '0 ceiling for this type of card for credit transaction.',
171
+ '162' => '0 ceiling for this type of card for instalments transaction.',
172
+ '163' => 'American Express card issued abroad not permitted for instalments transaction.',
173
+ '164' => 'JCB cards permitted to carry out regular credit transactions.',
174
+ '165' => 'Amount in stars/points/miles larger than transaction amount.',
175
+ '166' => 'Club card not in terminal range.',
176
+ '167' => 'Stars/points/miles transaction cannot be executed.',
177
+ '168' => 'Dollar transaction cannot be executed for this type of card.',
178
+ '169' => 'Credit transaction cannot be executed with other than regular credit.',
179
+ '170' => 'Amount of discount on stars/points/miles greater than permitted.',
180
+ '171' => 'Forced transaction cannot be executed with credit/immediate debut card.',
181
+ '172' => 'Previous transaction cannot be cancelled (credit transaction or card number not identical).',
182
+ '173' => 'Double transaction.',
183
+ '174' => 'Terminal not permitted for index linkage for this type of credit.',
184
+ '175' => 'Terminal not permitted for dollar linkage for this type of credit.',
185
+ '176' => 'Card invalid according to system definition (Isracard VECTOR1)',
186
+ '177' => 'Cannot execute "Self-Service" transaction at gas stations except at "Self-Service at gas stations".',
187
+ '178' => 'Credit transaction forbidden with stars/points/miles.',
188
+ '179' => 'Dollar credit transaction forbidden on tourist card.',
189
+ '180' => 'Club Card can not preform Telephone Transactions',
190
+ '200' => 'Application error.',
191
+ '700' => 'Approved TEST Masav transaction',
192
+ '701' => 'Invalid Bank Number',
193
+ '702' => 'Invalid Branch Number',
194
+ '703' => 'Invalid Account Number',
195
+ '704' => 'Incorrect Bank/Branch/Account Combination',
196
+ '705' => 'Application Error',
197
+ '706' => 'Supplier directory does not exist',
198
+ '707' => 'Supplier configuration does not exist',
199
+ '708' => 'Charge amount zero or negative',
200
+ '709' => 'Invalid configuration file',
201
+ '710' => 'Invalid date format',
202
+ '711' => 'DB Error',
203
+ '712' => 'Required parameter is missing',
204
+ '800' => 'Transaction Canceled',
205
+ '900' => '3D Secure Failed',
206
+ '903' => 'Fraud suspected',
207
+ '951' => 'Protocol Error',
208
+ '952' => 'Payment not completed',
209
+ '954' => 'Payment Failed',
210
+ '955' => 'Payment status error',
211
+ '959' => 'Payment completed unsuccessfully',
212
+ }
213
+
214
+ # The homepage URL of the gateway
215
+ self.homepage_url = 'http://tranzila.com'
216
+
217
+ # The name of the gateway
218
+ self.display_name = 'Tranzila'
219
+
220
+ # Creates a new TranzilaGateway
221
+ #
222
+ # The gateway requires that a valid supplier name be passed
223
+ # in the +options+ hash.
224
+ #
225
+ # ==== Options
226
+ #
227
+ # * <tt>options</tt>
228
+ # * <tt>:currency</tt> - Possible values:
229
+ # 1 - Shekels
230
+ # 2 - US Dollars
231
+ # 3 - GBP
232
+ # 4 - Shekel transaction with installments linked to the US Dollar
233
+ # 5 - HKD
234
+ # 6 - JPY
235
+ # 7 - Euro
236
+ # 8 - Index-linked installments transaction
237
+ # * <tt>:supplier</tt> - The Tranzila account name.
238
+ def initialize(options = {})
239
+ requires!(options, :supplier, :currency)
240
+ @options = options
241
+ super
242
+ end
243
+
244
+ # Authorize and immediately capture funds from a credit card.
245
+ #
246
+ # ==== Parameters
247
+ #
248
+ # * <tt>money</tt> - The amount to be authorized and captured as an Integer value in cents or agorot.
249
+ # * <tt>creditcard</tt> - The CreditCard details for the transaction.
250
+ # * <tt>options</tt>
251
+ # * <tt>:cred_type</tt> - Possible values:
252
+ # 1- Regular Credit
253
+ # 2- Isracredit, Visa Adif/30+, Amex Credit, Diners Adif/30+
254
+ # 3- Immediate Debit
255
+ # 4- Club Credit
256
+ # 5- Leumi Special
257
+ # 6- Visa credit, Diners credit, Isra36, Amex 36
258
+ # 8- Installments
259
+ # 9- Club installments
260
+ # * <tt>:myid</tt> - Israeli ID number (9 digits)
261
+ def purchase(cents, creditcard, options = {})
262
+ requires!(options, :cred_type, :myid)
263
+ commit('sale', cents, creditcard, options)
264
+ end
265
+
266
+ # Authorize
267
+ #
268
+ # ==== Parameters
269
+ #
270
+ # * <tt>money</tt> - The amount to be authorized as an Integer value in cents or agorot.
271
+ # * <tt>creditcard</tt> - The CreditCard details for the transaction.
272
+ # * <tt>options</tt>
273
+ # * <tt>:cred_type</tt> - Possible values:
274
+ # 1- Regular Credit
275
+ # 2- Isracredit, Visa Adif/30+, Amex Credit, Diners Adif/30+
276
+ # 3- Immediate Debit
277
+ # 4- Club Credit
278
+ # 5- Leumi Special
279
+ # 6- Visa credit, Diners credit, Isra36, Amex 36
280
+ # 8- Installments
281
+ # 9- Club installments
282
+ # * <tt>:myid</tt> - Israeli ID number (9 digits)
283
+ def authorize(money, creditcard, options = {})
284
+ requires!(options, :cred_type, :myid)
285
+ commit('authorize', money, creditcard, options)
286
+ end
287
+
288
+ # Capture funds
289
+ #
290
+ # ==== Parameters
291
+ #
292
+ # * <tt>money</tt> - The amount to be authorized as an Integer value in cents or agorot.
293
+ # * <tt>creditcard</tt> - The CreditCard details for the transaction.
294
+ # * <tt>options</tt>
295
+ # * <tt>:ConfirmationCode</tt> - The ConfirmationCode parameter got from the from the Purchase or Authorize request
296
+ # * <tt>:cred_type</tt> - Possible values:
297
+ # 1- Regular Credit
298
+ # 2- Isracredit, Visa Adif/30+, Amex Credit, Diners Adif/30+
299
+ # 3- Immediate Debit
300
+ # 4- Club Credit
301
+ # 5- Leumi Special
302
+ # 6- Visa credit, Diners credit, Isra36, Amex 36
303
+ # 8- Installments
304
+ # 9- Club installments
305
+ # * <tt>:myid</tt> - Israeli ID number (9 digits)
306
+ def capture(money, creditcard, options = {})
307
+ requires!(options, :cred_type, :myid, :ConfirmationCode)
308
+ commit('capture', money, creditcard, options)
309
+ end
310
+
311
+ # Refund (credit) the transaction
312
+ #
313
+ # ==== Parameters
314
+ #
315
+ # * <tt>money</tt> - The amount to be authorized as an Integer value in cents or agorot.
316
+ # * <tt>creditcard</tt> - The CreditCard details for the transaction.
317
+ # * <tt>options</tt>
318
+ # * <tt>:index</tt> - Tranzila transaction index number. Should be reseived from the Purchase or Authorize request
319
+ # * <tt>:ConfirmationCode</tt> - The ConfirmationCode parameter got from the from the Purchase or Authorize request
320
+ # * <tt>:cred_type</tt> - Possible values:
321
+ # 1- Regular Credit
322
+ # 2- Isracredit, Visa Adif/30+, Amex Credit, Diners Adif/30+
323
+ # 3- Immediate Debit
324
+ # 4- Club Credit
325
+ # 5- Leumi Special
326
+ # 6- Visa credit, Diners credit, Isra36, Amex 36
327
+ # 8- Installments
328
+ # 9- Club installments
329
+ # * <tt>:myid</tt> - Israeli ID number (9 digits)
330
+ def refund(money, creditcard, options = {})
331
+ requires!(options, :index, :ConfirmationCode)
332
+ commit('refund', money, creditcard, options)
333
+ end
334
+
335
+ private
336
+
337
+ def parse(body)
338
+ response_to_h(body.try(:chop!).try(:chop!))
339
+ end
340
+
341
+ def response_to_h(body)
342
+ parts = body.split(/&|=/)
343
+ Hash[*parts]
344
+ end
345
+
346
+ def commit(action, money, creditcard, options = {})
347
+ response = parse(ssl_post(multicurrency? ? MULTICURRENCY_URL : SHEKEL_DOLLAR_URL, post_data(action, money, creditcard, options)))
348
+
349
+ Response.new(successful?(response), message_from(response), response,
350
+ :test => test?,
351
+ :authorization => response['ConfirmationCode'],
352
+ :cvv_result => response['CVVstatus']
353
+ )
354
+ end
355
+
356
+ def multicurrency?
357
+ ![1, 2, 4].include?(@options[:currency])
358
+ end
359
+
360
+ def successful?(response)
361
+ response['Response'] == "000"
362
+ end
363
+
364
+ def message_from(response)
365
+ RESPONSE_MESSAGES.fetch(response.fetch('Response', nil), nil)
366
+ end
367
+
368
+ def post_data(action, money, creditcard, options = {})
369
+ return purchase_parameters(money, creditcard, options) if action == 'sale'
370
+ return refund_parametes(money, creditcard, options) if action == 'refund'
371
+ return authorize_parameters(money, creditcard, options) if action == 'authorize'
372
+ return capture_parameters(money, creditcard, options) if action == 'capture'
373
+ end
374
+
375
+ def capture_parameters(money, creditcard, options = {})
376
+ to_query_s({
377
+ :task => "Doforce",
378
+ :tranmode => 'F',
379
+ :authnr => options[:ConfirmationCode]
380
+ }.merge(default_parameters_hash(money, creditcard, options)))
381
+ end
382
+
383
+ def authorize_parameters(money, creditcard, options = {})
384
+ to_query_s({
385
+ :task => 'Doverify',
386
+ :tranmode => 'V',
387
+ }.merge(default_parameters_hash(money, creditcard, options)))
388
+ end
389
+
390
+ def refund_parametes(money, creditcard, options = {})
391
+ to_query_s({
392
+ :tranmode => "C#{options[:index]}",
393
+ :authnr => options[:ConfirmationCode],
394
+ }.merge(default_parameters_hash(money, creditcard, options)))
395
+ end
396
+
397
+ def purchase_parameters(money, creditcard, options = {})
398
+ to_query_s(default_parameters_hash(money, creditcard, options))
399
+ end
400
+
401
+ def default_parameters_hash(money, creditcard, options = {})
402
+ {
403
+ :sum => amount(money),
404
+ :ccno => creditcard.number,
405
+ :expyear => creditcard.year.to_s[-2, 2],
406
+ :expmonth => creditcard.month,
407
+ :expdate => "#{creditcard.month}#{creditcard.year.to_s[-2, 2]}",
408
+ :mycvv => creditcard.verification_value,
409
+
410
+ #Possible Values:
411
+ #1- Regular Credit
412
+ #2- Isracredit, Visa Adif/30+,Amex Credit, Diners Adif/30+
413
+ #3- Immediate Debit
414
+ #4- Club Credit
415
+ #5- Leumi Special
416
+ #6- Visa credit, Diners credit, Isra36, Amex 36
417
+ #8- Installments
418
+ #9- Club installments
419
+ :cred_type => options[:cred_type],
420
+ :currency => @options[:currency],
421
+ :myid => options[:myid],
422
+
423
+ #transaction with monthly installments not supported yet
424
+ #:fpay => options[:myid],
425
+ #:spay => options[:spay],
426
+ #:npay => options[:npay],
427
+
428
+ #tranzila registered supplier (test3)
429
+ :supplier => @options[:supplier]
430
+ }
431
+ end
432
+
433
+ def to_query_s(hash)
434
+ hash.map{|k,v| "#{k}=#{v}"}.join("&")
435
+ end
436
+ end
437
+ end
438
+ end
@@ -0,0 +1 @@
1
+ require 'active_merchant/billing/gateways/tranzila'
@@ -0,0 +1,107 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'mocha'
4
+
5
+
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ require 'active_merchant_tranzila'
9
+
10
+ ActiveMerchant::Billing::Base.mode = :test
11
+
12
+ module ActiveMerchant
13
+ module Assertions
14
+ AssertionClass = RUBY_VERSION > '1.9' ? MiniTest::Assertion : Test::Unit::AssertionFailedError
15
+
16
+ def assert_field(field, value)
17
+ clean_backtrace do
18
+ assert_equal value, @helper.fields[field]
19
+ end
20
+ end
21
+
22
+ # Allows the testing of you to check for negative assertions:
23
+ #
24
+ # # Instead of
25
+ # assert !something_that_is_false
26
+ #
27
+ # # Do this
28
+ # assert_false something_that_should_be_false
29
+ #
30
+ # An optional +msg+ parameter is available to help you debug.
31
+ def assert_false(boolean, message = nil)
32
+ message = build_message message, '<?> is not false or nil.', boolean
33
+
34
+ clean_backtrace do
35
+ assert_block message do
36
+ not boolean
37
+ end
38
+ end
39
+ end
40
+
41
+ # A handy little assertion to check for a successful response:
42
+ #
43
+ # # Instead of
44
+ # assert_success response
45
+ #
46
+ # # DRY that up with
47
+ # assert_success response
48
+ #
49
+ # A message will automatically show the inspection of the response
50
+ # object if things go afoul.
51
+ def assert_success(response)
52
+ clean_backtrace do
53
+ assert response.success?, "Response failed: #{response.inspect}"
54
+ end
55
+ end
56
+
57
+ # The negative of +assert_success+
58
+ def assert_failure(response)
59
+ clean_backtrace do
60
+ assert_false response.success?, "Response expected to fail: #{response.inspect}"
61
+ end
62
+ end
63
+
64
+ def assert_valid(validateable)
65
+ clean_backtrace do
66
+ assert validateable.valid?, "Expected to be valid"
67
+ end
68
+ end
69
+
70
+ def assert_not_valid(validateable)
71
+ clean_backtrace do
72
+ assert_false validateable.valid?, "Expected to not be valid"
73
+ end
74
+ end
75
+
76
+ private
77
+ def clean_backtrace(&block)
78
+ yield
79
+ rescue AssertionClass => e
80
+ path = File.expand_path(__FILE__)
81
+ raise AssertionClass, e.message, e.backtrace.reject { |line| File.expand_path(line) =~ /#{path}/ }
82
+ end
83
+ end
84
+
85
+ module Fixtures
86
+ private
87
+ def credit_card(number = '4242424242424242', options = {})
88
+ defaults = {
89
+ :number => number,
90
+ :month => 9,
91
+ :year => Time.now.year + 1,
92
+ :first_name => 'Longbob',
93
+ :last_name => 'Longsen',
94
+ :verification_value => '123',
95
+ :type => 'visa'
96
+ }.update(options)
97
+
98
+ Billing::CreditCard.new(defaults)
99
+ end
100
+ end
101
+ end
102
+
103
+ class Test::Unit::TestCase
104
+ include ActiveMerchant::Billing
105
+ include ActiveMerchant::Fixtures
106
+ include ActiveMerchant::Assertions
107
+ end
@@ -0,0 +1,108 @@
1
+ require 'helper'
2
+ require 'rubygems'
3
+ require 'ruby-debug'
4
+
5
+ class TranzilaTest < Test::Unit::TestCase
6
+ def setup
7
+ @gateway = TranzilaGateway.new(:supplier => 'test3', :currency => '1')
8
+
9
+ @credit_card = credit_card('4444333322221111')
10
+ @amount = 100.00
11
+
12
+ @options = {
13
+ :cred_type => '1',
14
+ :myid => '306122847',
15
+ :ConfirmationCode => '0000000',
16
+ :index => '11'
17
+ }
18
+ end
19
+
20
+ def test_successful(successful_response, action)
21
+ @gateway.expects(:ssl_post).returns(successful_response)
22
+
23
+ assert response = @gateway.send(action, @amount, @credit_card, @options)
24
+ assert_instance_of Response, response
25
+ assert_success response
26
+
27
+ assert_equal '000', response.params['Response']
28
+ assert response.test?
29
+ end
30
+
31
+ def test_unsuccessful(failed_response, action, opts = {})
32
+ @gateway.expects(:ssl_post).returns(failed_response)
33
+
34
+ assert response = @gateway.send(action, @amount, @credit_card, @options)
35
+ assert_failure response
36
+ assert response.test?
37
+ end
38
+
39
+ def test_successful_purchase
40
+ test_successful(successful_purchase_response, :purchase)
41
+ end
42
+
43
+ def test_unsuccessful_purchase
44
+ test_unsuccessful(failed_purchase_response, :purchase)
45
+ end
46
+
47
+ def test_successful_authorize
48
+ test_successful(successful_authorize_response, :authorize)
49
+ end
50
+
51
+ def test_unsuccessful_authorize
52
+ test_unsuccessful(failed_authorize_response, :authorize)
53
+ end
54
+
55
+ def test_successful_capture
56
+ test_successful(successful_capture_response, :capture)
57
+ end
58
+
59
+ def test_unsuccessful_capture
60
+ test_unsuccessful(failed_capture_response, :capture)
61
+ end
62
+
63
+ def test_successful_refund
64
+ test_successful(successful_refund_response, :refund)
65
+ end
66
+
67
+ def test_unsuccessful_capture
68
+ test_unsuccessful(failed_refund_response, :refund)
69
+ end
70
+
71
+ private
72
+
73
+ def failed_refund_response
74
+ "<html><head><META NAME=\"ROBOTS\" CONTENT=\"NOINDEX, NOFOLLOW\"></head><body>\n<center><h1>Tranzila</h1><br>\nAn error ocurred with the following message:<br>\n<h3><b><font color=red> Transaction can't be credited </font></b><br></h3>\nPlease use the BACK button in your browser.<br>\n</center></body></html>"
75
+ end
76
+
77
+ def successful_refund_response
78
+ "Response=000&mycvv=333&expmonth=09&task=Doforce&myid=306122847&currency=1&cred_type=1&ccno=4444333322221111&expyear=15&authnr=0000000&supplier=test3&expdate=0915&tranmode=F&sum=1.00&ConfirmationCode=0000000&index=112&Tempref=03870001\n\n"
79
+ end
80
+
81
+ def successful_capture_response
82
+ "Response=000&mycvv=333&expmonth=09&task=Doforce&myid=306122847&currency=1&cred_type=1&ccno=4444333322221111&expyear=15&authnr=0000000&supplier=test3&expdate=0915&tranmode=F&sum=1.00&ConfirmationCode=0000000&index=112&Tempref=03870001\n\n"
83
+ end
84
+
85
+ def failed_capture_response
86
+ "Response=004&mycvv=333&expmonth=09&task=Doforce&myid=306122847&currency=1&cred_type=1&ccno=4444333322221111&expyear=15&authnr=0000000&supplier=test3&expdate=0915&tranmode=F&sum=1.00&ConfirmationCode=0000000&index=112&Tempref=03870001\n\n"
87
+ end
88
+
89
+ #
90
+ def successful_authorize_response
91
+ "Response=000&mycvv=333&expmonth=09&task=Doverify&myid=306122847&currency=1&cred_type=1&ccno=4444333322221111&expyear=15&supplier=test3&expdate=0915&tranmode=V&sum=1.00&ConfirmationCode=0000000&index=110&Tempref=03480001\n\n"
92
+ end
93
+
94
+ def failed_authorize_response
95
+ "Response=004&mycvv=333&expmonth=09&task=Doverify&myid=306122847&currency=1&cred_type=1&ccno=4444333322221111&expyear=15&supplier=test3&expdate=0915&tranmode=V&sum=1.00&ConfirmationCode=0000000&index=110&Tempref=03480001\n\n"
96
+ end
97
+
98
+ # raw failed response from gateway here
99
+ def failed_purchase_response
100
+ "Response=004&fpay=&mycvv=123&expmonth=9&spay=&myid=306122847&currency=1&ccno=4444333322221111&cred_type=1&expyear=15&supplier=test3&npay=&id=6&expdate=915&sum=100.0&ConfirmationCode=0000000&index=11&Tempref=01130001&CVVstatus=3&Responsesource=2\n\n"
101
+ end
102
+
103
+ # raw successful response from gateway here
104
+ def successful_purchase_response
105
+ "Response=000&ccno=4444333322221111&currency=1&cred_type=1&mycvv=123&expyear=15&supplier=test3&expmonth=09&myid=306122847&expdate=0915&sum=1.00&ConfirmationCode=0000000&index=88&Tempref=01300001&CVVstatus=3&Responsesource=0\n\n"
106
+ end
107
+
108
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_merchant_tranzila
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Astrails Ltd.
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-11 00:00:00 +03:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Tranzila gateway support for ActiveMerchant
22
+ email: we@astrails.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - LICENSE
29
+ - README.markdown
30
+ files:
31
+ - LICENSE
32
+ - README.markdown
33
+ - Rakefile
34
+ - VERSION
35
+ - active_merchant_tranzila.gemspec
36
+ - lib/active_merchant/billing/gateways/tranzila.rb
37
+ - lib/active_merchant_tranzila.rb
38
+ - test/helper.rb
39
+ - test/unit/gateways/tranzila_test.rb
40
+ has_rdoc: true
41
+ homepage: http://github.com/astrails/active_merchant_tranzila
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --charset=UTF-8
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.6
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Tranzila gateway support for ActiveMerchant
70
+ test_files:
71
+ - test/helper.rb
72
+ - test/unit/gateways/tranzila_test.rb