Esempio n. 1
0
def paypal_setup(request, addon_id, addon, webapp):
    if addon.premium_type == amo.ADDON_FREE:
        messages.error(request, 'Your app does not use payments.')
        return redirect(addon.get_dev_url('payments'))

    paypal_form = PaypalSetupForm(request.POST or None)
    currency_form = CurrencyForm(request.POST or None,
                        initial={'currencies': addon.premium.currencies
                                               if addon.premium else {}})

    context = {'addon': addon, 'paypal_form': paypal_form,
               'currency_form': currency_form}

    if request.POST.get('form') == 'paypal' and paypal_form.is_valid():
        existing = paypal_form.cleaned_data['business_account']
        if existing != 'yes':
            # Go create an account.
            # TODO: this will either become the API or something some better
            # URL for the future.
            return redirect(settings.PAYPAL_CGI_URL)
        else:
            # Go setup your details on paypal.
            addon.update(paypal_id=paypal_form.cleaned_data['email'])
            if addon.premium and addon.premium.paypal_permissions_token:
                addon.premium.update(paypal_permissions_token='')
            return redirect(addon.get_dev_url('paypal_setup_bounce'))

    if request.POST.get('form') == 'currency' and currency_form.is_valid():
        currencies = currency_form.cleaned_data['currencies']
        addon.premium.update(currencies=currencies)
        messages.success(request, _('Currencies updated.'))
        return redirect(addon.get_dev_url('paypal_setup'))

    return jingo.render(request, 'developers/payments/paypal-setup.html',
                        context)
Esempio n. 2
0
def paypal_setup(request, addon_id, addon, webapp):
    if addon.premium_type == amo.ADDON_FREE:
        messages.error(request, "Your app does not use payments.")
        return redirect(addon.get_dev_url("payments"))

    paypal_form = PaypalSetupForm(request.POST or None)
    currency_form = CurrencyForm(
        request.POST or None, initial={"currencies": addon.premium.currencies if addon.premium else {}}
    )

    context = {"addon": addon, "paypal_form": paypal_form, "currency_form": currency_form}

    if request.POST.get("form") == "paypal" and paypal_form.is_valid():
        existing = paypal_form.cleaned_data["business_account"]
        if existing != "yes":
            # Go create an account.
            # TODO: this will either become the API or something some better
            # URL for the future.
            return redirect(settings.PAYPAL_CGI_URL)
        else:
            # Go setup your details on paypal.
            addon.update(paypal_id=paypal_form.cleaned_data["email"])
            if addon.premium and addon.premium.paypal_permissions_token:
                addon.premium.update(paypal_permissions_token="")
            return redirect(addon.get_dev_url("paypal_setup_bounce"))

    if waffle.switch_is_active("currencies") and request.POST.get("form") == "currency" and currency_form.is_valid():
        currencies = currency_form.cleaned_data["currencies"]
        addon.premium.update(currencies=currencies)
        messages.success(request, _("Currencies updated."))
        return redirect(addon.get_dev_url("paypal_setup"))

    return jingo.render(request, "developers/payments/paypal-setup.html", context)
Esempio n. 3
0
def paypal_setup(request, addon_id, addon, webapp):
    if addon.premium_type == amo.ADDON_FREE:
        messages.error(request, 'Your app does not use payments.')
        return redirect(addon.get_dev_url('payments'))

    paypal_form = PaypalSetupForm(request.POST or None)
    currency_form = CurrencyForm(
        request.POST or None,
        initial={
            'currencies': addon.premium.currencies if addon.premium else {}
        })

    context = {
        'addon': addon,
        'paypal_form': paypal_form,
        'currency_form': currency_form
    }

    if request.POST.get('form') == 'paypal' and paypal_form.is_valid():
        existing = paypal_form.cleaned_data['business_account']
        if existing != 'yes':
            # Go create an account.
            # TODO: this will either become the API or something some better
            # URL for the future.
            return redirect(settings.PAYPAL_CGI_URL)
        else:
            # Go setup your details on paypal.
            addon.update(paypal_id=paypal_form.cleaned_data['email'])
            if addon.premium and addon.premium.paypal_permissions_token:
                addon.premium.update(paypal_permissions_token='')
            return redirect(addon.get_dev_url('paypal_setup_bounce'))

    if (waffle.switch_is_active('currencies')
            and request.POST.get('form') == 'currency'
            and currency_form.is_valid()):
        currencies = currency_form.cleaned_data['currencies']
        addon.premium.update(currencies=currencies)
        messages.success(request, _('Currencies updated.'))
        return redirect(addon.get_dev_url('paypal_setup'))

    return jingo.render(request, 'developers/payments/paypal-setup.html',
                        context)