Exemple #1
0
    def test_reportfail(self):
        """ Test whether errors in report code are caught. """

        # Create a cluster
        pc = PaymentCluster(pk=self.get_transaction_id())
        pc.cluster_key = 'banana'
        self.assertRaises(PaymentException, pc.update_status)
Exemple #2
0
    def test_showurl(self):
        """ See whether we can generate a show url. """

        # Create a cluster
        pc = PaymentCluster(pk=self.get_transaction_id())
        pc.create_cluster(**self.default_data)
        self.assertTrue(pc.payment_url())
Exemple #3
0
    def test_reportfail(self):
        """ Test whether errors in report code are caught. """

        # Create a cluster
        pc = PaymentCluster(pk=self.get_transaction_id())
        pc.cluster_key = 'banana'
        self.assertRaises(PaymentException, pc.update_status)
Exemple #4
0
    def test_showurl(self):
        """ See whether we can generate a show url. """

        # Create a cluster
        pc = PaymentCluster(pk=self.get_transaction_id())
        pc.create_cluster(**self.default_data)
        self.assertTrue(pc.payment_url())
Exemple #5
0
    def test_createcluster(self):
        pc = PaymentCluster(pk=self.get_transaction_id())

        pc.create_cluster(**self.default_data)

        pc.save()

        self.assertTrue(pc.cluster_key)
        self.assertTrue(pc.cluster_id)
Exemple #6
0
    def test_transaction_id(self):
        """ Test transaction_id -> pk resolution. """

        pc = PaymentCluster(pk=self.get_transaction_id())
        pc.save()

        transaction_id = pc.transaction_id
        pc2 = PaymentCluster.get_by_transaction_id(transaction_id)

        self.assertEqual(pc.pk, pc2.pk)
    def test_transaction_id(self):
        """ Test transaction_id -> pk resolution. """

        pc = PaymentCluster(pk=self.get_transaction_id())
        pc.save()

        transaction_id = pc.transaction_id
        pc2 = PaymentCluster.get_by_transaction_id(transaction_id)

        self.assertEqual(pc.pk, pc2.pk)
Exemple #8
0
    def test_status_success(self):
        # Create a cluster
        pc = PaymentCluster(pk=self.get_transaction_id())
        pc.create_cluster(**self.default_data)
        transaction_id = pc.transaction_id

        url = self.status_change_url
        url += '?' + urlencode({'merchant_transaction_id': transaction_id})

        response = self.client.get(url)
        self.failUnlessEqual(response.status_code, 200)
Exemple #9
0
    def test_report(self):
        """ Test payment cluster status reports. """

        # Create a cluster
        pc = PaymentCluster(pk=self.get_transaction_id())
        pc.create_cluster(**self.default_data)

        pc.update_status()

        self.assertFalse(pc.paid)
        self.assertFalse(pc.closed)
Exemple #10
0
    def test_status_success(self):
        # Create a cluster
        pc = PaymentCluster(pk=self.get_transaction_id())
        pc.create_cluster(**self.default_data)
        transaction_id = pc.transaction_id

        url = self.status_change_url
        url += '?' + urlencode({'merchant_transaction_id': transaction_id})

        response = self.client.get(url)
        self.failUnlessEqual(response.status_code, 200)
Exemple #11
0
    def test_createclusterunicode(self):
        """
        Test creating a cluster with some unicode data
        Regression test.
        """
        pc = PaymentCluster(pk=self.get_transaction_id())

        self.default_data.update({'client_firstname': u'Margr\xe8t'})

        pc.create_cluster(**self.default_data)

        pc.save()

        self.assertTrue(pc.cluster_key)
        self.assertTrue(pc.cluster_id)
Exemple #12
0
def status_change(request):
    """ Update URL should have ?merchant_transaction_id=<id> set. """
    transaction_id = request.GET.get('merchant_transaction_id')

    if not transaction_id:
        logger.warning('No transaction id in status change message')
        return HttpResponseNotFound('')

    logger.debug('Received status change message for transaction_id %s',
                 transaction_id)

    try:
        payment_cluster = \
            PaymentCluster.get_by_transaction_id(transaction_id)
    except (PaymentCluster.DoesNotExist, ValueError):
        logger.warning(
            'Status change for payment cluster with merchant \
                        transaction_id %s not matched', transaction_id)
        return HttpResponseNotFound('')

    payment_cluster.update_status()

    logger.debug('Status for payment with transaction_id %s updated',
                 transaction_id)

    # Allways return a 200
    return HttpResponse('')
