Esempio n. 1
0
def payments_confirm(request, addon_id, addon):
    data = {}
    # TODO(solitude): remove all references to AddonPaymentData.
    if waffle.flag_is_active(request, 'solitude-payments'):
        data = client.get_seller_paypal_if_exists(addon) or {}

    adp, created = AddonPaymentData.objects.safer_get_or_create(addon=addon)
    if not data:
        data = model_to_dict(adp)

    form = PaypalPaymentData(request.POST or data)
    if request.method == 'POST' and form.is_valid():
        if waffle.flag_is_active(request, 'solitude-payments'):
            # TODO(solitude): when the migration of data is completed, we
            # will be able to remove this.
            pk = client.create_seller_for_pay(addon)
            client.patch_seller_paypal(pk=pk, data=form.cleaned_data)

        # TODO(solitude): remove this.
        adp.update(**form.cleaned_data)
        AppSubmissionChecklist.objects.get(addon=addon).update(payments=True)
        addon.mark_done()
        return redirect('submit.app.done', addon.app_slug)

    return jingo.render(request, 'submit/payments-confirm.html', {
                        'step': 'payments',
                        'addon': addon,
                        'form': form
                        })
Esempio n. 2
0
def payments_paypal(request, addon_id, addon):
    form = PaypalSetupForm(request.POST or None)
    if request.POST and form.is_valid():
        existing = form.cleaned_data['business_account']
        if existing == 'later':
            # We'll have a premium or similar account with no PayPal id
            # at this point.
            (AppSubmissionChecklist.objects.get(addon=addon)
                                           .update(payments=True))
            return redirect('submit.app.done', addon.app_slug)
        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)

        if waffle.flag_is_active(request, 'solitude-payments'):
            obj = client.create_seller_paypal(addon)
            client.patch_seller_paypal(pk=obj['resource_pk'],
                         data={'paypal_id': form.cleaned_data['email']})

        addon.update(paypal_id=form.cleaned_data['email'])
        return redirect('submit.app.payments.bounce', addon.app_slug)
    return jingo.render(request, 'submit/payments-paypal.html', {
                        'step': 'payments',
                        'addon': addon,
                        'form': form
                        })
Esempio n. 3
0
def paypal_setup_confirm(request, addon_id, addon, webapp, source='paypal'):
    # If you bounce through paypal as you do permissions changes set the
    # source to paypal.
    if source == 'paypal':
        msg = _('PayPal set up complete.')
        title = _('Confirm Details')
        button = _('Continue')
    # If you just hit this page from the Manage Paypal, show some less
    # wizardy stuff.
    else:
        msg = _('Changes saved.')
        title = _('Contact Details')
        button = _('Save')

    data = {}
    if waffle.flag_is_active(request, 'solitude-payments'):
        data = client.get_seller_paypal_if_exists(addon) or {}

    # TODO(solitude): remove this bit.
    # If it's not in solitude, use the local version
    adp, created = (AddonPaymentData.objects
                                    .safer_get_or_create(addon=addon))
    if not data:
        data = model_to_dict(adp)

    form = forms.PaypalPaymentData(request.POST or data)
    if request.method == 'POST' and form.is_valid():
        if waffle.flag_is_active(request, 'solitude-payments'):
            # TODO(solitude): when the migration of data is completed, we
            # will be able to remove this.
            pk = client.create_seller_for_pay(addon)
            client.patch_seller_paypal(pk=pk, data=form.cleaned_data)

        # TODO(solitude): remove this.
        adp.update(**form.cleaned_data)
        messages.success(request, msg)
        if source == 'paypal' and addon.is_incomplete() and addon.paypal_id:
            addon.mark_done()
        return redirect(addon.get_dev_url('paypal_setup'))

    return jingo.render(request,
                        'developers/payments/paypal-details-confirm.html',
                        {'addon': addon, 'button': button, 'form': form,
                         'title': title})
Esempio n. 4
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.
            # TODO(solitude): we will remove this.
            addon.update(paypal_id=paypal_form.cleaned_data['email'])

            if waffle.flag_is_active(request, 'solitude-payments'):
                obj = client.create_seller_paypal(addon)
                client.patch_seller_paypal(pk=obj['resource_pk'],
                        data={'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. 5
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.
            # TODO(solitude): we will remove this.
            addon.update(paypal_id=paypal_form.cleaned_data["email"])

            if waffle.flag_is_active(request, "solitude-payments"):
                obj = client.create_seller_paypal(addon)
                client.patch_seller_paypal(pk=obj["resource_pk"], data={"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)