# coding: utf8
from __future__ import unicode_literals
import logging

from django.contrib.auth.models import User
from eth_account.messages import defunct_hash_message
from web3 import Web3

from tixsell import settings
import stripe
from backoffice.models import *

def run():

    payment = Payment.objects.get(id="4f646a88-1ab3-4b5e-b160-53a1c08dadd4")
    if not payment.paymentIntent:
        print("==Pas de intent")
        
    # Verify payment status with Stripe
    payment_intent = stripe.PaymentIntent.retrieve(payment.paymentIntent,stripe_account=payment.refUser.seller.stripe_user_id)
    if payment_intent.status != 'succeeded':
        print("STATus kO")
        print(payment_intent.status)
    else:
        print("=OK")
    """
    w3 = Web3(Web3.HTTPProvider(settings.CONTRACT_NODE_URL))
    user = User.objects.get(username="0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266")
    nonce = user.first_name
    messageToSign = "Welcome to exhib.fans. You must sign in this message to be authenticated. Authentication code is :" + nonce
    message_hash = defunct_hash_message(text=messageToSign)
    signature="0x597d71f475a12ddd4ff12a1462b0226ddef3a04fe105fda5c512fec7c4150af03b27b03d06cdd3d72495edab059a8016bf75d1ed2bf36eab2883943f6e8b16bc1c"
    address = w3.eth.account.recoverHash(message_hash, signature=signature)
    print(address)
"""
    #walletUsed = w3.eth.account.recover_message(messageToSign, "0x5d3fcf40482dd45765abe032a9b9a946e61f7e676dbfd27af13087895f09ded54d71dc12b588db1f098ad74774d2642abaabfdb51c1d5073bcee282c1c6269ee1c")
