Esempio n. 1
0
 def test_required_fields_invalid_email_not_set(self):
     data = {
         'total': 13.37,
     }
     globee_payment = GlobeePayment(payment_data=data)
     with self.assertRaises(ValidationError):
         globee_payment.check_required_fields()
Esempio n. 2
0
 def test_required_fields_invalid_total_not_set(self):
     data = {
         'customer': {
             'email': '*****@*****.**'
         },
     }
     globee_payment = GlobeePayment(payment_data=data)
     with self.assertRaises(ValidationError):
         globee_payment.check_required_fields()
Esempio n. 3
0
 def test_required_fields_valid(self):
     data = {
         'total': 13.37,
         'customer': {
             'name': 'foobar',
             'email': '*****@*****.**'
         },
     }
     globee_payment = GlobeePayment(payment_data=data)
     self.assertTrue(globee_payment.check_required_fields())
Esempio n. 4
0
 def test_required_fields_invalid_email(self):
     data = {
         'total': 13.37,
         'customer': {
             'email': 'invalid_mail.com'
         },
     }
     globee_payment = GlobeePayment(payment_data=data)
     with self.assertRaises(ValidationError):
         globee_payment.check_required_fields()
Esempio n. 5
0
 def test_create_payment_invalid_email_not_set(self):
     data = {
         'total': 13.37,
         'customer': {
             'name': 'foobar',
         },
     }
     globee_payment = GlobeePayment(payment_data=data)
     with self.assertRaises(ValidationError):
         globee_payment.create_request()
Esempio n. 6
0
 def test_create_payment_invalid_key(self):
     data = {
         'total': 13.37,
         'customer': {
             'name': 'foobar',
             'email': '*****@*****.**'
         },
     }
     globee_payment = GlobeePayment(payment_data=data)
     self.assertTrue(globee_payment.check_required_fields())
     with self.assertRaises(ValidationError):
         globee_payment.create_request()
Esempio n. 7
0
 def test_update_payment_invalid_payment_id(self):
     globee_payment = GlobeePayment()
     custom_payment_id = "NEWID"
     custom_store_reference = "NEWSTOREREF"
     updated_data = {
         "custom_payment_id": custom_payment_id,
         "custom_store_reference": custom_store_reference,
         'customer': {
             'email': '*****@*****.**'
         },
     }
     globee_payment.payment_data = updated_data
     with self.assertRaises(ValidationError):
         globee_payment.update_payment_request("INVALID_KEY")
Esempio n. 8
0
 def test_create_payment_invalid_urls(self):
     data = {
         'total': 13.37,
         'customer': {
             'email': '*****@*****.**'
         },
         'success_url': 'invalid-url',
         'cancel_url': 'invalid-url',
         'ipn_url': 'invalid-url',
     }
     globee_payment = GlobeePayment(payment_data=data)
     self.assertTrue(globee_payment.check_required_fields())
     with self.assertRaises(ValidationError):
         globee_payment.create_request()
Esempio n. 9
0
 def test_get_payment_details_for_currency_valid(self):
     data = {
         'total': 13.37,
         'currency': 'EUR',
         'customer': {
             'name': 'foobar',
             'email': '*****@*****.**'
         },
     }
     globee_payment = GlobeePayment(payment_data=data)
     self.assertTrue(globee_payment.check_required_fields())
     self.assertIn("https://test.globee.com/",
                   globee_payment.create_request())
     response = globee_payment.get_payment_currency_details("BTC")
     self.assertIsInstance(response, dict)
Esempio n. 10
0
 def test_create_payment_valid(self):
     data = {
         'total': 13.37,
         'currency': 'EUR',
         'customer': {
             'name': 'foobar',
             'email': '*****@*****.**'
         },
     }
     globee_payment = GlobeePayment(payment_data=data)
     self.assertTrue(globee_payment.check_required_fields())
     self.assertIn("https://test.globee.com/",
                   globee_payment.create_request())
     self.assertIn("https://test.globee.com/",
                   globee_payment.get_payment_url())
Esempio n. 11
0
def globee_ipn_view(request):
    paranoid = getattr(settings, 'GLOBEE_PARANOID_MODE', False)
    auto_validate = getattr(settings, 'GLOBEE_AUTO_VERIFY', False)
    payment_response = request.body.decode("utf-8")
    payment_data = json_loads(payment_response)
    if auto_validate:
        globee_payment = GlobeePayment()
        payment_data = globee_payment.get_payment_by_id(payment_data['id'])
    pretty_data = json_dumps(payment_data, indent=4, sort_keys=True)
    logger.debug('Globee POST data: %s' % pretty_data)

    try:
        created_at = datetime.strptime(payment_data['created_at'],
                                       '%Y-%m-%d %H:%M:%S')
        expires_at = datetime.strptime(payment_data['expires_at'],
                                       '%Y-%m-%d %H:%M:%S')

        defaults = {
            'payment_status': payment_data['status'],
            'total': float(payment_data['total']),
            'currency': payment_data['currency'],
            'custom_payment_id': payment_data['custom_payment_id'],
            'callback_data': payment_data['callback_data'],
            'customer_email': payment_data['customer']['email'],
            'customer_name': payment_data['customer']['name'],
            'created_at': pytz_utc.localize(created_at),
            'expires_at': pytz_utc.localize(expires_at),
        }

        payment, created = GlobeeIPN.objects.update_or_create(
            payment_id=payment_data['id'], defaults=defaults)
        payment.send_valid_signal()
    except KeyError as e:
        logger.error('Key %s not found in payment data.' % e)
        status = 200 if paranoid else 400
        return HttpResponse(status=status)
    except (ValueError, ValidationError) as e:
        logger.error(e)
        status = 200 if paranoid else 400
        return HttpResponse(status=status)
    return HttpResponse(status=200)
