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

from authorizenet_rest.apis.paymentmethods_api import PaymentmethodsApi
from pprint import pprint
import os
import sys

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

def get_customer_payment_method(customer_id, payment_method_id):
    # create an instance of the API class
    ExternalConfig.setConfig();
    apiclient = ExternalConfig.configureApiClient();
    authorization = ExternalConfig.getAuthorization()
    futdate = ExternalConfig.futuredate()
    api_instance = authorizenet_rest.apis.paymentmethods_api.PaymentmethodsApi(apiclient)

    bankAccount = authorizenet_rest.BankAccount("Checking", "01245524321", "000000204", "test", "WEB", "testbank",
                                               "131231242343424")

    creditCard = authorizenet_rest.CreditCard("4111111111111111", futdate, "Test", "1220")

    paymentInstrument = authorizenet_rest.PaymentInstrument()
    paymentInstrument.bankAccount = "null"
    paymentInstrument.creditCard = creditCard
    paymentInstrument.fluidData = "null"
    paymentInstrument.customer = "null"

    baseAddress = authorizenet_rest.CreateCustomerAddress("Electonics City Phase d1", "ABxdfC", "ABsdsC",
                                                         "India", None, "Red Cross", "Main Cross",
                                                         "locality", "8748486465", "784684")

    createPaymentMethod = authorizenet_rest.CreatePaymentMethod()
    createPaymentMethod.bill_to = baseAddress
    createPaymentMethod.payment_instrument = paymentInstrument
    print("Check Output")
    try:
        # Create Customer Payment Method
        api_response = api_instance.update_payment_method(customer_id,payment_method_id, createPaymentMethod, authorization=authorization)
        pprint(api_response)
    except ApiException as e:
        print("Exception when calling PaymentmethodsApi->get_customer_payment_method: %s\n" % e)

if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
    get_customer_payment_method('1813040747','5435456667')