Esempio n. 1
0
def acquire_refund_permission(request, addon_id, addon, webapp=False):
    """This is the callback from Paypal."""
    # Set up our redirects.
    if request.GET.get('dest', '') == 'submission':
        on_good = reverse('submit.app.payments.confirm', args=[addon.app_slug])
        on_error = reverse('submit.app.payments.paypal', args=[addon.app_slug])
        show_good_msgs = False
    else:
        # The management pages are the default.
        on_good = addon.get_dev_url('paypal_setup_confirm')
        on_error = addon.get_dev_url('paypal_setup_bounce')
        show_good_msgs = True

    if 'request_token' not in request.GET:
        paypal_log.debug('User did not approve permissions for'
                         ' addon: %s' % addon_id)
        messages.error(
            request, 'You will need to accept the permissions '
            'to continue.')
        return redirect(on_error)

    paypal_log.debug('User approved permissions for addon: %s' % addon_id)
    token = paypal.get_permissions_token(request.GET['request_token'],
                                         request.GET['verification_code'])

    paypal_log.debug('Getting personal data for token: %s' % addon_id)
    data = paypal.get_personal_data(token)
    email = data.get('email')

    # If the email from paypal is different, something has gone wrong.
    if email != addon.paypal_id:
        paypal_log.debug('Addon paypal_id and personal data differ: '
                         '%s vs %s' % (email, addon.paypal_id))
        messages.warning(
            request,
            _('The email returned by Paypal, '
              'did not match the PayPal email you '
              'entered. Please login using %s.') % email)
        return redirect(on_error)

    # Set the permissions token that we have just successfully used
    # in get_personal_data.
    addonpremium, created = (AddonPremium.objects.safer_get_or_create(
        addon=addon))
    addonpremium.update(paypal_permissions_token=token)

    # Finally update the data returned from PayPal for this addon.
    paypal_log.debug('Updating personal data for: %s' % addon_id)
    apd, created = AddonPaymentData.objects.safer_get_or_create(addon=addon)
    apd.update(**data)
    amo.log(amo.LOG.EDIT_PROPERTIES, addon)

    if show_good_msgs:
        messages.success(request, 'Please confirm the data we '
                         'received from PayPal.')
    return redirect(on_good)
Esempio n. 2
0
def acquire_refund_permission(request, addon_id, addon, webapp=False):
    """This is the callback from Paypal."""
    # Set up our redirects.
    if request.GET.get('dest', '') == 'submission':
        on_good = reverse('submit.app.payments.confirm', args=[addon.app_slug])
        on_error = reverse('submit.app.payments.paypal', args=[addon.app_slug])
        show_good_msgs = False
    else:
        # The management pages are the default.
        on_good = addon.get_dev_url('paypal_setup_confirm')
        on_error = addon.get_dev_url('paypal_setup_bounce')
        show_good_msgs = True

    if 'request_token' not in request.GET:
        paypal_log.debug('User did not approve permissions for'
                         ' addon: %s' % addon_id)
        messages.error(request, 'You will need to accept the permissions '
                                'to continue.')
        return redirect(on_error)

    paypal_log.debug('User approved permissions for addon: %s' % addon_id)
    token = paypal.get_permissions_token(request.GET['request_token'],
                                         request.GET['verification_code'])

    paypal_log.debug('Getting personal data for token: %s' % addon_id)
    data = paypal.get_personal_data(token)
    email = data.get('email')

    # If the email from paypal is different, something has gone wrong.
    if email != addon.paypal_id:
        paypal_log.debug('Addon paypal_id and personal data differ: '
                         '%s vs %s' % (email, addon.paypal_id))
        messages.warning(request, _('The email returned by Paypal, '
                                    'did not match the PayPal email you '
                                    'entered. Please login using %s.')
                         % email)
        return redirect(on_error)

    # Set the permissions token that we have just successfully used
    # in get_personal_data.
    addonpremium, created = (AddonPremium.objects
                                         .safer_get_or_create(addon=addon))
    addonpremium.update(paypal_permissions_token=token)

    # Finally update the data returned from PayPal for this addon.
    paypal_log.debug('Updating personal data for: %s' % addon_id)
    apd, created = AddonPaymentData.objects.safer_get_or_create(addon=addon)
    apd.update(**data)
    amo.log(amo.LOG.EDIT_PROPERTIES, addon)

    if show_good_msgs:
        messages.success(request, 'Please confirm the data we '
                                  'received from PayPal.')
    return redirect(on_good)
