Exemplo n.º 1
0
 def test_paytrail_begin_payment_process_bad_request(self, mock_post):
     """ Make sure paytrail fails properly (we should get a failure redirect url) """
     mock_post.return_value = PaytrailFakeResponse(
         401, PaytrailFakeResponse.create_failure())
     result = begin_payment_process(PaymentMethod(1), self.transaction)
     self.assertEqual(result, reverse('store:pm:paytrail-failure'))
     self.assertEqual(self.transaction.token, '')
Exemplo n.º 2
0
 def validate(self, data):
     data = super(StoreTransactionSerializer, self).validate(data)
     try:
         validate_payment_method(data['items'], PaymentMethod(data['payment_method']))
     except TransactionException as e:
         raise ValidationError(str(e))
     return data
Exemplo n.º 3
0
 def test_bitpay_begin_payment_process_good_request(self, mock_post):
     """ Make sure bitpay works with a good request (we should get a redirect URL) """
     mock_post.return_value = BitpayFakeResponse(201, BitpayFakeResponse.create_success(order_no="3456454560"))
     result = begin_payment_process(PaymentMethod(0), self.transaction)
     self.transaction.refresh_from_db()
     self.assertEqual(self.transaction.token, '3456454560')
     self.assertEqual(self.transaction.payment_method_name, "Bitpay")
     self.assertEqual(result, "https://test.bitpay.com/invoice?id={}".format(self.transaction.token))
Exemplo n.º 4
0
 def test_paytrail_begin_payment_process_good_request(self, mock_post):
     """ Make sure paytrail works with a good request (we should get a redirect URL) """
     mock_post.return_value = PaytrailFakeResponse(201, PaytrailFakeResponse.create_success(
         order_no="234246654", token=uuid.uuid4().hex))
     result = begin_payment_process(PaymentMethod(1), self.transaction)
     self.transaction.refresh_from_db()
     self.assertNotEqual(self.transaction.token, None)
     self.assertEqual(self.transaction.payment_method_name, "Paytrail")
     self.assertEqual(result, "https://payment.paytrail.com/payment/load/token/{}".format(self.transaction.token))
Exemplo n.º 5
0
 def create(self, request, *args, **kwargs):
     serializer = self.get_serializer(data=request.data)
     if serializer.is_valid():
         if serializer.validated_data['save']:
             ta = serializer.save()
             payment_method = PaymentMethod(serializer.validated_data['payment_method'])
             response_url = begin_payment_process(payment_method, ta)
             return Response({"url": response_url}, status=status.HTTP_201_CREATED)
         else:
             return Response(status=status.HTTP_200_OK)
     else:
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 6
0
    def test_validate_payment_method(self):
        """ Make sure that payment validation works (NO_METHOD especially) """
        item_tpl = {
            "item_id": self.items[0].id,
            "variant_id": None,
            "amount": 2
        }

        free_items = [
            {**item_tpl, **{"item_id": self.items[5].id}},
        ]
        expensive_items = [
            {**item_tpl, **{"item_id": self.items[0].id}},
            {**item_tpl, **{"item_id": self.items[1].id}},
            {**item_tpl, **{"item_id": self.items[2].id}},
            {**item_tpl, **{"item_id": self.items[3].id}}
        ]

        validate_payment_method(free_items, PaymentMethod(-1))
        with self.assertRaises(TransactionException):
            validate_payment_method(expensive_items, PaymentMethod(-1))
        validate_payment_method(free_items, PaymentMethod(0))
        validate_payment_method(expensive_items, PaymentMethod(0))
        validate_payment_method(free_items, PaymentMethod(1))
        validate_payment_method(expensive_items, PaymentMethod(1))
Exemplo n.º 7
0
 def test_no_method_begin_payment_process_good_request(self):
     """ Make sure NO_METHOD works with a good request (we should get a redirect URL) """
     result = begin_payment_process(PaymentMethod(-1), self.transaction)
     self.transaction.refresh_from_db()
     self.assertEqual(self.transaction.payment_method_name, "No payment")
     self.assertEqual(result, reverse('store:pm:no-method-success'))
Exemplo n.º 8
0
 def test_bitpay_begin_payment_process_bad_request(self, mock_post):
     """ Make sure bitpay fails properly (we should get a failure redirect url) """
     mock_post.return_value = BitpayFakeResponse(
         401, BitpayFakeResponse.create_failure())
     result = begin_payment_process(PaymentMethod(0), self.transaction)
     self.assertEqual(result, reverse('store:pm:bitpay-failure'))