from django import forms from django.conf import settings from django.core.exceptions import ObjectDoesNotExist import requests from lib.brains.models import (BraintreeBuyer, BraintreePaymentMethod, BraintreeSubscription) from lib.buyers.models import Buyer from lib.sellers.models import SellerProduct from payments_config import products from solitude.base import getLogger from solitude.related_fields import PathRelatedFormField log = getLogger('s.brains') class BuyerForm(forms.Form): uuid = forms.CharField(max_length=255) def clean_uuid(self): data = self.cleaned_data['uuid'] try: self.buyer = Buyer.objects.get(uuid=data) except ObjectDoesNotExist: raise forms.ValidationError('Buyer does not exist.', code='does_not_exist') if BraintreeBuyer.objects.filter(buyer=self.buyer).exists(): raise forms.ValidationError('Braintree buyer already exists.',
from django.conf import settings from django.core.exceptions import ObjectDoesNotExist from lib.brains.models import BraintreeSubscription, BraintreeTransaction from lib.brains.serializers import serialize_webhook from lib.transactions import constants from lib.transactions.models import Transaction from solitude.base import getLogger log = getLogger('s.webhooks') class Processor(object): """ Process a webhook from Braintree. Each response contains a different value depending upon the subject. """ def __init__(self, webhook): self.webhook = webhook # All the transactions found on this webhook. self.transactions = [] # The one transaction that matters for serialization. self.transaction = None # The subscription this webhook is about. self.subscription = None self.processed = False def process(self):
from django import forms from django.conf import settings from django.core.exceptions import ObjectDoesNotExist import requests from lib.brains.models import BraintreeBuyer, BraintreePaymentMethod from lib.buyers.models import Buyer from lib.sellers.models import SellerProduct from solitude.base import getLogger from solitude.related_fields import PathRelatedFormField log = getLogger('s.brains') class BuyerForm(forms.Form): uuid = forms.CharField(max_length=255) def clean_uuid(self): data = self.cleaned_data['uuid'] try: self.buyer = Buyer.objects.get(uuid=data) except ObjectDoesNotExist: raise forms.ValidationError('Buyer does not exist.', code='does_not_exist') if BraintreeBuyer.objects.filter(buyer=self.buyer).exists(): raise forms.ValidationError('Braintree buyer already exists.', code='already_exists')
from django.test import LiveServerTestCase from django.test.utils import override_settings from nose.plugins.attrib import attr from curling import lib from solitude.base import getLogger log = getLogger('s.tests') configs = { 'REQUIRE_OAUTH': True, 'SITE_URL': 'http://*****:*****@attr('live') @override_settings(**configs) class LiveTestCase(LiveServerTestCase): @property def request(self): api = lib.API(self.live_server_url) api.activate_oauth(*configs['CLIENT_OAUTH_KEYS'].items()[0]) return api
import time from django.conf import settings from django.core.exceptions import ObjectDoesNotExist from lib.brains.models import BraintreeSubscription, BraintreeTransaction from lib.brains.serializers import serialize_webhook from lib.transactions import constants from lib.transactions.models import Transaction from solitude.base import getLogger from solitude.utils import shorter log = getLogger('s.webhooks') class Processor(object): """ Process a webhook from Braintree. Each response contains a different value depending upon the subject. """ def __init__(self, webhook): self.webhook = webhook # All the transactions found on this webhook. self.transactions = [] # The one transaction that matters for serialization. self.transaction = None # The subscription this webhook is about. self.subscription = None self.processed = False