I am trying to automate a Task for my Discord Server. The Task is that if someone donates me via paypal, my Discord bot should send a message and add the donator role to the discord user.
Well, I am currently trying to that using Paypal Webhooks, a webserver and an endpoint (using Spark).
Paypal can successfully send the webhook to my web-server from zap-hosting.com. But code wise, everything except the post request works out,
This is the code (I censored all private data):
package org.example;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;
import spark.Spark;
import spark.Spark.*;
public class Main{
private static JDABuilder jda;
public static void main(String[] args) {
jda = JDABuilder.createDefault("[Discord Token]");
jda.setStatus(OnlineStatus.ONLINE);
jda.setActivity(Activity.watching(" your bank account."));
jda.build();
webHookGathering webthread = new webHookGathering();
Thread thread = new Thread(webthread);
thread.start();
Spark.port(8443);
Spark.init();
Spark.awaitInitialization();
}
public static class webHookGathering extends Thread
{
@Override
public void run() {
while (true)
{
try {
System.out.println("Gathering Started");
Spark.post("https://[Adress].com", (request, response) -> {
String webhookData = request.body();
System.out.println(webhookData);
response.status(200);
return "Webhook erhalten!";
});
}
catch (Exception e)
{
e.printStackTrace();
}
try{
Thread.sleep(1000);
System.out.println("next");
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}
}
I created comments using sysout to see where my code gets and where not. This resulted that I was able to see that all the outputs are working except for the one in the post request.