def mark_payment(pp_obj, order_state=PAID): order = None try: logging.info("getting order for uuid %s" % pp_obj.custom) order_uuid = pp_obj.custom order = Order.objects.get(uuid=order_uuid) if order is not None: if order.state != PAID and order_state == PAID: order_paid.send({"order": order, "request": None}) if getattr(settings, 'LFS_SEND_ORDER_MAIL_ON_PAYMENT', False): mail_utils.send_order_received_mail(order) order.state = order_state order.save() except Order.DoesNotExist, e: logging.error(e)
def web_hook_view(request): hit = CompropagoWebHookHit( scheme = request.is_secure() and 'HTTPS' or 'HTTP', headers = repr(request.META), path = request.path_info, body = request.raw_post_data ) hit.save() payload = json.loads(request.raw_post_data) api_version = payload['api_version'] if api_version == '1.1': payment_id = payload['id'] else: #assume 1.0 payment_id = payload['data']['object']['id'] txn = get_object_or_404(CompropagoTransaction, payment_id=payment_id) hit.transaction = txn hit.save() api = CompropagoAPI(api_key=settings.LFS_COMPROPAGO_API_KEY) res = api.verify_charge(payment_id) if 'type' in res: pay_status = res['type'] if pay_status == 'charge.success': txn.payment_status = pay_status txn.verified = True txn.save(); lfs_order_paid_signal.send({'order': txn.order}) if getattr(settings, 'LFS_SEND_ORDER_MAIL_ON_PAYMENT', False): mail_utils.send_order_received_mail(txn.order) txn.order.state = PAID elif pay_status == 'error': txn.payment_status = PAYMENT_FAILED txn.order.state = PAYMENT_FAILED txn.order.state_changed = datetime.now() txn.save() txn.order.save() return HttpResponse(str(res), content_type="text/plain")
def paid_cartasi(request): """ Cartasi documentation (italian only). Formato VPOSNotification ======================== Pag 49, messaggio http inviato con metodo POST, in modalità SSL. Rappresenta il messaggio inoltrato da X-PAY agli URL (NOTIFICATION_URL e RESULT_URL) specificati dall’esercente nel messaggio di apertura dell’ordine (VPOSReqFull o nel nostro caso VPOSReqLight), per potergli comunicare l’esito positivo della transazione. La comunicazione verso il NOTIFICATION_URL avviene tramite una chiamata diretta server to server, quella verso il RESULT_URL avviene tramite il browser dell’acquirente. Parametri: * TERMINAL_ID * TRANSACTION_ID * RESPONSE -> TRANSACTION_OK * AUTH_CODE -> alfanum max 10 char (codice auth ricevuto dall'emittente della carta di credito, anche con spazi) * TRANSACTION_DATE -> gg/mm/aaaa hh.mm.ss * CARD_TYPE -> tipo carta usata (es VISA) * AMOUNT * CURRENCY * TRANSACTION_TYPE, tipo transazione con livelli di sicurezza (vedi App A2) * MAC Es: TERMINAL_ID=0000000050242004&TRANSACTION_ID=T000000000000000001&RE SPONSE=TRANSACTION_OK&AUTH_CODE=901867&TRANSACTION_DATE=06/07/2005 16.55.56&CARD_TYPE=VISA&AMOUNT=000123056&CURRENCY=978 &TRANSACTION_TYPE=VBV_FULL&MAC=70C4F1F621A5DED95C7EE8C5507A9E1F297 0BCFE®ION=Europe&COUNTRY=Italy&PRODUCT_TYPE=Consumer&LIABILITY_ SHIFT=N I parametri utilizzati per il calcolo questo tipo di messaggio sono i seguenti: o TERMINAL_ID o TRANSACTION_ID o RESPONSE o AMOUNT o CURRENCY o Chiave per MAC Al termine ritorna una VPOSNotificationRes Formato VPOSNotificationRes =========================== Pag 58. Messaggio http inviato con metodo POST, in modalità SSL RESPONSE -> 0 (operazione elaborata correttamente) """ try: response = request.POST['RESPONSE'] if response == 'TRANSACTION_OK': transaction_id = request.POST['TRANSACTION_ID'] log("Received TRANSACTION OK for %s" % transaction_id) order_id = transaction2order_id(transaction_id) log_debug("internal order id: %s" % transaction_id) order = lfs_get_object_or_404(Order, pk=order_id) order.state = PAID order.save() order_paid.send({"order": order}) log("TRANSACTION SAVED for %s" % transaction_id) return HttpResponse('RESPONSE=0') else: log("WARNING, received a non TRANSACTION_OK for %s" % str(request.POST)) except Exception, e: log("AN ERROR IS OCCURRED FOR request %s [%s]" % (str(request.POST), str(e)))