Exemple #1
0
 def test_missing_update_params(self):
     form = SubscriptionUpdateForm({})
     form.is_valid()
     errors = form.errors
     # Make sure empty params are caught.
     assert 'subscription' in errors, errors.as_text()
     assert 'paymethod' in errors, errors.as_text()
Exemple #2
0
 def test_missing_update_params(self):
     form = SubscriptionUpdateForm({})
     form.is_valid()
     errors = form.errors
     # Make sure empty params are caught.
     assert 'subscription' in errors, errors.as_text()
     assert 'paymethod' in errors, errors.as_text()
Exemple #3
0
def change(request):
    client = get_client().Subscription
    form = SubscriptionUpdateForm(request.DATA)

    if not form.is_valid():
        raise FormError(form.errors)

    subscription = form.cleaned_data['subscription']
    method = form.cleaned_data['paymethod']
    result = client.update(
        subscription.provider_id,
        {'payment_method_token': method.provider_id}
    )

    log_msgs = (subscription.id, subscription.paymethod_id, method.pk)

    if not result.is_success:
        log.warning('Error on changing subscription: {} from {} to {}'
                    .format(*log_msgs))
        raise BraintreeResultError(result)

    subscription.paymethod = method
    subscription.save()

    log.info('Subscription changed: {} from {} to {}'.format(*log_msgs))
    res = Namespaced(
        mozilla=LocalSubscription(instance=subscription),
        braintree=Subscription(instance=result.subscription)
    )
    return Response(res.data, status=200)
Exemple #4
0
def change(request):
    client = get_client().Subscription
    form = SubscriptionUpdateForm(request.DATA)

    if not form.is_valid():
        raise FormError(form.errors)

    subscription = form.cleaned_data['subscription']
    method = form.cleaned_data['paymethod']
    result = client.update(subscription.provider_id,
                           {'payment_method_token': method.provider_id})

    log_msgs = (subscription.id, subscription.paymethod_id, method.pk)

    if not result.is_success:
        log.warning('Error on changing subscription: {} from {} to {}'.format(
            *log_msgs))
        raise BraintreeResultError(result)

    subscription.paymethod = method
    subscription.save()

    log.info('Subscription changed: {} from {} to {}'.format(*log_msgs))
    res = Namespaced(mozilla=LocalSubscription(instance=subscription),
                     braintree=Subscription(instance=result.subscription))
    return Response(res.data, status=200)