Esempio n. 12
0
 def test_update_payment_valid(self):
     data = {
         'total': 13.37,
         'currency': 'EUR',
         'customer': {
             'name': 'foobar',
             'email': '*****@*****.**'
         },
     }
     globee_payment = GlobeePayment(payment_data=data)
     self.assertTrue(globee_payment.check_required_fields())
     self.assertIn("https://test.globee.com/",
                   globee_payment.create_request())
     custom_payment_id = "NEWID"
     custom_store_reference = "NEWSTOREREF"
     updated_data = {
         "custom_payment_id": custom_payment_id,
         "custom_store_reference": custom_store_reference,
         'customer': {
             'email': '*****@*****.**'
         },
     }
     globee_payment.payment_data = updated_data
     response = globee_payment.update_payment_request()
     self.assertEqual(response['id'], globee_payment.payment_id)
     self.assertEqual(response['custom_payment_id'], custom_payment_id)
     self.assertEqual(response['custom_store_reference'],
                      custom_store_reference)
Esempio n. 13
0
 def test_update_payment_invalid_payment_id_is_none(self):
     globee_payment = GlobeePayment()
     custom_payment_id = "NEWID"
     custom_store_reference = "NEWSTOREREF"
     updated_data = {
         "custom_payment_id": custom_payment_id,
         "custom_store_reference": custom_store_reference,
     }
     globee_payment.payment_data = updated_data
     globee_payment.payment_id = None
     with self.assertRaises(ValidationError):
         globee_payment.update_payment_request()
Esempio n. 14
0
 def test_update_payment_invalid_email_not_set(self):
     data = {
         'total': 13.37,
         'currency': 'EUR',
         'customer': {
             'name': 'foobar',
             'email': '*****@*****.**'
         },
     }
     globee_payment = GlobeePayment(payment_data=data)
     self.assertTrue(globee_payment.check_required_fields())
     self.assertIn("https://test.globee.com/",
                   globee_payment.create_request())
     custom_payment_id = "NEWID"
     custom_store_reference = "NEWSTOREREF"
     updated_data = {
         "custom_payment_id": custom_payment_id,
         "custom_store_reference": custom_store_reference,
     }
     globee_payment.payment_data = updated_data
     with self.assertRaises(ValidationError):
         globee_payment.update_payment_request()
Esempio n. 15
0
 def test_update_payment_invalid_payment_data_is_none(self):
     globee_payment = GlobeePayment()
     globee_payment.payment_data = None
     globee_payment.payment_id = "SOME KEY"
     with self.assertRaises(ValidationError):
         globee_payment.update_payment_request()
Esempio n. 16
0
 def test_create_payment_invalid_empty_data(self):
     globee_payment = GlobeePayment()
     with self.assertRaises(ValidationError):
         globee_payment.check_required_fields()
     with self.assertRaises(ValidationError):
         globee_payment.create_request()
Esempio n. 17
0
 def test_init_invalid_key_is_empty(self):
     with self.assertRaises(ValidationError):
         globee_payment = GlobeePayment()
Esempio n. 18
0
 def test_get_payment_details_for_currency_invalid_payment_id_is_invalid(
         self):
     globee_payment = GlobeePayment()
     with self.assertRaises(ValidationError):
         globee_payment.get_payment_currency_details("BTC", "INVALID_KEY")
Esempio n. 19
0
 def test_get_payment_details_invalid_payment_id_is_none(self):
     globee_payment = GlobeePayment()
     with self.assertRaises(ValidationError):
         globee_payment.get_payment_details()
Esempio n. 20
0
 def test_ping_valid(self):
     globee_payment = GlobeePayment()
     self.assertTrue(globee_payment.ping())
Esempio n. 21
0
 def test_get_payment_methods_invalid(self):
     globee_payment = GlobeePayment()
     with self.assertRaises(ValidationError):
         globee_payment.get_payment_methods()
Esempio n. 22
0
 def test_get_payment_methods_valid(self):
     globee_payment = GlobeePayment()
     response = globee_payment.get_payment_methods()
     self.assertIsInstance(response, list)
Esempio n. 23
0
 def test_get_payment_invalid_empty_key(self):
     globee_payment = GlobeePayment()
     with self.assertRaises(ValidationError):
         globee_payment.get_payment_by_id()
Esempio n. 24
0
 def test_ping_invalid_key(self):
     globee_payment = GlobeePayment()
     with self.assertRaises(ValidationError):
         globee_payment.ping()
Esempio n. 25
0
 def test_get_payment_invalid(self):
     globee_payment = GlobeePayment()
     with self.assertRaises(ValidationError):
         globee_payment.get_payment_by_id("INVALID_KEY")