def handle_POST(postvars): logging.info("Received message") creds = get_creds() ok_to_release, release_url = is_ok_to_release(postvars) if ok_to_release: logging.debug("Getting LB client") client = LocalBitcoinsAPI(creds['lb_client_id'], creds['lb_client_secret'], creds['lb_username'], creds['lb_password']) logging.debug("Got LB client") ad_no = release_url.split('/')[-2] ad_url = ('https://localbitcoins.com/escrow_seller/' + ad_no) client.send_message( ad_url, 'Automated response: Thanks for your order - your coins will now be released.' ) response = client.release_escrow(release_url) logging.info("Released transaction") logging.info("Transaction reference %s" % postvars['ok_txn_comment'][0]) logging.info(response['data']['message']) else: print ad_url client.send_message( ad_url, 'Automated response: There was a problem with your payment. Please email [email protected] for human intervention.' ) response = client.release_escrow(release_url) logging.info("Released transaction") logging.info("Transaction reference %s - %s" % (postvars['ok_txn_comment'][0])) logging.info(response['data']['message'])
def is_transaction_details_ok(postvars): logging.debug("Checking transaction details match") creds = get_creds() # Check currency and amount from the escrow release API lb_client = LocalBitcoinsAPI(creds['lb_client_id'], creds['lb_client_secret'], creds['lb_username'], creds['lb_password']) escrows = lb_client.get_escrows() for escrow in escrows['data']['escrow_list']: if escrow['data']['reference_code'] == postvars['ok_txn_comment'][0]: lb_transaction = escrow logging.debug("Got LB transaction") if (lb_transaction['data']['currency'] == postvars['ok_txn_currency'][0] and lb_transaction['data']['amount'] == postvars['ok_txn_amount'][0]): return True, lb_transaction['actions']['release_url'] else: return False, ''
def handle_POST(postvars): logging.info("Received message") creds = get_creds() ok_to_release, release_url = is_ok_to_release(postvars) if ok_to_release: logging.debug("Getting LB client") client = LocalBitcoinsAPI(creds['lb_client_id'], creds['lb_client_secret'], creds['lb_username'], creds['lb_password']) logging.debug("Got LB client") ad_no = release_url.split('/')[-2] ad_url = ('https://localbitcoins.com/escrow_seller/' + ad_no) client.send_message(ad_url, 'Automated response: Thanks for your order - your coins will now be released.') response = client.release_escrow(release_url) logging.info("Released transaction") logging.info("Transaction reference %s" % postvars['ok_txn_comment'][0]) logging.info(response['data']['message']) else: print ad_url client.send_message(ad_url, 'Automated response: There was a problem with your payment. Please email [email protected] for human intervention.') response = client.release_escrow(release_url) logging.info("Released transaction") logging.info("Transaction reference %s - %s" % (postvars['ok_txn_comment'][0])) logging.info(response['data']['message'])