<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: CreateCustomerPaymentProfile in sandbox fails to validate when validationMode='liveMode' in Integration and Testing</title>
    <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/CreateCustomerPaymentProfile-in-sandbox-fails-to-validate-when/m-p/63301#M37460</link>
    <description>&lt;P&gt;I reolved the issue by deleting this line&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;profile.validationMode = validation_mode.value&lt;/PRE&gt;&lt;P&gt;and adding this line&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;createCustomerPaymentProfile.validationMode = validation_mode.value&lt;/PRE&gt;</description>
    <pubDate>Tue, 05 Jun 2018 18:41:54 GMT</pubDate>
    <dc:creator>sanaani</dc:creator>
    <dc:date>2018-06-05T18:41:54Z</dc:date>
    <item>
      <title>CreateCustomerPaymentProfile in sandbox fails to validate when validationMode='liveMode'</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/CreateCustomerPaymentProfile-in-sandbox-fails-to-validate-when/m-p/63300#M37459</link>
      <description>&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my enum:&lt;/P&gt;&lt;PRE&gt;from enum import Enum


class ValidationMode(Enum):
    testMode = 'testMode'
    liveMode = 'liveMode'&lt;/PRE&gt;&lt;P&gt;And here's my code that doesn't validate the card prior to creating the payment profile.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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)&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Jun 2018 16:23:32 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/CreateCustomerPaymentProfile-in-sandbox-fails-to-validate-when/m-p/63300#M37459</guid>
      <dc:creator>sanaani</dc:creator>
      <dc:date>2018-06-05T16:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: CreateCustomerPaymentProfile in sandbox fails to validate when validationMode='liveMode'</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/CreateCustomerPaymentProfile-in-sandbox-fails-to-validate-when/m-p/63301#M37460</link>
      <description>&lt;P&gt;I reolved the issue by deleting this line&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;profile.validationMode = validation_mode.value&lt;/PRE&gt;&lt;P&gt;and adding this line&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;createCustomerPaymentProfile.validationMode = validation_mode.value&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Jun 2018 18:41:54 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/CreateCustomerPaymentProfile-in-sandbox-fails-to-validate-when/m-p/63301#M37460</guid>
      <dc:creator>sanaani</dc:creator>
      <dc:date>2018-06-05T18:41:54Z</dc:date>
    </item>
  </channel>
</rss>

