コード例 #1
0
ファイル: test_utils.py プロジェクト: GapData/django-konfera
    def test_attendee_paid_less(self):
        order = models.Order.objects.create(price=100, discount=10)
        payment = make_payment({'amount': 80, 'transaction_id': '7'})

        utils._process_payment(order, payment)

        self.assertEqual(order.amount_paid, 80)
        self.assertEqual(order.status, models.order.Order.PARTLY_PAID)
コード例 #2
0
    def test_payment_marked_as_processed(self):
        order = models.Order.objects.create(price=100, discount=10)
        payment = make_payment({'amount': 80, 'transaction_id': '7'})

        self.assertEqual(ProcessedTransaction.objects.count(), 0)

        utils._process_payment(order, payment)

        self.assertEqual(ProcessedTransaction.objects.count(), 1)
        self.assertEqual(ProcessedTransaction.objects.all()[0].transaction_id, '7')
コード例 #3
0
    def test_attendee_paid_enough(self):
        order = models.Order.objects.create(
            price=100,
            discount=10,
            amount_paid=5,
            status=models.order.Order.PARTLY_PAID)
        payment = make_payment({
            'amount': 85,
            'transaction_id': '7',
            'executor': 'Executor Executorovac'
        })

        utils._process_payment(order, payment)

        self.assertEqual(order.amount_paid, 90)
        self.assertEqual(order.status, models.order.Order.PAID)
        self.assertEqual(ProcessedTransaction.objects.all()[0].executor,
                         'Executor Executorovac')
コード例 #4
0
ファイル: views.py プロジェクト: pyconsk/django-konfera
    def success(request, order):
        """ If the payment was successful process it, otherwise show an error and log what went wrong """
        payment_id = request.session.get('paypal_payment_id')
        payment = paypalrestsdk.Payment.find(payment_id)

        payer_id = payment['payer']['payer_info']['payer_id']

        if not payment.execute({"payer_id": payer_id}):
            logger.error(
                "Payment for order order(pk={order}) couldn't be paid! Error: {err}"
                .format(order=order.pk, err=payment.error))
            return False

        payment_dict = {
            'payment_method':
            'paypal',
            'amount':
            payment['transactions'][0]['amount']['total'],
            'currency':
            payment['transactions'][0]['amount']['currency'],
            'transaction_id':
            payment['id'],
            'variable_symbol':
            order.variable_symbol,
            'date':
            payment['create_time'].split('T')[0],
            'executor':
            '{first} {last} <{email}>'.format(
                first=payment['payer']['payer_info']['first_name'],
                last=payment['payer']['payer_info']['last_name'],
                email=payment['payer']['payer_info']['email']),
            'comment':
            '',
        }

        _process_payment(order, payment_dict)
        return True