cancel
Showing results for 
Search instead for 
Did you mean: 

python, fail to provide payment information for createCustomProfileRequest()

 

I need to validate payment information during createCustomProfileRequest() call, to avoid of doing subseqent requests. In Request specification listed payment and paymentProfiles, but when I try to include one of them to sample code it just silently ignores it. Here is my code below. Please point me what I doing wrong? May be it is simply not realized for python? Thanks.

 

def create_customer_profile():

	merchantAuth = apicontractsv1.merchantAuthenticationType()
	merchantAuth.name = constants.apiLoginId
	merchantAuth.transactionKey = constants.transactionKey


	createCustomerProfile = apicontractsv1.createCustomerProfileRequest()
	createCustomerProfile.merchantAuthentication = merchantAuth
	createCustomerProfile.profile = apicontractsv1.customerProfileType('jdoe' + str(random.randint(0, 10000)), 'John2 Doe', 'jdoe@mail.com')


	creditCard = apicontractsv1.creditCardType()
	creditCard.cardNumber = "4111111111111111"
	creditCard.expirationDate = "2020-12"

	payment = apicontractsv1.paymentType()
	payment.creditCard = creditCard


	createCustomerProfile.payment = payment

	controller = createCustomerProfileController(createCustomerProfile)

	controller.execute()

	response = controller.getresponse()

	if (response.messages.resultCode=="Ok"):
		print "Successfully created a customer profile with id: %s" % response.customerProfileId
	else:
		print "Failed to create customer payment profile %s" % response.messages.message[0].text

	return response

if(os.path.basename(__file__) == sys.argv[0].split('/')[-1]):
	create_customer_profile()

 

Aidamir
Member
1 REPLY 1

I have found mistake, I did place my paymentProfiles to the root createCustomerProfileRequest class

but it needs to be placed to profile element of the root class. Here is working code:

def create_customer_profile():

	merchantAuth = apicontractsv1.merchantAuthenticationType()
	merchantAuth.name = constants.apiLoginId
	merchantAuth.transactionKey = constants.transactionKey


	createCustomerProfile = apicontractsv1.createCustomerProfileRequest()
	createCustomerProfile.merchantAuthentication = merchantAuth
	createCustomerProfile.profile = apicontractsv1.customerProfileType('jdoe' + str(random.randint(0, 10000)), 'John2 Doe', 'jdoe@mail.com')


	creditCard = apicontractsv1.creditCardType()
	creditCard.cardNumber = "4111111111111111"
	creditCard.expirationDate = "2020-12"

	payment = apicontractsv1.paymentType()
	payment.creditCard = creditCard

	billTo = apicontractsv1.customerAddressType()
	billTo.firstName = "John"
	billTo.lastName = "Snow"

	profile = apicontractsv1.customerPaymentProfileType()
	profile.payment = payment
	profile.billTo = billTo

	createCustomerProfile.profile.paymentProfiles = [profile]
	controller = createCustomerProfileController(createCustomerProfile)

	controller.execute()

	response = controller.getresponse()

	if (response.messages.resultCode=="Ok"):
		print "Successfully created a customer profile with id: %s" % response.customerProfileId
	else:
		print "Failed to create customer payment profile %s" % response.messages.message[0].text

	return response

 

 

 

Aidamir
Member