示例#1
0
    def test_create_customer_profile(self):
        """ Create customer profile and payment methods
        """
        customer = CustomerFactory()
        credit_card = CreditCard()

        profile = apicontractsv1.customerProfileType()
        profile.merchantCustomerId = customer['ref_id']
        profile.description = '%s %s' % (customer['first_name'], customer['last_name'])
        profile.email = customer['email']

        card = apicontractsv1.creditCardType()
        card.cardNumber = credit_card['card_number']
        card.expirationDate = credit_card['expire_date'].strftime('%Y-%m')

        payment_profile = apicontractsv1.customerPaymentProfileType()
        payment_profile.customerType = 'individual'
        payment = apicontractsv1.paymentType()
        payment.creditCard = card
        payment_profile.payment = payment

        profile.paymentProfiles = [payment_profile]

        create_profile_request = apicontractsv1.createCustomerProfileRequest()
        create_profile_request.merchantAuthentication = self.merchant
        create_profile_request.profile = profile

        controller = apicontrollers.CreateCustomerProfileController(create_profile_request)

        response = controller.execute()
        rc = etree.tostring(response.root)

        response.get_element_text('ns:customerProfileId')
        # response.customerPaymentProfileIdList.numericString[0]
        print(response)
示例#2
0
    def create_saved_profile(self, internal_id, payments=None, email=None):
        """
        Creates a user profile to which you can attach saved payments.
        Requires an internal_id to uniquely identify this user. If a list of
        saved payments is provided, as generated by create_saved_payment,
        these will be automatically added to the user profile. Returns the
        user profile id.
        """
        createCustomerProfile = apicontractsv1.createCustomerProfileRequest()
        createCustomerProfile.merchantAuthentication = self.merchantAuth
        createCustomerProfile.profile = apicontractsv1.customerProfileType()
        createCustomerProfile.profile.merchantCustomerId = str(internal_id)
        createCustomerProfile.profile.email = email

        controller = createCustomerProfileController(createCustomerProfile)
        if not self.debug:
            controller.setenvironment(constants.PRODUCTION)
        controller.execute()

        response = controller.getresponse()

        if response.messages.resultCode == "Ok":
            customer_profile_id = response.customerProfileId
        else:
            if response.messages.message[0]['code'].text == 'E00039':
                customer_profile_id = filter(str.isdigit, response.messages.message[0]['text'].text)
            else:
                raise AuthorizeResponseError(
                    "Failed to create customer profile: %s, debug mode: %s" % (
                        response.messages.message[0]['text'].text, self.debug))

        customer_payment_profile_id = None
        if payments:
            createCustomerPaymentProfile = apicontractsv1.createCustomerPaymentProfileRequest()
            createCustomerPaymentProfile.merchantAuthentication = self.merchantAuth
            createCustomerPaymentProfile.paymentProfile = payments
            createCustomerPaymentProfile.customerProfileId = str(customer_profile_id)

            controller = createCustomerPaymentProfileController(createCustomerPaymentProfile)
            if not self.debug:
                controller.setenvironment(constants.PRODUCTION)
            controller.execute()

            response = controller.getresponse()
            if response.messages.resultCode == "Ok":
                customer_payment_profile_id = response.customerPaymentProfileId
            else:
                raise AuthorizeResponseError(
                    "Failed to create customer payment profile: %s" % response.messages.message[0]['text'].text)

        return customer_profile_id, customer_payment_profile_id
    def _create_customer_profile(self, customer, customer_data):
        """ Run a request to create a customer profile with
        Authorize.Net, from customer data including credit card info.

        :param customer: A Silver customer instance
        :param customer_data: A CustomerData instance
        :returns True if successful, False if otherwise:
        """
        customer_id = customer_data.get('id')

        ## Create a customer profile

        createCustomerProfile = apicontractsv1.createCustomerProfileRequest()
        createCustomerProfile.merchantAuthentication = self.merchantAuth
        createCustomerProfile.profile = apicontractsv1.customerProfileType(
            customer_id,
            customer.last_name + ' ' + customer.first_name,
            customer.email
        )

        controller = createCustomerProfileController(createCustomerProfile)

        try:
            controller.execute()
        except Exception as e:
            logger.warning(
                'Error in request to create Authorize.net customer profile %s', {
                    'customer_id': customer_id,
                    'exception': str(e)
                }
            )

        profile_response = controller.getresponse()

        if (profile_response.messages.resultCode == apicontractsv1.messageTypeEnum.Ok):
            return self._update_customer(
                customer,
                {'id': customer_id,
                 'profile_id': str(profile_response.customerProfileId)}
            )
        else:
            logger.warning(
                'Couldn\'t create Authorize.net customer profile %s', {
                    'customer_id': customer_id,
                    'messages': profile_response.messages.message[0]['text'].text
                }
            )

        return False
