Пример #1
0
    def _create_entry_line_item(self, doc_entry):
        # description = models.CharField(max_length=1024)
        # unit = models.CharField(max_length=1024, blank=True, null=True)
        # quantity = models.DecimalField(max_digits=19, decimal_places=4,
        #                                validators=[MinValueValidator(0.0)])
        # unit_price = models.DecimalField(max_digits=19, decimal_places=4)
        # product_code = models.ForeignKey('ProductCode', null=True, blank=True,
        #                                  related_name='invoices')
        # start_date = models.DateField(null=True, blank=True)
        # end_date = models.DateField(null=True, blank=True)
        # prorated = models.BooleanField(default=False)

        logger.info("Creating line item for: %s" % repr(doc_entry))
        line_item = apicontractsv1.lineItemType()

        if doc_entry.product_code:
            line_item.itemId = doc_entry.product_code.value
            line_item.name = doc_entry.unit
        else:
            line_item.itemId = doc_entry.id
            line_item.name = doc_entry.unit

        line_item.description = doc_entry.description
        line_item.quantity = doc_entry.quantity
        line_item.unitPrice = abs(doc_entry.unit_price)
        logger.info(line_item)

        return line_item
Пример #2
0
 def create_line_item(self, order_item):
     """
     Create a single line order_item (products) that is attached to a line order_item array
     """
     line_item = apicontractsv1.lineItemType()
     line_item.itemId = str(order_item.pk)
     line_item.name = order_item.name[:30]
     line_item.description = str(order_item.offer.description)[:250]
     line_item.quantity = str(order_item.quantity)
     line_item.unitPrice = str(order_item.price)
     return line_item
Пример #3
0
def _getLineItems(cart):
    line_items = apicontractsv1.ArrayOfLineItem()
    for item in cart.items:
        line_item = apicontractsv1.lineItemType()
        line_item.itemId = item.uid[:31]
        line_item.name = item.category
        line_item.description = item.name[:255]
        line_item.quantity = six.text_type(item.quantity)
        line_item.unitPrice = six.text_type(item.price)
        line_items.lineItem.append(line_item)
    return line_items
Пример #4
0
def _getLineItems(cart):
    line_items = apicontractsv1.ArrayOfLineItem()
    for item in cart.items:
        line_item = apicontractsv1.lineItemType()
        line_item.itemId = item.uid[:31]
        line_item.name = item.category
        line_item.description = item.name[:255]
        line_item.quantity = str(item.quantity)
        line_item.unitPrice = str(item.price)
        line_items.lineItem.append(line_item)
    return line_items
Пример #5
0
 def get_authorizenet_lineitems(self, basket):
     """
         return AuthorizeNet_sdk lineItem List Instance containing all items data received from basket.
     """
     line_items_list = apicontractsv1.ArrayOfLineItem()
     for line in basket.all_lines():
         line_item = apicontractsv1.lineItemType()
         line_item.itemId = line.product.course_id
         line_item.name = line.product.course_id
         line_item.description = line.product.title
         line_item.quantity = line.quantity
         line_item.unitPrice = line.line_price_incl_tax_incl_discounts / line.quantity
         line_items_list.lineItem.append(line_item)
     return line_items_list
