Example #1
0
    def subscription_payment(self, subscription):
        """
        subscription: Type: OrderItem
        Creates a subscription for a user. Subscriptions can be monthy or yearly.objects.all()
        """
        # Setting subscription details
        self.transaction_type = apicontractsv1.ARBSubscriptionType()
        self.transaction_type.name = subscription.offer.name
        self.transaction_type.paymentSchedule = self.create_payment_scheduale_interval_type(
            subscription, subscription.offer.terms)
        self.transaction_type.amount = self.to_valid_decimal(
            subscription.total)
        self.transaction_type.trialAmount = Decimal('0.00')
        self.transaction_type.billTo = self.create_billing_address(
            apicontractsv1.nameAndAddressType())
        self.transaction_type.payment = self.create_authorize_payment()

        # Optional to add Order information.
        self.transaction_type.order = self.create_order_type()

        # Creating the request
        self.transaction = apicontractsv1.ARBCreateSubscriptionRequest()
        self.transaction.merchantAuthentication = self.merchant_auth
        self.transaction.subscription = self.transaction_type

        # Creating and executing the controller
        self.controller = ARBCreateSubscriptionController(self.transaction)
        self.set_controller_api_endpoint()
        self.controller.execute()

        # Getting the response
        response = self.controller.getresponse()
        self.check_subscription_response(response)

        self.save_payment_subscription()
Example #2
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"
Example #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 = 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"
    
 
     
Example #4
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(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
Example #6
0
    def subscription_payment(self, subscription):
        """
        Creates a subscription for a user. Subscriptions can be monthy or yearly.objects.all()
        """

        # Setting billing information
        billto = apicontractsv1.nameAndAddressType()
        billto.firstName = " ".join(
            self.payment_info.data.get('full_name', "").split(" ")[:-1])[:50]
        billto.lastName = (self.payment_info.data.get('full_name',
                                                      "").split(" ")[-1])[:50]

        # Setting subscription details
        self.transaction_type = apicontractsv1.ARBSubscriptionType()
        self.transaction_type.name = subscription.offer.name
        self.transaction_type.paymentSchedule = self.create_payment_scheduale_interval_type(
            subscription, subscription.offer.terms)
        self.transaction_type.amount = self.to_valid_decimal(
            subscription.total)
        self.transaction_type.trialAmount = Decimal('0.00')
        self.transaction_type.billTo = billto
        self.transaction_type.payment = self.create_authorize_payment()

        # Creating the request
        self.transaction = apicontractsv1.ARBCreateSubscriptionRequest()
        self.transaction.merchantAuthentication = self.merchant_auth
        self.transaction.subscription = self.transaction_type

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

        self.check_subscription_response(response)

        receipt = subscription.receipts.get(
            transaction=self.payment.transaction)
        receipt.meta = {'raw': str({**self.transaction_message, **response})}

        if self.transaction_submitted:
            receipt.meta[
                'subscription_id'] = self.transaction_response.subscriptionId.pyval

        receipt.save()
Example #7
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)
Example #8
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)
Example #9
0
# 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')
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