Esempio n. 3
0
def acquire_refund_permission(request, addon_id, addon, webapp=False):
    """This is the callback from Paypal."""
    # Set up our redirects.
    if request.GET.get("dest", "") == "submission":
        on_good = reverse("submit.app.payments.confirm", args=[addon.app_slug])
        on_error = reverse("submit.app.payments.paypal", args=[addon.app_slug])
        show_good_msgs = False
    else:
        # The management pages are the default.
        on_good = addon.get_dev_url("paypal_setup_confirm")
        on_error = addon.get_dev_url("paypal_setup_bounce")
        show_good_msgs = True

    if "request_token" not in request.GET:
        paypal_log.debug("User did not approve permissions for" " addon: %s" % addon_id)
        messages.error(request, "You will need to accept the permissions " "to continue.")
        return redirect(on_error)

    paypal_log.debug("User approved permissions for addon: %s" % addon_id)
    token = paypal.get_permissions_token(request.GET["request_token"], request.GET["verification_code"])

    paypal_log.debug("Getting personal data for token: %s" % addon_id)
    data = paypal.get_personal_data(token)
    email = data.get("email")

    # If the email from paypal is different, something has gone wrong.
    if email != addon.paypal_id:
        paypal_log.debug("Addon paypal_id and personal data differ: " "%s vs %s" % (email, addon.paypal_id))
        messages.warning(
            request,
            _("The email returned by Paypal, " "did not match the PayPal email you " "entered. Please login using %s.")
            % email,
        )
        return redirect(on_error)

    # Set the permissions token that we have just successfully used
    # in get_personal_data.
    addonpremium, created = AddonPremium.objects.safer_get_or_create(addon=addon)
    addonpremium.update(paypal_permissions_token=token)

    # Finally update the data returned from PayPal for this addon.
    paypal_log.debug("Updating personal data for: %s" % addon_id)
    apd, created = AddonPaymentData.objects.safer_get_or_create(addon=addon)
    apd.update(**data)
    amo.log(amo.LOG.EDIT_PROPERTIES, addon)

    if show_good_msgs:
        messages.success(request, "Please confirm the data we " "received from PayPal.")
    return redirect(on_good)
Esempio n. 4
0
 def test_preapproval_unicode(self, _call):
     key = "response.personalData(2).personalDataValue"
     value = u"Österreich"
     self.data["GetAdvancedPersonalData"][key] = value
     _call.side_effect = self._call
     eq_(paypal.get_personal_data("foo")["city"], value)
Esempio n. 5
0
 def test_preapproval_absent(self, _call):
     _call.side_effect = self._call
     eq_(paypal.get_personal_data("foo")["address_two"], "")
Esempio n. 6
0
 def test_preapproval_works(self, _call):
     _call.side_effect = self._call
     eq_(paypal.get_personal_data("foo")["email"], "*****@*****.**")
     eq_(_call.call_count, 2)
