Exemple #1
0
 def test_flip(self):
     process = Processor(notification(subject=subscription()))
     process.subscription = self.braintree_sub
     process.get_subscription()
     process.update_subscription(True)
     eq_(self.braintree_sub.reget().active, True)
     process.update_subscription(False)
     eq_(self.braintree_sub.reget().active, False)
Exemple #2
0
    def test_transactions_order(self):
        process = Processor(notification(
            subject=subscription(transactions=[
                # Repeated transactions only most recent (first)
                # should be used.
                transaction(id='first:id'),
                transaction(id='another:id')
            ]),
            kind=self.kind))
        process.process()

        eq_(process.transactions[0].uid_support, 'first:id')
Exemple #3
0
    def test_transactions_order(self):
        process = Processor(
            notification(
                subject=subscription(transactions=[
                    # Repeated transactions only most recent (first)
                    # should be used.
                    transaction(id='first:id'),
                    transaction(id='another:id')
                ]),
                kind=self.kind))
        process.process()

        eq_(process.transactions[0].uid_support, 'first:id')
Exemple #4
0
 def test_flip(self):
     process = Processor(notification(subject=subscription()))
     process.subscription = self.braintree_sub
     process.get_subscription()
     process.update_subscription(True)
     eq_(self.braintree_sub.reget().active, True)
     process.update_subscription(False)
     eq_(self.braintree_sub.reget().active, False)
Exemple #5
0
 def test_ok(self):
     sub = subscription(transactions=[
         transaction(status='processor_declined',
                     processor_response_code='nah')
     ])
     Processor(notification(kind=self.kind, subject=sub)).process()
     eq_(Transaction.objects.get().status, constants.STATUS_FAILED)
Exemple #6
0
def parse(request):
    form = WebhookParseForm(request.DATA)
    if not form.is_valid():
        raise FormError(form.errors)

    # Parse the gateway without doing a validation on this server.
    # The validation has happened on the solitude-auth server.
    gateway = get_client().Configuration.instantiate().gateway()
    payload = base64.decodestring(form.cleaned_data['bt_payload'])
    attributes = XmlUtil.dict_from_xml(payload)
    parsed = WebhookNotification(gateway, attributes['notification'])

    log.info('Received webhook: {p.kind}.'.format(p=parsed))
    debug_log.debug(parsed)

    processor = Processor(parsed)
    processor.process()
    data = processor.data
    return Response(data, status=200 if data else 204)
Exemple #7
0
 def test_subscription_inactive(self):
     Processor(notification(kind=self.kind, subject=self.sub)).process()
     eq_(self.braintree_sub.reget().active, False)
Exemple #8
0
 def test_ok(self):
     Processor(notification(kind=self.kind, subject=self.sub)).process()
     eq_(Transaction.objects.get().status, constants.STATUS_CHECKED)
Exemple #9
0
 def test_none(self):
     self.braintree_sub.delete()
     obj = Processor(notification(kind=self.kind, subject=self.sub))
     with self.assertRaises(BraintreeSubscription.DoesNotExist):
         obj.process()
Exemple #10
0
 def test_subscription_active(self):
     self.braintree_sub.active = False
     self.braintree_sub.save()
     Processor(notification(kind=self.kind, subject=self.sub)).process()
     eq_(self.braintree_sub.reget().active, True)
Exemple #11
0
 def test_ok(self):
     Processor(notification(kind=self.kind, subject=self.sub)).process()
     transaction = Transaction.objects.get()
     eq_(transaction.status, constants.STATUS_CHECKED)
     eq_(BraintreeTransaction.objects.get().transaction, transaction)
     eq_(self.braintree_sub.reget().active, True)
Exemple #12
0
 def test_no_transactions_data(self):
     process = Processor(
         notification(subject=subscription(transactions=[]),
                      kind=self.kind))
     process.process()
     eq_(process.transaction, None)
Exemple #13
0
 def process(self, subscription):
     hook = Processor(notification(subject=subscription, kind=self.kind))
     hook.process()
     hook.get_subscription()
     hook.update_transactions()
     return hook
Exemple #14
0
 def test_none(self):
     self.braintree_sub.delete()
     obj = Processor(notification(kind=self.kind, subject=self.sub))
     with self.assertRaises(BraintreeSubscription.DoesNotExist):
         obj.process()
Exemple #15
0
 def test_no_transactions_data(self):
     process = Processor(notification(
         subject=subscription(transactions=[]), kind=self.kind))
     process.process()
     eq_(process.transaction, None)
Exemple #16
0
 def process(self, subscription):
     hook = Processor(notification(subject=subscription, kind=self.kind))
     hook.process()
     hook.get_subscription()
     hook.update_transactions()
     return hook