Skip to content

Commit 0252548

Browse files
committed
Update all samples to use logger instead of puts.
1 parent eb353ee commit 0252548

File tree

59 files changed

+725
-606
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+725
-606
lines changed

CustomerProfiles/create-customer-payment-profile.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require 'logger'
56

67
include AuthorizeNet::API
78

89
def create_customer_payment_profile(customerProfileId = '1813343337')
910
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
11+
logger = Logger.new(STDOUT).tap { |logger| logger.level = Logger.const_get(ENV['LOGLEVEL'] || 'INFO') }
1012
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1113

1214
# Build the payment object
@@ -44,14 +46,14 @@ def create_customer_payment_profile(customerProfileId = '1813343337')
4446

4547
if response != nil
4648
if response.messages.resultCode == MessageTypeEnum::Ok
47-
puts "Successfully created a customer payment profile with id: #{response.customerPaymentProfileId}."
49+
logger.info "Successfully created a customer payment profile with id: #{response.customerPaymentProfileId}."
4850
else
49-
puts response.messages.messages[0].code
50-
puts response.messages.messages[0].text
51-
puts "Failed to create a new customer payment profile."
51+
logger.info response.messages.messages[0].code
52+
logger.info response.messages.messages[0].text
53+
logger.info "Failed to create a new customer payment profile."
5254
end
5355
else
54-
puts "Response is null"
56+
logger.error "Response is null"
5557
raise "Failed to create a new customer payment profile."
5658
end
5759
return response

CustomerProfiles/create-customer-profile-from-transaction.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require 'logger'
56

67
include AuthorizeNet::API
78

89
def create_customer_profile_from_a_transaction(transId = 60031516226)
910
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
11+
logger = Logger.new(STDOUT).tap { |logger| logger.level = Logger.const_get(ENV['LOGLEVEL'] || 'INFO') }
1012

1113
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1214

@@ -35,12 +37,12 @@ def create_customer_profile_from_a_transaction(transId = 60031516226)
3537

3638

3739
if response.messages.resultCode == MessageTypeEnum::Ok
38-
puts "Successfully created a customer profile from transaction ID #{transId}"
39-
puts "Customer profile ID: #{response.customerProfileId}"
40-
puts "New customer payment profile ID: #{response.customerPaymentProfileIdList.numericString[0]}"
41-
puts "New customer shipping profile ID (if created): #{response.customerShippingAddressIdList.numericString[0]}"
40+
logger.info "Successfully created a customer profile from transaction ID #{transId}"
41+
logger.info "Customer profile ID: #{response.customerProfileId}"
42+
logger.info "New customer payment profile ID: #{response.customerPaymentProfileIdList.numericString[0]}"
43+
logger.info "New customer shipping profile ID (if created): #{response.customerShippingAddressIdList.numericString[0]}"
4244
else
43-
puts response.messages.messages[0].text
45+
logger.error response.messages.messages[0].text
4446
raise "Failed to create a customer profile from an existing transaction."
4547
end
4648
return response

CustomerProfiles/create-customer-profile.rb

+12-10
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require 'logger'
56

67
include AuthorizeNet::API
78

89
def create_customer_profile()
910
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
1011
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
12+
logger = Logger.new(STDOUT).tap { |logger| logger.level = Logger.const_get(ENV['LOGLEVEL'] || 'INFO') }
1113

1214
# Build the payment object
1315
payment = PaymentType.new(CreditCardType.new)
@@ -60,27 +62,27 @@ def create_customer_profile()
6062
request.validationMode = ValidationModeEnum::LiveMode
6163

6264
response = transaction.create_customer_profile(request)
63-
puts response.messages.resultCode
65+
logger.info response.messages.resultCode
6466

