2727from market .transactions import BitcoinTransaction
2828from protos .countries import CountryCode
2929from protos .objects import Listings
30+ from market .smtpnotification import SMTPNotification
3031
3132
3233class Contract (object ):
@@ -531,6 +532,13 @@ def accept_order_confirmation(self, notification_listener, confirmation_json=Non
531532 vendor_guid = self .contract ["vendor_offer" ]["listing" ]["id" ]["guid" ]
532533 self .notification_listener .notify (vendor_guid , handle , "order confirmation" , contract_hash , title ,
533534 image_hash )
535+
536+ # Send SMTP notification
537+ notification = SMTPNotification (self .db )
538+ notification .send ("[OpenBazaar] Order Confirmed and Shipped" ,
539+ "You have received an order confirmation.<br><br>"
540+ "Order: %s<br>Vendor: %s<br>Title: %s<br>" % (contract_hash , vendor_guid , title ))
541+
534542 return True
535543 except Exception , e :
536544 return e .message
@@ -747,6 +755,14 @@ def accept_receipt(self, notification_listener, blockchain, receipt_json=None):
747755
748756 self .notification_listener .notify (buyer_guid , handle , "rating received" , order_id , title , image_hash )
749757
758+ notification_rater = handle if handle else buyer_guid .encode ('hex' )
759+
760+ notification = SMTPNotification (self .db )
761+ notification .send ("[OpenBazaar] New Rating Received" ,
762+ "You received a new rating from %s for Order #%s - \" %s\" . " % (notification_rater ,
763+ order_id ,
764+ title ))
765+
750766 if "rating" in self .contract ["buyer_receipt" ]["receipt" ]:
751767 self .db .ratings .add_rating (self .contract ["buyer_receipt" ]["receipt" ]
752768 ["rating" ]["tx_summary" ]["listing" ],
@@ -803,9 +819,11 @@ def await_funding(self, notification_listener, libbitcoin_client, proofSig, is_p
803819 self .contract ["vendor_offer" ]["listing" ]["metadata" ]["category" ])
804820 else :
805821 file_path = os .path .join (DATA_FOLDER , "store" , "contracts" , "unfunded" , order_id + ".json" )
822+ title = self .contract ["vendor_offer" ]["listing" ]["item" ]["title" ]
823+ description = self .contract ["vendor_offer" ]["listing" ]["item" ]["description" ]
806824 self .db .sales .new_sale (order_id ,
807- self . contract [ "vendor_offer" ][ "listing" ][ "item" ][ " title" ] ,
808- self . contract [ "vendor_offer" ][ "listing" ][ "item" ][ " description" ] ,
825+ title ,
826+ description ,
809827 time .time (),
810828 self .contract ["buyer_order" ]["order" ]["payment" ]["amount" ],
811829 payment_address ,
@@ -814,6 +832,17 @@ def await_funding(self, notification_listener, libbitcoin_client, proofSig, is_p
814832 buyer ,
815833 self .contract ["vendor_offer" ]["listing" ]["metadata" ]["category" ])
816834
835+ try :
836+ notification = SMTPNotification (self .db )
837+ notification .send ("[OpenBazaar] Order Received" , "Order #%s<br>"
838+ "Buyer: %s<br>"
839+ "BTC Address: %s<br>"
840+ "Title: %s<br>"
841+ "Description: %s<br>"
842+ % (order_id , buyer , payment_address , title , description ))
843+ except Exception as e :
844+ self .log .info ("Error with SMTP notification: %s" % e .message )
845+
817846 with open (file_path , 'w' ) as outfile :
818847 outfile .write (json .dumps (self .contract , indent = 4 ))
819848 self .blockchain .subscribe_address (str (payment_address ), notification_cb = self .on_tx_received )
@@ -843,8 +872,8 @@ def on_tx_received(self, address_version, address_hash, height, block_hash, tx):
843872 if self .amount_funded >= amount_to_pay : # if fully funded
844873 self .payment_received ()
845874
846- except Exception :
847- self .log .critical ("Error processing bitcoin transaction" )
875+ except Exception as e :
876+ self .log .critical ("Error processing bitcoin transaction: %s" % e . message )
848877
849878 def payment_received (self ):
850879 self .blockchain .unsubscribe_address (
@@ -865,6 +894,14 @@ def payment_received(self):
865894 vendor_guid = self .contract ["vendor_offer" ]["listing" ]["id" ]["guid" ]
866895 self .notification_listener .notify (unhexlify (vendor_guid ), handle , "payment received" ,
867896 order_id , title , image_hash )
897+
898+ notification = SMTPNotification (self .db )
899+ notification .send ("[OpenBazaar] Purchase Payment Received" , "Your payment was received.<br><br>"
900+ "Order: %s<br>"
901+ "Vendor: %s<br>"
902+ "Title: %s"
903+ % (order_id , vendor_guid , title ))
904+
868905 # update the db
869906 if self .db .purchases .get_status (order_id ) == 0 :
870907 self .db .purchases .update_status (order_id , 1 )
@@ -880,6 +917,11 @@ def payment_received(self):
880917 handle = ""
881918 self .notification_listener .notify (unhexlify (buyer_guid ), handle , "new order" , order_id ,
882919 title , image_hash )
920+
921+ notification = SMTPNotification (self .db )
922+ notification .send ("[OpenBazaar] Payment for Order Received" , "Payment was received for Order #%s."
923+ % order_id )
924+
883925 self .db .sales .update_status (order_id , 1 )
884926 self .db .sales .update_outpoint (order_id , json .dumps (self .outpoints ))
885927 self .log .info ("Received new order %s" % order_id )
@@ -1070,6 +1112,11 @@ def process_refund(self, refund_json, blockchain, notification_listener):
10701112 handle = ""
10711113 notification_listener .notify (buyer_guid , handle , "refund" , order_id , title , image_hash )
10721114
1115+ notification = SMTPNotification (self .db )
1116+ notification .send ("[OpenBazaar] Refund Received" , "You received a refund.<br><br>"
1117+ "Order: %s<br>Title: %s"
1118+ % (order_id , title ))
1119+
10731120 def verify (self , sender_key ):
10741121 """
10751122 Validate that an order sent over by a buyer is filled out correctly.
0 commit comments