コード例 #1
0
ファイル: customer.py プロジェクト: dev221989/authorizesauce
    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
コード例 #2
0
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
ファイル: customer.py プロジェクト: dev221989/authorizesauce
    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
コード例 #5
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 = "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.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
  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()

  paymentprofileid=response.customerPaymentProfileId
  sql3 = 'update payment_info set payment_id = "%s" where username="******"' %(paymentprofileid,username)
  c.execute(sql3)
  conn.commit()
  env = Environment(loader=FileSystemLoader('templates'))
コード例 #8
0
ファイル: utils.py プロジェクト: pramodpalIndia/onhand
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