def process_promotion(request, page):
    """
    The meat of the form processor, pulled out for ease of customization.
    """
    # Initialize transaction and credentials. This must run before mezzanine's
    # form processor in order for the credentials to be included in the email.
    transaction = transact(request)

    # Call mezzanine's form_processor.
    form_processor(request, page)

    # HACK: Depends on the form entry created in form_processor having
    # the latest entry_time.
    formentry = (
        FormEntry.objects
        .filter(form=page.form)
        .order_by('entry_time')
        .last())

    # Associate downloads with transaction.
    for download in page.form.downloads.all():
        promotion = Promotion(
            download=download,
            transaction=transaction,
            formentry=formentry)
        promotion.save()

    return redirect('downloads_index')
Esempio n. 2
0
 def get_context_data(self, **kwargs):
     context = super(ContributionList, self).get_context_data(**kwargs)
     contribute_form_page = get_page("Contribute Form")
     contribute_form = form_processor(self.request, contribute_form_page)
     context["contribute_form"] = contribute_form["form"]
     context["contribute_form_page"] = contribute_form_page
     return context
def process_promotion(request, page):
    """
    The meat of the form processor, pulled out for ease of customization.
    """
    # Initialize transaction and credentials. This must run before mezzanine's
    # form processor in order for the credentials to be included in the email.
    transaction = transact(request)

    # Call mezzanine's form_processor.
    form_processor(request, page)

    # HACK: Depends on the form entry created in form_processor having
    # the latest entry_time.
    formentry = (FormEntry.objects.filter(
        form=page.form).order_by('entry_time').last())

    # Associate downloads with transaction.
    for download in page.form.downloads.all():
        promotion = Promotion(download=download,
                              transaction=transaction,
                              formentry=formentry)
        promotion.save()

    return redirect('downloads_index')
