def testo(key, labelToVoid): intoTheVoid = calls.void_label_call(key, labelToVoid) response = "Call unsuccessful. Response status code {}.".format(intoTheVoid[0]) try: response += " Response message:\n{}\n".format(intoTheVoid[1]) except IndexError: pass return response
def void_label(sessionSeller): if sessionSeller.validKey == False: return "Please make sure you have valid keys before making this call." print( "Feel free to void a label created during this session or any other ShipEngine originated label." ) while True: choice = input( "Would you like a list of the labels created in this session? [y\\n]: " ) if choice == "y": print("\n{}".format(display.displayLabels(sessionSeller))) break elif choice == "n": break elif choice == "q": return "Exiting label voiding section.\n" else: print( "Sorry, I didn't quite get that. If you'd like to quit this section enter (q)." ) labelToVoid = input("Enter the label ID to be voided: ").lower().strip(" ") try: intoTheVoid = calls.void_label_call(sessionSeller.apiKey, labelToVoid) except Exception: return "Call failed. Please make sure you have working connection to the internet." if intoTheVoid[0] == 200 and intoTheVoid[1]["approved"] == True: if labelToVoid in sessionSeller.labelList: sessionSeller.labelList[labelToVoid]["label_voided"] = True return "Label {} voided.".format(labelToVoid) elif intoTheVoid[0] == 200 and intoTheVoid[1]["approved"] == False: return "Label void request not approved. {}".format( intoTheVoid[1]["message"]) else: response = "Call unsuccessful. Response status code {}.".format( intoTheVoid[0]) try: response += " Response message:\n{}\n".format(intoTheVoid[1]) except IndexError: pass return response