예제 #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)
def createCustomerPaymentProfile(customerInfo):
    merchantAuth = apicontractsv1.merchantAuthenticationType()
    merchantAuth.name = '4urP8Y47'
    merchantAuth.transactionKey = '538g4Tg2uMBte3W8'

    creditCard = apicontractsv1.creditCardType()
    creditCard.cardNumber = "6011000000000012"  # for the sake of testing this doesn't change
    creditCard.expirationDate = "2021-12"  # this too

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

    billTo = apicontractsv1.customerAddressType()
    billTo.firstName = customerInfo["firstName"]
    billTo.lastName = customerInfo["lastName"]

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

    createCustomerPaymentProfile = apicontractsv1.createCustomerPaymentProfileRequest(
    )
    createCustomerPaymentProfile.merchantAuthentication = merchantAuth
    createCustomerPaymentProfile.paymentProfile = profile
    customerProfileId = customerInfo[
        "customerId"]  # grab the same info from the dictionary but place it in their variable
    print(
        "customerProfileId in createCustomerPaymentProfile. customerProfileId = %s"
        % customerProfileId)
    createCustomerPaymentProfile.customerProfileId = str(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)

    return response.customerPaymentProfileId
예제 #3
0
def create_customer_payment_profile(customerProfileId):
    merchantAuth = apicontractsv1.merchantAuthenticationType()
    merchantAuth.name = constants.apiLoginId
    merchantAuth.transactionKey = constants.transactionKey

    creditCard = apicontractsv1.creditCardType()
    creditCard.cardNumber = "4111111111111111"
    creditCard.expirationDate = "2035-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

    createCustomerPaymentProfile = apicontractsv1.createCustomerPaymentProfileRequest(
    )
    createCustomerPaymentProfile.merchantAuthentication = merchantAuth
    createCustomerPaymentProfile.paymentProfile = profile
    print(
        "customerProfileId in create_customer_payment_profile. customerProfileId = %s"
        % customerProfileId)
    createCustomerPaymentProfile.customerProfileId = str(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)

    return response
예제 #4
0
    def create_saved_payment(self, credit_card, address=None, profile_id=None):
        """
        Creates a payment profile.
        """
        creditCard = apicontractsv1.creditCardType()
        creditCard.cardNumber = credit_card.card_number
        creditCard.expirationDate = '{0.exp_year}-{0.exp_month:0>2}'.format(credit_card)
        creditCard.cardCode = credit_card.cvv

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

        billTo = apicontractsv1.customerAddressType()
        if credit_card.first_name:
            billTo.firstName = credit_card.first_name
        if credit_card.last_name:
            billTo.lastName = credit_card.last_name

        profile = apicontractsv1.customerPaymentProfileType()
        profile.payment = payment
        profile.billTo = billTo
        self._address_to_profile(address, profile)

        if profile_id:
            createCustomerPaymentProfile = apicontractsv1.createCustomerPaymentProfileRequest()
            createCustomerPaymentProfile.merchantAuthentication = self.merchantAuth
            createCustomerPaymentProfile.paymentProfile = profile
            createCustomerPaymentProfile.customerProfileId = str(profile_id)

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

            response = controller.getresponse()
            if response.messages.resultCode == "Ok":
                return response.customerPaymentProfileId
            else:
                raise AuthorizeResponseError(
                    "Failed to create customer payment profile %s" % response.messages.message[0]['text'].text)
        else:
            return profile
def create_customer_payment_profile(customerProfileId):
    merchantAuth = apicontractsv1.merchantAuthenticationType()
    merchantAuth.name = constants.apiLoginId
    merchantAuth.transactionKey = constants.transactionKey

    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

    createCustomerPaymentProfile = apicontractsv1.createCustomerPaymentProfileRequest()
    createCustomerPaymentProfile.merchantAuthentication = merchantAuth
    createCustomerPaymentProfile.paymentProfile = profile
    print("customerProfileId in create_customer_payment_profile. customerProfileId = %s" %customerProfileId)
    createCustomerPaymentProfile.customerProfileId = str(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)

    return response
from authorizenet import apicontractsv1
from authorizenet.apicontrollers import *

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

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

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

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

createCustomerPaymentProfile = apicontractsv1.createCustomerPaymentProfileRequest()
createCustomerPaymentProfile.merchantAuthentication = merchantAuth
createCustomerPaymentProfile.paymentProfile = profile
createCustomerPaymentProfile.customerProfileId = '36731856'

createCustomerPaymentProfileController = createCustomerPaymentProfileController(createCustomerPaymentProfile)
createCustomerPaymentProfileController.execute()

