Skip to content

Commit 84f4560

Browse files
committed
Update all samples to use logger instead of puts.
1 parent c055d90 commit 84f4560

File tree

59 files changed

+665
-717
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

+665
-717
lines changed

CustomerProfiles/create-customer-payment-profile.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require_relative '../shared_helper'
56

67
include AuthorizeNet::API
78

89
def create_customer_payment_profile(customerProfileId = '1813343337')
9-
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
1010
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1111

1212
# Build the payment object
@@ -44,14 +44,14 @@ def create_customer_payment_profile(customerProfileId = '1813343337')
4444

4545
if response != nil
4646
if response.messages.resultCode == MessageTypeEnum::Ok
47-
puts "Successfully created a customer payment profile with id: #{response.customerPaymentProfileId}."
47+
logger.info "Successfully created a customer payment profile with id: #{response.customerPaymentProfileId}."
4848
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."
49+
logger.info response.messages.messages[0].code
50+
logger.info response.messages.messages[0].text
51+
logger.info "Failed to create a new customer payment profile."
5252
end
5353
else
54-
puts "Response is null"
54+
logger.error "Response is null"
5555
raise "Failed to create a new customer payment profile."
5656
end
5757
return response

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

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require_relative '../shared_helper'
56

67
include AuthorizeNet::API
78

89
def create_customer_profile_from_a_transaction(transId = 60031516226)
9-
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
10-
1110
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1211

1312

@@ -35,12 +34,12 @@ def create_customer_profile_from_a_transaction(transId = 60031516226)
3534

3635

3736
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]}"
37+
logger.info "Successfully created a customer profile from transaction ID #{transId}"
38+
logger.info "Customer profile ID: #{response.customerProfileId}"
39+
logger.info "New customer payment profile ID: #{response.customerPaymentProfileIdList.numericString[0]}"
40+
logger.info "New customer shipping profile ID (if created): #{response.customerShippingAddressIdList.numericString[0]}"
4241
else
43-
puts response.messages.messages[0].text
42+
logger.error response.messages.messages[0].text
4443
raise "Failed to create a customer profile from an existing transaction."
4544
end
4645
return response

CustomerProfiles/create-customer-profile.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require_relative '../shared_helper'
56

67
include AuthorizeNet::API
78

89
def create_customer_profile()
9-
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
1010
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1111

1212
# Build the payment object
@@ -60,27 +60,27 @@ def create_customer_profile()
6060
request.validationMode = ValidationModeEnum::LiveMode
6161

6262
response = transaction.create_customer_profile(request)
63-
puts response.messages.resultCode
63+
logger.info response.messages.resultCode
6464

6565
if response != nil
6666
if response.messages.resultCode == MessageTypeEnum::Ok
67-
puts "Successfully created a customer profile with id: #{response.customerProfileId}"
68-
puts " Customer Payment Profile Id List:"
67+
logger.info "Successfully created a customer profile with id: #{response.customerProfileId}"
68+
logger.info " Customer Payment Profile Id List:"
6969
response.customerPaymentProfileIdList.numericString.each do |id|
70-
puts " #{id}"
70+
logger.info " #{id}"
7171
end
72-
puts " Customer Shipping Address Id List:"
72+
logger.info " Customer Shipping Address Id List:"
7373
response.customerShippingAddressIdList.numericString.each do |id|
74-
puts " #{id}"
74+
logger.info " #{id}"
7575
end
76-
puts
76+
logger.info
7777
else
78-
puts response.messages.messages[0].code
79-
puts response.messages.messages[0].text
78+
logger.error response.messages.messages[0].code
79+
logger.error response.messages.messages[0].text
8080
raise "Failed to create a new customer profile."
8181
end
8282
else
83-
puts "Response is null"
83+
logger.info "Response is null"
8484
raise "Failed to create a new customer profile."
8585
end
8686

CustomerProfiles/create-customer-shipping-address.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require_relative '../shared_helper'
56

67
include AuthorizeNet::API
78

89
def create_customer_shipping_address(customerProfileId = '1813343337')
9-
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
10-
1110
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1211

1312

@@ -19,9 +18,9 @@ def create_customer_shipping_address(customerProfileId = '1813343337')
1918

2019

