Ejemplo n.º 1
0
def get_cards():
    msg = None
    try:
        user = get_current_user()
        if not user:
            email = request.args.get("email")
            password = request.args.get("password")
            user = User.authenticate(email, password)
        cards = []
        if user.stripe_id:
            customer = stripe.Customer.retrieve(user.stripe_id)
            for _card in customer.cards.data:
                card = {"name": "**** **** **** " + _card.last4, "id": _card.id}

                if _card.id == customer.default_card:
                    card["default"] = True
                cards.append(card)

        return jsonify(status="SUCCESS", data={"cards": cards})
    except Exception as e:
        if msg is None:
            msg = "An error occured whilst retrieving your details from stripe"

        logging.exception(e)
        return jsonify(status="ERROR", msg=msg)
Ejemplo n.º 2
0
def get_cards():
    msg = None
    try:
        user = get_current_user()
        if not user:
            email = request.args.get('email')
            password = request.args.get('password')
            user = User.authenticate(email, password)
        cards = []
        if user.stripe_id:
            customer = stripe.Customer.retrieve(user.stripe_id)
            for _card in customer.cards.data:
                card = {
                    "name": "**** **** **** " + _card.last4,
                    "id": _card.id
                }

                if _card.id == customer.default_card:
                    card['default'] = True
                cards.append(card)

        return jsonify(
            status='SUCCESS', data={'cards': cards})
    except:
        if msg is None:
            msg = "An error occured whilst retrieving your details from stripe"

            msg += "\n\n" + sys.exc_info()[0]

        logging.exception(msg)
        return jsonify(status='ERROR', msg=msg)
Ejemplo n.º 3
0
def check_password():
    """Checks whether the submitted password is correct."""
    email = request.args.get("email")
    password = request.args.get("password")
    msg = None
    try:
        User.authenticate(email, password)
        msg = "An error occured whilst retrieving your details from stripe"
        return jsonify(status="SUCCESS", data={"user": "******"})
    except UserAuthenticationFailedError:
        return jsonify(status="SUCCESS", data={"user": "******"})
    except:
        if msg is None:
            msg = "An error occured whilst trying to check login credentials"

            msg += "\n\n" + sys.exc_info()[0]

        logging.exception(msg)
        return jsonify(status="ERROR", msg=msg)