response = createCustomerPaymentProfileController.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
예제 #7
0
파일: card.py 프로젝트: vysakh98/moviez
  conn.commit()
  merchantAuth = apicontractsv1.merchantAuthenticationType()
  merchantAuth.name = constants.apiLoginId
  merchantAuth.transactionKey = constants.transactionKey

  creditCard = apicontractsv1.creditCardType()
  creditCard.cardNumber = cardnumber
  creditCard.expirationDate = expirationDate

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

  billTo = apicontractsv1.customerAddressType()
  billTo.firstName = name

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


  createCustomerPaymentProfile = apicontractsv1.createCustomerPaymentProfileRequest()
  createCustomerPaymentProfile.merchantAuthentication = merchantAuth
  createCustomerPaymentProfile.paymentProfile = profile

  createCustomerPaymentProfile.customerProfileId = str(customer_profile_id)

  controller = createCustomerPaymentProfileController(createCustomerPaymentProfile)
  controller.execute()

  response = controller.getresponse()
예제 #8
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
예제 #9
0
    def create_customer_payment_profile(
            self,
            payment,
            customer_type,
            first_name,
            last_name,
            contact_dictionary,
            company_name,
            set_as_default,
            validation_mode=ValidationMode.liveMode):
        """Add a payment profile on the CIM.
        This function is called as part of adding a credit card or echeck
        payment profile. It is NOT intended to be directly called outside
        of this app"""

        if not isinstance(customer_type, CustomerType):
            msg = 'customer_type must be a CustomerType enum. ' \
                  'Your type is {}\n{}'
            raise ValueError(msg.format(type(customer_type), customer_type))

        address = contact_dictionary.get('address')
        city = contact_dictionary.get('city')
        state = contact_dictionary.get('state')
        zip_code = contact_dictionary.get('zip_code')
        country = 'US'
        phone = contact_dictionary.get('phone')

        profile = apicontractsv1.customerPaymentProfileType()
        profile.payment = payment
        profile.customerType = customer_type.name
        profile.billTo = CustomerProfile.make_billTo(first_name, last_name,
                                                     company_name, address,
                                                     city, state, zip_code,
                                                     country, phone)

        print(first_name, last_name, company_name, address, city, state,
              zip_code, country, phone)

        createCustomerPaymentProfile = apicontractsv1.createCustomerPaymentProfileRequest(
        )  # noqa
        createCustomerPaymentProfile.merchantAuthentication = self.merchantAuth
        createCustomerPaymentProfile.paymentProfile = profile
        createCustomerPaymentProfile.customerProfileId = str(
            self.instance.authorizenet_customer_profile_id)
        createCustomerPaymentProfile.validationMode = validation_mode.name

        controller = createCustomerPaymentProfileController(
            createCustomerPaymentProfile)
        controller.setenvironment(self.post_url)
        controller.execute()

        response = controller.getresponse()

        if response.messages.resultCode == OK:
            msg = 'Successfully created a customer payment profile with id: {}'
            print(msg.format(response.customerPaymentProfileId))

            if set_as_default:
                self.instance.authorizenet_default_payment_profile_id = int(
                    response.customerPaymentProfileId)
                print('\tsaved as default')
                self.instance.save()
            else:
                print('\tThis payment method is NOT the default')

            return self.instance.authorizenet_default_payment_profile_id
        else:
            raise AuthorizeNetError(response.messages.message[0]['text'].text)
예제 #10
0
    def _create_customer_payment_profile(self, customer, customer_data):
        """ Run a request to create a customer payment 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')
        customer_profile_id         = customer_data.get('profile_id')

        if customer_profile_id is None:
            logger.warning(
                'Couldn\'t create Authorize.net customer payment profile %s, customer profile does not exist', {
                    'customer_id': customer_id,
                }
            )
            return False

        payment            = apicontractsv1.paymentType()
        payment.creditCard = self._create_credit_card(customer)

        profile         = apicontractsv1.customerPaymentProfileType()
        profile.payment = payment
        profile.billTo  = self._create_bill_to(customer)

        createCustomerPaymentProfile                        = apicontractsv1.createCustomerPaymentProfileRequest()
        createCustomerPaymentProfile.merchantAuthentication = self.merchantAuth
        createCustomerPaymentProfile.paymentProfile         = profile
        createCustomerPaymentProfile.customerProfileId      = str(customer_profile_id)

        controller = createCustomerPaymentProfileController(createCustomerPaymentProfile)

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

        response = controller.getresponse()

        if response is None:
            logger.warning(
                'No response returned', {
                    'customer_id': customer_id,
                    'messages': response.messages.message[0]['text'].text
                }
            )
            return False

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

        return False