def verify(self): # # Get Payment details # data = self.request.form ordernumber = data['orderID'] if get_status_category(int(data['STATUS'])) != SUCCESS_STATUS: return False # # SHA passphrase verification # signer = OgoneSignature(data, 'sha512', SHA_OUT_PASSWORD) order_uid = IPaymentData(self.context).uid_for(ordernumber) payment = Payments(self.context).get('ogone_payment') if data['SHASIGN'] == signer.signature(): payment.succeed(self.context, order_uid) order = OrderData(self.context, uid=order_uid) order.salaried = ifaces.SALARIED_YES return True else: payment.failed(self.context, order_uid) return False
def payment_failed(event): if event.payment.pid == 'pxpay_payment': data = event.data order = OrderData(event.context, uid=event.order_uid) # Processed already if data['tid'] in order.tid: return order.salaried = ifaces.SALARIED_FAILED order.tid = data['tid'] order.receipt = data['receipt']
def verify(self): # # Get Payment details # # Get order order = None tickets = is_context_ticket(self.context) skip_payment = False order_data = { "order_id": "", "total": "", "shipping": "", "currency": "", "tax": "", "ticket": tickets, "download_link": None, "verified": False } data = self.request.form ordernumber = data.get('orderID', '') if ordernumber: order_uid = IPaymentData(self.context).uid_for(ordernumber) if get_status_category(int(data['STATUS'])) != SUCCESS_STATUS: return order_data else: order_uid = data.get('order_uid', '') if order_uid: try: order = OrderData(self.context, uid=order_uid) except: order = None if order: if order.total > 0: return order_data else: skip_payment = True else: return order_data else: return order_data # # SHA passphrase verification # signer = OmnikassaSignature(data, 'sha512', SHA_OUT_PASSWORD) payment = Payments(self.context).get('omnikassa_payment') if not order: try: order = OrderData(self.context, uid=order_uid) except: order = None # Check if order exists if order_uid != None and order != None: order = OrderData(self.context, uid=order_uid) order_nr = order.order.attrs['ordernumber'] # Build order data order_data = { "ordernumber": str(order_nr), "order_id": str(order_uid), "total": str(order.total), "shipping": str(order.shipping), "currency": str(order.currency), "tax": str(order.vat), "ticket": tickets, "download_link": None, "verified": False, "already_sent":False, "bookings":json.dumps([]) } order_bookings = [] for booking in order.bookings: try: booking_uid = booking.attrs['buyable_uid'] item_number = booking.attrs['item_number'] if item_number: sku = str(item_number) else: sku = str(booking_uid) item_category = "Product" # Default category if tickets: item_category = "E-Ticket" order_bookings.append({ 'id':sku, 'price': str(float(booking.attrs['net'])), 'name': str(booking.attrs['title']), 'category': item_category, 'quantity': int(booking.attrs['buyable_count']), }) except: pass try: order_data['bookings'] = json.dumps(order_bookings) except: # Invalid JSON format order_data['bookings'] = json.dumps([]) if tickets: base_url = self.context.portal_url() params = "?order_id=%s" %(str(order_uid)) download_as_pdf_link = "%s/download_as_pdf?page_url=%s/tickets/etickets%s" %(base_url, base_url, params) order_data['download_link'] = download_as_pdf_link else: # Order doesn't exist in the database # return blank ticket order_data = { "order_id": "", "total": "", "shipping": "", "currency": "", "tax": "", "ticket": tickets, "download_link": None, "verified": False } return order_data shasign = data.get('SHASIGN', '') if shasign == signer.signature() or skip_payment: order_data['verified'] = True order = OrderData(self.context, uid=order_uid) order.salaried = ifaces.SALARIED_YES if order.order.attrs['email_sent'] != 'yes': order.order.attrs['email_sent'] = 'yes' orders_soup = get_orders_soup(self.context) order_record = order.order orders_soup.reindex(records=[order_record]) transaction.get().commit() if not skip_payment: payment.succeed(self.context, order_uid) return order_data else: return order_data else: payment.failed(self.context, order_uid) return order_data