def test_get_payment_url(self):
        transaction = TransactionFactory()

        expected_url = '/pay/token/'
        with patch('silver.utils.payments._get_jwt_token') as mocked_token:
            mocked_token.return_value = 'token'

            self.assertEqual(get_payment_url(transaction, None), expected_url)

            assert mocked_token.mock_calls == [call(transaction)]
示例#2
0
    def test_get_payment_url(self):
        transaction = TransactionFactory()

        expected_url = '/pay/token/'
        with patch('silver.utils.payments._get_jwt_token') as mocked_token:
            mocked_token.return_value = 'token'

            self.assertEqual(get_payment_url(transaction, None), expected_url)

            assert mocked_token.mock_calls == [call(transaction)]
示例#3
0
    def test_pay_transaction_view_invalid_state(self):
        transaction = TransactionFactory.create(state=Transaction.States.Settled)

        response = self.client.get(get_payment_url(transaction, None))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(force_text(response.content),
                         render_to_string('transactions/complete_payment.html', {
                             'transaction': transaction,
                             'document': transaction.document,
                         }))
示例#4
0
    def test_pay_transaction_view_not_consumable_transaction(self):
        last_year = timezone.now() - timedelta(days=365)
        transaction = TransactionFactory.create(state=Transaction.States.Initial,
                                                valid_until=last_year)

        response = self.client.get(get_payment_url(transaction, None))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(force_text(response.content),
                         render_to_string('transactions/expired_payment.html', {
                             'document': transaction.document,
                         }))
示例#5
0
    def test_pay_transaction_view_expired(self):
        transaction = TransactionFactory.create()

        with patch('silver.utils.payments.datetime') as mocked_datetime:
            mocked_datetime.utcnow.return_value = datetime.utcnow() - timedelta(days=365)
            url = get_payment_url(transaction, None)

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(force_text(response.content),
                         render_to_string('transactions/expired_payment.html', {
                             'document': transaction.document,
                         }))
示例#6
0
    def test_pay_transaction_not_implemented_get_call(self):
        last_year = timezone.now() - timedelta(days=365)
        transaction = TransactionFactory.create(state=Transaction.States.Initial,
                                                valid_until=last_year)

        def get_view(processor, transaction, request):
            return not_implemented_view

        with patch('silver.tests.fixtures.ManualProcessor.get_view',
                   new=get_view):
            response = self.client.get(get_payment_url(transaction, None))

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(force_text(response.content),
                         render_to_string('transactions/expired_payment.html', {
                             'document': transaction.document,
                         }))
示例#7
0
    def _transaction_data(self, transaction):
        transaction.refresh_from_db()

        payment_method = transaction.payment_method
        customer = transaction.customer
        provider = transaction.provider
        proforma = transaction.proforma
        invoice = transaction.invoice

        with patch('silver.utils.payments._get_jwt_token') as mocked_token:
            mocked_token.return_value = 'token'

            return OrderedDict([
                ('id', unicode(transaction.uuid)),
                ('url',
                 reverse('transaction-detail',
                         kwargs={
                             'customer_pk': customer.id,
                             'transaction_uuid': transaction.uuid
                         })),
                ('customer', reverse('customer-detail', args=[customer.pk])),
                ('provider', reverse('provider-detail', args=[provider.pk])),
                ('amount', unicode(Decimal('0.00') + transaction.amount)),
                ('currency', unicode(transaction.currency)),
                ('state', unicode(transaction.state)),
                ('proforma', reverse('proforma-detail', args=[proforma.pk])),
                ('invoice', reverse('invoice-detail', args=[invoice.pk])),
                ('can_be_consumed', transaction.can_be_consumed),
                ('payment_processor', payment_method.payment_processor),
                ('payment_method',
                 reverse('payment-method-detail',
                         kwargs={
                             'customer_pk': customer.id,
                             'payment_method_id': payment_method.id
                         })),
                ('pay_url',
                 'http://testserver' + get_payment_url(transaction, None)),
                ('valid_until', None),
                ('updated_at', transaction.updated_at.isoformat()[:-6] + 'Z'),
                ('created_at', transaction.created_at.isoformat()[:-6] + 'Z'),
                ('fail_code', transaction.fail_code),
                ('refund_code', transaction.refund_code),
                ('cancel_code', transaction.cancel_code)
            ])
示例#8
0
 def get_pay_url(self, obj):
     return '<a href="%s">%s</a>' % (get_payment_url(obj, None),
                                      obj.payment_processor)
示例#9
0
文件: admin.py 项目: PressLabs/silver
 def get_pay_url(self, obj):
     return u'<a href="%s">%s</a>' % (get_payment_url(obj, None),
                                      obj.payment_processor)
示例#10
0
 def get_url(self, obj, view_name, request, format):
     if not obj.can_be_consumed:
         return None
     return get_payment_url(obj, request)
示例#11
0
 def get_url(self, obj, view_name, request, format):
     if not obj.can_be_consumed:
         return None
     return get_payment_url(obj, request)