2424import  java .io .IOException ;
2525import  java .io .InputStream ;
2626import  java .math .BigInteger ;
27+ import  java .net .MalformedURLException ;
2728import  java .net .URISyntaxException ;
2829import  java .net .URL ;
2930import  java .util .ArrayList ;
5253import  com .google .common .annotations .VisibleForTesting ;
5354
5455import  de .bigamgamen .java .helper .IOHelper ;
56+ import  de .bigamgamen .java .helper .PaypalLinkGenerator ;
5557import  de .bigamgamen .java .telegrambots .hertlhendl .api .RightController ;
5658import  de .bigamgamen .java .telegrambots .hertlhendl .api .RoleController ;
5759import  de .bigamgamen .java .telegrambots .hertlhendl .builder .TelegramKeyBoardBuilder ;
@@ -84,6 +86,7 @@ public class HertlHendlBot extends AbilityBot
8486	public  static  final  String  ABILITY_NAME_ADMIN_CLOSE_ORDERS  = "admincloseorders" ;
8587	public  static  final  String  ABILITY_NAME_CLOSE_ORDER  = "closeorder" ;
8688	public  static  final  String  ABILITY_NAME_COMMIT_ORDER  = "commitorder" ;
89+ 	public  static  final  String  ABILITY_NAME_PAYPAL_LINK  = "paypallink" ;
8790
8891	private  static  final  String  MESSAGE_CLOSE_SUCCESSFULL  = "Die Bestellung wurde erfolgreich geschlossen." ;
8992	private  static  final  String  ALL_MESSAGE_CLOSE_SUCCESSFULL  =
@@ -98,6 +101,7 @@ public class HertlHendlBot extends AbilityBot
98101	private  final  static  String  BOT_TOKEN  = "" ;
99102	private  final  static  String  BOT_USERNAME  = "" ;
100103	private  final  static  String  ADMIN_DEFAULT_NAME  = "Admin" ;
104+ 
101105	private  static  Integer  CREATOR_ID  = 0 ;
102106	private  static  String  HERTL_URL  =
103107		"http://ks3266365.kimsufi.com:2341/?url=https://hertel-haehnchen.de/standplatzsuche?search=92637" ;
@@ -108,6 +112,10 @@ public class HertlHendlBot extends AbilityBot
108112	private  final  RoleController  roleController ;
109113	private  final  Long  creatorId ;
110114
115+ 	private  String  creatorPayPalEmail  ="" ;
116+ 	private  final  PaypalLinkGenerator  payPalGenerator  = new  PaypalLinkGenerator ();
117+ 	
118+ 	
111119	public  static  void  main (final  String [] args )
112120		throws  ParserConfigurationException , SAXException , IOException , URISyntaxException , TelegramApiException 
113121	{
@@ -116,13 +124,14 @@ public static void main(final String[] args)
116124		final  String  token  = args [0 ] != null  ? args [0 ] : BOT_TOKEN ;
117125		final  String  username  = args [1 ] != null  ? args [1 ] : BOT_USERNAME ;
118126		final  Long  creatorId  = args [2 ] != null  ? Long .valueOf (args [2 ]) : CREATOR_ID ;
119- 		final  HertlHendlBot  bot  = new  HertlHendlBot (token , username , creatorId );
127+ 		final  String  creatorPayPalEmail  = args [3 ] != null  ? args [3 ] : "" ;
128+ 		final  HertlHendlBot  bot  = new  HertlHendlBot (token , username , creatorId , creatorPayPalEmail );
120129		final  TelegramBotsApi  api  = new  TelegramBotsApi (DefaultBotSession .class );
121130		api .registerBot (bot );
122131		LOG .info ("HertlHendlBot successfull started" );
123132	}
124133
125- 	public  HertlHendlBot (final  String  botToken , final  String  botUsername , Long  creatorId )
134+ 	public  HertlHendlBot (final  String  botToken , final  String  botUsername , Long  creatorId ,  String   creatorPayPalEmail )
126135		throws  ParserConfigurationException , SAXException , IOException , URISyntaxException 
127136	{
128137		super (botToken , botUsername );
@@ -132,6 +141,7 @@ public HertlHendlBot(final String botToken, final String botUsername, Long creat
132141		this .rightController  = new  HertlRightController (creatorId );
133142		this .roleController  = new  HertlRoleController (this .rightController );
134143		this .creatorId  = creatorId ;
144+ 		this .creatorPayPalEmail  = creatorPayPalEmail ;
135145		this .initAdminUser ();
136146	}
137147
@@ -515,6 +525,41 @@ public Ability showLocationPhoto()
515525			}).build ();
516526	}
517527
528+ 	public  Ability  showPayPalLink ()
529+ 	{
530+ 		return  Ability .builder ().name (ABILITY_NAME_PAYPAL_LINK ).info ("PaypalLink" ).locality (
531+ 			ALL ).privacy (PUBLIC ).input (1 ).action (context  ->
532+ 			{
533+ 				//TOFDO nur mit Recht dazu 
534+ 				
535+ 				final  int  bestellId  = Integer .parseInt (context .firstArg ());
536+ 				final  Long  chatId  = context .chatId ();
537+ 				final  HertlBotOrder  bestellung  = hertlBotDao .loadBestellung (
538+ 					chatId ,
539+ 					TelegramHelper .getTotalUserName (context .user ()),
540+ 					bestellId );
541+ 				//TODO logik for closed Order 
542+ 				
543+ 				final  SendMessage  message  = new  SendMessage ();
544+ 				message .setChatId (Long .toString (context .chatId ()));
545+ 				try 
546+ 				{
547+ 					message .setText (this .payPalGenerator .generatePayPalLinkForOrder (bestellung , this .creatorPayPalEmail ).toString ());
548+ 					this .silent .execute (message );
549+ 				}
550+ 				catch (final  MalformedURLException  e )
551+ 				{
552+ 					e .printStackTrace ();
553+ 					LOG .error ("Fehler beim genieren PayPalLink:{}" , e );
554+ 				}
555+ 				
556+ 
557+ 				
558+ 
559+ 				
560+ 			}).build ();
561+ 	}
562+ 	
518563	private  void  sendPhotoFromUpload (final  InputStream  is , String  fileName , final  Long  chatId )
519564	{
520565		final  SendPhoto  sendPhotoRequest  = new  SendPhoto (); // 1 
@@ -534,7 +579,7 @@ private void sendPhotoFromUpload(final InputStream is, String fileName, final Lo
534579		}
535580		catch (final  TelegramApiException  e )
536581		{
537- 			e . printStackTrace ( );
582+ 			LOG . error ( "Fehler beim schicken des Photos:{}" ,  e );
538583		}
539584	}
540585
0 commit comments