def charge_credit_card(amount):
    """
    Charge a credit card
    """

    # Create a merchantAuthenticationType object with authentication details
    # retrieved from the constants file
    merchantAuth = apicontractsv1.merchantAuthenticationType()
    merchantAuth.name = CONSTANTS.apiLoginId
    merchantAuth.transactionKey = CONSTANTS.transactionKey

    # Create the payment data for a credit card
    creditCard = apicontractsv1.creditCardType()
    creditCard.cardNumber = "4111111111111111"
    creditCard.expirationDate = "2020-12"
    creditCard.cardCode = "123"

    # Add the payment data to a paymentType object
    payment = apicontractsv1.paymentType()
    payment.creditCard = creditCard

    # Create order information
    order = apicontractsv1.orderType()
    order.invoiceNumber = "10101"
    order.description = "Golf Shirts"

    # Set the customer's Bill To address
    customerAddress = apicontractsv1.customerAddressType()
    customerAddress.firstName = "Ellen"
    customerAddress.lastName = "Johnson"
    customerAddress.company = "Souveniropolis"
    customerAddress.address = "14 Main Street"
    customerAddress.city = "Pecan Springs"
    customerAddress.state = "TX"
    customerAddress.zip = "44628"
    customerAddress.country = "USA"

    # Set the customer's identifying information
    customerData = apicontractsv1.customerDataType()
    customerData.type = "individual"
    customerData.id = "99999456654"
    customerData.email = "*****@*****.**"

    # Add values for transaction settings
    duplicateWindowSetting = apicontractsv1.settingType()
    duplicateWindowSetting.settingName = "duplicateWindow"
    duplicateWindowSetting.settingValue = "600"
    settings = apicontractsv1.ArrayOfSetting()
    settings.setting.append(duplicateWindowSetting)

    # setup individual line items
    line_item_1 = apicontractsv1.lineItemType()
    line_item_1.itemId = "12345"
    line_item_1.name = "first"
    line_item_1.description = "Here's the first line item"
    line_item_1.quantity = "2"
    line_item_1.unitPrice = "12.95"
    line_item_2 = apicontractsv1.lineItemType()
    line_item_2.itemId = "67890"
    line_item_2.name = "second"
    line_item_2.description = "Here's the second line item"
    line_item_2.quantity = "3"
    line_item_2.unitPrice = "7.95"

    # build the array of line items
    line_items = apicontractsv1.ArrayOfLineItem()
    line_items.lineItem.append(line_item_1)
    line_items.lineItem.append(line_item_2)

    # Create a transactionRequestType object and add the previous objects to it.
    transactionrequest = apicontractsv1.transactionRequestType()
    transactionrequest.transactionType = "authCaptureTransaction"
    transactionrequest.amount = amount
    transactionrequest.payment = payment
    transactionrequest.order = order
    transactionrequest.billTo = customerAddress
    transactionrequest.customer = customerData
    transactionrequest.transactionSettings = settings
    transactionrequest.lineItems = line_items

    # Assemble the complete transaction request
    createtransactionrequest = apicontractsv1.createTransactionRequest()
    createtransactionrequest.merchantAuthentication = merchantAuth
    createtransactionrequest.refId = "MerchantID-0001"
    createtransactionrequest.transactionRequest = transactionrequest
    # Create the controller
    createtransactioncontroller = createTransactionController(
        createtransactionrequest)
    createtransactioncontroller.execute()

    response = createtransactioncontroller.getresponse()

    if response is not None:
        # Check to see if the API request was successfully received and acted upon
        if response.messages.resultCode == "Ok":
            # Since the API request was successful, look for a transaction response
            # and parse it to display the results of authorizing the card
            if hasattr(response.transactionResponse, 'messages') is True:
                print(
                    'Successfully created transaction with Transaction ID: %s'
                    % response.transactionResponse.transId)
                print('Transaction Response Code: %s' %
                      response.transactionResponse.responseCode)
                print('Message Code: %s' %
                      response.transactionResponse.messages.message[0].code)
                print('Description: %s' % response.transactionResponse.
                      messages.message[0].description)
            else:
                print('Failed Transaction.')
                if hasattr(response.transactionResponse, 'errors') is True:
                    print('Error Code:  %s' % str(response.transactionResponse.
                                                  errors.error[0].errorCode))
                    print(
                        'Error message: %s' %
                        response.transactionResponse.errors.error[0].errorText)
        # Or, print errors if the API request wasn't successful
        else:
            print('Failed Transaction.')
            if hasattr(response, 'transactionResponse') is True and hasattr(
                    response.transactionResponse, 'errors') is True:
                print('Error Code: %s' % str(
                    response.transactionResponse.errors.error[0].errorCode))
                print('Error message: %s' %
                      response.transactionResponse.errors.error[0].errorText)
            else:
                print('Error Code: %s' %
                      response.messages.message[0]['code'].text)
                print('Error message: %s' %
                      response.messages.message[0]['text'].text)
    else:
        print('Null Response.')

    return response
