Beispiel #1
0
    def create_payment_scheduale_interval_type(self, subscription,
                                               subscription_type):
        """
        Create an interval schedule with fixed months as units for period lenght.
        It calculates that start date depending on the term_units and trail_occurrences defined in the term_details.
        term_units can either be by day or by month. Start date is the first billing date of the subscriptions.
        Eg. for a 1 year 1 month free subscription:
            term_unit=20 (Month), trail_occurrences=1
            start_date = now + 1 month
        Eg. for a 7 day free 1 Month subscription:
            term_units=10 (Day), trail_occurrences=7
            start_date = now + 7 days
        """
        payment_schedule = apicontractsv1.paymentScheduleType()
        payment_schedule.interval = apicontractsv1.paymentScheduleTypeInterval(
        )
        payment_schedule.interval.unit = apicontractsv1.ARBSubscriptionUnitEnum.months

        payment_schedule.interval.length = self.get_period_length(
            subscription, subscription_type)
        payment_schedule.totalOccurrences = self.get_payment_occurrences(
            subscription, subscription_type)
        payment_schedule.startDate = self.get_payment_schedule_start_date(
            subscription)
        # Authorize.Net does not have a way to differenciate trail occurrences term_units for period length.
        # Set to zero as the start date takes into account the trail occurrences.
        payment_schedule.trialOccurrences = 0
        return payment_schedule
Beispiel #2
0
    def create_payment_scheduale_interval_type(self, subscription,
                                               subscription_type):
        """
        Create an interval schedule with fixed months.
        period_length: The period length the service paided mor last 
            eg: period_length = 2. the user will be billed every 2 months.
        payment_occurrences: The number of occurrences the payment should be made.
            eg: payment_occurrences = 6. There will be six payments made at each period_length.
        trial_occurrences: The number of ignored payments out of the payment_occurrences
        """
        trial_occurrences = self.get_trail_occurrences(subscription)

        payment_schedule = apicontractsv1.paymentScheduleType()
        payment_schedule.interval = apicontractsv1.paymentScheduleTypeInterval(
        )
        payment_schedule.interval.unit = apicontractsv1.ARBSubscriptionUnitEnum.months
        payment_schedule.startDate = datetime.now()

        payment_schedule.interval.length = self.get_period_length(
            subscription, subscription_type)
        payment_schedule.totalOccurrences = self.get_payment_occurrences(
            subscription, subscription_type)
        payment_schedule.trialOccurrences = trial_occurrences

        return payment_schedule
Beispiel #3
0
    def setUp(self):
        utility.helper.setpropertyfile('anet_python_sdk_properties.ini')

        self.amount = str(round(random.random() * 100, 2))

        self.merchantAuthentication = apicontractsv1.merchantAuthenticationType(
        )
        self.merchantAuthentication.name = utility.helper.getproperty(
            'api.login.id')
        self.merchantAuthentication.transactionKey = utility.helper.getproperty(
            'transaction.key')
        self.ref_id = 'Sample'

        self.dateOne = datetime.date(2020, 8, 30)
        self.interval = CTD_ANON()
        self.interval.length = 1
        self.interval.unit = 'months'
        self.paymentScheduleOne = apicontractsv1.paymentScheduleType()
        self.paymentScheduleOne.interval = self.interval
        self.paymentScheduleOne.startDate = self.dateOne
        self.paymentScheduleOne.totalOccurrences = 12
        self.paymentScheduleOne.trialOccurrences = 1

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

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

        self.customerOne = apicontractsv1.nameAndAddressType()
        self.customerOne.firstName = "John"
        self.customerOne.lastName = "Smith"

        self.customerData = apicontractsv1.customerDataType()
        self.customerData.id = "99999456654"

        self.subscriptionOne = apicontractsv1.ARBSubscriptionType()
        self.subscriptionOne.paymentSchedule = self.paymentScheduleOne
        self.subscriptionOne.amount = Decimal(
            str(round(random.random() * 100, 2)))
        self.subscriptionOne.trialAmount = Decimal('0.03')
        self.subscriptionOne.payment = self.payment
        self.subscriptionOne.billTo = self.customerOne

        self.order = apicontractsv1.orderType()
        self.order.invoiceNumber = "INV-21345"
        self.order.description = "Product description"

        self.billTo = apicontractsv1.customerAddressType()
        self.billTo.firstName = "Ellen"
        self.billTo.lastName = "Johnson"
        self.billTo.company = "Souveniropolis"
        self.billTo.address = "14 Main St"
        self.billTo.city = "Seattle"
        self.billTo.state = "WA"
        self.billTo.zip = "98122"
        self.billTo.country = "USA"
