Exemplo n.º 1
0
def makeDonation():
    if not has_args(request.json, [
            'sender_first_name', 'sender_last_name', 'sender_email',
            'sender_address', 'city', 'state', 'zipcode', 'cardholder_name',
            'card_number', 'exp_date', 'cvc', 'dollars'
    ]):
        raise InvalidUsage('Missing paramenters')
        return 400
    # get matchmaker obj
    recipient = Matchmaker().get_recipientProfile()
    if recipient is None:
        return "Sorry there are no users to donate to at this time. Try again in a bit", 503
    purchase_status = False
    #fill out form
    full_name = request.json['sender_first_name'] + request.json[
        'sender_last_name']
    payment = DoorDash()
    if payment.preFill(dollars=request.json['dollars'],
                       recipient_name=recipient.get_first_name(),
                       recipient_email=recipient.get_email(),
                       sender_name=full_name) == True:
        sleep(randint(1, 2))
        # pay and deliver
        purchase_status = payment.purchase(
            sender_email=request.json['sender_email'],
            sender_address=request.json['sender_address'],
            city=request.json['city'],
            state=request.json['state'],
            zipcode=request.json['zipcode'],
            cardholder_name=request.json['cardholder_name'],
            card_number=request.json['card_number'],
            exp_date=request.json['exp_date'],
            cvc=request.json['cvc'])
        if purchase_status['status'] == True:
            # render template for donor:
            d2 = date.today().strftime("%B %d, %Y")
            template = env.get_template('billing.html')
            html = template.render(amount_donated=request.json["dollars"],
                                   invoice_number=1,
                                   Transaction_date=d2)
            # send confirm email to donor
            donor_confirm_email = send_donor_order_confirmation(
                donor_email=request.json["sender_email"], bodyContent=html)
            # render template for recipient:
            template = env.get_template('recipient_confirmation.html')
            html = template.render(recipient_name=recipient.get_first_name(),
                                   amount_donated=request.json["dollars"])
            recipient_confirm_email = send_recipient_order_confirmation(
                recipient_email=recipient.get_email(), bodyContent=html)
            # update User DB
            user_update_status = update_user_entry(recipient,
                                                   request.json["dollars"])
            # insert to Transactions DB
            timestamp_string = time.strftime(
                "%a, %d %b %Y %H:%M:%S +0000",
                datetime.fromtimestamp(int(time.time())).timetuple())
            donation_update_status = insert_donation(
                recipient, request.json["dollars"],
                request.json["sender_email"],
                request.json["sender_first_name"],
                request.json["sender_last_name"], timestamp_string,
                donor_confirm_email, recipient_confirm_email)

            return "Transaction Complete:" + str(
                purchase_status) + " | User Table Updated:" + str(
                    user_update_status
                ) + " | Transactions Table Inserted:" + str(
                    donation_update_status), 200
        else:
            return "Transaction Complete:" + str(
                purchase_status
            ) + " | User Table Updated:" + "False" + " | Transactions Table Inserted:" + "False", 400
    else:
        return "There was an error", 500
Exemplo n.º 2
0
def get_next_recipient():
    recipient = Matchmaker().get_recipientProfile()
    profile_dict = get_recipient_profile(recipient.get_email())

    return jsonify(profile_dict), 200