Пример #7
0
def charge_credit_card(data, card_number, expiration_date, card_code):
    """
	Charge a credit card
	"""
    data = json.loads(data)
    data = frappe._dict(data)

    # Create Integration Request
    integration_request = create_request_log(data, "Host", "Authorizenet")

    # Authenticate with Authorizenet
    merchant_auth = apicontractsv1.merchantAuthenticationType()
    merchant_auth.name = frappe.db.get_single_value("Authorizenet Settings",
                                                    "api_login_id")
    merchant_auth.transactionKey = get_decrypted_password(
        'Authorizenet Settings',
        'Authorizenet Settings',
        fieldname='api_transaction_key',
        raise_exception=False)

    # Create the payment data for a credit card
    credit_card = apicontractsv1.creditCardType()
    credit_card.cardNumber = card_number
    credit_card.expirationDate = expiration_date
    credit_card.cardCode = card_code

    # Add the payment data to a paymentType object
    payment = apicontractsv1.paymentType()
    payment.creditCard = credit_card

    pr = frappe.get_doc(data.reference_doctype, data.reference_docname)
    reference_doc = frappe.get_doc(pr.reference_doctype,
                                   pr.reference_name).as_dict()

    customer_address = apicontractsv1.customerAddressType()
    customer_address.firstName = data.payer_name
    customer_address.email = data.payer_email
    customer_address.address = reference_doc.customer_address[:60]

    # Create order information
    order = apicontractsv1.orderType()
    order.invoiceNumber = reference_doc.name

    # build the array of line items
    line_items = apicontractsv1.ArrayOfLineItem()

    for item in reference_doc.get("items"):
        # setup individual line items
        line_item = apicontractsv1.lineItemType()
        line_item.itemId = item.item_code
        line_item.name = item.item_name[:30]
        line_item.description = item.item_name
        line_item.quantity = item.qty
        line_item.unitPrice = cstr(item.rate)

        line_items.lineItem.append(line_item)

    # Create a transactionRequestType object and add the previous objects to it.
    transaction_request = apicontractsv1.transactionRequestType()
    transaction_request.transactionType = "authCaptureTransaction"
    transaction_request.amount = data.amount
    transaction_request.payment = payment
    transaction_request.order = order
    transaction_request.billTo = customer_address
    transaction_request.lineItems = line_items

    # Assemble the complete transaction request
    create_transaction_request = apicontractsv1.createTransactionRequest()
    create_transaction_request.merchantAuthentication = merchant_auth
    create_transaction_request.transactionRequest = transaction_request

    # Create the controller
    createtransactioncontroller = createTransactionController(
        create_transaction_request)
    if not frappe.db.get_single_value("Authorizenet Settings", "sandbox_mode"):
        createtransactioncontroller.setenvironment(constants.PRODUCTION)
    createtransactioncontroller.execute()

    response = createtransactioncontroller.getresponse()

    status = "Failed"
    if response is not None:
        # Check to see if the API request was successfully received and acted upon
        if response.messages.resultCode == "Ok" and hasattr(
                response.transactionResponse, 'messages') is True:
            status = "Completed"

    if status != "Failed":
        try:
            pr.run_method("on_payment_authorized", status)
        except Exception as ex:
            raise ex

    response_dict = to_dict(response)
    integration_request.update_status(data, status)
    description = "Something went wrong while trying to complete the transaction. Please try again."

    if status == "Completed":
        description = response_dict.get("transactionResponse").get(
            "messages").get("message").get("description")
    elif status == "Failed":
        description = error_text = response_dict.get(
            "transactionResponse").get("errors").get("error").get("errorText")
        integration_request.error = error_text
        integration_request.save(ignore_permissions=True)

    return frappe._dict({"status": status, "description": description})
