from __future__ import print_function
import time
import authorizenet_rest
from authorizenet_rest.rest import ApiException

from authorizenet_rest.apis.invoices_api import InvoicesApi
from pprint import pprint
import warnings
import os
import sys
# QA modification
import csv
# QA modification
# import imp
# constants = imp.load_source('modulename', 'constants.py')
# warnings.filterwarnings("ignore",category=DeprecationWarning)
import base64
import urllib3

ExternalConfig = imp.load_source('modulename', '.\ExternalConfiguration.py')

def update_invoice(invoiceid):
    ExternalConfig.setConfig();
    apiclient = ExternalConfig.configureApiClient();
    authorization = ExternalConfig.getAuthorization()
    futdate = ExternalConfiguration.__futuredate__(None, "%Y-%m-%d")
    api_instance = authorizenet_rest.apis.invoices_api.InvoicesApi(apiclient)
    # QA modification
    identifier = authorizenet_rest.Identifier()
    identifier.email = "Testeamadil@gmail.com"
    identifier.reference = "Refernce"


    linkSelf = ["Href1", "title", "Method"]
    paymentMethods = ["Href2", "paymethodstitle", "paymethods"]
    address = ["Href3", "addresstitle", "address"]
    customerLinks =authorizenet_rest.CustomerLinks(linkSelf,paymentMethods,address);
    customer = ["1813162390", "TESTdDesss01",identifier,customerLinks]
    lineItem = ["1", "Name", "Desc", 2, "4", "false"]
    tax =[1, "tax", 2, "taxt"]
    createinvoice =["76","Invoice description",customer, "Test Payer", futdate, 10, 1, 1, 20, lineItem, tax, "false"]

    pprint(createinvoice)

    try:
        # Create A Webhook
        api_response = api_instance.update_invoice(invoiceid, createinvoice, authorization=authorization)
        pprint(api_response)

    except ApiException as e:
        print("Exception when calling AddressesApi->update_invoice: %s\n" % e)
        # QA modification


if (os.path.basename(__file__) == os.path.basename(sys.argv[0])):
    update_invoice("AVT-104")