Beispiel #4
0
 def setUp(self):
     utility.helper.setpropertyfile('anet_python_sdk_properties.ini')
     
     self.amount = str(round(random.random()*100, 2))
    
     self.merchantAuthentication = apicontractsv1.merchantAuthenticationType()       
     self.merchantAuthentication.name = helper.getproperty('api_login_id')
     self.merchantAuthentication.transactionKey = helper.getproperty('transaction_key')
     self.ref_id = 'Sample'
     
     self.dateOne = datetime.date(2020, 8, 30)
     self.interval = CTD_ANON()
     self.interval.length = 1
     self.interval.unit = 'months'
     self.paymentScheduleOne = apicontractsv1.paymentScheduleType()
     self.paymentScheduleOne.interval = self.interval
     self.paymentScheduleOne.startDate = self.dateOne
     self.paymentScheduleOne.totalOccurrences = 12
     self.paymentScheduleOne.trialOccurrences = 1
     
     self.creditCardOne = apicontractsv1.creditCardType()
     self.creditCardOne.cardNumber = "4111111111111111"
     self.creditCardOne.expirationDate = "2020-12"
     
     self.payment = apicontractsv1.paymentType()
     self.payment.creditCard = self.creditCardOne
     
     self.customerOne = apicontractsv1.nameAndAddressType()
     self.customerOne.firstName = "John"
     self.customerOne.lastName = "Smith"
     
     self.customerData = apicontractsv1.customerDataType()
     self.customerData.id = "99999456654"
     
     self.subscriptionOne = apicontractsv1.ARBSubscriptionType()
     self.subscriptionOne.paymentSchedule = self.paymentScheduleOne
     self.subscriptionOne.amount = Decimal(self.amount)
     self.subscriptionOne.trialAmount = Decimal ('0.03')
     self.subscriptionOne.payment = self.payment
     self.subscriptionOne.billTo = self.customerOne
     
     self.order = apicontractsv1.orderType()
     self.order.invoiceNumber = "INV-21345"
     self.order.description = "Product description"
     
     self.billTo = apicontractsv1.customerAddressType()
     self.billTo.firstName = "Ellen"
     self.billTo.lastName = "Johnson"
     self.billTo.company = "Souveniropolis"
     self.billTo.address = "14 Main St"
     self.billTo.city = "Seattle"
     self.billTo.state = "WA"
     self.billTo.zip = "98122"
     self.billTo.country = "USA"
    
 
     
Beispiel #5
0
def create_subscription(amount, days):

    # Setting the merchant details
    merchantAuth = apicontractsv1.merchantAuthenticationType()
    merchantAuth.name = constants.apiLoginId
    merchantAuth.transactionKey = constants.transactionKey
    # Setting payment schedule
    paymentschedule = apicontractsv1.paymentScheduleType()
    paymentschedule.interval = apicontractsv1.paymentScheduleTypeInterval(
    )  #apicontractsv1.CTD_ANON() #modified by krgupta
    paymentschedule.interval.length = days
    paymentschedule.interval.unit = apicontractsv1.ARBSubscriptionUnitEnum.days
    paymentschedule.startDate = datetime(2021, 12, 30)
    paymentschedule.totalOccurrences = 12
    paymentschedule.trialOccurrences = 1
    # Giving the credit card info
    creditcard = apicontractsv1.creditCardType()
    creditcard.cardNumber = "4111111111111111"
    creditcard.expirationDate = "2035-12"
    payment = apicontractsv1.paymentType()
    payment.creditCard = creditcard
    # Setting billing information
    billto = apicontractsv1.nameAndAddressType()
    billto.firstName = "John"
    billto.lastName = "Smith"
    # Setting subscription details
    subscription = apicontractsv1.ARBSubscriptionType()
    subscription.name = "Sample Subscription"
    subscription.paymentSchedule = paymentschedule
    subscription.amount = amount
    subscription.trialAmount = Decimal('0.00')
    subscription.billTo = billto
    subscription.payment = payment
    # Creating the request
    request = apicontractsv1.ARBCreateSubscriptionRequest()
    request.merchantAuthentication = merchantAuth
    request.subscription = subscription
    # Creating and executing the controller
    controller = ARBCreateSubscriptionController(request)
    controller.execute()
    # Getting the response
    response = controller.getresponse()

    if (response.messages.resultCode == "Ok"):
        print("SUCCESS:")
        print("Message Code : %s" % response.messages.message[0]['code'].text)
        print("Message text : %s" %
              str(response.messages.message[0]['text'].text))
        print("Subscription ID : %s" % response.subscriptionId)
    else:
        print("ERROR:")
        print("Message Code : %s" % response.messages.message[0]['code'].text)
        print("Message text : %s" % response.messages.message[0]['text'].text)

    return response