Пример #8
0
def authnet_charge(request):
	# data refs
	data = request.data
	card = request.card
	reference_doc = request.reference_doc

	# Create the payment data for a credit card
	credit_card = apicontractsv1.creditCardType()
	credit_card.cardNumber = request.card.number
	credit_card.expirationDate = request.card.expiration_date
	credit_card.cardCode = request.card.code

	# Add the payment data to a paymentType object
	payment = apicontractsv1.paymentType()
	payment.creditCard = credit_card

	# determin company name to attach to customer address record
	customer_name = None
	if reference_doc.doctype == "Quotation" and frappe.db.exists("Customer", reference_doc.party_name):
		# sanity test, only fetch customer record from party_name
		customer_name = reference_doc.party_name
	else:
		customer_name = reference_doc.customer

	name_parts = card.holder_name.split(None, 1)
	customer_address = apicontractsv1.customerAddressType()
	customer_address.firstName = name_parts[0] or data.payer_name
	customer_address.lastName = name_parts[1] if len(name_parts) > 1 else ""
	customer_address.email = card.holder_email or data.payer_email

	# setting billing address details
	if frappe.db.exists("Address", reference_doc.customer_address):
		address = frappe.get_doc("Address", reference_doc.customer_address)
		customer_address.address = (address.address_line1 or "")[:60]
		customer_address.city = (address.city or "")[:40]
		customer_address.state = (address.state or "")[:40]
		customer_address.zip = (address.pincode or "")[:20]
		customer_address.country = (address.country or "")[:60]


	# record company name when not an individual
	customer_type = frappe.db.get_value("Customer", customer_name, "customer_type")
	if customer_type != "Individual":
		customer_address.company = reference_doc.customer_name

	# Create order information
	order = apicontractsv1.orderType()
	order.invoiceNumber = reference_doc.name

	# build the array of line items
	line_items = apicontractsv1.ArrayOfLineItem()

	for item in reference_doc.get("items"):
		# setup individual line items
		line_item = apicontractsv1.lineItemType()
		line_item.itemId = item.item_code
		line_item.name = item.item_name[:30]
		line_item.description = item.item_name
		line_item.quantity = item.qty
		line_item.unitPrice = cstr(item.rate)

		line_items.lineItem.append(line_item)

	# Adjust duplicate window to avoid duplicate window issues on declines
	duplicateWindowSetting = apicontractsv1.settingType()
	duplicateWindowSetting.settingName = "duplicateWindow"
	# seconds before an identical transaction can be submitted
	duplicateWindowSetting.settingValue = "10"
	settings = apicontractsv1.ArrayOfSetting()
	settings.setting.append(duplicateWindowSetting)

	# Create a transactionRequestType object and add the previous objects to it.
	transaction_request = apicontractsv1.transactionRequestType()
	transaction_request.transactionType = "authCaptureTransaction"
	transaction_request.amount = data.amount
	transaction_request.payment = payment
	transaction_request.order = order
	transaction_request.billTo = customer_address
	transaction_request.lineItems = line_items
	transaction_request.transactionSettings = settings

	# Assemble the complete transaction request
	create_transaction_request = apicontractsv1.createTransactionRequest()
	create_transaction_request.merchantAuthentication = request.merchant_auth
	create_transaction_request.transactionRequest = transaction_request
	create_transaction_request.refId = reference_doc.name

	# Create the controller
	createtransactioncontroller = createTransactionController(create_transaction_request)
	if not frappe.db.get_single_value("Authorizenet Settings", "sandbox_mode"):
		createtransactioncontroller.setenvironment(constants.PRODUCTION)
	createtransactioncontroller.execute()

	return createtransactioncontroller.getresponse()
