Example #1
0
 def test_get_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.assertIsInstance(
         globee_payment.get_payment_by_id(globee_payment.payment_id), dict)
Example #2
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)
Example #3
0
 def test_get_payment_invalid_empty_key(self):
     globee_payment = GlobeePayment()
     with self.assertRaises(ValidationError):
         globee_payment.get_payment_by_id()
Example #4
0
 def test_get_payment_invalid(self):
     globee_payment = GlobeePayment()
     with self.assertRaises(ValidationError):
         globee_payment.get_payment_by_id("INVALID_KEY")