Пример #1
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) """
     result = begin_payment_process(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))
Пример #2
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, '')
Пример #3
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) """
     result = begin_payment_process(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))
Пример #4
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))
Пример #5
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))
Пример #6
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))
Пример #7
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))
Пример #8
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 = 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)
Пример #9
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)
Пример #10
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'))
Пример #11
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'))
Пример #12
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, '')
Пример #13
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'))
Пример #14
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'))
Пример #15
0
 def test_bitpay_begin_payment_process_bad_request(self, mock_post):
     """ Make sure bitpay fails properly (we should get a failure redirect url) """
     result = begin_payment_process(0, self.transaction)
     self.assertEqual(result, reverse('store:pm:bitpay-failure'))
Пример #16
0
 def test_paytrail_begin_payment_process_bad_request(self, mock_post):
     """ Make sure paytrail fails properly (we should get a failure redirect url) """
     result = begin_payment_process(1, self.transaction)
     self.assertEqual(result, reverse('store:pm:paytrail-failure'))
     self.assertEqual(self.transaction.token, '')