6567
if response != nil
6668
if response.messages.resultCode == MessageTypeEnum::Ok
67-
puts "Successfully created a customer profile with id: #{response.customerProfileId}"
68-
puts " Customer Payment Profile Id List:"
69+
logger.info "Successfully created a customer profile with id: #{response.customerProfileId}"
70+
logger.info " Customer Payment Profile Id List:"
6971
response.customerPaymentProfileIdList.numericString.each do |id|
70-
puts " #{id}"
72+
logger.info " #{id}"
7173
end
72-
puts " Customer Shipping Address Id List:"
74+
logger.info " Customer Shipping Address Id List:"
7375
response.customerShippingAddressIdList.numericString.each do |id|
74-
puts " #{id}"
76+
logger.info " #{id}"
7577
end
76-
puts
78+
logger.info
7779
else
78-
puts response.messages.messages[0].code
79-
puts response.messages.messages[0].text
80+
logger.error response.messages.messages[0].code
81+
logger.error response.messages.messages[0].text
8082
raise "Failed to create a new customer profile."
8183
end
8284
else
83-
puts "Response is null"
85+
logger.info "Response is null"
8486
raise "Failed to create a new customer profile."
8587
end
8688

CustomerProfiles/create-customer-shipping-address.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require 'logger'
56

67
include AuthorizeNet::API
78

89
def create_customer_shipping_address(customerProfileId = '1813343337')
910
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
11+
logger = Logger.new(STDOUT).tap { |logger| logger.level = Logger.const_get(ENV['LOGLEVEL'] || 'INFO') }
1012

1113
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1214

@@ -19,9 +21,9 @@ def create_customer_shipping_address(customerProfileId = '1813343337')
1921

2022

2123
if response.messages.resultCode == MessageTypeEnum::Ok
22-
puts "Successfully created a customer shipping address with id: #{response.customerAddressId}."
24+
logger.info "Successfully created a customer shipping address with id: #{response.customerAddressId}."
2325
else
24-
puts "Failed to create a new customer shipping address: #{response.messages.messages[0].text}"
26+
logger.info "Failed to create a new customer shipping address: #{response.messages.messages[0].text}"
2527
end
2628
return response
2729
end

CustomerProfiles/delete-customer-payment-profile.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require 'logger'
56

67
include AuthorizeNet::API
78

89
def delete_customer_payment_profile(customerProfileId='35894174', customerPaymentProfileId='33604709')
910
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
11+
logger = Logger.new(STDOUT).tap { |logger| logger.level = Logger.const_get(ENV['LOGLEVEL'] || 'INFO') }
1012

1113
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1214

