diff --git a/CustomerProfiles/create-customer-profile-from-a-transaction.rb b/CustomerProfiles/create-customer-profile-from-a-transaction.rb deleted file mode 100644 index 1f5a812..0000000 --- a/CustomerProfiles/create-customer-profile-from-a-transaction.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'rubygems' - require 'yaml' - require 'authorizenet' - require 'securerandom' - - include AuthorizeNet::API - - def create_customer_profile_from_a_transaction(transId = 2242762682) - config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml") - - transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox) - - - request = CreateCustomerProfileFromTransactionRequest.new - request.transId = transId - response = transaction.create_customer_profile_from_transaction(request) - - - if response.messages.resultCode == MessageTypeEnum::Ok - puts "Successfully created a customer profile from the transaction id #{response.customerProfileId}" - else - puts response.messages.messages[0].text - raise "Failed to create a customer profile from an existing transaction." - end - return response - end - -if __FILE__ == $0 - create_customer_profile_from_a_transaction() -end diff --git a/CustomerProfiles/create-customer-profile-from-transaction.rb b/CustomerProfiles/create-customer-profile-from-transaction.rb index 13b23c1..da2f56e 100644 --- a/CustomerProfiles/create-customer-profile-from-transaction.rb +++ b/CustomerProfiles/create-customer-profile-from-transaction.rb @@ -1,11 +1,11 @@ require 'rubygems' - require 'yaml' - require 'authorizenet' - require 'securerandom' +require 'yaml' +require 'authorizenet' +require 'securerandom' include AuthorizeNet::API - def create_customer_profile_from_a_transaction(transId = 2242762682) + 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) @@ -14,20 +14,31 @@ def create_customer_profile_from_a_transaction(transId = 2242762682) request = CreateCustomerProfileFromTransactionRequest.new request.transId = transId - #You can either specify the customer information in form of customerProfileBaseType object - request.customer = CustomerProfileBaseType.new - request.customer.merchantCustomerId = "1231232" + # You can either specify the customer information to create a new customer profile + # or, specify an existing customer profile ID to create a new customer payment profile + # attached to the existing customer profile. If no profile information is specified, + # a new profile will still be created as long as either an ID or email exists in the + # original transaction that can be used to identify a new profile. + # + # To create a new customer profile containing a payment profile with this transaction's + # payment information, submit the new profile information in the form of a + # customerProfileBaseType object + request.customer = CustomerProfileBaseType.new + request.customer.merchantCustomerId = "1231232" request.customer.description = "This is a sample customer profile" request.customer.email = "johnsnow@castleblack.com" - # OR - # You can just provide the customer Profile ID - # customerProfileId = "123343" + # -OR- to create a payment profile under an existing customer profile, + # just provide the customer Profile ID + # customerProfileId = "123343" response = transaction.create_customer_profile_from_transaction(request) if response.messages.resultCode == MessageTypeEnum::Ok - puts "Successfully created a customer profile from the transaction id #{response.customerProfileId}" + 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]}" else puts response.messages.messages[0].text raise "Failed to create a customer profile from an existing transaction." diff --git a/CustomerProfiles/create-customer-profile-with-accept.rb b/CustomerProfiles/create-customer-profile-with-accept.rb deleted file mode 100644 index 083951b..0000000 --- a/CustomerProfiles/create-customer-profile-with-accept.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'rubygems' - require 'yaml' - require 'authorizenet' - - require 'securerandom' - - include AuthorizeNet::API - - def create_customer_profile_with_accept() - config = YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml") - - - transaction = Transaction.new(config['api_login_id'], config['api_transaction_key'], :gateway => :sandbox) - - - request = CreateCustomerProfileRequest.new - payment = PaymentType.new - payment.opaqueData = OpaqueDataType.new('COMMON.ACCEPT.INAPP.PAYMENT','9487004388327322604603',nil) - profile = CustomerPaymentProfileType.new(nil,nil,payment,nil,nil) - - request.profile = CustomerProfileType.new('jdoe'+rand(10000).to_s,'John2 Doe',rand(10000).to_s + '@mail.com', [profile], nil) - - response = transaction.create_customer_profile(request) - - 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:" - response.customerPaymentProfileIdList.numericString.each do |id| - puts id - end - puts "Customer Shipping Address Id List:" - response.customerShippingAddressIdList.numericString.each do |id| - puts id - end - else - puts "Transaction Failed" - puts response.messages.messages[0].text - raise "Failed to create a new customer profile." - end - else - puts "Transaction Failed" - end - return response - end - -if __FILE__ == $0 - create_customer_profile_with_accept() -end -