Example #1
0
	def get(self, *args, **kwargs):
		nomtien = kwargs['nom_tien']
		token=self.request.get('token') # EC-60U79048BN7719609&
		if not self.session or not self.session.has_key("ec_token") or not self.session.get("ec_token") == token:
			self.response.out.write(u"mal en cancelurlHandler url no hay session, token=%s,payerid=%s" % token)
			return
		regtra=todosmodelos.Transferencia.query(todosmodelos.Transferencia.token_ec==token).get()
		if not regtra:
			self.response.out.write(u"mal en cancelurlhandler url no hay registro transferencia , token=%s" % token)
			return
		tienda,tikey=utils.getMemTiendaMulti(nomtien)
		"""nomtien=nomtien.upper()
		tienda=memcache.get(nomtien+"tienda")
		tikey=memcache.get(nomtien+"key")"""
		if not tienda:
			tien=regtra.tienda.get()
			if tien:
				tienda=utils.getTienda(tien,utils.getSegundos())
				tikey=tien.key
			else:
				tien=ti=todosmodelos.Tienda.query(todosmodelos.Tienda.nombreupper==nomtien).get()
				if tien:
					tienda=utils.getTienda(tien,utils.getSegundos())
					tikey=tien.key
				else:
					self.response.out.write(u"no puedo llamar a tienda cancelurlhandler, token=%s" % token)
					return
		tienda["paypal"]["modo"]= regtra.modo
		pay=tokenPay(tienda,tikey)
		if not pay.getPaypalToken():
			self.response.out.write(u"%s, token=%s" % (pay.error,token))
			return
		
		#GET /v1/payments/payment/{paymentId}
		try:
			result = urlfetch.fetch(url=pay.url_execute + regtra.id_payment,
					    method=urlfetch.GET,
					    headers={
					    "Authorization": ("Bearer %s" % pay.tienda["paypal"]["access_token"]),
	                	"Content-Type": "application/json"
						},validate_certificate=False)
		except Exception as e:
			self.response.out.write(u"exception en hacerPayment: %s" % e.message)
			return
		if result.status_code == 200:
			respujson=json.loads(result.content)
			if respujson.has_key("state") and respujson["state"] == "canceled":
				regtra.response_lookup=respujson
				regtra.estado="canceled"
				regtra.put()
				self.response.out.write("ok en cancelurlhandler lookup status 200 content = %s <br> y <p>regtra._id_pay=%s </p>,<p> <br> pay.tienda.acces_token=%s </p>, <p> token=%s </p>" % (respujson,regtra.id_payment, pay.tienda["paypal"]["access_token"],token))
			else:
				self.response.out.write("no state aprobado en return url %s <br> y <p>regtra._id_pay=%s </p>, <p> <br> pay.tienda.acces_token=%s </p>, <p> token=%s </p>" % (respujson,regtra.id_payment,pay.tienda["paypal"]["access_token"],token))
		else:
			self.response.out.write(u"mal en cancelurlhandler lookup paymen status_code %d = %s ,<p> content = %s</p>, token=%s, access_token=%s" % (result.status_code,pay.error_status_code(result),result.content,token,pay.tienda["paypal"]["access_token"]))