2120
if response.messages.resultCode == MessageTypeEnum::Ok
22-
puts "Successfully created a customer shipping address with id: #{response.customerAddressId}."
21+
logger.info "Successfully created a customer shipping address with id: #{response.customerAddressId}."
2322
else
24-
puts "Failed to create a new customer shipping address: #{response.messages.messages[0].text}"
23+
logger.info "Failed to create a new customer shipping address: #{response.messages.messages[0].text}"
2524
end
2625
return response
2726
end

CustomerProfiles/delete-customer-payment-profile.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require_relative '../shared_helper'
56

67
include AuthorizeNet::API
78

89
def delete_customer_payment_profile(customerProfileId='35894174', customerPaymentProfileId='33604709')
9-
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
10-
1110
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1211

1312

@@ -19,9 +18,9 @@ def delete_customer_payment_profile(customerProfileId='35894174', customerPaymen
1918

2019

2120
if response.messages.resultCode == MessageTypeEnum::Ok
22-
puts "Successfully deleted payment profile with customer payment profile ID #{request.customerPaymentProfileId}."
21+
logger.info "Successfully deleted payment profile with customer payment profile ID #{request.customerPaymentProfileId}."
2322
else
24-
puts "Failed to delete payment profile with profile ID #{request.customerPaymentProfileId}: #{response.messages.messages[0].text}"
23+
logger.info "Failed to delete payment profile with profile ID #{request.customerPaymentProfileId}: #{response.messages.messages[0].text}"
2524
end
2625
return response
2726
end

CustomerProfiles/delete-customer-profile.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require_relative '../shared_helper'
56

67
include AuthorizeNet::API
78

89
def delete_customer_profile(customerProfileId = '36551110')
9-
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
10-
1110
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1211

1312

@@ -18,9 +17,9 @@ def delete_customer_profile(customerProfileId = '36551110')
1817

1918

2019
if response.messages.resultCode == MessageTypeEnum::Ok
21-
puts "Successfully deleted customer with customer profile ID #{request.customerProfileId}."
20+
logger.info "Successfully deleted customer with customer profile ID #{request.customerProfileId}."
2221
else
23-
puts response.messages.messages[0].text
22+
logger.error response.messages.messages[0].text
2423
raise "Failed to delete customer with customer profile ID #{request.customerProfileId}."
2524
end
2625
return response

CustomerProfiles/delete-customer-shipping-address.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require_relative '../shared_helper'
56

67
include AuthorizeNet::API
78

89
def delete_customer_shipping_address(customerProfileId = '36551110', customerAddressId = '35894174')
9-
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
10-
1110
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1211

1312

@@ -19,9 +18,9 @@ def delete_customer_shipping_address(customerProfileId = '36551110', customerAdd
1918

2019

2120
if response.messages.resultCode == MessageTypeEnum::Ok
22-
puts "Successfully deleted shipping address with customer shipping profile ID #{request.customerAddressId}."
21+
logger.info "Successfully deleted shipping address with customer shipping profile ID #{request.customerAddressId}."
2322
else
24-
puts response.messages.messages[0].text
23+
logger.error response.messages.messages[0].text
2524
raise "Failed to delete payment profile with profile ID #{request.customerAddressId}."
2625
end
2726
return response

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require_relative '../shared_helper'
56

67
include AuthorizeNet::API
78

89
def get_accept_customer_profile_page(customerProfileId = '37696245')
9-
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
10-
1110
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1211

1312
setting = SettingType.new
@@ -25,13 +24,13 @@ def get_accept_customer_profile_page(customerProfileId = '37696245')
2524
response = transaction.get_hosted_profile_page(request)
2625

2726
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}"
27+
logger.info "Successfully got Accept Customer page token."
28+
logger.info " Response code: #{response.messages.messages[0].code}"
29+
logger.info " Response message: #{response.messages.messages[0].text}"
30+
logger.info " Token: #{response.token}"
3231
else
33-
puts "#{response.messages.messages[0].code}"
34-
puts "#{response.messages.messages[0].text}"
32+
logger.info "#{response.messages.messages[0].code}"
33+
logger.info "#{response.messages.messages[0].text}"
3534
raise "Failed to get hosted profile page with customer profile ID #{request.customerProfileId}"
3635
end
3736
return response

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

+10-11
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require_relative '../shared_helper'
56

67
include AuthorizeNet::API
78

89
def get_customer_payment_profile_list()
9-
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
10-
1110
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1211

1312
searchTypeEnum = CustomerPaymentProfileSearchTypeEnum::CardsExpiringInMonth
@@ -31,18 +30,18 @@ def get_customer_payment_profile_list()
3130
response = transaction.get_customer_payment_profile_list(request)
3231

3332
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}"
33+
logger.info "Successfully got customer payment profile list."
34+
logger.info response.messages.messages[0].code
35+
logger.info response.messages.messages[0].text
36+
logger.info " Total number in result set: #{response.totalNumInResultSet}"
3837
# 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}"
38+
# logger.info "Payment profile ID = #{paymentProfile.customerPaymentProfileId}"
39+
# logger.info "First Name in Billing Address = #{paymentProfile.billTo.firstName}"
40+
# logger.info "Credit Card Number = #{paymentProfile.payment.creditCard.cardNumber}"
4241
# end
4342
else
44-
puts response.messages.messages[0].code
45-
puts response.messages.messages[0].text
43+
logger.error response.messages.messages[0].code
44+
logger.error response.messages.messages[0].text
4645
raise "Failed to get customer payment profile list"
4746
end
4847
return response

