def error_commercegate(request, user_payment_id): up = UserPayment.get_by_id(user_payment_id) template = 'error/paymenterror.html' if up is not None: if 'errMsg' in request.GET and 'errNum' in request.GET: message = "code: %s - message: %s" % (request.GET['errNum'], request.GET['errMsg']) else: message = '' up.reply_error(message) ph = PaymentHistory.get(up, 'P') if ph is not None: ph.reject('', message) # POST to promiscuus if ph.trial: ph.trial_duration = up.trial_recurrence else: ph.trial_duration = 0 resp_promiscuus = post_to_promiscuus(ph, 'payment_commit') if resp_promiscuus['status'] == 'error': ph.message = "%s - Promiscuus error: %s" % ( ph.message, resp_promiscuus['message']) ph.save() # Obtengo Integrator Settings redirect_url_failed = IntegratorSetting.get_var(ph.integrator, 'redirect_url_failed') context = {'redirect_url': redirect_url_failed} return render(request, template, context)
def manual_payment(request): if request.is_ajax(): if request.method == 'POST': try: json_data = json.loads(request.body) userpayment_id = json_data['userpayment_id'] up = UserPayment.get_by_id(userpayment_id) if up is None: return JsonResponse( { 'message': 'Error al realizar el pago, el usuario no existe' }, status=500) if up.user.has_active_recurrence(): return JsonResponse( { 'message': 'Error al realizar el pago: el usuario ya posee una recurrencia activa' }, status=500) logging.basicConfig( format= '%(asctime)s - manual_payments -[%(levelname)s]: %(message)s', filename=Setting.get_var('log_path'), level=logging.INFO) # Cambio a estado Pending up.status = 'PE' up.save() # Obtengo la tarjeta habilitada para el usuario card = up.user.get_card() if card is None: msg = 'Error al obtener la tarjeta para el usuario' up.error(msg) return JsonResponse({'message': msg}, status=500) pay = make_payment(up, card, logging, True) if pay: return JsonResponse( {'message': 'Pago efectuado correctamente'}, status=200) else: return JsonResponse( { 'message': 'Error al realizar el pago: verificar PaymentHistory' }, status=500) except Exception: return JsonResponse({'message': 'Hubo un error'}, status=500) return JsonResponse({'message': 'metodo no permitido'}, status=500)
def getuserpayment(request): if request.method == 'POST': if request.body: print '-- Request body --' print request.body try: up = UserPayment.get_by_id(request.body) except Exception as e: return JsonResponse( { 'message': 'Hubo un error', 'data': e.message }, status=500) return JsonResponse({'message': '', 'data': up.status}, status=200) else: return JsonResponse({'message': 'El ID es mandatorio'}, status=500) else: return JsonResponse({'message': 'Metodo no permitido'}, status=500)