def create_subscription_from_customer_profile(amount, days, profileId,
                                              paymentProfileId,
                                              customerAddressId):

    # Setting the merchant details
    merchantAuth = apicontractsv1.merchantAuthenticationType()
    merchantAuth.name = constants.apiLoginId
    merchantAuth.transactionKey = constants.transactionKey
    # Setting payment schedule
    paymentschedule = apicontractsv1.paymentScheduleType()
    paymentschedule.interval = apicontractsv1.paymentScheduleTypeInterval(
    )  #apicontractsv1.CTD_ANON() #modified by krgupta
    paymentschedule.interval.length = days
    paymentschedule.interval.unit = apicontractsv1.ARBSubscriptionUnitEnum.days
    paymentschedule.startDate = datetime(2021, 12, 30)
    paymentschedule.totalOccurrences = 12
    paymentschedule.trialOccurrences = 1

    #setting the customer profile details
    profile = apicontractsv1.customerProfileIdType()
    profile.customerProfileId = profileId
    profile.customerPaymentProfileId = paymentProfileId
    profile.customerAddressId = customerAddressId

    # Setting subscription details
    subscription = apicontractsv1.ARBSubscriptionType()
    subscription.name = "Sample Subscription"
    subscription.paymentSchedule = paymentschedule
    subscription.amount = amount
    subscription.trialAmount = Decimal('0.00')
    subscription.profile = profile

    # Creating the request
    request = apicontractsv1.ARBCreateSubscriptionRequest()
    request.merchantAuthentication = merchantAuth
    request.subscription = subscription

    # Creating and executing the controller
    controller = ARBCreateSubscriptionController(request)
    controller.execute()
    # Getting the response
    response = controller.getresponse()

    if (response.messages.resultCode == "Ok"):
        print("SUCCESS:")
        print("Message Code : %s" % response.messages.message[0]['code'].text)
        print("Message text : %s" % response.messages.message[0]['text'].text)
        print("Subscription ID : %s" % response.subscriptionId)
    else:
        print("ERROR:")
        print("Message Code : %s" % response.messages.message[0]['code'].text)
        print("Message text : %s" % response.messages.message[0]['text'].text)

    return response