@@ -19,9 +21,9 @@ def delete_customer_payment_profile(customerProfileId='35894174', customerPaymen
1921

2022

2123
if response.messages.resultCode == MessageTypeEnum::Ok
22-
puts "Successfully deleted payment profile with customer payment profile ID #{request.customerPaymentProfileId}."
24+
logger.info "Successfully deleted payment profile with customer payment profile ID #{request.customerPaymentProfileId}."
2325
else
24-
puts "Failed to delete payment profile with profile ID #{request.customerPaymentProfileId}: #{response.messages.messages[0].text}"
26+
logger.info "Failed to delete payment profile with profile ID #{request.customerPaymentProfileId}: #{response.messages.messages[0].text}"
2527
end
2628
return response
2729
end

CustomerProfiles/delete-customer-profile.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require 'logger'
56

67
include AuthorizeNet::API
78

89
def delete_customer_profile(customerProfileId = '36551110')
910
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
11+
logger = Logger.new(STDOUT).tap { |logger| logger.level = Logger.const_get(ENV['LOGLEVEL'] || 'INFO') }
1012

1113
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1214

@@ -18,9 +20,9 @@ def delete_customer_profile(customerProfileId = '36551110')
1820

1921

2022
if response.messages.resultCode == MessageTypeEnum::Ok
21-
puts "Successfully deleted customer with customer profile ID #{request.customerProfileId}."
23+
logger.info "Successfully deleted customer with customer profile ID #{request.customerProfileId}."
2224
else
23-
puts response.messages.messages[0].text
25+
logger.error response.messages.messages[0].text
2426
raise "Failed to delete customer with customer profile ID #{request.customerProfileId}."
2527
end
2628
return response

CustomerProfiles/delete-customer-shipping-address.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require 'logger'
56

67
include AuthorizeNet::API
78

89
def delete_customer_shipping_address(customerProfileId = '36551110', customerAddressId = '35894174')
910
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
11+
logger = Logger.new(STDOUT).tap { |logger| logger.level = Logger.const_get(ENV['LOGLEVEL'] || 'INFO') }
1012

1113
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1214

@@ -19,9 +21,9 @@ def delete_customer_shipping_address(customerProfileId = '36551110', customerAdd
1921

2022

2123
if response.messages.resultCode == MessageTypeEnum::Ok
22-
puts "Successfully deleted shipping address with customer shipping profile ID #{request.customerAddressId}."
24+
logger.info "Successfully deleted shipping address with customer shipping profile ID #{request.customerAddressId}."
2325
else
24-
puts response.messages.messages[0].text
26+
logger.error response.messages.messages[0].text
2527
raise "Failed to delete payment profile with profile ID #{request.customerAddressId}."
2628
end
2729
return response

CustomerProfiles/get-accept-customer-profile-page.rb

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require 'logger'
56

67
include AuthorizeNet::API
78

89
def get_accept_customer_profile_page(customerProfileId = '37696245')
910
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
11+
logger = Logger.new(STDOUT).tap { |logger| logger.level = Logger.const_get(ENV['LOGLEVEL'] || 'INFO') }
1012

1113
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1214

@@ -25,13 +27,13 @@ def get_accept_customer_profile_page(customerProfileId = '37696245')
2527
response = transaction.get_hosted_profile_page(request)
2628

2729
if response.messages.resultCode == MessageTypeEnum::Ok
28-
puts "Successfully got Accept Customer page token."
29-
puts " Response code: #{response.messages.messages[0].code}"
30-
puts " Response message: #{response.messages.messages[0].text}"
31-
puts " Token: #{response.token}"
30+
logger.info "Successfully got Accept Customer page token."
31+
logger.info " Response code: #{response.messages.messages[0].code}"
32+
logger.info " Response message: #{response.messages.messages[0].text}"
33+
logger.info " Token: #{response.token}"
3234
else
33-
puts "#{response.messages.messages[0].code}"
34-
puts "#{response.messages.messages[0].text}"
35+
logger.info "#{response.messages.messages[0].code}"
36+
logger.info "#{response.messages.messages[0].text}"
3537
raise "Failed to get hosted profile page with customer profile ID #{request.customerProfileId}"
3638
end
3739
return response

CustomerProfiles/get-customer-payment-profile-list.rb

+11-9
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require 'logger'
56

67
include AuthorizeNet::API
78

89
def get_customer_payment_profile_list()
910
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
11+
logger = Logger.new(STDOUT).tap { |logger| logger.level = Logger.const_get(ENV['LOGLEVEL'] || 'INFO') }
1012

1113
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1214

@@ -31,18 +33,18 @@ def get_customer_payment_profile_list()
3133
response = transaction.get_customer_payment_profile_list(request)
3234

3335
if response.messages.resultCode == MessageTypeEnum::Ok
34-
puts "Successfully got customer payment profile list."
35-
puts response.messages.messages[0].code
36-
puts response.messages.messages[0].text
37-
puts " Total number in result set: #{response.totalNumInResultSet}"
36+
logger.info "Successfully got customer payment profile list."
37+
logger.info response.messages.messages[0].code
38+
logger.info response.messages.messages[0].text
39+
logger.info " Total number in result set: #{response.totalNumInResultSet}"
3840
# response.paymentProfiles.paymentProfile.each do |paymentProfile|
39-
# puts "Payment profile ID = #{paymentProfile.customerPaymentProfileId}"
40-
# puts "First Name in Billing Address = #{paymentProfile.billTo.firstName}"
41-
# puts "Credit Card Number = #{paymentProfile.payment.creditCard.cardNumber}"
41+
# logger.info "Payment profile ID = #{paymentProfile.customerPaymentProfileId}"
42+
# logger.info "First Name in Billing Address = #{paymentProfile.billTo.firstName}"
43+
# logger.info "Credit Card Number = #{paymentProfile.payment.creditCard.cardNumber}"
4244
# end
4345
else
44-
puts response.messages.messages[0].code
45-
puts response.messages.messages[0].text
46+
logger.error response.messages.messages[0].code
47+
logger.error response.messages.messages[0].text
4648
raise "Failed to get customer payment profile list"
4749
end
4850
return response

CustomerProfiles/get-customer-payment-profile.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require 'logger'
56

67
include AuthorizeNet::API
78

89
def get_customer_payment_profile(customerProfileId = '40036377', customerPaymentProfileId = '36315992')
910
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
11+
logger = Logger.new(STDOUT).tap { |logger| logger.level = Logger.const_get(ENV['LOGLEVEL'] || 'INFO') }
1012

1113
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1214

@@ -19,17 +21,17 @@ def get_customer_payment_profile(customerProfileId = '40036377', customerPayment
1921

2022

2123
if response.messages.resultCode == MessageTypeEnum::Ok
22-
puts "Successfully retrieved a payment profile with profile ID #{request.customerPaymentProfileId} and whose customer ID is #{request.customerProfileId}."
24+
logger.info "Successfully retrieved a payment profile with profile ID #{request.customerPaymentProfileId} and whose customer ID is #{request.customerProfileId}."
2325

2426
if response.paymentProfile.subscriptionIds != nil && response.paymentProfile.subscriptionIds.subscriptionId != nil
25-
puts " List of subscriptions: "
27+
logger.info " List of subscriptions: "
2628
response.paymentProfile.subscriptionIds.subscriptionId.each do |subscriptionId|
27-
puts "#{subscriptionId}"
29+
logger.info "#{subscriptionId}"
2830
end
2931
end
3032

3133
else
32-
puts response.messages.messages[0].text
34+
logger.error response.messages.messages[0].text
3335
raise "Failed to get payment profile information with ID #{request.customerPaymentProfileId}."
3436
end
3537
return response

CustomerProfiles/get-customer-profile-ids.rb

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require 'logger'
56

67
include AuthorizeNet::API
78

89
def get_customer_profile_ids()
910
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
11+
logger = Logger.new(STDOUT).tap { |logger| logger.level = Logger.const_get(ENV['LOGLEVEL'] || 'INFO') }
1012

1113
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1214

@@ -17,23 +19,23 @@ def get_customer_profile_ids()
1719

1820

1921
if response.messages.resultCode == MessageTypeEnum::Ok
20-
puts "Successfully retrieved customer IDs."
21-
puts " Number of IDs returned: #{response.ids.numericString.count}"
22+
logger.info "Successfully retrieved customer IDs."
23+
logger.info " Number of IDs returned: #{response.ids.numericString.count}"
2224
# There's no paging options in this API request; the full list is returned every call.
2325
# If the result set is going to be large, for this sample we'll break it down into smaller
2426
# chunks so that we don't put 72,000 lines into a log file
25-
puts " First 20 results:"
27+
logger.info " First 20 results:"
2628
for profileId in 0..19 do
27-
puts " #{response.ids.numericString[profileId]}"
29+
logger.info " #{response.ids.numericString[profileId]}"
2830
end
2931
# If we wanted to just return the whole list, we'd do something like this:
3032
#
3133
# response.ids.numericString.each do |id|
32-
# puts id
34+
# logger.info id
3335
# end
3436

3537
else
36-
puts response.messages.messages[0].text
38+
logger.error response.messages.messages[0].text
3739
raise "Failed to get customer IDs."
3840
end
3941
return response

0 commit comments

Comments
 (0)