Пример #1
0
def artwork_buy(id):
    artwork = crud.get_artwork(crud.new_transaction(), id, 240)
    artwork_url = url_for('artwork',
                          slug=slugify_title(artwork["title"]),
                          id=id,
                          _external=True)
    if artwork is None:
        abort(404)
    enquiry_email_template = crud.get_artwork_buy_email_template()

    enquirer_email_address = request.form.get('email')
    enquirer_name = request.form.get('name')
    enquirer_address = f"{request.form.get('city')}, {request.form.get('country')}"
    enquirer_address_type = request.form.get('address_type')
    enquirer_message = request.form.get('message')

    email_subject = f"Psyclonic Studios artwork enquiry: {artwork['title']}"
    email_body = Environment(
        loader=BaseLoader()).from_string(enquiry_email_template).render(
            name=enquirer_name,
            address=enquirer_address,
            address_type=enquirer_address_type,
            artwork=artwork,
            message=enquirer_message,
            artwork_url=artwork_url)
    email = gmail.compose_email_from_me(enquirer_email_address,
                                        email_subject,
                                        email_body,
                                        alias='Customer')
    email_response = gmail.send_email(email)

    trello_title = f'Buyer - {enquirer_name}'
    trello_description = render_template(
        'trello_shipping_enquiry_description.md',
        gmail_link=gmail.get_email_link(email_response['id']),
        enquirer_name=enquirer_name,
        enquirer_email_address=enquirer_email_address,
        enquirer_address=enquirer_address,
        artwork=artwork,
        artwork_url=artwork_url,
        enquirer_message=enquirer_message)
    trello_due = datetime.today() + timedelta(3)
    trello_helper.create_customer_card(
        trello_helper.AWAITING_RESPONSE_LIST_ID,
        trello_title,
        desc=trello_description,
        due=str(trello_due),
        labels=[trello_helper.ARTWORK_ENQUIRY_LABEL],
        position='top')
    return render_template('enquiry_success.html',
                           thankyou_text=crud.get_enquire_thankyou(),
                           enquiry_type='artwork_shipping')
Пример #2
0
def contact_send_email():
    token = request.form.get('recaptchaToken')
    recaptcha_response = requests.post(
        'https://www.google.com/recaptcha/api/siteverify',
        data={
            'secret': RECAPTCHA_SECRET,
            'response': token
        })
    recaptcha = recaptcha_response.json()
    if not recaptcha or 'action' not in recaptcha or not recaptcha[
            'action'] == 'contact_submit' or recaptcha['score'] < 0.5:
        contact_message = crud.get_contact_message()
        return render_template('contact.html',
                               contact_message=contact_message,
                               give_details=False,
                               suspected_bot=True)
    enquiry_email_template = crud.get_contact_email_template()

    enquirer_email_address = request.form.get('email')
    enquirer_name = request.form.get('name')
    enquirer_message = request.form.get('message')

    email_subject = f"Contact Psyclonic Studios"
    email_body = Environment(
        loader=BaseLoader()).from_string(enquiry_email_template).render(
            name=enquirer_name, message=enquirer_message)
    email = gmail.compose_email_from_me(enquirer_email_address,
                                        email_subject,
                                        email_body,
                                        alias='Customer')
    email_response = gmail.send_email(email)

    trello_title = f'Contact - {enquirer_name}'
    trello_description = render_template(
        'trello_contact_description.md',
        gmail_link=gmail.get_email_link(email_response['id']),
        enquirer_name=enquirer_name,
        enquirer_email_address=enquirer_email_address,
        enquirer_message=enquirer_message)
    trello_due = datetime.today() + timedelta(3)
    trello_helper.create_customer_card(
        trello_helper.AWAITING_RESPONSE_LIST_ID,
        trello_title,
        desc=trello_description,
        due=str(trello_due),
        labels=[trello_helper.ARTWORK_ENQUIRY_LABEL],
        position='top')
    return render_template('enquiry_success.html',
                           thankyou_text=crud.get_enquire_thankyou(),
                           enquiry_type='contact')
Пример #3
0
def confirm_payment():
    stripe_event = request.json
    event = None
    try:
        event = stripe.Event.construct_from(request.json, stripe.api_key)
    except ValueError as e:
        abort(400)

    if event.type == 'payment_intent.succeeded':
        payment_intent = event.data.object
        if 'channel' not in payment_intent.metadata or payment_intent.metadata.channel != 'website':
            return '', 204
        crud.finalise_order(payment_intent)
        final_order = crud.get_order(payment_intent.id)

        order_confirmation_email_subject = "Your order from Psyclonic Studios"
        order_confirmation_email_body = render_template(
            'order_confirmation_email.html', order=final_order)
        order_confirmation_email = gmail.compose_email_from_me(
            final_order['customer']['email'],
            order_confirmation_email_subject,
            order_confirmation_email_body,
            alias='Orders')
        order_confirmation_email_response = gmail.send_email(
            order_confirmation_email)

        trello_title = f"Order - {final_order['customer']['name']}"
        gmail_link = gmail.get_email_link(
            order_confirmation_email_response['id'])
        trello_description = render_template('trello_order_description.md',
                                             order=final_order,
                                             gmail_link=gmail_link)
        trello_due = datetime.today() + timedelta(3)
        trello_helper.create_customer_card(
            trello_helper.PAYMENT_RECIEVED_LIST_ID,
            trello_title,
            desc=trello_description,
            due=str(trello_due),
            labels=[trello_helper.ONLINE_ORDER_LABEL],
            position='top')
    else:
        abort(400)
    return '', 204