예제 #1
0
def send_abandoned_cart(name, email, phone, payment_item_slug):
    """
    Send a potential client who filled their data but not complete the buy to hotzapp
    :param name: name filled at the form
    :param phone: phone filled at the form
    :param email: email filled at the form
    :param payment_item_slug: slug of the item of purchase
    """
    payment_config_item = django_pagarme_facade.get_payment_item(
        payment_item_slug)
    price = total_price([payment_config_item])
    potential_customer = {
        'created_at':
        datetime.now().isoformat(),
        'name':
        name,
        'phone':
        phone,
        'email':
        email,
        'currency_code_from':
        'R$',
        'total_price':
        price,
        'line_items': [{
            'product_name': payment_config_item.name,
            'quantity': 1,
            'price': price
        }],
    }
    return requests.post(settings.HOTZAPP_API_URL,
                         json=potential_customer).status_code
예제 #2
0
def capture(request, slug, token):
    try:
        payment = facade.capture(token, request.user.id)
    except facade.PaymentViolation as e:
        logger.exception(str(e))
        return HttpResponseBadRequest()
    except facade.TokenDifferentFromTransactionIdxception as e:
        return redirect(reverse('django_pagarme:capture',
                                kwargs={
                                    'slug': slug,
                                    'token': e.transaction_id
                                }),
                        permanent=True)
    else:
        if payment.payment_method == facade.BOLETO:
            ctx = {
                'payment': payment,
                'upsell': facade.get_payment_item(slug).upsell
            }
            suffix = slug.replace('-', '_')
            templates = [
                f'django_pagarme/show_boleto_data_{suffix}.html',
                'django_pagarme/show_boleto_data.html'
            ]

            return render(request, templates, ctx)
        else:
            return redirect(
                reverse('django_pagarme:thanks', kwargs={'slug': slug}))
예제 #3
0
def pagarme(request, slug):
    payment_item = facade.get_payment_item(slug)
    if not facade.is_payment_config_item_available(payment_item, request):
        return redirect(
            reverse('django_pagarme:unavailable', kwargs={'slug': slug}))
    open_modal = request.GET.get('open_modal', '').lower() == 'true'
    review_informations = not (request.GET.get('review_informations',
                                               '').lower() == 'false')
    customer_qs_data = {
        k: request.GET.get(k, '')
        for k in ['name', 'email', 'phone']
    }
    customer_qs_data = {k: v for k, v in customer_qs_data.items() if v}
    user = request.user
    address = None
    if user.is_authenticated:
        user_data = {
            'external_id': user.id,
            'name': user.first_name,
            'email': user.email
        }
        try:
            payment_profile = facade.get_user_payment_profile(user)
        except facade.UserPaymentProfileDoesNotExist:
            customer = ChainMap(customer_qs_data, user_data)
        else:
            customer = ChainMap(customer_qs_data,
                                payment_profile.to_customer_dict(), user_data)
            address = payment_profile.to_billing_address_dict()
    else:
        customer = customer_qs_data
    ctx = {
        'payment_item': payment_item,
        'open_modal': open_modal,
        'review_informations': review_informations,
        'customer': customer,
        'slug': slug,
        'address': address
    }
    suffix = slug.replace('-', '_')
    templates = [
        f'django_pagarme/pagarme_{suffix}.html', 'django_pagarme/pagarme.html'
    ]

    return render(request, templates, ctx)
예제 #4
0
def contact_info(request, slug):
    payment_item = facade.get_payment_item(slug)
    if not facade.is_payment_config_item_available(payment_item, request):
        return redirect(
            reverse('django_pagarme:unavailable', kwargs={'slug': slug}))
    if request.method == 'GET':
        user = request.user
        if user.is_authenticated:
            try:
                payment_profile = facade.get_user_payment_profile(user.id)
            except facade.UserPaymentProfileDoesNotExist:
                form = facade.ContactForm({
                    'name': user.first_name,
                    'email': user.email
                })
            else:
                form = facade.ContactForm({
                    'name': payment_profile.name,
                    'email': payment_profile.email,
                    'phone': payment_profile.phone
                })
        else:
            form = facade.ContactForm()
        ctx = {'contact_form': form, 'slug': slug}
        return render(request, 'django_pagarme/contact_form.html', ctx)

    dct = {key: request.POST[key] for key in 'name phone email'.split()}
    dct['payment_item_slug'] = slug
    try:
        dct = facade.validate_and_inform_contact_info(user=request.user, **dct)
    except facade.InvalidContactData as e:
        ctx = {'contact_form': e.contact_form, 'slug': slug}
        resp = render(request,
                      'django_pagarme/contact_form_errors.html',
                      ctx,
                      status=400)
        return resp
    else:
        path = reverse('django_pagarme:pagarme', kwargs={'slug': slug})
        dct['open_modal'] = 'true'
        query_string = urlencode(dct)
        return redirect(f'{path}?{query_string}')
예제 #5
0
def pagarme(request, slug):
    open_modal = request.GET.get('open_modal', '').lower() == 'true'
    customer_qs_data = {
        k: request.GET.get(k, '')
        for k in ['name', 'email', 'phone']
    }
    customer_qs_data = {k: v for k, v in customer_qs_data.items() if v}
    user = request.user
    if user.is_authenticated:
        user_data = {
            'external_id': user.id,
            'name': user.first_name,
            'email': user.email
        }
        customer = ChainMap(customer_qs_data, user_data)
    else:
        customer = customer_qs_data
    ctx = {
        'payment_item': facade.get_payment_item(slug),
        'open_modal': open_modal,
        'customer': customer,
        'slug': slug
    }
    return render(request, 'django_pagarme/pagarme.html', ctx)
예제 #6
0
def pagarme(request, slug):
    open_modal = request.GET.get('open_modal', '').lower() == 'true'
    review_informations = not (request.GET.get('review_informations',
                                               '').lower() == 'false')
    customer_qs_data = {
        k: request.GET.get(k, '')
        for k in ['name', 'email', 'phone']
    }
    customer_qs_data = {k: v for k, v in customer_qs_data.items() if v}
    user = request.user
    address = None
    if user.is_authenticated:
        user_data = {
            'external_id': user.id,
            'name': user.first_name,
            'email': user.email
        }
        try:
            payment_profile = facade.get_user_payment_profile(user)
        except facade.UserPaymentProfileDoesNotExist:
            customer = ChainMap(customer_qs_data, user_data)
        else:
            customer = ChainMap(customer_qs_data,
                                payment_profile.to_customer_dict(), user_data)
            address = payment_profile.to_billing_address_dict()
    else:
        customer = customer_qs_data
    ctx = {
        'payment_item': facade.get_payment_item(slug),
        'open_modal': open_modal,
        'review_informations': review_informations,
        'customer': customer,
        'slug': slug,
        'address': address
    }
    return render(request, 'django_pagarme/pagarme.html', ctx)
예제 #7
0
def unavailable_config():
    cfg = facade.get_payment_item('pytools')
    cfg.available_until = timezone.now() - timedelta(seconds=1)
    cfg.save()
    return cfg
예제 #8
0
def unavailable(request, slug):
    payment_item = facade.get_payment_item(slug)
    return render(request, 'django_pagarme/unavailable_payment_item.html',
                  {'payment_item_config': payment_item})