Skip to content

Use logger #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions CustomerProfiles/create-customer-payment-profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
require 'yaml'
require 'authorizenet'
require 'securerandom'
require_relative '../shared_helper'

include AuthorizeNet::API

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

# Build the payment object
Expand Down Expand Up @@ -44,14 +44,14 @@ def create_customer_payment_profile(customerProfileId = '1813343337')

if response != nil
if response.messages.resultCode == MessageTypeEnum::Ok
puts "Successfully created a customer payment profile with id: #{response.customerPaymentProfileId}."
logger.info "Successfully created a customer payment profile with id: #{response.customerPaymentProfileId}."
else
puts response.messages.messages[0].code
puts response.messages.messages[0].text
puts "Failed to create a new customer payment profile."
logger.info response.messages.messages[0].code
logger.info response.messages.messages[0].text
logger.info "Failed to create a new customer payment profile."
end
else
puts "Response is null"
logger.error "Response is null"
raise "Failed to create a new customer payment profile."
end
return response
Expand Down
13 changes: 6 additions & 7 deletions CustomerProfiles/create-customer-profile-from-transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
require 'yaml'
require 'authorizenet'
require 'securerandom'
require_relative '../shared_helper'

include AuthorizeNet::API

def create_customer_profile_from_a_transaction(transId = 60031516226)
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")

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


Expand Down Expand Up @@ -35,12 +34,12 @@ def create_customer_profile_from_a_transaction(transId = 60031516226)


if response.messages.resultCode == MessageTypeEnum::Ok
puts "Successfully created a customer profile from transaction ID #{transId}"
puts "Customer profile ID: #{response.customerProfileId}"
puts "New customer payment profile ID: #{response.customerPaymentProfileIdList.numericString[0]}"
puts "New customer shipping profile ID (if created): #{response.customerShippingAddressIdList.numericString[0]}"
logger.info "Successfully created a customer profile from transaction ID #{transId}"
logger.info "Customer profile ID: #{response.customerProfileId}"
logger.info "New customer payment profile ID: #{response.customerPaymentProfileIdList.numericString[0]}"
logger.info "New customer shipping profile ID (if created): #{response.customerShippingAddressIdList.numericString[0]}"
else
puts response.messages.messages[0].text
logger.error response.messages.messages[0].text
raise "Failed to create a customer profile from an existing transaction."
end
return response
Expand Down
22 changes: 11 additions & 11 deletions CustomerProfiles/create-customer-profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
require 'yaml'
require 'authorizenet'
require 'securerandom'
require_relative '../shared_helper'

include AuthorizeNet::API

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

# Build the payment object
Expand Down Expand Up @@ -60,27 +60,27 @@ def create_customer_profile()
request.validationMode = ValidationModeEnum::LiveMode

response = transaction.create_customer_profile(request)
puts response.messages.resultCode
logger.info response.messages.resultCode

if response != nil
if response.messages.resultCode == MessageTypeEnum::Ok
puts "Successfully created a customer profile with id: #{response.customerProfileId}"
puts " Customer Payment Profile Id List:"
logger.info "Successfully created a customer profile with id: #{response.customerProfileId}"
logger.info " Customer Payment Profile Id List:"
response.customerPaymentProfileIdList.numericString.each do |id|
puts " #{id}"
logger.info " #{id}"
end
puts " Customer Shipping Address Id List:"
logger.info " Customer Shipping Address Id List:"
response.customerShippingAddressIdList.numericString.each do |id|
puts " #{id}"
logger.info " #{id}"
end
puts
logger.info
else
puts response.messages.messages[0].code
puts response.messages.messages[0].text
logger.error response.messages.messages[0].code
logger.error response.messages.messages[0].text
raise "Failed to create a new customer profile."
end
else
puts "Response is null"
logger.info "Response is null"
raise "Failed to create a new customer profile."
end

Expand Down
7 changes: 3 additions & 4 deletions CustomerProfiles/create-customer-shipping-address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
require 'yaml'
require 'authorizenet'
require 'securerandom'
require_relative '../shared_helper'

include AuthorizeNet::API

def create_customer_shipping_address(customerProfileId = '1813343337')
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")

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


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


if response.messages.resultCode == MessageTypeEnum::Ok
puts "Successfully created a customer shipping address with id: #{response.customerAddressId}."
logger.info "Successfully created a customer shipping address with id: #{response.customerAddressId}."
else
puts "Failed to create a new customer shipping address: #{response.messages.messages[0].text}"
logger.info "Failed to create a new customer shipping address: #{response.messages.messages[0].text}"
end
return response
end
Expand Down
7 changes: 3 additions & 4 deletions CustomerProfiles/delete-customer-payment-profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
require 'yaml'
require 'authorizenet'
require 'securerandom'
require_relative '../shared_helper'

include AuthorizeNet::API

def delete_customer_payment_profile(customerProfileId='35894174', customerPaymentProfileId='33604709')
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")

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


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


if response.messages.resultCode == MessageTypeEnum::Ok
puts "Successfully deleted payment profile with customer payment profile ID #{request.customerPaymentProfileId}."
logger.info "Successfully deleted payment profile with customer payment profile ID #{request.customerPaymentProfileId}."
else
puts "Failed to delete payment profile with profile ID #{request.customerPaymentProfileId}: #{response.messages.messages[0].text}"
logger.info "Failed to delete payment profile with profile ID #{request.customerPaymentProfileId}: #{response.messages.messages[0].text}"
end
return response
end
Expand Down
7 changes: 3 additions & 4 deletions CustomerProfiles/delete-customer-profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
require 'yaml'
require 'authorizenet'
require 'securerandom'
require_relative '../shared_helper'

