I am developing a service where the user need to sign the seller agreement with Mobile BankID (Swedish e-sign service). To make this work I need to make SOAP request to get the progress status of the signing request in Mobile BankID.
Is this code understandable? How can I make it more clean?
def collect_request(transaction_id): '''You can make a delay for 9 seconds before you start to call the Collect method. After 9s you begin to make CollectRequest with a 3 seconds delay between each collect. First answer will probably be OUTSTANDING_TRANSACTION, then USER_SIGN and at last COMPLETE. (After six OUTSTANDING_TRANSACTION you get NO_CLIENT, just to indicate that the user not yet has started her BankID client. After 180 seconds, you will at last get faultStatus EXPIRED_TRANSACTION''' time.sleep(9) seller_agreement = SellerAgreement.objects.get(id=transaction_id) url = '<WSDL URL HERE>' client = Client(url) val = 'OUTSTANDING_TRANSACTION' while True: try: response = client.service.Collect(policy='logtest001', provider='bankid', displayName='Test av Mobilt BankID', transactionId=transaction_id, orderRef=seller_agreement.order_ref) print response if response.progressStatus != val: trigger_new_sign_event(seller_agreement.user.id, response.progressStatus) val = response.progressStatus if (response.progressStatus == 'OUTSTANDING_TRANSACTION' or response.progressStatus == 'USER_SIGN' or response.progressStatus == 'NO_CLIENT'): # Try again in 3 seconds time.sleep(3) continue if response.progressStatus == 'COMPLETE': # TODO: Save to db print "Done!" break except WebFault, f: print f # Django log? trigger_new_sign_event(seller_agreement.user.id, f.fault.faultstring) # TODO: cancelled_at? break