示例#4
0
 def testCreateCustomerProfile(self):
     createdCustomerProfileID = None
     createCustomerProfile = apicontractsv1.createCustomerProfileRequest()
     createCustomerProfile.merchantAuthentication = self.merchantAuthentication
     randomInt = random.randint(0, 10000)
     createCustomerProfile.profile = apicontractsv1.customerProfileType()
     createCustomerProfile.profile.merchantCustomerId = 'jdoe%s' % randomInt
     createCustomerProfile.profile.description = 'John Doe%s' % randomInt
     createCustomerProfile.profile.email = '*****@*****.**' % randomInt
     controller = createCustomerProfileController(createCustomerProfile)
     controller.execute()
     response = controller.getresponse()
     if hasattr(response, 'messages') == True:
         if hasattr(response.messages, 'resultCode') == True:
             self.assertEquals('Ok', response.messages.resultCode)
     if hasattr(response, 'customerProfileId') == True:
         createdCustomerProfileID = response.customerProfileId
     return str(createdCustomerProfileID)
示例#5
0
 def testCreateCustomerProfile(self):
     createdCustomerProfileID = None
     createCustomerProfile = apicontractsv1.createCustomerProfileRequest()
     createCustomerProfile.merchantAuthentication = self.merchantAuthentication
     randomInt = random.randint(0, 10000)
     createCustomerProfile.profile = apicontractsv1.customerProfileType()
     createCustomerProfile.profile.merchantCustomerId = 'jdoe%s' % randomInt
     createCustomerProfile.profile.description = 'John Doe%s' % randomInt
     createCustomerProfile.profile.email = '*****@*****.**' % randomInt
     controller = createCustomerProfileController(createCustomerProfile)
     controller.execute()
     response = controller.getresponse()
     if hasattr(response, 'messages') == True:
         if hasattr(response.messages, 'resultCode') == True:
             self.assertEquals('Ok', response.messages.resultCode)
     if hasattr(response, 'customerProfileId') == True: 
         createdCustomerProfileID = response.customerProfileId
     return str(createdCustomerProfileID)
示例#6
0
    def create_customer_profile(self, email):
        """
        This information is viewed on the authorize.net website as
        Customer Information Manager (CIM). The API confusingly references
        the CIM as a CustomerProfile. They are synonymous.
        """

        createCustomerProfile = apicontractsv1.createCustomerProfileRequest()
        createCustomerProfile.merchantAuthentication = self.merchantAuth

        createCustomerProfile.profile = apicontractsv1.customerProfileType(
            str(self.instance.pk), str(self.instance), email)

        controller = createCustomerProfileController(createCustomerProfile)
        controller.setenvironment(self.post_url)
        controller.execute()

        response = controller.getresponse()

        if response.messages.resultCode == OK:
            print("Successfully created a customer profile with id: {}".format(
                response.customerProfileId))
            self.instance.authorizenet_customer_profile_id = int(
                response.customerProfileId)
            self.instance.save()
            print('saved', self.instance)
            return True
        else:
            error = response.messages.message[0]['text'].text
            duplicate_text = 'A duplicate record with ID  already exists.'
            error_no_digits = ''.join([i for i in error if not i.isdigit()])
            profile_id_list = re.findall(r"\D(\d{10})\D", error)

            if duplicate_text == error_no_digits and len(profile_id_list) == 1:
                profile_id = profile_id_list[0]
                self.instance.authorizenet_customer_profile_id = int(
                    profile_id)
                self.instance.save()
                print('saved', self.instance)
            else:
                raise AuthorizeNetError(
                    response.messages.message[0]['text'].text)
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', '*****@*****.**')

    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'].text)

    return response
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', '*****@*****.**')

	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'].text

	return response