Esempio n. 4
0
def payment_form_processor(request, page):
    payment_form = page.paymentformpage.payment_form
    payment_form.form.send_email = False

    upal_transactions = get_upal_transactions_info(page.paymentformpage)
    zpal_transactions = get_zpal_transactions_info(page.paymentformpage)

    successful_payments = 0
    if page.paymentformpage.payment_gateway.type == "upal":
        successful_payments += upal_transactions.filter(is_payed=True).count()
    if page.paymentformpage.payment_gateway.type == "zpal":
        successful_payments += zpal_transactions.filter(is_payed=True).count()

    if payment_form.form.fields.filter(label="UUID").count() != 1:
        return {"status": "design_error"}

    uuid_key = "field_{}".format(payment_form.form.fields.get(label="UUID").id)
    if request.POST:
        mutable = request.POST._mutable
        request.POST._mutable = True
        request_uuid = uuid.uuid4()
        request.POST[uuid_key] = request_uuid
        request.POST._mutable = mutable

    form = form_processor(request, payment_form)

    if isinstance(form, dict) and form.has_key("form"):
        if request.user.has_perm('transactions.can_view_payment_transactions'):
            if page.paymentformpage.payment_gateway.type == "upal":
                form_fields = page.paymentformpage.payment_form.form.fields.all().order_by("id")
                form_fields = [field.label for field in form_fields]
                for title in [_("Creation Time"), _("Form Entry UUID"), _("Bank Token"), _("Random Token"),
                              _("Price Group"), _("Amount in Rials"), _("Is Payed"), _("Payment Time")]:
                    form_fields.append(title)
                upal_transactions.filter(creation_time__lt=timezone.now() - datetime.timedelta(minutes=20),
                                         is_payed=None).update(is_payed=False)
                successful_transactions = upal_transactions.filter(is_payed=True)
                pending_transactions = upal_transactions.filter(is_payed=None)
                failed_transactions = upal_transactions.filter(is_payed=False)
                transactions = chain(successful_transactions, pending_transactions, failed_transactions)
                transactions_info = []
                for transaction in transactions:
                    entries = get_transaction_entries(transaction)
                    if entries is not None:
                        entries = [entry.value for entry in entries]
                        for value in [transaction.creation_time, transaction.uuid , transaction.bank_token,
                                      transaction.random_token,
                                      transaction.price_group.group_identifier + " (" +str(transaction.price_group.payment_amount) + ")",
                                      transaction.payment_amount,
                                      transaction.is_payed, transaction.payment_time]:
                            entries.append(value)
                        transactions_info.append(entries)

            if page.paymentformpage.payment_gateway.type == "zpal":
                form_fields = page.paymentformpage.payment_form.form.fields.all().order_by("id")
                form_fields = [field.label for field in form_fields]
                for title in [_("Creation Time"), _("Form Entry UUID"), _("Authority"), _("Price Group"),
                    _("Amount in Rials"), _("Is Payed"), _("Reference ID"), _("Payment Time")]:
                    form_fields.append(title)
                zpal_transactions.filter(creation_time__lt=timezone.now() - datetime.timedelta(minutes=20),
                                         is_payed=None).update(is_payed=False)
                successful_transactions = zpal_transactions.filter(is_payed=True)
                pending_transactions = zpal_transactions.filter(is_payed=None)
                failed_transactions = zpal_transactions.filter(is_payed=False)
                transactions = chain(successful_transactions, pending_transactions, failed_transactions)
                transactions_info = []
                for transaction in transactions:
                    entries = get_transaction_entries(transaction)
                    if entries is not None:
                        entries = [entry.value for entry in entries]
                        for value in [transaction.creation_time, transaction.uuid , transaction.authority,
                                      transaction.price_group.group_identifier + " (" +str(transaction.price_group.payment_amount) + ")",
                                      transaction.payment_amount,
                                      transaction.is_payed, transaction.ref_id, transaction.payment_time]:
                            entries.append(value)
                        transactions_info.append(entries)

            return {"status": "form", "form": form["form"],
                    "form_fields": form_fields, "transactions_info": transactions_info}

        if page.paymentformpage.capacity != 0:
            if successful_payments >= page.paymentformpage.capacity:
                return {"status": "at_full_capacity"}

        return {"status": "form", "form": form["form"]}

    plan = PriceGroup.objects.get(id=request.POST.get("payment_plan_id"))
    if plan.capacity != 0:
        plan_successful_payments = 0
        if page.paymentformpage.payment_gateway.type == "upal":
            plan_successful_payments += upal_transactions.filter(is_payed=True, price_group=plan).count()
        if page.paymentformpage.payment_gateway.type == "zpal":
            plan_successful_payments += zpal_transactions.filter(is_payed=True, price_group=plan).count()

        if plan_successful_payments >= plan.capacity:
            return {"status": "at_full_capacity"}

    if page.paymentformpage.payment_gateway.type == "upal":
        transaction = new_upal_payment(request, page.paymentformpage, plan, request_uuid)
    if page.paymentformpage.payment_gateway.type == "zpal":
        transaction = new_zpal_payment(request, page.paymentformpage, plan, request_uuid)

    if transaction is None:
        return {"status": "gateway_error"}

    if page.paymentformpage.payment_gateway.type == "upal":
        #payment_url = 'https://upal.ir/transaction/submit?id={}'.format(transaction.bank_token)
        payment_url = 'http://salam.im/transaction/submit?id={}'.format(transaction.bank_token)
    if page.paymentformpage.payment_gateway.type == "zpal":
        payment_url = 'https://www.zarinpal.com/pg/StartPay/{}'.format(transaction.authority)

    if page.paymentformpage.capacity != 0:
        if page.paymentformpage.payment_gateway.type == "upal":
            pending_payments = successful_payments + upal_transactions.filter(
                is_payed=None, creation_time__gt=timezone.now() - datetime.timedelta(minutes=10)).count()
        if page.paymentformpage.payment_gateway.type == "zpal":
            pending_payments = successful_payments + zpal_transactions.filter(
                is_payed=None, creation_time__gt=timezone.now() - datetime.timedelta(minutes=10)).count()
        if pending_payments > page.paymentformpage.capacity:
            return {"status": "payment", "payment_url": payment_url, "warning": "reserved_list"}

    if plan.capacity != 0:
        if page.paymentformpage.payment_gateway.type == "upal":
            plan_pending_payments = plan_successful_payments + upal_transactions.filter(
                    is_payed=None, creation_time__gt=timezone.now() - datetime.timedelta(minutes=10),
                    price_group=plan).count()
        if page.paymentformpage.payment_gateway.type == "zpal":
            plan_pending_payments = plan_successful_payments + zpal_transactions.filter(
                    is_payed=None, creation_time__gt=timezone.now() - datetime.timedelta(minutes=10),
                    price_group=plan).count()
        if plan_pending_payments > plan.capacity:
            return {"status": "payment", "payment_url": payment_url, "warning": "reserved_list"}

    return {"status": "payment", "payment_url": payment_url}
Esempio n. 5
0
def contactlandingpage_form(request, page):
    """
    Use mezzanine builtin form_processor & processor for handling forms.
    """

    return form_processor(request, page.contactlandingpage.contact_form)