include AuthorizeNet::API

def delete_customer_profile(customerProfileId = '36551110')
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")

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


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


if response.messages.resultCode == MessageTypeEnum::Ok
puts "Successfully deleted customer with customer profile ID #{request.customerProfileId}."
logger.info "Successfully deleted customer with customer profile ID #{request.customerProfileId}."
else
puts response.messages.messages[0].text
logger.error response.messages.messages[0].text
raise "Failed to delete customer with customer profile ID #{request.customerProfileId}."
end
return response
Expand Down
7 changes: 3 additions & 4 deletions CustomerProfiles/delete-customer-shipping-address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
require 'yaml'
require 'authorizenet'
require 'securerandom'
require_relative '../shared_helper'

include AuthorizeNet::API

def delete_customer_shipping_address(customerProfileId = '36551110', customerAddressId = '35894174')
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")

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


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


if response.messages.resultCode == MessageTypeEnum::Ok
puts "Successfully deleted shipping address with customer shipping profile ID #{request.customerAddressId}."
logger.info "Successfully deleted shipping address with customer shipping profile ID #{request.customerAddressId}."
else
puts response.messages.messages[0].text
logger.error response.messages.messages[0].text
raise "Failed to delete payment profile with profile ID #{request.customerAddressId}."
end
return response
Expand Down
15 changes: 7 additions & 8 deletions CustomerProfiles/get-accept-customer-profile-page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
require 'yaml'
require 'authorizenet'
require 'securerandom'
require_relative '../shared_helper'

include AuthorizeNet::API

def get_accept_customer_profile_page(customerProfileId = '37696245')
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")

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

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

if response.messages.resultCode == MessageTypeEnum::Ok
puts "Successfully got Accept Customer page token."
puts " Response code: #{response.messages.messages[0].code}"
puts " Response message: #{response.messages.messages[0].text}"
puts " Token: #{response.token}"
logger.info "Successfully got Accept Customer page token."
logger.info " Response code: #{response.messages.messages[0].code}"
logger.info " Response message: #{response.messages.messages[0].text}"
logger.info " Token: #{response.token}"
else
puts "#{response.messages.messages[0].code}"
puts "#{response.messages.messages[0].text}"
logger.info "#{response.messages.messages[0].code}"
logger.info "#{response.messages.messages[0].text}"
raise "Failed to get hosted profile page with customer profile ID #{request.customerProfileId}"
end
return response
Expand Down
21 changes: 10 additions & 11 deletions CustomerProfiles/get-customer-payment-profile-list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
require 'yaml'
require 'authorizenet'
require 'securerandom'
require_relative '../shared_helper'

include AuthorizeNet::API

def get_customer_payment_profile_list()
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")

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

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

if response.messages.resultCode == MessageTypeEnum::Ok
puts "Successfully got customer payment profile list."
puts response.messages.messages[0].code
puts response.messages.messages[0].text
puts " Total number in result set: #{response.totalNumInResultSet}"
logger.info "Successfully got customer payment profile list."
logger.info response.messages.messages[0].code
logger.info response.messages.messages[0].text
logger.info " Total number in result set: #{response.totalNumInResultSet}"
# response.paymentProfiles.paymentProfile.each do |paymentProfile|
# puts "Payment profile ID = #{paymentProfile.customerPaymentProfileId}"
# puts "First Name in Billing Address = #{paymentProfile.billTo.firstName}"
# puts "Credit Card Number = #{paymentProfile.payment.creditCard.cardNumber}"
# logger.info "Payment profile ID = #{paymentProfile.customerPaymentProfileId}"
# logger.info "First Name in Billing Address = #{paymentProfile.billTo.firstName}"
# logger.info "Credit Card Number = #{paymentProfile.payment.creditCard.cardNumber}"
# end
else
puts response.messages.messages[0].code
puts response.messages.messages[0].text
logger.error response.messages.messages[0].code
logger.error response.messages.messages[0].text
raise "Failed to get customer payment profile list"
end
return response
Expand Down
11 changes: 5 additions & 6 deletions CustomerProfiles/get-customer-payment-profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
require 'yaml'
require 'authorizenet'
require 'securerandom'
require_relative '../shared_helper'

include AuthorizeNet::API

def get_customer_payment_profile(customerProfileId = '40036377', customerPaymentProfileId = '36315992')
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")

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


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


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

if response.paymentProfile.subscriptionIds != nil && response.paymentProfile.subscriptionIds.subscriptionId != nil
puts " List of subscriptions: "
logger.info " List of subscriptions: "
response.paymentProfile.subscriptionIds.subscriptionId.each do |subscriptionId|
puts "#{subscriptionId}"
logger.info "#{subscriptionId}"
end
end

else
puts response.messages.messages[0].text
logger.error response.messages.messages[0].text
raise "Failed to get payment profile information with ID #{request.customerPaymentProfileId}."
end
return response
Expand Down
15 changes: 7 additions & 8 deletions CustomerProfiles/get-customer-profile-ids.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
require 'yaml'
require 'authorizenet'
require 'securerandom'
require_relative '../shared_helper'

include AuthorizeNet::API

def get_customer_profile_ids()
config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")

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


Expand All @@ -17,23 +16,23 @@ def get_customer_profile_ids()


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

else
puts response.messages.messages[0].text
logger.error response.messages.messages[0].text
raise "Failed to get customer IDs."
end
return response
Expand Down
Loading