Example #2
0
	def get(self, *args, **kwargs):
		nomtien = kwargs['nom_tien']
		token=self.request.get('token') 
		PayerID=self.request.get('PayerID')
		if not self.session or not self.session.has_key("ec_token") or not self.session.get("ec_token") == token:
			self.response.out.write(u"mal en returnpayapl url no hay session, token=%s,payerid=%s" % (token,PayerID))
			return
		regtra=todosmodelos.Transferencia.query(todosmodelos.Transferencia.token_ec==token).get()
		if not regtra:
			self.response.out.write(u"mal en returnpayapl url no hay registro transferencia , token=%s,payerid=%s" % (token,PayerID))
			return
		tienda,tikey=utils.getMemTiendaMulti(nomtien)
		"""nomtien=nomtien.upper()
		tienda=memcache.get(nomtien+"tienda")
		tikey=memcache.get(nomtien+"key")"""
		if not tienda:
			tien=regtra.tienda.get()
			if tien:
				tienda=utils.getTienda(tien,utils.getSegundos())
				tikey=tien.key
			else:
				tien=todosmodelos.Tienda.query(todosmodelos.Tienda.nombreupper==nomtien).get()
				if tien:
					tienda=utils.getTienda(tien,utils.getSegundos())
					tikey=tien.key
				else:
					self.response.out.write(u"no puedo llamar a tienda , token=%s,payerid=%s" % (token,PayerID))
					return

		tienda["paypal"]["modo"]= regtra.modo
		pay=tokenPay(tienda,tikey)
		if not pay.getPaypalToken():
			self.response.out.write(u"%s, token=%s,payerid=%s" % (pay.error,token,PayerID))
			return
		vaex={
			"payer_id":PayerID
		}
		try:
			#Create a payment by constructing a payment object using access token.
			result = urlfetch.fetch(url=pay.url_execute + regtra.id_payment+"/execute/",
					    payload=json.dumps(vaex),
					    method=urlfetch.POST,
					    headers={
					    "Authorization": ("Bearer %s" % pay.tienda["paypal"]["access_token"]),
	                	"Content-Type": "application/json"
						},validate_certificate=False)
		except Exception as e:
			self.response.out.write(u"exception en hacerPayment: %s" % e.message)
			return
		if result.status_code == 200:
			respujson=json.loads(result.content)
			if respujson.has_key("state") and respujson["state"] == "approved":
				regtra.response_executed=respujson
				regtra.estado="approved"
				resp=self.env_pago_grab_pedido(2,tikey,regtra)
				if resp[0]:
					regtra.reg_pedido=resp[1]
					self.session["ec_token"]=None
					self.session["pedido"]=None
					self.session.pop('pedido')
					self.session.pop('ec_token')
					self.response.out.write("ok seha enviado y grabado el pedido, en execute status 200 content = %s <br> y <p>regtra._id_pay=%s </p>, <p> PayerID=%s </p>,<p> <br> pay.tienda.acces_token=%s </p>, <p> token=%s </p>" % (respujson,regtra.id_payment, PayerID,pay.tienda["paypal"]["access_token"],token))
				else:
					self.response.out.write("error respuesta al enviar y grabar=%s, ok en execute status 200 content = %s <br> y <p>regtra._id_pay=%s </p>, <p> PayerID=%s </p>,<p> <br> pay.tienda.acces_token=%s </p>, <p> token=%s </p>" % (resp[1],respujson,regtra.id_payment, PayerID,pay.tienda["paypal"]["access_token"],token))
				regtra.put()
				return
				#hay que hacer llamada a tienda pasando los datos y que nos de el numero de pedido int(resto["numped"])
				#ahora lo hacemos asi 
				numped=1
				#grabar pedido
				pedido=regtra.pedido
				datped=pedido["datped"]
				detalle=json.loads(pedido["detallemio"])
				
				lisdet=[]
				for d in detalle:
					try:
						if d["oferta"]:
							lisdet.append(todosmodelos.Detalle(articulo=d["articulo"],det=d["det"],ofertaid=d["oferta"]["idofer"],ofertadet=d["oferta"],preart=d["oferta"]["precio"]))
						else:
							lisdet.append(todosmodelos.Detalle(articulo=d["articulo"],det=d["det"],preart=d["preart"]))
					except Exception as e:
						self.response.out.write("Exception en for detalle status 200 content = %s <br> y <p>regtra._id_pay=%s </p>, <p> PayerID=%s </p>,<p> <br> pay.tienda.acces_token=%s </p>, <p> token=%s </p><p> detalle pedido=%s</p> mensage exception=%s" % (respujson,regtra.id_payment, PayerID,pay.tienda["paypal"]["access_token"],token,json.dumps(detalle),e.message))
						return
				if datped["pedidoen"]>1:
					canom=todosmodelos.CalleNom(nom=datped["callenom"]["nom"],via=datped["callenom"]["via"],num=datped["callenom"]["num"],bloq=datped["callenom"]["bloq"],piso=datped["callenom"]["piso"],esca=datped["callenom"]["esca"],letra=datped["callenom"]["letra"],muni=datped["callenom"]["muni"])
				else:
					canom=None
				kcli=None
				if self.session.get('cliente'):
					kcli=self.session.get('cliente')

				ped=todosmodelos.Pedido(parent=tikey,pedidoen=datped["pedidoen"],cliente=kcli,numped=numped,telefono=datped["telefono"],callenom=canom,importe=datped["importe"],horapedido=datped["horaped"],horaent=datped["horaent"],comen=datped["comen"],detalle=lisdet,suplemento=regtra.suplemento,pago=2,regpago=regtra.key)
				okped=ped.put()
				regtra.response_executed=respujson
				regtra.estado="approved"
				txtped="No se ha grabado pedido"
				if okped:
					txtped="se ha grabado pedido"
					regtra.reg_pedido=okped
					if kcli:
						kcli.get()
						nped=kcli.numpedidos+1
						kcli.populate(ultimopedido=datped["horaped"],numpedidos=nped)
						kcli.put()
						txtped="se ha grabado pedido y se ha grabado cliente"
				regtra.put()
				self.response.out.write("ok en execute status 200 content = %s <br> y <p>regtra._id_pay=%s </p>, <p> PayerID=%s </p>,<p> <br> pay.tienda.acces_token=%s </p>, <p> token=%s </p><p> grabado=%s" % (respujson,regtra.id_payment, PayerID,pay.tienda["paypal"]["access_token"],token,txtped))
			else:
				self.response.out.write("no state aprobado en return url %s <br> y <p>egtra._id_pay=%s </p>, <p> PayerID=%s </p>,<p> <br> pay.tienda.acces_token=%s </p>, <p> token=%s </p>" % (respujson,regtra.id_payment, PayerID,pay.tienda["paypal"]["access_token"],token))
			#self.datadopay=json.loads(result.content)
		else:
			self.response.out.write(u"mal en execute paymen status_code %d = %s, content = %s, token=%s, memtoken=%s,payerid=%s" % (result.status_code,pay.error_status_code(result),result.content,token, memcache.get("access_token"),PayerID))