def create_subscription(amount, days):

    # Setting the merchant details
    merchantAuth = apicontractsv1.merchantAuthenticationType()
    merchantAuth.name = constants.apiLoginId
    merchantAuth.transactionKey = constants.transactionKey
    # Setting payment schedule
    paymentschedule = apicontractsv1.paymentScheduleType()
    paymentschedule.interval = apicontractsv1.paymentScheduleTypeInterval() #apicontractsv1.CTD_ANON() #modified by krgupta
    paymentschedule.interval.length = days
    paymentschedule.interval.unit = apicontractsv1.ARBSubscriptionUnitEnum.days
    paymentschedule.startDate = datetime(2020, 8, 30)
    paymentschedule.totalOccurrences = 12
    paymentschedule.trialOccurrences = 1
    # Giving the credit card info
    creditcard = apicontractsv1.creditCardType()
    creditcard.cardNumber = "4111111111111111"
    creditcard.expirationDate = "2020-12"
    payment = apicontractsv1.paymentType()
    payment.creditCard = creditcard
    # Setting billing information
    billto = apicontractsv1.nameAndAddressType()
    billto.firstName = "John"
    billto.lastName = "Smith"
    # Setting subscription details
    subscription = apicontractsv1.ARBSubscriptionType()
    subscription.name = "Sample Subscription"
    subscription.paymentSchedule = paymentschedule
    subscription.amount = amount
    subscription.trialAmount = Decimal('0.00')
    subscription.billTo = billto
    subscription.payment = payment
    # Creating the request
    request = apicontractsv1.ARBCreateSubscriptionRequest()
    request.merchantAuthentication = merchantAuth
    request.subscription = subscription
    # Creating and executing the controller
    controller = ARBCreateSubscriptionController(request)
    controller.execute()
    # Getting the response
    response = controller.getresponse()

    if (response.messages.resultCode=="Ok"):
        print ("SUCCESS:")
        print ("Message Code : %s" % response.messages.message[0]['code'].text)
        print ("Message text : %s" % str(response.messages.message[0]['text'].text))
        print ("Subscription ID : %s" % response.subscriptionId)
    else:
        print ("ERROR:")
        print ("Message Code : %s" % response.messages.message[0]['code'].text)
        print ("Message text : %s" % response.messages.message[0]['text'].text)

    return response
def create_subscription_from_customer_profile(amount, days, profileId, paymentProfileId, customerAddressId):

	# Setting the merchant details
	merchantAuth = apicontractsv1.merchantAuthenticationType()
	merchantAuth.name = constants.apiLoginId
	merchantAuth.transactionKey = constants.transactionKey
	# Setting payment schedule
	paymentschedule = apicontractsv1.paymentScheduleType()
	paymentschedule.interval = apicontractsv1.paymentScheduleTypeInterval() #apicontractsv1.CTD_ANON() #modified by krgupta
	paymentschedule.interval.length = days
	paymentschedule.interval.unit = apicontractsv1.ARBSubscriptionUnitEnum.days
	paymentschedule.startDate = datetime(2020, 8, 30)
	paymentschedule.totalOccurrences = 12
	paymentschedule.trialOccurrences = 1
	
	#setting the customer profile details
	profile = apicontractsv1.customerProfileIdType()
	profile.customerProfileId = profileId
	profile.customerPaymentProfileId = paymentProfileId
	profile.customerAddressId = customerAddressId
	
	# Setting subscription details
	subscription = apicontractsv1.ARBSubscriptionType()
	subscription.name = "Sample Subscription"
	subscription.paymentSchedule = paymentschedule
	subscription.amount = amount
	subscription.trialAmount = Decimal('0.00')
	subscription.profile = profile
	
	# Creating the request
	request = apicontractsv1.ARBCreateSubscriptionRequest()
	request.merchantAuthentication = merchantAuth
	request.subscription = subscription
	
	# Creating and executing the controller
	controller = ARBCreateSubscriptionController(request)
	controller.execute()
	# Getting the response
	response = controller.getresponse()

	if (response.messages.resultCode=="Ok"):
		print "SUCCESS:"
		print "Message Code : %s" % response.messages.message[0].code
		print "Message text : %s" % response.messages.message[0].text
		print "Subscription ID : %s" % response.subscriptionId
	else:
		print "ERROR:" 
		print "Message Code : %s" % response.messages.message[0].code
		print "Message text : %s" % response.messages.message[0].text

	return response
