authorize_cim 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +10 -0
- data/Gemfile.lock +34 -0
- data/README +0 -0
- data/Rakefile +27 -0
- data/VERSION +1 -0
- data/lib/authorize_cim.rb +687 -0
- data/spec/base.rb +2 -0
- data/spec/lib/authorize_cim_spec.rb +206 -0
- metadata +163 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.2.2)
|
5
|
+
builder (2.1.2)
|
6
|
+
crack (0.1.8)
|
7
|
+
diff-lcs (1.1.2)
|
8
|
+
git (1.2.5)
|
9
|
+
jeweler (1.5.1)
|
10
|
+
bundler (~> 1.0.0)
|
11
|
+
git (>= 1.2.5)
|
12
|
+
rake
|
13
|
+
rake (0.8.7)
|
14
|
+
rspec (2.1.0)
|
15
|
+
rspec-core (~> 2.1.0)
|
16
|
+
rspec-expectations (~> 2.1.0)
|
17
|
+
rspec-mocks (~> 2.1.0)
|
18
|
+
rspec-core (2.1.0)
|
19
|
+
rspec-expectations (2.1.0)
|
20
|
+
diff-lcs (~> 1.1.2)
|
21
|
+
rspec-mocks (2.1.0)
|
22
|
+
webmock (1.5.0)
|
23
|
+
addressable (>= 2.2.2)
|
24
|
+
crack (>= 0.1.7)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
builder
|
31
|
+
crack
|
32
|
+
jeweler
|
33
|
+
rspec
|
34
|
+
webmock
|
data/README
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'jeweler'
|
3
|
+
require 'rspec'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
|
8
|
+
gem.name = "authorize_cim"
|
9
|
+
gem.summary = %Q{Ruby Gem for integrating Authorize.net Customer Information Manager (CIM)}
|
10
|
+
gem.description = %Q{Ruby Gem for integrating Authorize.net Customer Information Manager (CIM)}
|
11
|
+
gem.email = "tylerflint@gmail.com"
|
12
|
+
gem.homepage = "http://github.com/tylerflint/authorize_cim"
|
13
|
+
gem.authors = ["Tyler Flint", "Lyon Hill"]
|
14
|
+
gem.files = Dir["{lib}/**/*", "{spec}/**/*","[A-Z]*"]
|
15
|
+
|
16
|
+
gem.add_dependency "crack"
|
17
|
+
gem.add_dependency "builder"
|
18
|
+
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Run all specs"
|
23
|
+
RSpec::Core::RakeTask.new('spec') do |t|
|
24
|
+
t.rspec_opts = ['--colour --format progress']
|
25
|
+
end
|
26
|
+
|
27
|
+
task :default => :spec
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,687 @@
|
|
1
|
+
require 'crack'
|
2
|
+
require 'builder'
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'net/https'
|
6
|
+
|
7
|
+
class InvalidOrMissingCredentials < Exception
|
8
|
+
end
|
9
|
+
|
10
|
+
class AuthorizeCim
|
11
|
+
|
12
|
+
def initialize(attrs)
|
13
|
+
|
14
|
+
raise InvalidOrMissingCredentials unless attrs[:key] && attrs[:login]
|
15
|
+
|
16
|
+
@key = attrs[:key]
|
17
|
+
@login = attrs[:login]
|
18
|
+
|
19
|
+
@endpoint = case attrs[:endpoint]
|
20
|
+
when :live then 'https://api.authorize.net/xml/v1/request.api'
|
21
|
+
when :test then 'https://apitest.authorize.net/xml/v1/request.api'
|
22
|
+
else 'https://api.authorize.net/xml/v1/request.api'
|
23
|
+
end
|
24
|
+
@uri = URI.parse(@endpoint)
|
25
|
+
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
# Create a new customer profile
|
30
|
+
#
|
31
|
+
#
|
32
|
+
# params:
|
33
|
+
# Necessary:
|
34
|
+
# :merchant_id => '<some id>' (up to 20 characters)
|
35
|
+
# or
|
36
|
+
# :description => '<some discription>' (up to 255 characters)
|
37
|
+
# or
|
38
|
+
# :email => '<emailaddress>' (up to 255 characters)
|
39
|
+
#
|
40
|
+
# return:
|
41
|
+
# xml return converted to hash containing the return_code and customer_profile_id
|
42
|
+
# note: a return code of I00001 is good, anything else is bad
|
43
|
+
#
|
44
|
+
def create_customer_profile(input)
|
45
|
+
data = build_request('createCustomerProfileRequest') do |xml|
|
46
|
+
xml.tag!('profile') do
|
47
|
+
xml.merchantCustomerId input[:merchant_id] if input[:merchant_id]
|
48
|
+
xml.description input[:description] if input[:description]
|
49
|
+
xml.email input[:email] if input[:email]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
parse send(data)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Create a new customer payment profile for an existing customer profile.
|
56
|
+
# You can create up to 10 payment profiles for each customer profile.
|
57
|
+
#
|
58
|
+
# params:
|
59
|
+
# A hash containing all necessary fields
|
60
|
+
# all possible params:
|
61
|
+
# :ref_id => '<id>' (up to 20 digits (optional))
|
62
|
+
# :customer_profile_id => <id of customer> (numeric (necessary))
|
63
|
+
# :payment_profile => {
|
64
|
+
# :bill_to => { (optional)
|
65
|
+
# :first_name => '<billing first name>' (up to 50 characters (optional))
|
66
|
+
# :last_name => '<billing last name>' (up to 50 characters (optional))
|
67
|
+
# :company => '<company name>' (up to 50 characters (optional))
|
68
|
+
# :address => '<address>' (up to 60 characters (optional))
|
69
|
+
# :city => '<city>' (up to 40 characters (optional))
|
70
|
+
# :state => '<state>' (valid 2 character state code (optional))
|
71
|
+
# :zip => '<zip code>' (up to 20 characters (optional))
|
72
|
+
# :country => '<country>' (up to 60 characters (optional))
|
73
|
+
# :phone_number => '<phone number>' (up to 25 digits (optional))
|
74
|
+
# :fax_number => '<fax number>' (up to 25 digits (optional))
|
75
|
+
# }
|
76
|
+
# :payment => { (NECESSARY > must include either bank info or credit card info)
|
77
|
+
# :credit_card => { (necessary if there is no bank_account in payment hash)
|
78
|
+
# :card_number => <number> (13 to 16 digits (necessary))
|
79
|
+
# :expiration_date => '<YYYY-MM>' (has to be 4 digit year, dash line, then 2 digit month (necessary))
|
80
|
+
# :card_code => <number> (3 or 4 digit number on back of card (optional))
|
81
|
+
# }
|
82
|
+
# :bank_account => { (necessary if there is no credit_card in payment hash)
|
83
|
+
# :account_type => '<type of account>' (must be "checking", "savings", or "businessChecking" (necessary))
|
84
|
+
# :routing_number => <number> (9 digit bank routing number (necessary))
|
85
|
+
# :account_number => <number> (5 to 17 digit number (necessary))
|
86
|
+
# :name_on_account => '<name>' (up to 22 characters (necessary))
|
87
|
+
# :echeck_type => '<type>' (needs to be 'CCD', 'PPD', 'TEL', or 'WEB' (optional))
|
88
|
+
# :bank_name => '<bank name>' (up to 50 characters (optional))
|
89
|
+
# }
|
90
|
+
#
|
91
|
+
# }
|
92
|
+
# }
|
93
|
+
# :validation_mode => '<mode>' (needs to be 'none', 'testMode', 'liveMode', or 'oldLiveMode' (necessary))
|
94
|
+
#
|
95
|
+
# returns:
|
96
|
+
# xml converted to hash table for easy access
|
97
|
+
#
|
98
|
+
def create_customer_payment_profile(input)
|
99
|
+
data = build_request('createCustomerPaymentProfileRequest') do |xml|
|
100
|
+
xml.refId input[:ref_id] if input[:ref_id]
|
101
|
+
xml.customerProfileId input[:customer_profile_id] if input[:customer_profile_id]
|
102
|
+
xml.tag!('paymentProfile') do
|
103
|
+
if input[:payment_profile][:bill_to]
|
104
|
+
xml.tag!('billTo') do
|
105
|
+
xml.firstName input[:payment_profile][:bill_to][:first_name] if input[:payment_profile][:bill_to][:first_name]
|
106
|
+
xml.lastName input[:payment_profile][:bill_to][:last_name] if input[:payment_profile][:bill_to][:last_name]
|
107
|
+
xml.company input[:payment_profile][:bill_to][:company] if input[:payment_profile][:bill_to][:company]
|
108
|
+
xml.address input[:payment_profile][:bill_to][:address] if input[:payment_profile][:bill_to][:address]
|
109
|
+
xml.city input[:payment_profile][:bill_to][:city] if input[:payment_profile][:bill_to][:city]
|
110
|
+
xml.state input[:payment_profile][:bill_to][:state] if input[:payment_profile][:bill_to][:state]
|
111
|
+
xml.zip input[:payment_profile][:bill_to][:zip] if input[:payment_profile][:bill_to][:zip]
|
112
|
+
xml.country input[:payment_profile][:bill_to][:country] if input[:payment_profile][:bill_to][:country]
|
113
|
+
xml.phoneNumber input[:payment_profile][:bill_to][:phone_number] if input[:payment_profile][:bill_to][:phone_number]
|
114
|
+
xml.faxNumber input[:payment_profile][:bill_to][:fax_number] if input[:payment_profile][:bill_to][:fax_number]
|
115
|
+
end
|
116
|
+
end
|
117
|
+
xml.tag!('payment') do
|
118
|
+
if input[:payment_profile][:payment][:credit_card]
|
119
|
+
xml.tag!('creditCard') do
|
120
|
+
xml.cardNumber input[:payment_profile][:payment][:credit_card][:card_number] if input[:payment_profile][:payment][:credit_card][:card_number]
|
121
|
+
xml.expirationDate input[:payment_profile][:payment][:credit_card][:expiration_date] if input[:payment_profile][:payment][:credit_card][:expiration_date]
|
122
|
+
xml.cardCode input[:payment_profile][:payment][:credit_card][:card_code] if input[:payment_profile][:payment][:credit_card][:card_code]
|
123
|
+
end
|
124
|
+
elsif input[:payment_profile][:payment][:bank_account]
|
125
|
+
xml.tag!('bankAccount') do
|
126
|
+
xml.accountType input[:payment_profile][:payment][:bank_account][:account_type] if input[:payment_profile][:payment][:bank_account][:account_type]
|
127
|
+
xml.routingNumber input[:payment_profile][:payment][:bank_account][:routing_number] if input[:payment_profile][:payment][:bank_account][:routing_number]
|
128
|
+
xml.accountNumber input[:payment_profile][:payment][:bank_account][:account_number] if input[:payment_profile][:payment][:bank_account][:account_number]
|
129
|
+
xml.nameOnAccount input[:payment_profile][:payment][:bank_account][:name_on_account] if input[:payment_profile][:payment][:bank_account][:name_on_account]
|
130
|
+
xml.echeckType input[:payment_profile][:payment][:bank_account][:echeck_type] if input[:payment_profile][:payment][:bank_account][:echeck_type]
|
131
|
+
xml.bankName input[:payment_profile][:payment][:bank_account][:bank_name] if input[:payment_profile][:payment][:bank_account][:bank_name]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
xml.validationMode input[:payment_profile][:validation_mode] if input[:payment_profile][:validation_mode]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
parse send(data)
|
139
|
+
end
|
140
|
+
|
141
|
+
# Create a new customer shipping address for an existing customer profile.
|
142
|
+
# You can create up to 100 customer shipping addresses for each customer profile.
|
143
|
+
#
|
144
|
+
# params:
|
145
|
+
# A hash containing all necessary fields
|
146
|
+
# all possible params:
|
147
|
+
# :ref_id => '<id>' (up to 20 digits (optional))
|
148
|
+
# :customer_profile_id => <id of customer> (numeric (necessary))
|
149
|
+
# :address => { (a hash containing address information(necessary)
|
150
|
+
# :first_name => '<billing first name>' (up to 50 characters (optional))
|
151
|
+
# :last_name => '<billing last name>' (up to 50 characters (optional))
|
152
|
+
# :company => '<company name>' (up to 50 characters (optional))
|
153
|
+
# :address => '<address>' (up to 60 characters (optional))
|
154
|
+
# :city => '<city>' (up to 40 characters (optional))
|
155
|
+
# :state => '<state>' (valid 2 character state code (optional))
|
156
|
+
# :zip => '<zip code>' (up to 20 characters (optional))
|
157
|
+
# :country => '<country>' (up to 60 characters (optional))
|
158
|
+
# :phone_number => '<phone number>' (up to 25 digits (optional))
|
159
|
+
# :fax_number => '<fax number>' (up to 25 digits (optional))
|
160
|
+
# }
|
161
|
+
#
|
162
|
+
# returns:
|
163
|
+
# xml converted to hash table for easy access
|
164
|
+
def create_customer_shipping_address(input)
|
165
|
+
data = build_request('createCustomerShippingAddressRequest') do |xml|
|
166
|
+
xml.refId input[:ref_id] if input[:ref_id]
|
167
|
+
xml.customerProfileId input[:customer_profile_id] if input[:customer_profile_id]
|
168
|
+
xml.tag!('address') do
|
169
|
+
xml.firstName input[:address][:first_name] if input[:address][:first_name]
|
170
|
+
xml.lastName input[:address][:last_name] if input[:address][:last_name]
|
171
|
+
xml.company input[:address][:company] if input[:address][:company]
|
172
|
+
xml.address input[:address][:address] if input[:address][:address]
|
173
|
+
xml.city input[:address][:city] if input[:address][:city]
|
174
|
+
xml.state input[:address][:state] if input[:address][:state]
|
175
|
+
xml.zip input[:address][:zip] if input[:address][:zip]
|
176
|
+
xml.country input[:address][:country] if input[:address][:country]
|
177
|
+
xml.phoneNumber input[:address][:phone_number] if input[:address][:phone_number]
|
178
|
+
xml.faxNumber input[:address][:fax_number] if input[:address][:fax_number]
|
179
|
+
end
|
180
|
+
end
|
181
|
+
parse send(data)
|
182
|
+
end
|
183
|
+
|
184
|
+
# Create a new payment transaction from an existing customer profile.
|
185
|
+
# can handle all transactions except Void transaction.
|
186
|
+
#
|
187
|
+
# params:
|
188
|
+
# A hash containing all necessary fields
|
189
|
+
# all possible params:
|
190
|
+
# :ref_id => '<id>' (up to 20 digits (optional))
|
191
|
+
# :transaction => { (REQUIRED) TODO \/ I dont know the rest...
|
192
|
+
# :trans_type => '<transType>' (must be profileTransAuthCapture, profileTransAuthOnly, profileTransPriorAuthCapture, profileTransCaptureOnly, profileTransRefund, profileTransVoid' (REQUIRED))
|
193
|
+
# :transaction_type => {
|
194
|
+
# :amount => '<amount>' (total amound of transaction ie. 1234.23 (allow a maximum of 4 digits after decimal point)(REQUIRED))
|
195
|
+
# :tax => { (optional)
|
196
|
+
# :amount => '<amount>' (total tax amount ie 65.34 (allow a maximum of 4 digits after decimal point))
|
197
|
+
# :name => '<name>' (name of tax ie federal, state etc.)
|
198
|
+
# :description => '<description>' (up to 255 characters)
|
199
|
+
# }
|
200
|
+
# :shipping => { (optional)
|
201
|
+
# :amount => '<amount>' (total tax amount ie 65.34 (allow a maximum of 4 digits after decimal point))
|
202
|
+
# :name => '<name>' (name of tax ie federal, state etc.)
|
203
|
+
# :description => '<description>' (up to 255 characters)
|
204
|
+
# }
|
205
|
+
# :duty => { (optional)
|
206
|
+
# :amount => '<amount>' (total tax amount ie 65.34 (allow a maximum of 4 digits after decimal point))
|
207
|
+
# :name => '<name>' (name of tax ie federal, state etc.)
|
208
|
+
# :description => '<description>' (up to 255 characters)
|
209
|
+
# }
|
210
|
+
# :line_items => [ (an array of items on transaction, each array item is a hash containign \/ (optional))
|
211
|
+
# :item_id => '<id>' (up to 31 characters)
|
212
|
+
# :name => '<name>' (up to 31 characters)
|
213
|
+
# :description => '<description>' (up to 255 characters)
|
214
|
+
# :quantity => <number> (up to 4 digits(and 2 decimal places... but how could you have .34 things you sold...))
|
215
|
+
# :unit_price => <number> (up to 4 digits(and 2 decimal places))
|
216
|
+
# :taxable => <boolean> (must be "true" or "false")
|
217
|
+
# ]
|
218
|
+
# :customer_profile_id => <id number> (profile Identification number given by authorize.net (required))
|
219
|
+
# :customer_payment_profile_id => <payment id number> (profile payment ID given by authorize.net (required))
|
220
|
+
# :customer_Shipping_address_id => <address id> (address ID given by authorize.net (optional))
|
221
|
+
# :trans_id => <number> (original transactions transId (CONDITIONAL - required for "Prior Authorization and Capture Transactions"))
|
222
|
+
# :credit_card_number_masked => <numb> (last 4 digits of credit card (CONDITIONAL - require for "Refund Transactions"))
|
223
|
+
# :order => { (optional)
|
224
|
+
# :invoice_number => '<invoice number>' (up to 20 characters)
|
225
|
+
# :description => '<description>' (up to 255 characters)
|
226
|
+
# :purchase_order_number => '<order number>' (up to 25 characters)
|
227
|
+
# }
|
228
|
+
# :tax_exempt => <BOOLEAN> (must be "TRUE" or "FALSE" (optional))
|
229
|
+
# :recurring_billing => <BOOLEAN> (must be "TRUE" or "FALSE" (optional))
|
230
|
+
# :card_code => <num> (3 to 4 digits (Required IF merchent would like to use CCV)(optional))
|
231
|
+
# :split_tender_id => <number> (up to 6 digits (conditional)(optional))
|
232
|
+
# :approval_code => <code> (6 character authorication code of an original transaction (conditional - caption only transactions))
|
233
|
+
# }
|
234
|
+
# }
|
235
|
+
# :extra_options => <string> (information listed in name/value pair... things like customer ip address... etc(optional))
|
236
|
+
#
|
237
|
+
# Returns:
|
238
|
+
# XML converted to hash for easy reading
|
239
|
+
#
|
240
|
+
def create_customer_profile_transaction(input)
|
241
|
+
data = build_request('createCustomerProfileTransactionRequest') do |xml|
|
242
|
+
xml.refId input[:ref_id] if input[:ref_id]
|
243
|
+
xml.tag!('transaction') do
|
244
|
+
xml.tag!(input[:transaction][:trans_type]) do
|
245
|
+
xml.amount input[:transaction][:transaction_type][:amount] if input[:transaction][:transaction_type][:amount]
|
246
|
+
if input[:transaction][:transaction_type][:tax]
|
247
|
+
xml.tag!('tax') do
|
248
|
+
xml.amount input[:transaction][:transaction_type][:tax][:amount] if input[:transaction][:transaction_type][:tax][:amount]
|
249
|
+
xml.name input[:transaction][:transaction_type][:tax][:name] if input[:transaction][:transaction_type][:tax][:name]
|
250
|
+
xml.description input[:transaction][:transaction_type][:tax][:description] if input[:transaction][:transaction_type][:tax][:description]
|
251
|
+
end
|
252
|
+
end
|
253
|
+
if input[:transaction][:transaction_type][:shipping]
|
254
|
+
xml.tag!('shipping') do
|
255
|
+
xml.amount input[:transaction][:transaction_type][:shipping][:amount] if input[:transaction][:transaction_type][:shipping][:amount]
|
256
|
+
xml.name input[:transaction][:transaction_type][:shipping][:name] if input[:transaction][:transaction_type][:shipping][:name]
|
257
|
+
xml.description input[:transaction][:transaction_type][:shipping][:description] if input[:transaction][:transaction_type][:shipping][:description]
|
258
|
+
end
|
259
|
+
end
|
260
|
+
if input[:transaction][:transaction_type][:duty]
|
261
|
+
xml.tag!('duty') do
|
262
|
+
xml.amount input[:transaction][:transaction_type][:duty][:amount] if input[:transaction][:transaction_type][:duty][:amount]
|
263
|
+
xml.name input[:transaction][:transaction_type][:duty][:name] if input[:transaction][:transaction_type][:duty][:name]
|
264
|
+
xml.description input[:transaction][:transaction_type][:duty][:description] if input[:transaction][:transaction_type][:duty][:description]
|
265
|
+
end
|
266
|
+
end
|
267
|
+
if input[:transaction][:transaction_type][:line_item]
|
268
|
+
xml.tag!('lineItems') do
|
269
|
+
arr = input[:transaction][:transaction_type][:line_item]
|
270
|
+
arr.each { |item|
|
271
|
+
xml.itemId item[:item_id]
|
272
|
+
xml.name item[:name]
|
273
|
+
xml.description item[:description]
|
274
|
+
xml.quantity item[:quantity]
|
275
|
+
xml.unitPrice item[:unit_price]
|
276
|
+
xml.taxable item[:taxable]
|
277
|
+
}
|
278
|
+
end
|
279
|
+
end
|
280
|
+
xml.customerProfileId input[:transaction][:transaction_type][:customer_profile_id] if input[:transaction][:transaction_type][:customer_profile_id]
|
281
|
+
xml.customerPaymentProfileId input[:transaction][:transaction_type][:customer_payment_profile_id] if input[:transaction][:transaction_type][:customer_payment_profile_id]
|
282
|
+
xml.customerShippingAddressId input[:transaction][:transaction_type][:customer_shipping_address_id] if input[:transaction][:transaction_type][:customer_shipping_address_id]
|
283
|
+
xml.transId input[:transaction][:transaction_type][:trans_id] if input[:transaction][:transaction_type][:trans_id]
|
284
|
+
xml.creditCardNumberMasked input[:transaction][:transaction_type][:credit_card_number_masked] if input[:transaction][:transaction_type][:credit_card_number_masked]
|
285
|
+
if input[:transaction][:transaction_type][:order]
|
286
|
+
xml.tag!('order') do
|
287
|
+
xml.invoiceNumber input[:transaction][:transaction_type][:order][:invoice_number] if input[:transaction][:transaction_type][:order][:invoice_number]
|
288
|
+
xml.description input[:transaction][:transaction_type][:order][:description] if input[:transaction][:transaction_type][:order][:description]
|
289
|
+
xml.purchaseOrderNumber input[:transaction][:transaction_type][:order][:purchase_order_number] if input[:transaction][:transaction_type][:order][:purchase_order_number]
|
290
|
+
end
|
291
|
+
end
|
292
|
+
xml.taxExempt input[:transaction][:transaction_type][:tax_exempt] if input[:transaction][:transaction_type][:tax_exempt]
|
293
|
+
xml.recurringBilling input[:transaction][:transaction_type][:recurring_billing] if input[:transaction][:transaction_type][:recurring_billing]
|
294
|
+
xml.cardCode input[:transaction][:transaction_type][:card_code] if input[:transaction][:transaction_type][:card_code]
|
295
|
+
xml.splitTenderId input[:transaction][:transaction_type][:split_tender_id] if input[:transaction][:transaction_type][:split_tender_id]
|
296
|
+
xml.approvalCode input[:transaction][:transaction_type][:approval_code] if input[:transaction][:transaction_type][:approval_code]
|
297
|
+
end
|
298
|
+
end
|
299
|
+
xml.extraOptions input[:extra_options] if input[:extra_options]
|
300
|
+
end
|
301
|
+
parse send(data)
|
302
|
+
end
|
303
|
+
|
304
|
+
# Void a transaction.
|
305
|
+
#
|
306
|
+
# params:
|
307
|
+
# A hash containing all necessary fileds
|
308
|
+
# all possible params:
|
309
|
+
# :customer_profile_id => <id number> (profile Identification number given by authorize.net (optional))
|
310
|
+
# :customer_payment_profile_id => <payment id number> (profile payment ID given by authorize.net (optional))
|
311
|
+
# :customer_Shipping_address_id => <address id> (address ID given by authorize.net (optional))
|
312
|
+
# :trans_id => <number> (original transactions transId (Required))
|
313
|
+
#
|
314
|
+
def void_transaction(input)
|
315
|
+
data = build_request('deleteCustomerProfileRequest') do |xml|
|
316
|
+
xml.transaction do
|
317
|
+
xml.profileTransVoid do
|
318
|
+
xml.customerProfileId input[:customer_profile_id] if input[:customer_profile_id]
|
319
|
+
xml.customerPaymentProfileId input[:customer_payment_profile_id] if input[:customer_payment_profile_id]
|
320
|
+
xml.customerShippingAddressId input[:customer_shipping_address_id] if input[:customer_shipping_address_id]
|
321
|
+
xml.transId input[:trans_id] if input[:trans_id]
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
end
|
327
|
+
|
328
|
+
|
329
|
+
|
330
|
+
# Delete an existing customer profile along with all associated customer payment profiles and customer shipping addresses.
|
331
|
+
#
|
332
|
+
# params:
|
333
|
+
# A hash containing all necessary fields
|
334
|
+
# all possible params:
|
335
|
+
# :ref_id => '<id>' (up to 20 digits (optional))
|
336
|
+
# :customer_profile_id => <id of customer> (numeric (necessary))
|
337
|
+
#
|
338
|
+
# returns:
|
339
|
+
# xml converted to hash for easy access
|
340
|
+
def delete_customer_profile(input)
|
341
|
+
data = build_request('deleteCustomerProfileRequest') do |xml|
|
342
|
+
xml.refId input[:ref_id] if input[:ref_id]
|
343
|
+
xml.customerProfileId input[:customer_profile_id] if input[:customer_profile_id]
|
344
|
+
end
|
345
|
+
parse send(data)
|
346
|
+
end
|
347
|
+
|
348
|
+
# Delete a customer payment profile from an existing customer profile.
|
349
|
+
#
|
350
|
+
# params:
|
351
|
+
# A hash containing all necessary fields
|
352
|
+
# all possible params:
|
353
|
+
# :ref_id => '<id>' (up to 20 digits (optional))
|
354
|
+
# :customer_profile_id => <id of customer> (numeric (necessary))
|
355
|
+
# :customer_payment_profile_id => <payment id> (numeric (necessary))
|
356
|
+
# returns:
|
357
|
+
# xml converted to hash for easy access
|
358
|
+
def delete_customer_payment_profile(input)
|
359
|
+
data = build_request('deleteCustomerPaymentProfileRequest') do |xml|
|
360
|
+
xml.refId input[:ref_id] if input[:ref_id]
|
361
|
+
xml.customerProfileId input[:customer_profile_id] if input[:customer_profile_id]
|
362
|
+
xml.customerPaymentProfileId input[:customer_payment_profile_id] if input[:customer_payment_profile_id]
|
363
|
+
end
|
364
|
+
parse send(data)
|
365
|
+
end
|
366
|
+
|
367
|
+
# Delete a customer shipping address from an existing customer profile.
|
368
|
+
#
|
369
|
+
# params:
|
370
|
+
# A hash containing all necessary fields
|
371
|
+
# all possible params:
|
372
|
+
# :ref_id => '<id>' (up to 20 digits (optional))
|
373
|
+
# :customer_profile_id => <id of customer> (numeric (necessary))
|
374
|
+
# :customer_address_id => <shipping id> (numeric (necessary))
|
375
|
+
#
|
376
|
+
# returns:
|
377
|
+
# xml converted to hash for easy access
|
378
|
+
def delete_customer_shipping_address(input)
|
379
|
+
data = build_request('deleteCustomerShippingAddressRequest') do |xml|
|
380
|
+
xml.refId input[:ref_id] if input[:ref_id]
|
381
|
+
xml.customerProfileId input[:customer_profile_id] if input[:customer_profile_id]
|
382
|
+
xml.customerAddressId input[:customer_address_id] if input[:customer_address_id]
|
383
|
+
end
|
384
|
+
parse send(data)
|
385
|
+
|
386
|
+
end
|
387
|
+
|
388
|
+
# Retrieve all customer profile IDs you have previously created.
|
389
|
+
# returns:
|
390
|
+
# xml converted to hash for easy access
|
391
|
+
def get_customer_profile_ids
|
392
|
+
data = build_request('getCustomerProfileIdsRequest') {}
|
393
|
+
parse send(data)
|
394
|
+
end
|
395
|
+
|
396
|
+
# Retrieve an existing customer profile along with all the associated customer payment profiles and customer shipping addresses.
|
397
|
+
# params:
|
398
|
+
# A hash containing all necessary fields
|
399
|
+
# all possible params:
|
400
|
+
# :customer_profile_id => <id of customer> (numeric (necessary))
|
401
|
+
def get_customer_profile(input)
|
402
|
+
data = build_request('getCustomerProfileRequest') do |xml|
|
403
|
+
xml.customerProfileId input[:customer_profile_id] if input[:customer_profile_id]
|
404
|
+
end
|
405
|
+
parse send(data)
|
406
|
+
|
407
|
+
end
|
408
|
+
|
409
|
+
# Retrieve a customer payment profile for an existing customer profile.
|
410
|
+
#
|
411
|
+
# params:
|
412
|
+
# A hash containing all necessary fields
|
413
|
+
# all possible params:
|
414
|
+
# :customer_profile_id => <id of customer> (numeric (necessary))
|
415
|
+
# :customer_payment_profile_id => <payment id> (numeric (necessary))
|
416
|
+
#
|
417
|
+
# returns:
|
418
|
+
# xml converted to hash for easy access
|
419
|
+
def get_customer_payment_profile(input)
|
420
|
+
data = build_request('getCustomerPaymentProfileRequest') do |xml|
|
421
|
+
xml.customerProfileId input[:customer_profile_id] if input[:customer_profile_id]
|
422
|
+
xml.customerPaymentProfileId input[:customer_payment_profile_id] if input[:customer_payment_profile_id]
|
423
|
+
end
|
424
|
+
parse send(data)
|
425
|
+
|
426
|
+
end
|
427
|
+
|
428
|
+
# Retrieve a customer shipping address for an existing customer profile.
|
429
|
+
# params:
|
430
|
+
# A hash containing all necessary fields
|
431
|
+
# all possible params:
|
432
|
+
# :ref_id => '<id>' (up to 20 digits (optional))
|
433
|
+
# :customer_profile_id => <id of customer> (numeric (necessary))
|
434
|
+
# :customer_address_id => <shipping id> (numeric (necessary))
|
435
|
+
#
|
436
|
+
# returns:
|
437
|
+
# xml converted to hash for easy access
|
438
|
+
def get_customer_shipping_address(input)
|
439
|
+
data = build_request('getCustomerShippingAddressRequest') do |xml|
|
440
|
+
xml.customerProfileId input[:customer_profile_id] if input[:customer_profile_id]
|
441
|
+
xml.customerAddressId input[:customer_address_id] if input[:customer_address_id]
|
442
|
+
end
|
443
|
+
parse send(data)
|
444
|
+
end
|
445
|
+
|
446
|
+
# Update an existing customer profile.
|
447
|
+
# params:
|
448
|
+
# Necessary:
|
449
|
+
# :customer_profile_id => <id of customer> (numeric (necessary))
|
450
|
+
# {
|
451
|
+
# :merchant_id => '<some id>' (up to 20 characters)
|
452
|
+
# or
|
453
|
+
# :description => '<some discription>' (up to 255 characters)
|
454
|
+
# or
|
455
|
+
# :email => '<emailaddress>' (up to 255 characters)
|
456
|
+
# }
|
457
|
+
# return:
|
458
|
+
# xml return converted to hash containing the return_code and customer_profile_id
|
459
|
+
# note: a return code of I00001 is good, anything else is bad
|
460
|
+
#
|
461
|
+
def update_customer_profile(input)
|
462
|
+
data = build_request('updateCustomerProfileRequest') do |xml|
|
463
|
+
xml.tag!('profile') do
|
464
|
+
xml.merchantCustomerId input[:merchant_id] if input[:merchant_id]
|
465
|
+
xml.description input[:description] if input[:description]
|
466
|
+
xml.email input[:email] if input[:email]
|
467
|
+
xml.customerProfileId input[:customer_profile_id] if input[:customer_profile_id]
|
468
|
+
end
|
469
|
+
end
|
470
|
+
parse send(data)
|
471
|
+
end
|
472
|
+
|
473
|
+
# Update a customer payment profile for an existing customer profile.
|
474
|
+
#
|
475
|
+
# params:
|
476
|
+
# A hash containing all necessary fields
|
477
|
+
# all possible params:
|
478
|
+
# :ref_id => '<id>' (up to 20 digits (optional))
|
479
|
+
# :customer_profile_id => <id of customer> (numeric (necessary))
|
480
|
+
# :payment_profile => {
|
481
|
+
# :bill_to => { (optional)
|
482
|
+
# :first_name => '<billing first name>' (up to 50 characters (optional))
|
483
|
+
# :last_name => '<billing last name>' (up to 50 characters (optional))
|
484
|
+
# :company => '<company name>' (up to 50 characters (optional))
|
485
|
+
# :address => '<address>' (up to 60 characters (optional))
|
486
|
+
# :city => '<city>' (up to 40 characters (optional))
|
487
|
+
# :state => '<state>' (valid 2 character state code (optional))
|
488
|
+
# :zip => '<zip code>' (up to 20 characters (optional))
|
489
|
+
# :country => '<country>' (up to 60 characters (optional))
|
490
|
+
# :phone_number => '<phone number>' (up to 25 digits (optional))
|
491
|
+
# :fax_number => '<fax number>' (up to 25 digits (optional))
|
492
|
+
# }
|
493
|
+
# :payment => { (NECESSARY > must include either bank info or credit card info)
|
494
|
+
# :credit_card => { (necessary if there is no bank_account in payment hash)
|
495
|
+
# :card_number => <number> (13 to 16 digits (necessary))
|
496
|
+
# :expiration_date => '<YYYY-MM>' (has to be 4 digit year, dash line, then 2 digit month (necessary))
|
497
|
+
# :card_code => <number> (3 or 4 digit number on back of card (optional))
|
498
|
+
# }
|
499
|
+
# :bank_account => { (necessary if there is no credit_card in payment hash)
|
500
|
+
# :account_type => '<type of account>' (must be "checking", "savings", or "businessChecking" (necessary))
|
501
|
+
# :routing_number => <number> (9 digit bank routing number (necessary))
|
502
|
+
# :account_number => <number> (5 to 17 digit number (necessary))
|
503
|
+
# :name_on_account => '<name>' (up to 22 characters (necessary))
|
504
|
+
# :echeck_type => '<type>' (needs to be 'CCD', 'PPD', 'TEL', or 'WEB' (optional))
|
505
|
+
# :bank_name => '<bank name>' (up to 50 characters (optional))
|
506
|
+
# }
|
507
|
+
# }
|
508
|
+
#
|
509
|
+
# }
|
510
|
+
# :customer_payment_profile_id => <payment id> (numeric (necessary))
|
511
|
+
# :validation_mode => '<mode>' (needs to be 'none', 'testMode', 'liveMode', or 'oldLiveMode' (necessary))
|
512
|
+
#
|
513
|
+
# returns:
|
514
|
+
# xml converted to hash table for easy access
|
515
|
+
#
|
516
|
+
def update_customer_payment_profile(input)
|
517
|
+
data = build_request('updateCustomerPaymentProfileRequest') do |xml|
|
518
|
+
xml.refId input[:ref_id] if input[:ref_id]
|
519
|
+
xml.customerProfileId input[:customer_profile_id] if input[:customer_profile_id]
|
520
|
+
xml.tag!('paymentProfile') do
|
521
|
+
if input[:payment_profile][:bill_to]
|
522
|
+
xml.tag!('billTo') do
|
523
|
+
xml.firstName input[:payment_profile][:bill_to][:first_name] if input[:payment_profile][:bill_to][:first_name]
|
524
|
+
xml.lastName input[:payment_profile][:bill_to][:last_name] if input[:payment_profile][:bill_to][:last_name]
|
525
|
+
xml.company input[:payment_profile][:bill_to][:company] if input[:payment_profile][:bill_to][:company]
|
526
|
+
xml.address input[:payment_profile][:bill_to][:address] if input[:payment_profile][:bill_to][:address]
|
527
|
+
xml.city input[:payment_profile][:bill_to][:city] if input[:payment_profile][:bill_to][:city]
|
528
|
+
xml.state input[:payment_profile][:bill_to][:state] if input[:payment_profile][:bill_to][:state]
|
529
|
+
xml.zip input[:payment_profile][:bill_to][:zip] if input[:payment_profile][:bill_to][:zip]
|
530
|
+
xml.country input[:payment_profile][:bill_to][:country] if input[:payment_profile][:bill_to][:country]
|
531
|
+
xml.phoneNumber input[:payment_profile][:bill_to][:phone_number] if input[:payment_profile][:bill_to][:phone_number]
|
532
|
+
xml.faxNumber input[:payment_profile][:bill_to][:fax_number] if input[:payment_profile][:bill_to][:fax_number]
|
533
|
+
end
|
534
|
+
end
|
535
|
+
xml.tag!('payment') do
|
536
|
+
if input[:payment_profile][:payment][:credit_card]
|
537
|
+
xml.tag!('creditCard') do
|
538
|
+
xml.cardNumber input[:payment_profile][:payment][:credit_card][:card_number] if input[:payment_profile][:payment][:credit_card][:card_number]
|
539
|
+
xml.expirationDate input[:payment_profile][:payment][:credit_card][:expiration_date] if input[:payment_profile][:payment][:credit_card][:expiration_date]
|
540
|
+
xml.cardCode input[:payment_profile][:payment][:credit_card][:card_code] if input[:payment_profile][:payment][:credit_card][:card_code]
|
541
|
+
end
|
542
|
+
elsif input[:payment_profile][:payment][:bank_account]
|
543
|
+
xml.tag!('bankAccount') do
|
544
|
+
xml.accountType input[:payment_profile][:payment][:bank_account][:account_type] if input[:payment_profile][:payment][:bank_account][:account_type]
|
545
|
+
xml.routingNumber input[:payment_profile][:payment][:bank_account][:routing_number] if input[:payment_profile][:payment][:bank_account][:routing_number]
|
546
|
+
xml.accountNumber input[:payment_profile][:payment][:bank_account][:account_number] if input[:payment_profile][:payment][:bank_account][:account_number]
|
547
|
+
xml.nameOnAccount input[:payment_profile][:payment][:bank_account][:name_on_account] if input[:payment_profile][:payment][:bank_account][:name_on_account]
|
548
|
+
xml.echeckType input[:payment_profile][:payment][:bank_account][:echeck_type] if input[:payment_profile][:payment][:bank_account][:echeck_type]
|
549
|
+
xml.bankName input[:payment_profile][:payment][:bank_account][:bank_name] if input[:payment_profile][:payment][:bank_account][:bank_name]
|
550
|
+
end
|
551
|
+
end
|
552
|
+
end
|
553
|
+
xml.customerPaymentProfileId input[:customer_payment_profile_id] if input[:customer_payment_profile_id]
|
554
|
+
xml.validationMode input[:payment_profile][:validation_mode] if input[:payment_profile][:validation_mode]
|
555
|
+
end
|
556
|
+
end
|
557
|
+
parse send(data)
|
558
|
+
end
|
559
|
+
|
560
|
+
# Update a shipping address for an existing customer profile.
|
561
|
+
#
|
562
|
+
# params:
|
563
|
+
# A hash containing all necessary fields
|
564
|
+
# all possible params:
|
565
|
+
# :ref_id => '<id>' (up to 20 digits (optional))
|
566
|
+
# :customer_profile_id => <id of customer> (numeric (necessary))
|
567
|
+
# :address => { (a hash containing address information(necessary)
|
568
|
+
# :first_name => '<billing first name>' (up to 50 characters (optional))
|
569
|
+
# :last_name => '<billing last name>' (up to 50 characters (optional))
|
570
|
+
# :company => '<company name>' (up to 50 characters (optional))
|
571
|
+
# :address => '<address>' (up to 60 characters (optional))
|
572
|
+
# :city => '<city>' (up to 40 characters (optional))
|
573
|
+
# :state => '<state>' (valid 2 character state code (optional))
|
574
|
+
# :zip => '<zip code>' (up to 20 characters (optional))
|
575
|
+
# :country => '<country>' (up to 60 characters (optional))
|
576
|
+
# :phone_number => '<phone number>' (up to 25 digits (optional))
|
577
|
+
# :fax_number => '<fax number>' (up to 25 digits (optional))
|
578
|
+
# :customer_address_id => <shipping id> (numeric (necessary))
|
579
|
+
# }
|
580
|
+
#
|
581
|
+
# returns:
|
582
|
+
# xml converted to hash table for easy access
|
583
|
+
def update_customer_shipping_address(input)
|
584
|
+
data = build_request('updateCustomerShippingAddressRequest') do |xml|
|
585
|
+
xml.refId input[:ref_id] if input[:ref_id]
|
586
|
+
xml.customerProfileId input[:customer_profile_id] if input[:customer_profile_id]
|
587
|
+
xml.tag!('address') do
|
588
|
+
xml.firstName input[:address][:first_name] if input[:address][:first_name]
|
589
|
+
xml.lastName input[:address][:last_name] if input[:address][:last_name]
|
590
|
+
xml.company input[:address][:company] if input[:address][:company]
|
591
|
+
xml.address input[:address][:address] if input[:address][:address]
|
592
|
+
xml.city input[:address][:city] if input[:address][:city]
|
593
|
+
xml.state input[:address][:state] if input[:address][:state]
|
594
|
+
xml.zip input[:address][:zip] if input[:address][:zip]
|
595
|
+
xml.country input[:address][:country] if input[:address][:country]
|
596
|
+
xml.phoneNumber input[:address][:phone_number] if input[:address][:phone_number]
|
597
|
+
xml.faxNumber input[:address][:fax_number] if input[:address][:fax_number]
|
598
|
+
xml.customerAddressId input[:address][:customer_address_id] if input[:address][:customer_address_id]
|
599
|
+
end
|
600
|
+
end
|
601
|
+
parse send(data)
|
602
|
+
end
|
603
|
+
|
604
|
+
# # Update the status of a split tender group (a group of transactions, each of which pays for part of one order).
|
605
|
+
# def update_split_tender_group(input)
|
606
|
+
# data = build_request('updateSplitTenderGroupRequest') do |xml|
|
607
|
+
#
|
608
|
+
# DONT WANNA DO IT
|
609
|
+
#
|
610
|
+
# end
|
611
|
+
# parse send(data)
|
612
|
+
# end
|
613
|
+
|
614
|
+
|
615
|
+
# Verify an existing customer payment profile by generating a test transaction.
|
616
|
+
def validate_customer_payment_profile(input)
|
617
|
+
data = build_request('validateCustomerPaymentProfileRequest') do |xml|
|
618
|
+
xml.customerProfileId input[:customer_profile_id] if input[:customer_profile_id]
|
619
|
+
xml.customerPaymentProfileId input[:customer_payment_profile_id] if input[:customer_payment_profile_id]
|
620
|
+
xml.customerAddressId input[:customer_address_id] if input[:customer_address_id]
|
621
|
+
xml.cardCode input[:card_code] if input[:card_code]
|
622
|
+
xml.validationMode input[:validation_mode] if input[:validation_mode]
|
623
|
+
end
|
624
|
+
parse send(data)
|
625
|
+
end
|
626
|
+
|
627
|
+
# Create request head that is required for all requests.
|
628
|
+
#
|
629
|
+
# params:
|
630
|
+
# request string
|
631
|
+
# block of code containing all the additional xml code
|
632
|
+
#
|
633
|
+
# return:
|
634
|
+
# completed xml as a string
|
635
|
+
#
|
636
|
+
def build_request(request, xml = Builder::XmlMarkup.new(:indent => 2))
|
637
|
+
xml.instruct!
|
638
|
+
xml.tag!(request, :xmlns => 'AnetApi/xml/v1/schema/AnetApiSchema.xsd') do
|
639
|
+
xml.tag!('merchantAuthentication') do
|
640
|
+
xml.name @login
|
641
|
+
xml.transactionKey @key
|
642
|
+
end
|
643
|
+
yield(xml)
|
644
|
+
end
|
645
|
+
xml.target!
|
646
|
+
end
|
647
|
+
|
648
|
+
# parse all xml documents given back from the API
|
649
|
+
# return:
|
650
|
+
# hash containing all values from the xml doc
|
651
|
+
def parse(xml)
|
652
|
+
Crack::XML.parse(xml)
|
653
|
+
end
|
654
|
+
|
655
|
+
# get the response code from any response.
|
656
|
+
#
|
657
|
+
# prerams:
|
658
|
+
# response xml already parsed to hash
|
659
|
+
# returns:
|
660
|
+
# string - response code (something like "I00001" or "E00039")
|
661
|
+
def response_code(hash)
|
662
|
+
hash[hash.keys[0]]['messages']['message']['code']
|
663
|
+
end
|
664
|
+
|
665
|
+
# get the response code from any response.
|
666
|
+
#
|
667
|
+
# prerams:
|
668
|
+
# response xml already parsed to hash
|
669
|
+
# returns:
|
670
|
+
# string - response text (should be something like "Successful." or some long explaination why we it didnt work)
|
671
|
+
def response_text(hash)
|
672
|
+
hash[hash.keys[0]]['messages']['message']['text']
|
673
|
+
end
|
674
|
+
|
675
|
+
|
676
|
+
def send(xml) # returns xmlDoc of response
|
677
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
678
|
+
http.use_ssl = 443 == @uri.port
|
679
|
+
begin
|
680
|
+
resp, body = http.post(@uri.path, xml, {'Content-Type' => 'text/xml'})
|
681
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
682
|
+
puts e.message
|
683
|
+
end
|
684
|
+
body
|
685
|
+
end
|
686
|
+
|
687
|
+
end
|
data/spec/base.rb
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../base"
|
2
|
+
|
3
|
+
describe AuthorizeCim do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = AuthorizeCim.new(:endpoint => :test, :login => <must fill in login to test>, :key => <must fill in key to test>)
|
7
|
+
end
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
hash = { :merchant_id => 'Lyon Hill', :description => 'Test User, should be deleted', :email => 'lyon@delorum.com'}
|
11
|
+
rtn = @client.create_customer_profile(hash)
|
12
|
+
@customer_profile = rtn['createCustomerProfileResponse']['customerProfileId']
|
13
|
+
|
14
|
+
hash2 = {:customer_profile_id => @customer_profile, :validation_mode => 'none', :payment_profile => {}}
|
15
|
+
hash2[:payment_profile] = {:customer_type => 'business', :payment => {}}
|
16
|
+
hash2[:payment_profile][:payment] = {:credit_card => {}}
|
17
|
+
hash2[:payment_profile][:payment][:credit_card] = {:card_number => '4007000000027', :expiration_date => '2011-03'}
|
18
|
+
rtn2 = @client.create_customer_payment_profile(hash2)
|
19
|
+
@customer_payment_profile = rtn2['createCustomerPaymentProfileResponse']['customerPaymentProfileId']
|
20
|
+
|
21
|
+
hash3 = {:customer_profile_id => @customer_profile, :address => {}}
|
22
|
+
hash3[:address] = {
|
23
|
+
:first_name => 'Lyon',
|
24
|
+
:last_name => 'Hill',
|
25
|
+
:company => 'Delorum',
|
26
|
+
:address => '218 N 2nd E',
|
27
|
+
:city => 'Rexburg',
|
28
|
+
:state => 'ID',
|
29
|
+
:zip => '83440',
|
30
|
+
:country => 'United States Of America',
|
31
|
+
:phone_number => '2086810512',
|
32
|
+
:fax_number => '(208)359-1103'}
|
33
|
+
rtn3 = @client.create_customer_shipping_address(hash3)
|
34
|
+
@customer_address_profile = rtn3['createCustomerShippingAddressResponse']['customerAddressId']
|
35
|
+
end
|
36
|
+
|
37
|
+
after :each do
|
38
|
+
hash4 = {:customer_profile_id => @customer_profile}
|
39
|
+
@client.delete_customer_profile(hash4)
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
it "creates a valid customer profile" do
|
44
|
+
thing = { :merchant_id => 'guy', :description => 'o GOODNESS!', :email => 'lyon@delorum.com'}
|
45
|
+
item = @client.create_customer_profile(thing)
|
46
|
+
item['createCustomerProfileResponse']['messages']['message']['code'].should == 'I00001'
|
47
|
+
kill = item['createCustomerProfileResponse']['customerProfileId']
|
48
|
+
@client.delete_customer_profile({:customer_profile_id => @customer_profile})
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should fail to create a valid customer profile when it recieves invalid input" do
|
52
|
+
thing = {:useless_stuff => 'HAY, Im not useless :_('}
|
53
|
+
item = @client.create_customer_profile(thing)
|
54
|
+
item['createCustomerProfileResponse']['messages']['message']['code'].should_not == 'I00001'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "create Customer payment profile with the minimum requirements" do
|
58
|
+
hash = {:customer_profile_id => @customer_profile, :validation_mode => 'none', :payment_profile => {}}
|
59
|
+
hash[:payment_profile] = {:customer_type => 'business', :payment => {}}
|
60
|
+
hash[:payment_profile][:payment] = {:credit_card => {}}
|
61
|
+
hash[:payment_profile][:payment][:credit_card] = {:card_number => '1234567890123456', :expiration_date => '2011-03'}
|
62
|
+
pay_profile_return = @client.create_customer_payment_profile(hash)
|
63
|
+
pay_profile_return['createCustomerPaymentProfileResponse']['messages']['message']['code'].should == 'I00001'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "create Customer payment profile with the maximum allowed fields" do
|
67
|
+
hash = {:ref_id => 'letters', :customer_profile_id => @customer_profile, :validation_mode => 'none', :payment_profile => {}}
|
68
|
+
hash[:payment_profile] = {:customer_type => 'business', :payment => {}, :bill_to => {}}
|
69
|
+
hash[:payment_profile][:bill_to] = {:first_name => 'Lyon', :last_name => 'Hill', :company => 'Delorum', :address => '185 N 2000 E', :city => 'Rexburg', :state => 'ID', :zip => '83440', :country => 'USA', :phone_number => 2083591103, :fax_number => 2085895149}
|
70
|
+
hash[:payment_profile][:payment] = {:credit_card => {}}
|
71
|
+
hash[:payment_profile][:payment][:credit_card] = {:card_number => '1234567890123456', :expiration_date => '2011-03'}
|
72
|
+
pay_profile_return = @client.create_customer_payment_profile(hash)
|
73
|
+
pay_profile_return['createCustomerPaymentProfileResponse']['messages']['message']['code'].should == 'I00001'
|
74
|
+
end
|
75
|
+
|
76
|
+
it "create a valid customer shipping address" do
|
77
|
+
hash = {:customer_profile_id => @customer_profile, :address => {}}
|
78
|
+
hash[:address] = {:first_name => 'Tyler', :last_name => 'Flint', :company => 'Delorum', :address => '23 N 2nd E', :city => 'Rexburg', :state => 'ID', :zip => '83440', :country => 'USA', :phone_number => 2083598909, :fax_number => 2082315149}
|
79
|
+
address_return = @client.create_customer_shipping_address(hash)
|
80
|
+
address_return['createCustomerShippingAddressResponse']['messages']['message']['code'].should == 'I00001'
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
it "create a valid customer profile transaction" do
|
85
|
+
hash = {:ref_id => '2', :transaction => {}, :trans_type => 'profileTransPriorAuthCapture'}
|
86
|
+
hash[:transaction] = {:trans_type => 'profileTransAuthOnly', :transaction_type => {}}
|
87
|
+
hash[:transaction][:transaction_type] = {:amount => '101.11', :customer_profile_id => @customer_profile , :customer_payment_profile_id => @customer_payment_profile, :tax => {}}
|
88
|
+
hash[:transaction][:transaction_type][:tax] = {:amount => '23.21', :name => 'state taxes'}
|
89
|
+
transaction = @client.create_customer_profile_transaction(hash)
|
90
|
+
transaction['createCustomerProfileTransactionResponse']['messages']['message']['code'].should == 'I00001'
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should get customer profile IDs" do
|
94
|
+
all_customer_profile_ids = @client.get_customer_profile_ids
|
95
|
+
all_customer_profile_ids['getCustomerProfileIdsResponse']['messages']['message']['code'].should == 'I00001'
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should get all of one customers profile info" do
|
99
|
+
hash = {:customer_profile_id => @customer_profile}
|
100
|
+
one_customer_info = @client.get_customer_profile(hash)
|
101
|
+
one_customer_info['getCustomerProfileResponse']['messages']['message']['code'].should == 'I00001'
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should get one customers payment profile(s)" do
|
105
|
+
one_customer_payment = @client.get_customer_payment_profile({:customer_profile_id => @customer_profile, :customer_payment_profile_id => @customer_payment_profile})
|
106
|
+
one_customer_payment['getCustomerPaymentProfileResponse']['messages']['message']['code'].should == 'I00001'
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should get one customers shipping address" do
|
110
|
+
one_customer_shipping = @client.get_customer_shipping_address({:customer_profile_id => @customer_profile, :customer_address_id => @customer_address_profile})
|
111
|
+
one_customer_shipping['getCustomerShippingAddressResponse']['messages']['message']['code'].should == 'I00001'
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should update a customer profile" do
|
115
|
+
hash = {:customer_profile_id => @customer_profile, :merchant_id => 'John Wayne'}
|
116
|
+
update_customer = @client.update_customer_profile(hash)
|
117
|
+
update_customer['updateCustomerProfileResponse']['messages']['message']['code'].should == 'I00001'
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should update customer payment profile" do
|
121
|
+
hash = {:customer_profile_id => @customer_profile, :customer_payment_profile_id => @customer_payment_profile, :validation_mode => 'none', :payment_profile => {}}
|
122
|
+
hash[:payment_profile] = {:customer_type => 'business', :payment => {}}
|
123
|
+
hash[:payment_profile][:payment] = {:credit_card => {}}
|
124
|
+
hash[:payment_profile][:payment][:credit_card] = {:card_number => '1234567890123456', :expiration_date => '2011-03'}
|
125
|
+
pay_profile_return = @client.update_customer_payment_profile(hash)
|
126
|
+
pay_profile_return['updateCustomerPaymentProfileResponse']['messages']['message']['code'].should == 'I00001'
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
it "should update customer shipping address" do
|
131
|
+
hash3 = {:customer_profile_id => @customer_profile, :address => {}}
|
132
|
+
hash3[:address] = {
|
133
|
+
:first_name => 'Lyon',
|
134
|
+
:last_name => 'Hill',
|
135
|
+
:company => 'Delorum',
|
136
|
+
:address => '218 N 2nd E',
|
137
|
+
:city => 'Rexburg',
|
138
|
+
:state => 'ID',
|
139
|
+
:zip => '83440',
|
140
|
+
:country => 'United States Of America',
|
141
|
+
:phone_number => '2086810512',
|
142
|
+
:fax_number => '(208)359-1103',
|
143
|
+
:customer_address_id => @customer_address_profile }
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should validate Customer Payment Profile Request" do
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should parse return statements for all xml returns except the get functions" do
|
152
|
+
xml = <<EOF
|
153
|
+
<?xml version="1.0" encoding="utf-8"?>
|
154
|
+
<createCustomerProfileResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
|
155
|
+
<messages>
|
156
|
+
<resultCode>Ok</resultCode>
|
157
|
+
<message>
|
158
|
+
<code>I00001</code>
|
159
|
+
<text>Successful.</text>
|
160
|
+
</message>
|
161
|
+
</messages>
|
162
|
+
<customerProfileId>2667736</customerProfileId>
|
163
|
+
<customerPaymentProfileIdList />
|
164
|
+
<customerShippingAddressIdList />
|
165
|
+
<validationDirectResponseList />
|
166
|
+
</createCustomerProfileResponse>
|
167
|
+
EOF
|
168
|
+
|
169
|
+
item = @client.parse(xml)
|
170
|
+
item['createCustomerProfileResponse']['messages']['message']['code'].should == 'I00001'
|
171
|
+
item['createCustomerProfileResponse']['customerProfileId'].should == '2667736'
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should delete a customer profile" do
|
175
|
+
hash = {:customer_profile_id => @customer_profile}
|
176
|
+
rtn = @client.delete_customer_profile(hash)
|
177
|
+
rtn['deleteCustomerProfileResponse']['messages']['message']['code'].should == 'I00001'
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should delete a customer payment profile" do
|
182
|
+
hash = {:customer_profile_id => @customer_profile, :customer_payment_profile_id => @customer_payment_profile}
|
183
|
+
rtn = @client.delete_customer_profile(hash)
|
184
|
+
rtn['deleteCustomerProfileResponse']['messages']['message']['code'].should == 'I00001'
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should delete a customer shipping address" do
|
189
|
+
hash = {:customer_profile_id => @customer_profile, :customer_address_id => @customer_address_profile}
|
190
|
+
rtn = @client.delete_customer_profile(hash)
|
191
|
+
rtn['deleteCustomerProfileResponse']['messages']['message']['code'].should == 'I00001'
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should get the response code from the hash" do
|
196
|
+
xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><createCustomerProfileResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><customerProfileId>2688406</customerProfileId><customerPaymentProfileIdList /><customerShippingAddressIdList /><validationDirectResponseList /></createCustomerProfileResponse>"
|
197
|
+
hash = @client.parse(xml)
|
198
|
+
"I00001".should == @client.response_code(hash)
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should get the plain text response from the hash" do
|
202
|
+
xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><createCustomerProfileResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><customerProfileId>2688406</customerProfileId><customerPaymentProfileIdList /><customerShippingAddressIdList /><validationDirectResponseList /></createCustomerProfileResponse>"
|
203
|
+
hash = @client.parse(xml)
|
204
|
+
"Successful.".should == @client.response_text(hash)
|
205
|
+
end
|
206
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: authorize_cim
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Tyler Flint
|
13
|
+
- Lyon Hill
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-29 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: crack
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
prerelease: false
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: builder
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *id002
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id003
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: webmock
|
62
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: *id004
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: jeweler
|
75
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: *id005
|
86
|
+
- !ruby/object:Gem::Dependency
|
87
|
+
name: crack
|
88
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: *id006
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: builder
|
101
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
type: :runtime
|
110
|
+
prerelease: false
|
111
|
+
version_requirements: *id007
|
112
|
+
description: Ruby Gem for integrating Authorize.net Customer Information Manager (CIM)
|
113
|
+
email: tylerflint@gmail.com
|
114
|
+
executables: []
|
115
|
+
|
116
|
+
extensions: []
|
117
|
+
|
118
|
+
extra_rdoc_files:
|
119
|
+
- README
|
120
|
+
files:
|
121
|
+
- Gemfile
|
122
|
+
- Gemfile.lock
|
123
|
+
- README
|
124
|
+
- Rakefile
|
125
|
+
- VERSION
|
126
|
+
- lib/authorize_cim.rb
|
127
|
+
- spec/base.rb
|
128
|
+
- spec/lib/authorize_cim_spec.rb
|
129
|
+
has_rdoc: true
|
130
|
+
homepage: http://github.com/tylerflint/authorize_cim
|
131
|
+
licenses: []
|
132
|
+
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
version: "0"
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
segments:
|
152
|
+
- 0
|
153
|
+
version: "0"
|
154
|
+
requirements: []
|
155
|
+
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 1.3.7
|
158
|
+
signing_key:
|
159
|
+
specification_version: 3
|
160
|
+
summary: Ruby Gem for integrating Authorize.net Customer Information Manager (CIM)
|
161
|
+
test_files:
|
162
|
+
- spec/base.rb
|
163
|
+
- spec/lib/authorize_cim_spec.rb
|