Example #3
0
def list_json(nomtikey,graurl,ulm):
	ti = nomtikey.get()
	if not ti: 
		return None
	tienda=utils.getTienda(ti,utils.getSegundos(),graurl)
	if ulm == tienda["ult_mod"]:
		return {"ok":"ok","tienda":tienda}
		
	ancestor_key=todosmodelos.ndb.Key(ti.key.kind(),ti.key.id(),todosmodelos.Pizzaespe,"pizza")
	masasQry = todosmodelos.Masa.query(ancestor=ancestor_key).order(todosmodelos.Masa.nombre)
	tamasQry =  todosmodelos.Tamano.query(ancestor=ancestor_key).order(todosmodelos.Tamano.nombre)
	mataQry =  todosmodelos.MasaTama.query(ancestor=ancestor_key)
	ingQry = todosmodelos.Ingredientes.query(ancestor=ancestor_key).order(todosmodelos.Ingredientes.nombre)
	salQry =  todosmodelos.Salsas.query(ancestor=ancestor_key).order(todosmodelos.Salsas.nombre)
	pizQry=todosmodelos.Pizzaespe.query(ancestor=ancestor_key).order(todosmodelos.Pizzaespe.grupo)
	lisma=[[i.key.id(),i.nombre,i.descrip] for i in masasQry]
	listam=[[i.key.id(),i.nombre,i.num_personas] for i in tamasQry] #if i.key.parent() == ancestor_key
	lismatas=[[i.key.id(),i.masa,i.tama,i.preciobase,i.precioing] for i in mataQry]
	lising=[[i.key.id(),i.nombre,i.valor] for i in ingQry]
	lissal=[[i.key.id(),i.nombre,i.valor] for i in salQry]
	lispiz=[[i.key.id(),i.nombre,i.descrip,i.salsa,i.queso,i.ingres,i.masas,i.apartir_numing_cobrar,i.grupo] for i in pizQry]
	ancestor_key= ti.key
	otrosQry = todosmodelos.Otros.query(ancestor=ancestor_key).order(todosmodelos.Otros.nombre)
	lisotr=[]
	jsuotr={}
	for i in otrosQry:
		id=i.key.id()
		lisotr.append([id,i.nombre,i.descrip])
		uoQry=todosmodelos.UnOtros.query(ancestor=i.key).order(todosmodelos.UnOtros.grupo)
		jsuotr[str(id)]=[(u.key.id(),u.nombre,u.descrip,u.precio,u.grupo) for u in uoQry]

	otrosQryx = todosmodelos.Otrosx.query(ancestor=ancestor_key).order(todosmodelos.Otrosx.nombre)
	lisotrx=[]
	jssalx={}
	jsingx={}
	jstamx={}
	jsuotrx={}
	for i in otrosQryx:
		id=str(i.key.id())
		if len(i.nomsalsa)>0:
			haysal=i.nomsalsa
			usal=todosmodelos.Salsas.query(ancestor=i.key).order(todosmodelos.Salsas.nombre)
			jssalx[id]=[[u.key.id(),u.nombre,u.valor] for u in usal]
		else:
			haysal="No"
		#lisotrx.append([int(id),i.nombre,i.descrip,haysal,[i.tama.nombre,"precio base:",i.tama.preba,"precio ing:",i.tama.preing]])
		lisotrx.append([int(id),i.nombre,i.descrip,haysal,[i.tama.nombre,i.tama.preba,i.tama.preing]])
		uing=todosmodelos.Ingredientes.query(ancestor=i.key).order(todosmodelos.Ingredientes.nombre)
		jsingx[id]=[[u.key.id(),u.nombre,u.valor] for u in uing]
		if i.tama.nombre=='Varios':
			utam=todosmodelos.Tamax.query(ancestor=i.key).order(todosmodelos.Tamax.nombre)
			jstamx[id]=[[u.key.id(),u.nombre,u.preba,u.preing] for u in utam]
		uoQry=todosmodelos.UnOtrosx.query(ancestor=i.key).order(todosmodelos.UnOtrosx.nombre)
		jsuotrx[id]=[(u.key.id(),u.nombre,u.descrip,u.salsa,u.ingres) for u in uoQry]
	hoy=datetime.datetime.now()
	hoy2=datetime.date(hoy.year,hoy.month,hoy.day)
	oferQry = todosmodelos.Oferta.query(todosmodelos.Oferta.fechas >= hoy2,ancestor=ancestor_key)
	#.order(todosmodelos.Oferta.grupo)
	lisofr=[]
	for i in oferQry:
		if i.fecdes <= hoy2:
			uoQry=todosmodelos.ofertadetalle.query(ancestor=i.key)
			mispro=[]
			for p in uoQry:
				if p.eurosoporcen:
					eupo=0
				else:
					eupo=1
				if p.tipoproducto==0:
					pro={
						"custom": { "acc":p.numofer, "dp":eupo, "de":p.descuento},
						"artis":p.idtipo,
						"tp":0,
						"tamas":p.tama,
						"masas":p.masa,
						"ingres":{ "condiing":p.condiing,"numing":p.numing }
					}
				elif p.tipoproducto==1:
					pro={
						"custom": { "acc":p.numofer, "cantidad":p.cantidad,"dp":eupo, "de":p.descuento},
						"artis":p.idtipo,
						"tp":1,
						"idp":p.idp
					}
				else:
					pro={
						"custom": { "acc":p.numofer, "dp":eupo, "de":p.descuento},
						"artis":p.idtipo,
						"tp":2,
						"idp":p.idp,
						"ingres":{ "condiing":p.condiing,"numing":p.numing },
						"tamas":p.tama
					}
				pro["nid"]=p.key.id()
				mispro.append(pro)
			lisofr.append([i.key.id(),i.nombre,i.descrip,i.fecdes.strftime("%d/%m/%Y"),i.fechas.strftime("%d/%m/%Y"),i.horde.strftime("%H:%M"),i.horh.strftime("%H:%M"),i.dias,i.localodomi,i.ofertaenart,i.numofer,i.preciofijo,i.descuento,i.eurosoporcen,i.increm,i.numproduc,i.grupo,mispro])
	lisofr.sort(key=lambda kv: kv[16])
	#clake=nomti+"key"
	memnomti={"ok":"ok","masas":lisma,"tamas":listam,"matas":lismatas,"ingres":lising,"sal":lissal,"piz":lispiz,"otros":lisotr,"unotros":jsuotr,"otrosx":lisotrx,"unotrosx":jsuotrx,"salsasx":jssalx,"ingresx":jsingx,"tamax":jstamx,"ofer":lisofr,"tienda":tienda}
	#memcache.set_multi({clake:ti.key,nomti:memnomti},time=segundos())
	#memcache.delete(nomti+"haymodi")
	#memcache.set(nomti+"key",ti.key,time=segundos)
	#memcache.set(nomti,{"ok":"ok","masas":lisma,"tamas":listam,"matas":lismatas,"ingres":lising,"sal":lissal,"piz":lispiz,"otros":lisotr,"unotros":jsuotr,"otrosx":lisotrx,"unotrosx":jsuotrx,"salsasx":jssalx,"ingresx":jsingx,"tamax":jstamx,"ofer":lisofr,"tien":tien},time=segundos)
#elif not memnomti["tienda"]["act"]:
#	return None
#elif not memnomti["tienda"]["url"] == graurl:
#	memnomti["tienda"]["url"]=graurl
#	memcache.set(nomti,memnomti,time=segundos())
		
	return memnomti