Util Safe Donation Tracker

Discussion in 'Resources' started by elancha98, Sep 5, 2015.

Thread Status:
Not open for further replies.
  1. WHAT DONATOR SEES
    • Easy and ready to use donate button
      [​IMG]
    • Friendly interface to donate
      [​IMG]
    • Normal PayPal transaction
      [​IMG]
    WHAT USER HAVE TO DO
    1. Go to donation-tracker (http://www.donation-tracker.com/)
    2. Register yourself
    3. The tutorial will guide you (IMPORTANT: set your currency and your PayPal email)
    4. OPTIONAL: Change your profile image to your logo
    5. Go to dashboard
    6. Copy this link:
      [​IMG]
    7. On Twitch (or wherever you want to put the donation button) go to your channel page and hit edit panels:
      [​IMG]
    8. click on add:
      [​IMG]
    9. Fill the title, the image and the description (optional), and paste the copied link in the link tab.
      [​IMG]
    10. Hit submit and your donation button it's done:
    11. Now go back to donation-tracker (http://www.donation-tracker.com/dashboard)
    12. Copy the channel and API key fields:
      [​IMG]
    13. Paste them in the config file of the plugin (may be different depend on the plugin)
    WHAT DEVELOPERS HAVE TO DO
    Devs have to connect to this url: https://www.donation-tracker.com/api/?channel=XXXX&api_key=XXXX (replacing the first "XXXX" with the channel and the second ones with the api_key). Here's an example of the result accessing that url:
    Code:
    {
    
    "donations":[
      {
       "username":"test",
       "note":"This is a test to see if it is working",
       "timestamp":"1441443654",
       "amount":"20.00",
       "currency":"EUR",
       "currency_symbol":"\u20ac",
       "transaction_id":"DT-A8VOIE8LD",
       "paypal_email":"[email protected]"
      }
    ],
    "api_check":"1"
    }

    Basic Plugin Example

    Main class:

    Code:
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.lang.reflect.Type;
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.List;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitScheduler;
    
    import com.google.gson.Gson;
    import com.google.gson.reflect.TypeToken;
    
    public class Main extends JavaPlugin {
    
        // We load the config
        private String channel = this.getConfig().getString("channel");
        private String api_key = this.getConfig().getString("api_key");
        // initialize the needed arrays
        private ArrayList<Donation> donations = new ArrayList<Donation>();
        private ArrayList<Donation> temp = new ArrayList<Donation>();
    
        public void onEnable() {
    
            //We create a new repeating task to access web (we do every 5 seconds because faster our IP will be banned)
            BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
            scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
                @Override
                public void run() {
                    try {
                        // gets the donations from the web
                        URL url = new URL(
                                "https://www.donation-tracker.com/api/?channel=" + channel + "&api_key=" + api_key);
                        BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
                        String strTemp = "";
                        String str = "";
                        // stores the donations in a string
                        while (null != (strTemp = br.readLine())) {
                            str += strTemp;
                        }
                        // initializes Gson (a JSON Parser for Java)
                        Gson gson = new Gson();
                        // stores the donations got from the page
                        Type type = new TypeToken<List<Donation>>() {}.getType();
                        //But first store the past response (to compare)
                        temp = donations;
                       
                        donations = gson.fromJson(str, type);
    
                        // loops trough all elements
                        for (Donation d : donations) {
                            if (!temp.contains(d)) {
                                //and sends a message with new ones
                                Player p = Bukkit.getPlayer("your_player_name");
                                p.sendMessage(d.getUsername() + " has donated " + d.getAmount() + d.getCurrency_symbol());
                            }
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }, 0L, 100L);
        }
    }
    Donation class:
    Code:
    public class Donation {
    
    
        public String username;
        public String note;
        public int timestamp;
        public String amount;
        public String currency;
        public String currency_symbol;
        public String transaction_id;
        public String paypal_email;
        public String getUsername() {
            return username;
        }
        public void setUsername(String username) {
            this.username = username;
        }
        public String getNote() {
            return note;
        }
        public void setNote(String note) {
            this.note = note;
        }
        public String getAmount() {
            return amount;
        }
        public void setAmount(String amount) {
            this.amount = amount;
        }
        public String getCurrency_symbol() {
            return currency_symbol;
        }
        public void setCurrency_symbol(String currency_symbol) {
            this.currency_symbol = currency_symbol;
        }
       
       
    }
     
    Last edited: Sep 5, 2015
    jusjus112 likes this.
Thread Status:
Not open for further replies.

Share This Page