def createCustomerProfile(customerInfo):
    
    merchantAuth = apicontractsv1.merchantAuthenticationType()
    merchantAuth.name = '4urP8Y47'
    merchantAuth.transactionKey = '538g4Tg2uMBte3W8' 


    createCustomerProfile = apicontractsv1.createCustomerProfileRequest()
    createCustomerProfile.merchantAuthentication = merchantAuth
    createCustomerProfile.profile = apicontractsv1.customerProfileType(customerInfo["firstName"] + str(random.randint(0, 10000)), customerInfo["lastName"], customerInfo["email"])

    controller = createCustomerProfileController(createCustomerProfile)
    controller.execute()

    response = controller.getresponse()
    
    if (response.messages.resultCode=="Ok"):
        message2 = ("Successfully created a customer profile for %s %s " % (customerInfo["firstName"],customerInfo["lastName"]))
        print("Successfully created customer profile with id: %s" % response.customerProfileId)
    else:
        message2 = ("Failed to create customer payment profile %s" % response.messages.message[0]['text'].text)
        print("Failed to create customer payment profile %s" % response.messages.message[0]['text'].text)

    return response.customerProfileId, message2
from authorizenet import apicontractsv1
from authorizenet.apicontrollers import *
import random

merchantAuth = apicontractsv1.merchantAuthenticationType()
merchantAuth.name = '5KP3u95bQpv'
merchantAuth.transactionKey = '4Ktq966gC55GAX7S'

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

createCustomerProfileController = createCustomerProfileController(
    createCustomerProfile)
createCustomerProfileController.execute()

response = createCustomerProfileController.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
示例#11
0
def provider_create_account(request, ohsubscription, person, company, address):

    print('In provider_create_account routine')
    try:
        print("Create Customer Profile -> Using AuthorizeNet : Start")
        merchantAuth = apicontractsv1.merchantAuthenticationType()
        merchantAuth.name = get_secret("API_LOGIN_ID")
        merchantAuth.transactionKey = get_secret("API_TRANSACTION_KEY")
        '''
        Create customer profile
        '''
        createCustomerProfile = apicontractsv1.createCustomerProfileRequest()
        createCustomerProfile.merchantAuthentication = merchantAuth

        createCustomerProfile.profile = apicontractsv1.customerProfileType(
            str(ohsubscription), person.first_name + ' ' + person.last_name,
            person.email)

        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'].text)
        '''
        Create customer payment profile
        '''
        if not response.customerProfileId is None:
            creditCard = apicontractsv1.creditCardType()

            creditCard.cardNumber = request.POST.get("cardnumber", None)
            creditCard.expirationDate = str(
                request.POST.get("cardyear", None) + '-' +
                request.POST.get("cardmonth", None))
            creditCard.cardCode = request.POST.get("cardcvv", None)
            payment = apicontractsv1.paymentType()
            payment.creditCard = creditCard

            billTo = apicontractsv1.customerAddressType()
            billTo.firstName = person.first_name
            billTo.lastName = person.last_name
            billTo.company = company.name
            # billTo.ip_address = get_client_ip(request)
            billTo.country = address.city.zipc_code.county.state.country_id
            billTo.address = address.address_line_1 + address.address_line_2
            billTo.city = address.city.name
            billTo.state = address.city.zipc_code.county.state.name
            billTo.zip = address.city.zipc_code_id

            profile = apicontractsv1.customerPaymentProfileType()
            profile.payment = payment
            profile.billTo = billTo
            profile.customerType = 'business'

            createCustomerPaymentProfile = apicontractsv1.createCustomerPaymentProfileRequest(
            )
            createCustomerPaymentProfile.merchantAuthentication = merchantAuth
            createCustomerPaymentProfile.paymentProfile = profile
            print(
                "customerProfileId in create_customer_payment_profile. customerProfileId = %s"
                % response.customerProfileId)
            createCustomerPaymentProfile.customerProfileId = str(
                response.customerProfileId)

            controller = createCustomerPaymentProfileController(
                createCustomerPaymentProfile)
            controller.execute()

            response = controller.getresponse()

            if (response.messages.resultCode == "Ok"):
                print(
                    "Successfully created a customer payment profile with id: %s"
                    % response.customerPaymentProfileId)
            else:
                print("Failed to create customer payment profile %s" %
                      response.messages.message[0]['text'].text)
                print("Create Account -> Using Recurly API : End")

    except ValueError:
        print('Exceprion occured while creating account with Recurly', )
        return None

    print('Authorize.Net.response', response.customerProfileId)
    return response.customerProfileId
from authorizenet import apicontractsv1
from authorizenet.apicontrollers import *
import random

merchantAuth = apicontractsv1.merchantAuthenticationType()
merchantAuth.name = '5KP3u95bQpv'
merchantAuth.transactionKey = '4Ktq966gC55GAX7S'


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

createCustomerProfileController = createCustomerProfileController(createCustomerProfile)
createCustomerProfileController.execute()

response = createCustomerProfileController.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