CustomerProfiles/get-customer-payment-profile.rb

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require_relative '../shared_helper'
56

67
include AuthorizeNet::API
78

89
def get_customer_payment_profile(customerProfileId = '40036377', customerPaymentProfileId = '36315992')
9-
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
10-
1110
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1211

1312

@@ -19,17 +18,17 @@ def get_customer_payment_profile(customerProfileId = '40036377', customerPayment
1918

2019

2120
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}."
21+
logger.info "Successfully retrieved a payment profile with profile ID #{request.customerPaymentProfileId} and whose customer ID is #{request.customerProfileId}."
2322

2423
if response.paymentProfile.subscriptionIds != nil && response.paymentProfile.subscriptionIds.subscriptionId != nil
25-
puts " List of subscriptions: "
24+
logger.info " List of subscriptions: "
2625
response.paymentProfile.subscriptionIds.subscriptionId.each do |subscriptionId|
27-
puts "#{subscriptionId}"
26+
logger.info "#{subscriptionId}"
2827
end
2928
end
3029

3130
else
32-
puts response.messages.messages[0].text
31+
logger.error response.messages.messages[0].text
3332
raise "Failed to get payment profile information with ID #{request.customerPaymentProfileId}."
3433
end
3534
return response

CustomerProfiles/get-customer-profile-ids.rb

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
require 'yaml'
33
require 'authorizenet'
44
require 'securerandom'
5+
require_relative '../shared_helper'
56

67
include AuthorizeNet::API
78

89
def get_customer_profile_ids()
9-
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
10-
1110
transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox)
1211

1312

@@ -17,23 +16,23 @@ def get_customer_profile_ids()
1716

1817

1918
if response.messages.resultCode == MessageTypeEnum::Ok
20-
puts "Successfully retrieved customer IDs."
21-
puts " Number of IDs returned: #{response.ids.numericString.count}"
19+
logger.info "Successfully retrieved customer IDs."
20+
logger.info " Number of IDs returned: #{response.ids.numericString.count}"
2221
# There's no paging options in this API request; the full list is returned every call.
2322
# If the result set is going to be large, for this sample we'll break it down into smaller
2423
# chunks so that we don't put 72,000 lines into a log file
25-
puts " First 20 results:"
24+
logger.info " First 20 results:"
2625
for profileId in 0..19 do
27-
puts " #{response.ids.numericString[profileId]}"
26+
logger.info " #{response.ids.numericString[profileId]}"
2827
end
2928
# If we wanted to just return the whole list, we'd do something like this:
3029
#
3130
# response.ids.numericString.each do |id|
32-
# puts id
31+
# logger.info id
3332
# end
3433

3534
else
36-
puts response.messages.messages[0].text
35+
logger.error response.messages.messages[0].text
3736
raise "Failed to get customer IDs."
3837
end
3938
return response

0 commit comments

Comments
 (0)