<s> '''<STR_LIT>''' <EOL> from django . utils . translation import ugettext as _ <EOL> from livesettings import config_get_group <EOL> from payment . utils import get_processor_by_key <EOL> from satchmo_store . shop . models import Cart , Order , OrderPayment <EOL> import re <EOL> def find_order ( data ) : <EOL> """<STR_LIT>""" <EOL> transaction_id = data [ '<STR_LIT>' ] <EOL> payment = OrderPayment . objects . filter ( transaction_id__exact = transaction_id ) [ <NUM_LIT:0> ] <EOL> order = payment . order <EOL> return order <EOL> def notify_neworder ( request , data ) : <EOL> """<STR_LIT>""" <EOL> private_data = data [ '<STR_LIT>' ] <EOL> order_id = re . search ( '<STR_LIT>' , private_data ) . group ( <NUM_LIT:1> ) <EOL> order = Order . objects . get ( pk = order_id ) <EOL> payment_module = config_get_group ( '<STR_LIT>' ) <EOL> processor = get_processor_by_key ( '<STR_LIT>' ) <EOL> amount = data [ '<STR_LIT>' ] <EOL> pending_payment = processor . create_pending_payment ( order ) <EOL> pending_payment . capture . transaction_id = data [ '<STR_LIT>' ] <EOL> pending_payment . capture . save ( ) <EOL> for cart in Cart . objects . filter ( customer = order . contact ) : <EOL> cart . empty ( ) <EOL> cart . delete ( ) <EOL> order . add_status ( status = '<STR_LIT>' , notes = _ ( "<STR_LIT>" ) ) <EOL> def do_charged ( request , data ) : <EOL> """<STR_LIT>""" <EOL> order = find_order ( data ) <EOL> for item in order . orderitem_set . all ( ) : <EOL> product = item . product <EOL> product . total_sold += item . quantity <EOL> product . items_in_stock -= item . quantity <EOL> product . save ( ) <EOL> processor = get_processor_by_key ( '<STR_LIT>' ) <EOL> order . add_status ( status = '<STR_LIT>' , notes = _ ( "<STR_LIT>" ) ) <EOL> def do_shipped ( request , data ) : <EOL> """<STR_LIT>""" <EOL> order = find_order ( data ) <EOL> processor = get_processor_by_key ( '<STR_LIT>' ) <EOL> order . add_status ( status = '<STR_LIT>' , notes = _ ( "<STR_LIT>" ) ) <EOL> def notify_statechanged ( request , data ) : <EOL> """<STR_LIT>""" <EOL> financial_state = data [ '<STR_LIT>' ] <EOL> fulfillment_state = data [ '<STR_LIT>' ] <EOL> if financial_state == '<STR_LIT>' : <EOL> if fulfillment_state == '<STR_LIT>' : <EOL> do_charged ( request , data ) <EOL> elif fulfillment_state == '<STR_LIT>' : <EOL> do_shipped ( request , data ) <EOL> def notify_chargeamount ( request , data ) : <EOL> """<STR_LIT>""" <EOL> order = find_order ( data ) <EOL> transaction_id = data [ '<STR_LIT>' ] <EOL> processor = get_processor_by_key ( '<STR_LIT>' ) <EOL> processor . record_payment ( amount = data [ '<STR_LIT>' ] , transaction_id = transaction_id , order = order ) </s>