Exemple #13
0
    def test_clusterfail(self):
        pc = PaymentCluster(pk=self.get_transaction_id())

        data = self.default_data.copy()

        del data['client_email']

        # Missing fields should be caught early
        self.assertRaises(
            AssertionError,
            pc.create_cluster,
            **data
        )

        data = self.default_data.copy()
        data['merchant_name'] = 'nobody'

        # Overriding the merchang name should yield an error
        self.assertRaises(
            PaymentException,
            pc.create_cluster,
            **data
        )

        data = self.default_data.copy()
        data['price'] = '0.00'

        # Zero amount should yield an error
        self.assertRaises(
            PaymentException,
            pc.create_cluster,
            **data
        )
Exemple #14
0
def status_change(request):
    """ Update URL should have ?merchant_transaction_id=<id> set. """
    transaction_id = request.GET.get('merchant_transaction_id')

    if not transaction_id:
        logger.warning('No transaction id in status change message')
        return HttpResponseNotFound('')

    logger.debug('Received status change message for transaction_id %s',
                 transaction_id)

    try:
        payment_cluster = \
            PaymentCluster.get_by_transaction_id(transaction_id)
    except (PaymentCluster.DoesNotExist, ValueError):
        logger.warning('Status change for payment cluster with merchant \
                        transaction_id %s not matched', transaction_id)
        return HttpResponseNotFound('')

    payment_cluster.update_status()

    logger.debug('Status for payment with transaction_id %s updated',
                 transaction_id)

    # Allways return a 200
    return HttpResponse('')
Exemple #15
0
    def create_payment(self):
        """ Create payment object for order. """
        order = self.object

        if order.payment_cluster:
            payment_cluster = order.payment_cluster
            logger.info(u'Found existing payment cluster %s, using this one',
                        payment_cluster)

            return payment_cluster

        assert order.customer
        customer = order.customer

        # We want the customer's data - not the order shipping details
        address = customer.get_address()

        full_address = u'%s\n%s' \
            % (address.postal_address, address.postal_address2)
        data = {
            "merchant_transaction_id": order.order_number,
            "client_id" : customer.pk,
            "price" : order.get_price(),
            "cur_price" : "eur",
            "client_company" : customer.company,
            "client_email" : customer.email,
            "client_firstname" : customer.first_name,
            "client_lastname" : customer.last_name,
            "client_address" : full_address,
            "client_zip" : address.zip_code,
            "client_city" : address.city,
            "client_country" : address.country.iso,
            "client_language" : customer.language,
            "description" : unicode(order),
            "days_pay_period": 14
        }
        payment = PaymentCluster()
        payment.create_cluster(**data)

        logger.debug(u'Created new payment cluster %s, saving', payment)
        order.payment_cluster = payment

        # Make sure we update the order state to (payment) pending
        order.state = ORDER_STATE_PENDING
        order.save()

        return payment
Exemple #16
0
    def test_createcluster(self):
        pc = PaymentCluster(pk=self.get_transaction_id())

        pc.create_cluster(**self.default_data)

        pc.save()

        self.assertTrue(pc.cluster_key)
        self.assertTrue(pc.cluster_id)
Exemple #17
0
    def test_report(self):
        """ Test payment cluster status reports. """

        # Create a cluster
        pc = PaymentCluster(pk=self.get_transaction_id())
        pc.create_cluster(**self.default_data)

        pc.update_status()

        self.assertFalse(pc.paid)
        self.assertFalse(pc.closed)
Exemple #18
0
    def test_createclusterunicode(self):
        """
        Test creating a cluster with some unicode data
        Regression test.
        """
        pc = PaymentCluster(pk=self.get_transaction_id())

        self.default_data.update({'client_firstname': u'Margr\xe8t'})

        pc.create_cluster(**self.default_data)

        pc.save()

        self.assertTrue(pc.cluster_key)
        self.assertTrue(pc.cluster_id)