Beispiel #9
0
def provider_create_subscriptiondetails_from_customer_profile(
        amount, days, startdate, profileId):
    # Setting the merchant details
    merchantAuth = apicontractsv1.merchantAuthenticationType()
    merchantAuth.name = get_secret("API_LOGIN_ID")
    merchantAuth.transactionKey = get_secret("API_TRANSACTION_KEY")
    # Setting payment schedule
    paymentschedule = apicontractsv1.paymentScheduleType()
    paymentschedule.interval = apicontractsv1.paymentScheduleTypeInterval(
    )  # apicontractsv1.CTD_ANON() #modified by krgupta
    paymentschedule.interval.length = days
    paymentschedule.interval.unit = apicontractsv1.ARBSubscriptionUnitEnum.days
    paymentschedule.startDate = startdate
    paymentschedule.totalOccurrences = 999
    paymentschedule.trialOccurrences = 0

    # setting the customer profile details
    profile = apicontractsv1.customerProfileIdType()

    getCustomerProfile = apicontractsv1.getCustomerProfileRequest()
    getCustomerProfile.merchantAuthentication = merchantAuth
    getCustomerProfile.customerProfileId = str(profileId)
    controller = getCustomerProfileController(getCustomerProfile)
    controller.execute()

    response = controller.getresponse()

    paymentProfileId = None
    if (response.messages.resultCode == "Ok"):
        print(
            "Successfully retrieved a customer with profile id %s and customer id %s"
            % (getCustomerProfile.customerProfileId,
               response.profile.merchantCustomerId))
        if hasattr(response, 'profile') == True:
            profile.customerProfileId = getCustomerProfile.customerProfileId
            if hasattr(response.profile, 'paymentProfiles') == True:
                for paymentProfile in response.profile.paymentProfiles:
                    print("paymentProfile in get_customerprofile is:" %
                          paymentProfile)
                    print("Payment Profile ID %s" %
                          str(paymentProfile.customerPaymentProfileId))
                    paymentProfileId = str(
                        paymentProfile.customerPaymentProfileId)
        else:
            print("Failed to get customer profile information with id %s" %
                  getCustomerProfile.customerProfileId)

    profile.customerPaymentProfileId = paymentProfileId
    profile.customerAddressId = None

    # Setting subscription details
    subscription = apicontractsv1.ARBSubscriptionType()
    subscription.name = "Sample Subscription"
    subscription.paymentSchedule = paymentschedule
    subscription.amount = amount
    subscription.trialAmount = Decimal('0.00')
    subscription.profile = profile

    # Creating the request
    request = apicontractsv1.ARBCreateSubscriptionRequest()
    request.merchantAuthentication = merchantAuth
    request.subscription = subscription

    # Creating and executing the controller
    controller = ARBCreateSubscriptionController(request)
    controller.execute()
    # Getting the response
    response = controller.getresponse()

    if (response.messages.resultCode == "Ok"):
        print("SUCCESS:")
        print("Message Code : %s" % response.messages.message[0]['code'].text)
        print("Message text : %s" % response.messages.message[0]['text'].text)
        print("Subscription ID : %s" % response.subscriptionId)
    else:
        print("ERROR:")
        print("Message Code : %s" % response.messages.message[0]['code'].text)
        print("Message text : %s" % response.messages.message[0]['text'].text)

    return response
Beispiel #10
0
def ARBCreateSubscriptionRequest(cart, refId, opaque_data, contact_info,
                                 months):

    # Get Authorize.net API credentials
    merchantAuth = _getMerchantAuth()

    # Setting payment schedule
    paymentschedule = apicontractsv1.paymentScheduleType()
    paymentschedule.interval = apicontractsv1.paymentScheduleTypeInterval()
    paymentschedule.interval.length = 1
    paymentschedule.interval.unit = apicontractsv1.ARBSubscriptionUnitEnum.months
    paymentschedule.startDate = date.today()
    paymentschedule.totalOccurrences = months

    # Get payment info
    payment = _getPayment(opaque_data)

    # Create order information
    order = apicontractsv1.orderType()
    order.description = refId

    # Setting billing information
    billto = apicontractsv1.nameAndAddressType()
    billto.firstName = contact_info['first_name']
    billto.lastName = contact_info['last_name']
    billto.address = contact_info['address']
    billto.city = contact_info['city']
    billto.state = contact_info['state']
    billto.zip = contact_info['zip']
    billto.country = contact_info['country']
    billto.phoneNumber = contact_info['phone']

    # Set the customer's identifying information
    customerData = apicontractsv1.customerType()
    customerData.type = "individual"
    customerData.email = contact_info['email']
    customerData.phoneNumber = contact_info['phone']

    # Setting subscription details
    subscription = apicontractsv1.ARBSubscriptionType()
    subscription.paymentSchedule = paymentschedule
    subscription.amount = six.text_type(cart.amount)
    subscription.order = order
    subscription.customer = customerData
    subscription.billTo = billto
    subscription.payment = payment

    # Creating the request
    request = apicontractsv1.ARBCreateSubscriptionRequest()
    request.merchantAuthentication = merchantAuth
    request.subscription = subscription

    with enhanced_authnet_logging():
        controller = ARBCreateSubscriptionController(request)
        if config.IN_PRODUCTION:
            controller.setenvironment(constants.PRODUCTION)
        controller.execute()
        response = controller.getresponse()

    logger.info('ARBCreateSubscriptionController response: {}'.format(
        response.__repr__()))
    if response.messages.resultCode == 'Ok':
        return response
    else:
        raise PaymentProcessingException(response.messages.message[0].text)
