I created a CustomerPaymentProfile (id=1503937419) in the sandbox using the code below. validationMode was set to 'liveMode', but there are no voided transactions in the sandbox. Why did it not validate the card?
Here's my enum:
from enum import Enum class ValidationMode(Enum): testMode = 'testMode' liveMode = 'liveMode'
And here's my code that doesn't validate the card prior to creating the payment profile.
from authorizenet import apicontractsv1 from authorizenet.apicontrollers import * from django.db import models from payment_authorizenet.merchant_auth import AuthNet, AuthorizeNetError from payment_authorizenet.enums import CustomerType, ValidationMode OK = "Ok" class CustomerProfile(AuthNet): """A class based implementation to relate a Django model to the creation of a CustomerProfile (aka CIM, Customer Information Manager)""" def __init__(self, instance, *args, **kwargs): """Attach a django model to the insatnce attribute of this class""" super().__init__(*args, **kwargs) if not hasattr(instance, 'authorizenet_customer_profile_id'): msg = 'Models used to create a customer profile must contain ' \ 'an authorizenet_customer_profile_id attribute' raise ValueError(msg) if not issubclass(type(instance), models.Model): raise ValueError('instance must be a Django model') self.instance = instance def create_customer_payment_profile_credit_card( self, credit_card, expiration_date, card_code, customer_type, first_name, last_name, company_name=None, use_model_address=True, set_as_default=True, validation_mode=ValidationMode.liveMode, **kwargs): """Add a payment profile on the CIM""" if not isinstance(customer_type, CustomerType): raise ValueError('customer_type must be a CustomerType enum') country = 'US' if not use_model_address: # If the model contains address information but # you don't want to use it, # or the model doesn't have address indormation in this format # then set the flag use_model_address to False if kwargs is None: msg = 'Expected kwargs with address details when ' \ 'use_model_address is False' raise ValueError(msg) address = kwargs.get('address') city = kwargs.get('city') state = kwargs.get('state') zip_code = kwargs.get('zip_code') phone = kwargs.get('phone') else: # Use address information from the model address = self.instance.address if hasattr(self.instance, 'address2'): address = address + self.instance.address2 city = self.instance.city state = self.instance.state zip_code = self.instance.zip_code phone = self.instance.phone creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = credit_card creditCard.expirationDate = expiration_date creditCard.cardCode = card_code payment = apicontractsv1.paymentType() payment.creditCard = creditCard billTo = apicontractsv1.customerAddressType() billTo.firstName = first_name billTo.lastName = last_name billTo.company = company_name billTo.address = address billTo.city = city billTo.state = state billTo.zip = zip_code billTo.country = country billTo.phoneNumber = phone profile = apicontractsv1.customerPaymentProfileType() profile.payment = payment profile.customerType = customer_type.value profile.billTo = billTo profile.validationMode = validation_mode.value createCustomerPaymentProfile = apicontractsv1.createCustomerPaymentProfileRequest() # noqa createCustomerPaymentProfile.merchantAuthentication = self.merchantAuth createCustomerPaymentProfile.paymentProfile = profile createCustomerPaymentProfile.customerProfileId = str( self.instance.authorizenet_customer_profile_id) controller = createCustomerPaymentProfileController( createCustomerPaymentProfile) controller.execute() response = controller.getresponse() if response.messages.resultCode == OK: msg = 'Successfully created a customer payment profile with id: {}' print(msg.format(response.customerPaymentProfileId)) else: raise AuthorizeNetError(response.messages.message[0]['text'].text)
Solved! Go to Solution.
06-05-2018 09:23 AM
I reolved the issue by deleting this line
profile.validationMode = validation_mode.value
and adding this line
createCustomerPaymentProfile.validationMode = validation_mode.value
06-05-2018 11:41 AM
I reolved the issue by deleting this line
profile.validationMode = validation_mode.value
and adding this line
createCustomerPaymentProfile.validationMode = validation_mode.value
06-05-2018 11:41 AM