Пример #9
0
def charge_credit_card(amount):
    """
    Charge a credit card
    """

    # Create a merchantAuthenticationType object with authentication details
    # retrieved from the constants file
    merchantAuth = apicontractsv1.merchantAuthenticationType()
    merchantAuth.name = CONSTANTS.apiLoginId
    merchantAuth.transactionKey = CONSTANTS.transactionKey

    # Create the payment data for a credit card
    creditCard = apicontractsv1.creditCardType()
    card_types = ['visa', 'discover', 'mastercard', 'jcb']
    creditCard.cardNumber = fake.credit_card_number(
        card_type=random.choice(card_types))
    creditCard.expirationDate = fake.credit_card_expire()
    creditCard.cardCode = fake.credit_card_security_code()

    # Add the payment data to a paymentType object
    payment = apicontractsv1.paymentType()
    payment.creditCard = creditCard

    # Create order information
    order = apicontractsv1.orderType()
    order.invoiceNumber = str(random.randint(1000, 3000))
    order.description = fake.bs()

    # Set the customer's Bill To address
    customerAddress = apicontractsv1.customerAddressType()
    customerAddress.firstName = fake.first_name()
    customerAddress.lastName = fake.last_name()
    customerAddress.company = fake.bs()
    customerAddress.address = fake.street_address()
    customerAddress.city = fake.city()
    customerAddress.state = fake.address().split()[-1].split()[0]
    customerAddress.zip = fake.postalcode_in_state()
    customerAddress.country = fake.country()
    customerAddress.phoneNumber = fake.phone_number()

    # Set the customer's identifying information
    customerData = apicontractsv1.customerDataType()
    customerData.type = "individual"
    customerData.id = fake.upc_e()
    customerData.email = fake.email()

    # Add values for transaction settings
    duplicateWindowSetting = apicontractsv1.settingType()
    duplicateWindowSetting.settingName = "duplicateWindow"
    duplicateWindowSetting.settingValue = "600"
    settings = apicontractsv1.ArrayOfSetting()
    settings.setting.append(duplicateWindowSetting)

    # setup individual line items
    line_item_1 = apicontractsv1.lineItemType()
    line_item_1.itemId = "12345"
    line_item_1.name = "first"
    line_item_1.description = fake.catch_phrase()
    line_item_1.quantity = "2"
    line_item_1.unitPrice = "12.95"
    line_item_2 = apicontractsv1.lineItemType()
    line_item_2.itemId = "67890"
    line_item_2.name = "second"
    line_item_2.description = fake.catch_phrase()
    line_item_2.quantity = "3"
    line_item_2.unitPrice = "7.95"
    line_item_3 = apicontractsv1.lineItemType()
    line_item_3.itemId = "ID num goes here"
    line_item_3.name = "third"
    line_item_3.description = fake.catch_phrase()
    line_item_3.quantity = "12"
    line_item_3.unitPrice = "100.00"

    # build the array of line items
    line_items = apicontractsv1.ArrayOfLineItem()
    line_items.lineItem.append(line_item_1)
    line_items.lineItem.append(line_item_2)
    line_items.lineItem.append(line_item_3)

    # Create a transactionRequestType object and add the previous objects to it.
    transactionrequest = apicontractsv1.transactionRequestType()
    transactionrequest.transactionType = "authCaptureTransaction"
    transactionrequest.amount = amount
    transactionrequest.payment = payment
    transactionrequest.order = order
    transactionrequest.billTo = customerAddress
    transactionrequest.customer = customerData
    transactionrequest.transactionSettings = settings
    transactionrequest.lineItems = line_items

    # Assemble the complete transaction request
    createtransactionrequest = apicontractsv1.createTransactionRequest()
    createtransactionrequest.merchantAuthentication = merchantAuth
    createtransactionrequest.refId = "1234-3432"
    createtransactionrequest.transactionRequest = transactionrequest
    # Create the controller
    createtransactioncontroller = createTransactionController(
        createtransactionrequest)
    createtransactioncontroller.execute()

    response = createtransactioncontroller.getresponse()

    if response is not None:
        # Check to see if the API request was successfully received and acted upon
        if response.messages.resultCode == "Ok":
            # Since the API request was successful, look for a transaction response
            # and parse it to display the results of authorizing the card
            if hasattr(response.transactionResponse, 'messages') is True:
                print(
                    'Successfully created transaction with Transaction ID: %s'
                    % response.transactionResponse.transId)
                print('Transaction Response Code: %s' %
                      response.transactionResponse.responseCode)
                print('Message Code: %s' %
                      response.transactionResponse.messages.message[0].code)
                print('Description: %s' % response.transactionResponse.
                      messages.message[0].description)
            else:
                print('Failed Transaction.')
                if hasattr(response.transactionResponse, 'errors') is True:
                    print('Error Code:  %s' % str(response.transactionResponse.
                                                  errors.error[0].errorCode))
                    print(
                        'Error message: %s' %
                        response.transactionResponse.errors.error[0].errorText)
        # Or, print errors if the API request wasn't successful
        else:
            print('Failed Transaction.')
            if hasattr(response, 'transactionResponse') is True and hasattr(
                    response.transactionResponse, 'errors') is True:
                print('Error Code: %s' % str(
                    response.transactionResponse.errors.error[0].errorCode))
                print('Error message: %s' %
                      response.transactionResponse.errors.error[0].errorText)
            else:
                print('Error Code: %s' %
                      response.messages.message[0]['code'].text)
                print('Error message: %s' %
                      response.messages.message[0]['text'].text)
    else:
        print('Null Response.')

    return response