Beispiel #11
0
def ARBCreateSubscriptionRequest(
        cart, refId, opaque_data, contact_info, months):

    # Get Authorize.net API credentials
    merchantAuth = _getMerchantAuth()

    # Setting payment schedule
    paymentschedule = apicontractsv1.paymentScheduleType()
    paymentschedule.interval = apicontractsv1.paymentScheduleTypeInterval()
    paymentschedule.interval.length = 1
    paymentschedule.interval.unit = apicontractsv1.ARBSubscriptionUnitEnum.months
    paymentschedule.startDate = date.today()
    paymentschedule.totalOccurrences = months

    # Get payment info
    payment = _getPayment(opaque_data)

    # Create order information
    order = apicontractsv1.orderType()
    order.description = refId

    # Setting billing information
    billto = apicontractsv1.nameAndAddressType()
    billto.firstName = contact_info['first_name']
    billto.lastName = contact_info['last_name']
    billto.address = contact_info['address']
    billto.city = contact_info['city']
    billto.state = contact_info['state']
    billto.zip = contact_info['zip']
    billto.country = contact_info['country']
    billto.phoneNumber = contact_info['phone']

    # Set the customer's identifying information
    customerData = apicontractsv1.customerType()
    customerData.type = "individual"
    customerData.email = contact_info['email']
    customerData.phoneNumber = contact_info['phone']

    # Setting subscription details
    subscription = apicontractsv1.ARBSubscriptionType()
    subscription.paymentSchedule = paymentschedule
    subscription.amount = str(cart.amount)
    subscription.order = order
    subscription.customer = customerData
    subscription.billTo = billto
    subscription.payment = payment

    # Creating the request
    request = apicontractsv1.ARBCreateSubscriptionRequest()
    request.merchantAuthentication = merchantAuth
    request.subscription = subscription

    # Creating and executing the controller
    controller = ARBCreateSubscriptionController(request)
    if config.IN_PRODUCTION:
        controller.setenvironment(constants.PRODUCTION)
    controller.execute()

    # Getting the response
    response = controller.getresponse()
    if response.messages.resultCode == 'Ok':
        return response
    else:
        raise PaymentProcessingException(response.messages.message[0].text)
Beispiel #12
0
from authorizenet import apicontractsv1
from authorizenet.apicontrollers import *
from decimal import *
from datetime import *
# Setting the merchant details
merchantAuth = apicontractsv1.merchantAuthenticationType()
merchantAuth.name = '5KP3u95bQpv'
merchantAuth.transactionKey = '4Ktq966gC55GAX7S'
# Setting payment schedule
paymentschedule = apicontractsv1.paymentScheduleType()
paymentschedule.interval = apicontractsv1.CTD_ANON()
paymentschedule.interval.length = 1
paymentschedule.interval.unit = apicontractsv1.ARBSubscriptionUnitEnum.months
paymentschedule.startDate = datetime(2020, 8, 30)
paymentschedule.totalOccurrences = 12
paymentschedule.trialOccurrences = 1
# Giving the credit card info
creditcard = apicontractsv1.creditCardType()
creditcard.cardNumber = "4111111111111111"
creditcard.expirationDate = "2020-12"
payment = apicontractsv1.paymentType()
payment.creditCard = creditcard
# Setting billing information
billto = apicontractsv1.nameAndAddressType()
billto.firstName = "John"
billto.lastName = "Smith"
# Setting subscription details
subscription = apicontractsv1.ARBSubscriptionType()
subscription.name = "Sample Subscription"
subscription.paymentSchedule = paymentschedule
subscription.amount = Decimal('22.29')