Пример #1
0
def create(request):
    client = get_client().Subscription
    form = SubscriptionForm(request.DATA)

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

    data = form.braintree_data
    result = client.create(data)

    if not result.is_success:
        log.warning('Error on creating subscription: {0}'
                    .format(result.message))
        raise BraintreeResultError(result)

    braintree_subscription = result.subscription
    log.info('Subscription created in braintree: {0}'
             .format(braintree_subscription.id))

    subscription = BraintreeSubscription.objects.create(
        paymethod=form.cleaned_data['paymethod'],
        seller_product=form.seller_product,
        provider_id=braintree_subscription.id
    )
    log.info('Subscription created in solitude: {0}'.format(subscription.pk))

    res = Namespaced(
        LocalSubscription(instance=subscription),
        Subscription(instance=braintree_subscription)
    )
    return Response(res.data, status=201)
Пример #2
0
def create(request):
    client = get_client().Subscription
    form = SubscriptionForm(request.DATA)

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

    data = form.braintree_data
    result = client.create(data)

    if not result.is_success:
        log.warning('Error on creating subscription: {0}'.format(
            result.message))
        raise BraintreeResultError(result)

    braintree_subscription = result.subscription
    log.info('Subscription created in braintree {} for paymethod {}'.format(
        braintree_subscription.id, form.cleaned_data['paymethod']))

    subscription = BraintreeSubscription.objects.create(
        amount=form.cleaned_data['amount'],
        paymethod=form.cleaned_data['paymethod'],
        seller_product=form.seller_product,
        provider_id=braintree_subscription.id)
    log.info('Subscription created in solitude: {}; braintree: {}'.format(
        subscription.pk, braintree_subscription.id))

    res = Namespaced(mozilla=LocalSubscription(instance=subscription),
                     braintree=Subscription(instance=braintree_subscription))
    return Response(res.data, status=201)
Пример #3
0
 def submit(self, expect_errors=False, data=None):
     if not data:
         data = {}
     submission = {
         'paymethod': self.paymethod.get_uri(),
         'plan_id': 'moz-brick',
     }
     submission.update(data)
     form = SubscriptionForm(submission)
     if not expect_errors:
         assert form.is_valid(), form.errors.as_text()
     return form
Пример #4
0
 def submit(self, expect_errors=False, data=None):
     if not data:
         data = {}
     submission = {
         'paymethod': self.paymethod.get_uri(),
         'plan_id': 'moz-brick',
     }
     submission.update(data)
     form = SubscriptionForm(submission)
     if not expect_errors:
         assert form.is_valid(), form.errors.as_text()
     return form