Пример #10
0
def charge_credit_card(amount):
    """
    Charge a credit card
    """

    # Create a merchantAuthenticationType object with authentication details
    # retrieved from the constants file
    merchantAuth = apicontractsv1.merchantAuthenticationType()
    merchantAuth.name = CONSTANTS.apiLoginId
    merchantAuth.transactionKey = CONSTANTS.transactionKey

    # Create the payment data for a credit card
    creditCard = apicontractsv1.creditCardType()
    creditCard.cardNumber = input("Credit card number please! ")
    creditCard.expirationDate = input("Expiration date (year-mo): ")
    creditCard.cardCode = input("CVV Code")

    # Add the payment data to a paymentType object
    payment = apicontractsv1.paymentType()
    payment.creditCard = creditCard

    # Create order information
    order = apicontractsv1.orderType()
    order.invoiceNumber = input("Invoice Number: ")
    order.description = input("Order description: ")

    # Set the customer's Bill To address
    customerAddress = apicontractsv1.customerAddressType()
    customerAddress.firstName = input("Customer first name: ")
    customerAddress.lastName = input("Customer last name: ")
    customerAddress.company = input("Customer company: ")
    customerAddress.address = input("Customer address: ")
    customerAddress.city = input("City: ")
    customerAddress.state = input("State: ")
    customerAddress.zip = input("Zip code: ")
    customerAddress.country = input("Country; ")

    # Set the customer's identifying information
    customerData = apicontractsv1.customerDataType()
    customerData.type = "individual"
    customerData.id = "99999456654"
    customerData.email = input("Customer email: ")

    # Add values for transaction settings
    duplicateWindowSetting = apicontractsv1.settingType()
    duplicateWindowSetting.settingName = "duplicateWindow"
    duplicateWindowSetting.settingValue = "600"
    settings = apicontractsv1.ArrayOfSetting()
    settings.setting.append(duplicateWindowSetting)

    # setup individual line items
    line_item_1 = apicontractsv1.lineItemType()
    line_item_1.itemId = "12345"
    line_item_1.name = "first"
    line_item_1.description = "Here's the first line item"
    line_item_1.quantity = int(input("How many do you want? "))
    line_item_1.unitPrice = line_item_1.quantity
    # print("That will cost " + line_item_1.quantity)

    # build the array of line items
    line_items = apicontractsv1.ArrayOfLineItem()
    line_items.lineItem.append(line_item_1)

    # Create a transactionRequestType object and add the previous objects to it.
    transactionrequest = apicontractsv1.transactionRequestType()
    transactionrequest.transactionType = "authCaptureTransaction"
    transactionrequest.amount = amount
    transactionrequest.payment = payment
    transactionrequest.order = order
    transactionrequest.billTo = customerAddress
    transactionrequest.customer = customerData
    transactionrequest.transactionSettings = settings
    transactionrequest.lineItems = line_items

    # Assemble the complete transaction request
    createtransactionrequest = apicontractsv1.createTransactionRequest()
    createtransactionrequest.merchantAuthentication = merchantAuth
    createtransactionrequest.refId = "MerchantID-0001"
    createtransactionrequest.transactionRequest = transactionrequest
    # Create the controller
    createtransactioncontroller = createTransactionController(
        createtransactionrequest)
    createtransactioncontroller.execute()

    response = createtransactioncontroller.getresponse()

    print("Thank you for shopping!")

    if response is not None:
        # Check to see if the API request was successfully received and acted upon
        if response.messages.resultCode == "Ok":
            # Since the API request was successful, look for a transaction response
            # and parse it to display the results of authorizing the card
            if hasattr(response.transactionResponse, 'messages') is True:
                print(
                    'Successfully created transaction with Transaction ID: %s'
                    % response.transactionResponse.transId)
                print('Transaction Response Code: %s' %
                      response.transactionResponse.responseCode)
                print('Message Code: %s' %
                      response.transactionResponse.messages.message[0].code)
                print('Description: %s' % response.transactionResponse.
                      messages.message[0].description)
            else:
                print('Failed Transaction.')
                if hasattr(response.transactionResponse, 'errors') is True:
                    print('Error Code:  %s' % str(response.transactionResponse.
                                                  errors.error[0].errorCode))
                    print(
                        'Error message: %s' %
                        response.transactionResponse.errors.error[0].errorText)
        # Or, print errors if the API request wasn't successful
        else:
            print('Failed Transaction.')
            if hasattr(response, 'transactionResponse') is True and hasattr(
                    response.transactionResponse, 'errors') is True:
                print('Error Code: %s' % str(
                    response.transactionResponse.errors.error[0].errorCode))
                print('Error message: %s' %
                      response.transactionResponse.errors.error[0].errorText)
            else:
                print('Error Code: %s' %
                      response.messages.message[0]['code'].text)
                print('Error message: %s' %
                      response.messages.message[0]['text'].text)
    else:
        print('Null Response.')

    return response