Esempio n. 7
0
def acquire_refund_permission(request, addon_id, addon, webapp=False):
    """This is the callback from Paypal."""
    # Set up our redirects.
    if request.GET.get('dest', '') == 'submission':
        on_good = reverse('submit.app.payments.confirm', args=[addon.app_slug])
        on_error = reverse('submit.app.payments.paypal', args=[addon.app_slug])
        show_good_msgs = False
    else:
        # The management pages are the default.
        on_good = addon.get_dev_url('paypal_setup_confirm')
        on_error = addon.get_dev_url('paypal_setup_bounce')
        show_good_msgs = True

    if 'request_token' not in request.GET:
        paypal_log.debug('User did not approve permissions for'
                         ' addon: %s' % addon_id)
        messages.error(request, 'You will need to accept the permissions '
                                'to continue.')
        return redirect(on_error)

    paypal_log.debug('User approved permissions for addon: %s' % addon_id)
    if waffle.flag_is_active(request, 'solitude-payments'):
        client.post_permission_token(data={
            'seller': addon, 'token': request.GET['request_token'],
            'verifier': request.GET['verification_code'],
        })
        try:
            data = client.post_personal_basic(data={'seller': addon})
        except client.Error as err:
            paypal_log.debug('%s for addon %s' % (err.message, addon.id))
            messages.warning(request, err.message)
            return redirect(on_error)

        data.update(client.post_personal_advanced(data={'seller': addon}))
    # TODO(solitude): remove these.
    else:
        token = paypal.get_permissions_token(request.GET['request_token'],
                                             request.GET['verification_code'])
        data = paypal.get_personal_data(token)

    # TODO(solitude): remove this.
    email = data.get('email')
    # If the email from paypal is different, something has gone wrong.
    if email != addon.paypal_id:
        paypal_log.debug('Addon paypal_id and personal data differ: '
                         '%s vs %s' % (email, addon.paypal_id))
        messages.warning(request, _('The email returned by Paypal, '
                                    'did not match the PayPal email you '
                                    'entered. Please login using %s.')
                         % email)
        return redirect(on_error)

    # TODO(solitude): remove this. Sadly because the permissions tokens
    # are never being traversed back we have a disconnect between what is
    # happening in solitude and here and this will not easily survive flipping
    # on and off the flag.
    if not waffle.flag_is_active(request, 'solitude-payments'):
        # Set the permissions token that we have just successfully used
        # in get_personal_data.
        addonpremium, created = (AddonPremium.objects
                                             .safer_get_or_create(addon=addon))
        addonpremium.update(paypal_permissions_token=token)

    # Finally update the data returned from PayPal for this addon.
    paypal_log.debug('Updating personal data for: %s' % addon_id)
    # TODO(solitude): delete this, as the data was pulled through solitude
    # it was saved.
    apd, created = AddonPaymentData.objects.safer_get_or_create(addon=addon)
    # This can be deleted with solitude, but this needs to change because
    # data will contain more than the fields on the object, this is a quick
    # workaround.
    for k, v in data.items():
        setattr(apd, k, v)
    apd.save()

    amo.log(amo.LOG.EDIT_PROPERTIES, addon)

    if show_good_msgs:
        messages.success(request, 'Please confirm the data we '
                                  'received from PayPal.')
    return redirect(on_good)
Esempio n. 8
0
 def test_preapproval_unicode(self, _call):
     key = 'response.personalData(2).personalDataValue'
     value = u'Österreich'
     self.data['GetAdvancedPersonalData'][key] = value
     _call.side_effect = self._call
     eq_(paypal.get_personal_data('foo')['city'], value)
Esempio n. 9
0
 def test_preapproval_absent(self, _call):
     _call.side_effect = self._call
     eq_(paypal.get_personal_data('foo')['address_two'], '')
Esempio n. 10
0
 def test_preapproval_works(self, _call):
     _call.side_effect = self._call
     eq_(paypal.get_personal_data('foo')['email'], '*****@*****.**')
     eq_(_call.call_count, 2)
Esempio n. 11
0
 def test_preapproval_unicode(self, _call):
     key = 'response.personalData(2).personalDataValue'
     value = u'Österreich'
     self.data['GetAdvancedPersonalData'][key] = value
     _call.side_effect = self._call
     eq_(paypal.get_personal_data('foo')['city'], value)
Esempio n. 12
0
 def test_preapproval_absent(self, _call):
     _call.side_effect = self._call
     eq_(paypal.get_personal_data('foo')['address_two'], '')
Esempio n. 13
0
 def test_preapproval_works(self, _call):
     _call.side_effect = self._call
     eq_(paypal.get_personal_data('foo')['email'], '*****@*****.**')
     eq_(_call.call_count, 2)