14
14
include AuthorizeNet ::API
15
15
16
16
describe "SampleCode Testing" do
17
+ # LOGLEVEL=INFO rspec ./spec/sample_code_spec.rb # INFO for verbose output, otherwise defaults to ERROR only.
18
+ def logger
19
+ ENV [ 'LOGLEVEL' ] ||= 'ERROR'
20
+ @logger ||= Logger . new ( STDOUT ) . tap { |logger | logger . level = Logger . const_get ( ENV [ 'LOGLEVEL' ] ) }
21
+ end
17
22
18
23
before :all do
19
24
begin
22
27
item = item [ 0 ..-4 ]
23
28
24
29
if item != specpath + 'sample_code_spec'
25
- puts "working on: #{ item } "
30
+ logger . info "requiring #{ item } "
26
31
require item
27
32
end
28
33
end
29
- # Dir.glob("./sample-code-ruby/RecurringBilling/*") do |item| # note one extra "*"
30
- # next if item == '.' or item == '..'
31
- # item = item[0..-4]
32
- # puts "working on: #{item}"
33
- # require item
34
- # end
35
34
36
35
creds = YAML . load_file ( File . dirname ( __FILE__ ) + "/credentials.yml" )
37
36
@api_key = creds [ 'api_transaction_key' ]
40
39
rescue Errno ::ENOENT => e
41
40
@api_key = "TEST"
42
41
@api_login = "TEST"
43
- warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml."
42
+ logger . warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml."
44
43
end
45
44
end
46
45
def validate_response ( response = nil )
@@ -51,7 +50,7 @@ def validate_response(response= nil)
51
50
end
52
51
53
52
it "should be able to run all Customer Profile sample code" do
54
- puts "START - Customer Profiles"
53
+ logger . info "START - Customer Profiles"
55
54
56
55
response = create_customer_profile ( )
57
56
validate_response ( response )
@@ -112,7 +111,7 @@ def validate_response(response= nil)
112
111
end
113
112
114
113
it "should be able to run all Recurring Billing sample code" do
115
- puts "START - Recurring Billing"
114
+ logger . info "START - Recurring Billing"
116
115
117
116
response = create_Subscription ( )
118
117
validate_response ( response )
@@ -124,9 +123,9 @@ def validate_response(response= nil)
124
123
shipping_response = create_customer_shipping_address ( profile_response . customerProfileId )
125
124
126
125
#waiting for creating customer profile.
127
- puts "Waiting for creation of customer profile..."
126
+ logger . info "Waiting for creation of customer profile..."
128
127
sleep 50
129
- puts "Proceeding"
128
+ logger . info "Proceeding"
130
129
131
130
response = create_subscription_from_customer_profile ( profile_response . customerProfileId , payment_response . customerPaymentProfileId , shipping_response . customerAddressId )
132
131
validate_response ( response )
@@ -155,7 +154,7 @@ def validate_response(response= nil)
155
154
156
155
157
156
it "should be able to run all Payment Transaction sample code" do
158
- puts "START - Payment Transactions"
157
+ logger . info "START - Payment Transactions"
159
158
160
159
response = authorize_credit_card ( )
161
160
validate_response ( response )
@@ -209,34 +208,34 @@ def validate_response(response= nil)
209
208
210
209
211
210
it "should be able to run all PayPal Express Checkout sample code" do
212
- puts "START - PayPal Express Checkout"
211
+ logger . info "START - PayPal Express Checkout"
213
212
214
- puts "TEST - authorization and capture"
213
+ logger . info "TEST - authorization and capture"
215
214
response = authorization_and_capture ( )
216
215
validate_response ( response )
217
216
218
217
# response = authorization_and_capture_continued()
219
218
# validate_response(response)
220
219
221
- puts "TEST - authorization only"
220
+ logger . info "TEST - authorization only"
222
221
response = authorization_only ( )
223
222
validate_response ( response )
224
223
225
224
authTransId = response . transactionResponse . transId
226
- puts "TransId to be used for AuthOnlyContinued, GetDetails & Void : #{ authTransId } "
225
+ logger . info "TransId to be used for AuthOnlyContinued, GetDetails & Void : #{ authTransId } "
227
226
228
- puts "TEST - authorization only continued"
227
+ logger . info "TEST - authorization only continued"
229
228
response = authorization_only_continued ( authTransId )
230
229
validate_response ( response )
231
230
232
231
# response = credit()
233
232
# validate_response(response)
234
233
235
- puts "TEST - Get Details"
234
+ logger . info "TEST - Get Details"
236
235
response = get_details ( authTransId )
237
236
validate_response ( response )
238
237
239
- puts "TEST - prior authorization and capture"
238
+ logger . info "TEST - prior authorization and capture"
240
239
response = prior_authorization_capture ( )
241
240
validate_response ( response )
242
241
@@ -248,7 +247,7 @@ def validate_response(response= nil)
248
247
end
249
248
250
249
it "should be able to run all Transaction Reporting sample code" do
251
- puts "START - Transaction Reporting"
250
+ logger . info "START - Transaction Reporting"
252
251
253
252
response = get_settled_batch_List ( )
254
253
validate_response ( response )
@@ -276,7 +275,7 @@ def validate_response(response= nil)
276
275
277
276
278
277
it "should be able to run Merchant Details sample code" do
279
- puts "START - Transaction Reporting / Merchant Details"
278
+ logger . info "START - Transaction Reporting / Merchant Details"
280
279
281
280
response = get_merchant_details ( )
282
281
validate_response ( response )
@@ -285,7 +284,7 @@ def validate_response(response= nil)
285
284
286
285
287
286
it "should be able to run all Visa Checkout sample code" do
288
- puts "START - Visa Checkout"
287
+ logger . info "START - Visa Checkout"
289
288
290
289
# response = create_visa_checkout_transaction()
291
290
# validate_response(response)
0 commit comments