#NEWLINE# @ gen . coroutine #NEWLINE# def ProcessSubscription( db_client , sub ) : #NEWLINE# #INDENT# logging . info ( 'processing subscription %s for user %d, expired %s' , sub . transaction_id , sub . user_id , time . ctime ( sub . expiration_ts ) ) #NEWLINE# assert sub . renewal_data , 'subscription without renewal_data' #NEWLINE# response = ( yield gen . Task ( ITunesStoreClient . Instance ( 'prod' ) . VerifyReceipt , sub . renewal_data ) ) #NEWLINE# if ( response . GetStatus ( ) == VerifyResponse . EXPIRED_ERROR ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# assert response . IsValid ( ) , 'new subscription is not valid' #NEWLINE# new_transaction_id = Subscription . GetITunesTransactionId ( response ) #NEWLINE# if ( new_transaction_id != sub . transaction_id ) : #NEWLINE# #INDENT# assert ( not response . IsExpired ( ) ) , ( 'new transaction already expired at %s' % response . GetExpirationTime ( ) ) #NEWLINE# assert ( Subscription . GetITunesSubscriptionId ( response ) == sub . subscription_id ) , 'subscription id changed' #NEWLINE# logging . info ( 'recording new subscription %s for user %d' , new_transaction_id , sub . user_id ) #NEWLINE# op_request = { #NEWLINE# #INDENT# 'headers' : { #NEWLINE# #INDENT# 'synchronous' : True , #NEWLINE# #UNINDENT# } , #NEWLINE# 'user_id' : sub . user_id , #NEWLINE# 'verify_response_str' : response . ToString ( ) , #NEWLINE# #UNINDENT# } #NEWLINE# ( yield gen . Task ( Operation . CreateAndExecute , db_client , sub . user_id , Operation . ANONYMOUS_DEVICE_ID , 'Subscription.RecordITunesTransactionOperation' , op_request ) )