diff --git a/src/main/java/org/toco/entity/logging_entity.java b/src/main/java/org/toco/entity/logging_entity.java
index 42d74af0bece40117980ab3979432a2e39b8bb5b..5189ceb8cfa62e0c45c170193ac950f327e3856c 100644
--- a/src/main/java/org/toco/entity/logging_entity.java
+++ b/src/main/java/org/toco/entity/logging_entity.java
@@ -1,4 +1,5 @@
 package org.toco.entity;
+
 import lombok.Data;
 
 @Data
@@ -13,5 +14,3 @@ public class logging_entity {
         this.endpoint = endpoint;
     }
 }
-
-
diff --git a/src/main/java/org/toco/entity/transaction_entity.java b/src/main/java/org/toco/entity/transaction_entity.java
index 4198368960373d1a7873f04cfe5e710250c31fce..56e5da1457b7262b11f0f7b99de2ba5583aa44c2 100644
--- a/src/main/java/org/toco/entity/transaction_entity.java
+++ b/src/main/java/org/toco/entity/transaction_entity.java
@@ -1,4 +1,5 @@
 package org.toco.entity;
+
 import lombok.Data;
 
 @Data
diff --git a/src/main/java/org/toco/entity/userGems_Entity.java b/src/main/java/org/toco/entity/userGems_Entity.java
index 1531fff172affd40bf26adb26b6cc3d8c5744ea9..7efb18ba482f90e7ab35765c8e8600214ea5e9fa 100644
--- a/src/main/java/org/toco/entity/userGems_Entity.java
+++ b/src/main/java/org/toco/entity/userGems_Entity.java
@@ -1,4 +1,5 @@
 package org.toco.entity;
+
 import lombok.Data;
 
 @Data
@@ -7,7 +8,7 @@ public class userGems_Entity {
     private Integer gem;
 
     public userGems_Entity(Integer user_id, Integer gem) {
-        this.user_id=user_id;
+        this.user_id = user_id;
         this.gem = gem;
     }
 }
diff --git a/src/main/java/org/toco/entity/voucher_entity.java b/src/main/java/org/toco/entity/voucher_entity.java
index ddedd43106da4dc369531b8c619e9b76d169f0cd..54d881dae17db628fea3ea6a609922c5eb6675a0 100644
--- a/src/main/java/org/toco/entity/voucher_entity.java
+++ b/src/main/java/org/toco/entity/voucher_entity.java
@@ -1,4 +1,5 @@
 package org.toco.entity;
+
 import lombok.Data;
 
 @Data
diff --git a/src/main/java/org/toco/model/api_model.java b/src/main/java/org/toco/model/api_model.java
index aefb8661c826e78a16424609ebf8cd664d0f29e7..1c2227fad48f3616069e584eaab3f2b9fb3a9ca1 100644
--- a/src/main/java/org/toco/model/api_model.java
+++ b/src/main/java/org/toco/model/api_model.java
@@ -7,16 +7,15 @@ import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
 public class api_model {
-    public Boolean checkApiKey (String apikey){
+    public Boolean checkApiKey(String apikey) {
         String sql = "select * from api where api_key = (?)";
-        try (Connection connection = connector.connect() ;
-             PreparedStatement command = connection.prepareStatement(sql)) {
+        try (Connection connection = connector.connect();
+                PreparedStatement command = connection.prepareStatement(sql)) {
             command.setString(1, apikey);
             command.execute();
-            if(command.getResultSet().next()){
+            if (command.getResultSet().next()) {
                 return true;
-            }
-            else{
+            } else {
                 return false;
             }
         } catch (SQLException exception) {
diff --git a/src/main/java/org/toco/model/logging_model.java b/src/main/java/org/toco/model/logging_model.java
index 0fe9ea8b2f4f17eaafca9d935fb55efe3379c275..7371c7951657a454eb0ce2aa0a9997b25470ff32 100644
--- a/src/main/java/org/toco/model/logging_model.java
+++ b/src/main/java/org/toco/model/logging_model.java
@@ -4,11 +4,12 @@ import java.sql.*;
 
 import org.toco.core.connector;
 import org.toco.entity.logging_entity;
+
 public class logging_model {
-    public void insert (logging_entity logging_entity) {
+    public void insert(logging_entity logging_entity) {
         String sql = "INSERT INTO logging (description, IP, endpoint) VALUES (?, ?, ?)";
-        try (Connection connection = connector.connect() ;
-             PreparedStatement command = connection.prepareStatement(sql)) {
+        try (Connection connection = connector.connect();
+                PreparedStatement command = connection.prepareStatement(sql)) {
             command.setString(1, logging_entity.getDescription());
             command.setString(2, logging_entity.getIP());
             command.setString(3, logging_entity.getEndpoint());
diff --git a/src/main/java/org/toco/model/transaction_model.java b/src/main/java/org/toco/model/transaction_model.java
index f7002a2a7687dec908e550f4b4057c3a28711759..a24b20165e48e51fc837c4300a0769fd521c00e7 100644
--- a/src/main/java/org/toco/model/transaction_model.java
+++ b/src/main/java/org/toco/model/transaction_model.java
@@ -1,15 +1,16 @@
 package org.toco.model;
+
 import java.sql.*;
 
 import org.toco.core.connector;
 import org.toco.entity.transaction_entity;
 
 public class transaction_model {
-//    insert a transaction
-    public void insert (transaction_entity transaction_entity) {
+    // insert a transaction
+    public void insert(transaction_entity transaction_entity) {
         String sqltrans = "INSERT INTO transaction (user_id, amount, image, status) VALUES (?, ?, ?, ?)";
-        try (Connection connection = connector.connect() ;
-             PreparedStatement command = connection.prepareStatement(sqltrans)) {
+        try (Connection connection = connector.connect();
+                PreparedStatement command = connection.prepareStatement(sqltrans)) {
             command.setInt(1, transaction_entity.getUser_id());
             command.setInt(2, transaction_entity.getAmount());
             command.setString(3, transaction_entity.getImage());
@@ -19,18 +20,20 @@ public class transaction_model {
             throw new RuntimeException("Error when inserting", exception);
         }
     }
-//    GET TRANSACTION a user does return in transaction_entity array
-    public transaction_entity[] getTransaction(Integer user_id){
+
+    // GET TRANSACTION a user does return in transaction_entity array
+    public transaction_entity[] getTransaction(Integer user_id) {
         String sql = "select * from transaction where user_id = (?) order by tid desc";
-        try (Connection connection = connector.connect() ;
-             PreparedStatement command = connection.prepareStatement(sql)) {
+        try (Connection connection = connector.connect();
+                PreparedStatement command = connection.prepareStatement(sql)) {
             command.setInt(1, user_id);
             command.execute();
             ResultSet rs = command.getResultSet();
             transaction_entity[] transactions = new transaction_entity[getTransactionCount(user_id)];
             int i = 0;
-            while(rs.next()){
-                transactions[i] = new transaction_entity(rs.getInt(2), rs.getInt(3), rs.getString(4), rs.getString(5), rs.getString(6));
+            while (rs.next()) {
+                transactions[i] = new transaction_entity(rs.getInt(2), rs.getInt(3), rs.getString(4), rs.getString(5),
+                        rs.getString(6));
                 i++;
             }
             return transactions;
@@ -39,11 +42,11 @@ public class transaction_model {
         }
     }
 
-//    get transaction count by a user
-    public Integer getTransactionCount(Integer user_id){
+    // get transaction count by a user
+    public Integer getTransactionCount(Integer user_id) {
         String sql = "select count(*) from transaction where user_id = (?)";
-        try (Connection connection = connector.connect() ;
-             PreparedStatement command = connection.prepareStatement(sql)) {
+        try (Connection connection = connector.connect();
+                PreparedStatement command = connection.prepareStatement(sql)) {
             command.setInt(1, user_id);
             command.execute();
             ResultSet rs = command.getResultSet();
diff --git a/src/main/java/org/toco/model/userGems_model.java b/src/main/java/org/toco/model/userGems_model.java
index 9e3e3fafb2faa850d6f9aca5e44868586a730770..7f232e47f04b6abd0cac56e551615dbaf2cdeee1 100644
--- a/src/main/java/org/toco/model/userGems_model.java
+++ b/src/main/java/org/toco/model/userGems_model.java
@@ -1,13 +1,15 @@
 package org.toco.model;
+
 import java.sql.*;
 
 import org.toco.core.connector;
 import org.toco.entity.userGems_Entity;
+
 public class userGems_model {
-    public void insert (userGems_Entity userGems) {
+    public void insert(userGems_Entity userGems) {
         String sql = "INSERT INTO userGems (user_id, gem) VALUES (?, ?)";
-        try (Connection connection = connector.connect() ;
-             PreparedStatement command = connection.prepareStatement(sql)) {
+        try (Connection connection = connector.connect();
+                PreparedStatement command = connection.prepareStatement(sql)) {
             command.setInt(1, userGems.getUser_id());
             command.setInt(2, userGems.getGem());
             command.execute();
@@ -15,10 +17,11 @@ public class userGems_model {
             throw new RuntimeException("Error when inserting", exception);
         }
     }
-    public void update (userGems_Entity userGems){
+
+    public void update(userGems_Entity userGems) {
         String sql = "update userGems set gem = (?) where user_id = (?)";
-        try (Connection connection = connector.connect() ;
-             PreparedStatement command = connection.prepareStatement(sql)) {
+        try (Connection connection = connector.connect();
+                PreparedStatement command = connection.prepareStatement(sql)) {
             command.setInt(1, userGems.getGem());
             command.setInt(2, userGems.getUser_id());
             command.execute();
@@ -27,35 +30,36 @@ public class userGems_model {
         }
 
     }
-    public Integer getUserGems(Integer user_id){
+
+    public Integer getUserGems(Integer user_id) {
         String sql = "select gem from userGems where user_id = (?)";
-        try (Connection connection = connector.connect() ;
-             PreparedStatement command = connection.prepareStatement(sql)) {
+        try (Connection connection = connector.connect();
+                PreparedStatement command = connection.prepareStatement(sql)) {
             command.setInt(1, user_id);
             command.execute();
             ResultSet rs = command.getResultSet();
             if (rs.next()) {
                 return rs.getInt(1);
-            }
-            else{
+            } else {
                 return 0;
             }
         } catch (SQLException exception) {
             throw new RuntimeException("Error when getting gem", exception);
         }
     }
-//    create a function to check if a user is on the userGems table or not return boolean
-    public boolean checkUser(Integer user_id){
+
+    // create a function to check if a user is on the userGems table or not return
+    // boolean
+    public boolean checkUser(Integer user_id) {
         String sql = "select * from userGems where user_id = (?)";
-        try (Connection connection = connector.connect() ;
-             PreparedStatement command = connection.prepareStatement(sql)) {
+        try (Connection connection = connector.connect();
+                PreparedStatement command = connection.prepareStatement(sql)) {
             command.setInt(1, user_id);
             command.execute();
             ResultSet rs = command.getResultSet();
-            if(rs.next()){
+            if (rs.next()) {
                 return true;
-            }
-            else{
+            } else {
                 return false;
             }
         } catch (SQLException exception) {
diff --git a/src/main/java/org/toco/model/voucher_model.java b/src/main/java/org/toco/model/voucher_model.java
index d6935abb2a3eac3e75c89836251be651ee19cc57..bf4e3b25b836543286ad493def75f1e2667a29dc 100644
--- a/src/main/java/org/toco/model/voucher_model.java
+++ b/src/main/java/org/toco/model/voucher_model.java
@@ -6,10 +6,10 @@ import org.toco.core.connector;
 import org.toco.entity.voucher_entity;
 
 public class voucher_model {
-    public void insert (voucher_entity voucher_entity) {
+    public void insert(voucher_entity voucher_entity) {
         String sql = "INSERT INTO voucher_record (code, user_id, amount) VALUES (?, ?, ?)";
-        try (Connection connection = connector.connect() ;
-             PreparedStatement command = connection.prepareStatement(sql)) {
+        try (Connection connection = connector.connect();
+                PreparedStatement command = connection.prepareStatement(sql)) {
             command.setString(1, voucher_entity.getCode());
             command.setInt(2, voucher_entity.getUser_id());
             command.setInt(3, voucher_entity.getAmount());
@@ -19,15 +19,16 @@ public class voucher_model {
         }
     }
 
-    public voucher_entity [] getAllVouchers () {
+    public voucher_entity[] getAllVouchers() {
         String sql = "SELECT * FROM voucher_record";
-        try (Connection connection = connector.connect() ;
-             PreparedStatement command = connection.prepareStatement(sql)) {
+        try (Connection connection = connector.connect();
+                PreparedStatement command = connection.prepareStatement(sql)) {
             ResultSet result = command.executeQuery();
-            voucher_entity [] voucher_entity = new voucher_entity[getAllCount()];
+            voucher_entity[] voucher_entity = new voucher_entity[getAllCount()];
             int i = 0;
             while (result.next()) {
-                voucher_entity[i] = new voucher_entity(result.getString("code"), result.getInt("user_id"), result.getInt("amount"), result.getString("timestamp"));
+                voucher_entity[i] = new voucher_entity(result.getString("code"), result.getInt("user_id"),
+                        result.getInt("amount"), result.getString("timestamp"));
                 i++;
             }
             return voucher_entity;
@@ -36,16 +37,17 @@ public class voucher_model {
         }
     }
 
-    public voucher_entity[] getSpecifiedVoucher(String code){
+    public voucher_entity[] getSpecifiedVoucher(String code) {
         String sql = "SELECT * FROM voucher_record WHERE code = ?";
-        try (Connection connection = connector.connect() ;
-             PreparedStatement command = connection.prepareStatement(sql)) {
+        try (Connection connection = connector.connect();
+                PreparedStatement command = connection.prepareStatement(sql)) {
             command.setString(1, code);
             ResultSet result = command.executeQuery();
-            voucher_entity [] voucher_entity = new voucher_entity[getSpecifiedCount(code)];
+            voucher_entity[] voucher_entity = new voucher_entity[getSpecifiedCount(code)];
             int i = 0;
             while (result.next()) {
-                voucher_entity[i] = new voucher_entity(result.getString("code"), result.getInt("user_id"), result.getInt("amount"),result.getString("timestamp"));
+                voucher_entity[i] = new voucher_entity(result.getString("code"), result.getInt("user_id"),
+                        result.getInt("amount"), result.getString("timestamp"));
                 i++;
             }
             return voucher_entity;
@@ -54,16 +56,15 @@ public class voucher_model {
         }
     }
 
-    public Integer getSpecifiedCount(String code){
+    public Integer getSpecifiedCount(String code) {
         String sql = "SELECT COUNT(*) FROM voucher_record WHERE code = ?";
-        try (Connection connection = connector.connect() ;
-             PreparedStatement command = connection.prepareStatement(sql)) {
+        try (Connection connection = connector.connect();
+                PreparedStatement command = connection.prepareStatement(sql)) {
             command.setString(1, code);
             ResultSet result = command.executeQuery();
             if (result.next()) {
                 return result.getInt(1);
-            }
-            else{
+            } else {
                 return 0;
             }
         } catch (SQLException exception) {
@@ -71,15 +72,14 @@ public class voucher_model {
         }
     }
 
-    public Integer getAllCount(){
+    public Integer getAllCount() {
         String sql = "SELECT COUNT(*) FROM voucher_record";
-        try (Connection connection = connector.connect() ;
-             PreparedStatement command = connection.prepareStatement(sql)) {
+        try (Connection connection = connector.connect();
+                PreparedStatement command = connection.prepareStatement(sql)) {
             ResultSet result = command.executeQuery();
             if (result.next()) {
                 return result.getInt(1);
-            }
-            else{
+            } else {
                 return 0;
             }
         } catch (SQLException exception) {
@@ -87,11 +87,21 @@ public class voucher_model {
         }
     }
 
-
-
-
-
-
-
+    public boolean isVoucherAlreadyRedeemed(String voucherCode, int userId) {
+        String sql = "SELECT COUNT(*) FROM voucher_record WHERE code = ? AND user_id = ?";
+        try (Connection connection = connector.connect();
+                PreparedStatement command = connection.prepareStatement(sql)) {
+            command.setString(1, voucherCode);
+            command.setInt(2, userId);
+            ResultSet result = command.executeQuery();
+            if (result.next()) {
+                return result.getInt(1) > 0;
+            } else {
+                return false;
+            }
+        } catch (SQLException exception) {
+            throw new RuntimeException("Error when checking voucher redemption", exception);
+        }
+    }
 
 }
diff --git a/src/main/java/org/toco/service/logging.java b/src/main/java/org/toco/service/logging.java
index 8c4f6f6fb244d5d484f7760f1fca75da8e8a3a6c..9b5c6183d9e57952bfe5c8be3fc34896682906d8 100644
--- a/src/main/java/org/toco/service/logging.java
+++ b/src/main/java/org/toco/service/logging.java
@@ -3,7 +3,6 @@ package org.toco.service;
 import org.toco.entity.logging_entity;
 import org.toco.model.logging_model;
 
-
 public class logging {
     public void addLogging(String description, String IP, String endpoint) {
         logging_entity logging = new logging_entity(description, IP, endpoint);
diff --git a/src/main/java/org/toco/service/mail.java b/src/main/java/org/toco/service/mail.java
index 8314229046772ec155814a312a760bf8bbc2f1b7..98c9284260aa04b88e43aad9ffbd64b1be46fe0e 100644
--- a/src/main/java/org/toco/service/mail.java
+++ b/src/main/java/org/toco/service/mail.java
@@ -9,7 +9,6 @@ import javax.mail.Transport;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeMessage;
 
-
 public class mail {
     public static void sendMail(String email, String body) {
         // Sender's email address and password
@@ -53,15 +52,16 @@ public class mail {
             // Now set the actual message
             message.setContent(
                     "<h1>Thank You for Your Purchase!</h1>\n" +
-                            "    <p>We appreciate your recent purchase of our merchandise. Your support means the world to us!</p>\n" +
+                            "    <p>We appreciate your recent purchase of our merchandise. Your support means the world to us!</p>\n"
+                            +
                             "    <p>" + body + "</p>\n" +
-                            "    <p>If you have any questions or concerns regarding your order, feel free to reply to this email and we'll be in contact ASAP.</p>\n" +
+                            "    <p>If you have any questions or concerns regarding your order, feel free to reply to this email and we'll be in contact ASAP.</p>\n"
+                            +
                             "    <p>Thank you again for choosing toco to be your partner in studying language!</p>\n" +
                             "    <p>Best regards,</p>\n" +
                             "    <p>Toco Team</p>\n" +
-                            "    <a href=\"http://localhost:8008\" class=\"button\">Visit Our Website</a>"
-                    , "text/html"
-            );
+                            "    <a href=\"http://localhost:8008\" class=\"button\">Visit Our Website</a>",
+                    "text/html");
 
             // Send the message
             Transport.send(message);
diff --git a/src/main/java/org/toco/service/toco_service.java b/src/main/java/org/toco/service/toco_service.java
index f3d82ce7f110fac14e6aa4252778ea0a339f09f7..9c96cf001aba9ced69dbce47239a58c8b30c96eb 100644
--- a/src/main/java/org/toco/service/toco_service.java
+++ b/src/main/java/org/toco/service/toco_service.java
@@ -7,7 +7,6 @@ import javax.jws.soap.SOAPBinding;
 import javax.jws.soap.SOAPBinding.Style;
 import javax.jws.soap.SOAPBinding.ParameterStyle;
 
-
 @WebService
 @SOAPBinding(style = Style.DOCUMENT, parameterStyle = ParameterStyle.WRAPPED)
 public interface toco_service {
@@ -15,45 +14,37 @@ public interface toco_service {
     public String addGems(
             @WebParam(name = "user_id") Integer user_id,
             @WebParam(name = "gem") Integer gem,
-            @WebParam(name = "type") String type
-    );
+            @WebParam(name = "type") String type);
 
     @WebMethod
     public Integer getGems(
-            @WebParam(name = "user_id") Integer user_id
-    );
+            @WebParam(name = "user_id") Integer user_id);
 
     @WebMethod
     public String createTransaction(
             @WebParam(name = "user_id") Integer user_id,
             @WebParam(name = "amount") Integer amount,
-            @WebParam(name = "type") String type, //add gems / buy item
-            @WebParam(name = "email") String email
-    );
+            @WebParam(name = "type") String type, // add gems / buy item
+            @WebParam(name = "email") String email);
 
     @WebMethod
     public String[] getTransactions(
-            @WebParam(name = "user_id") Integer user_id
-    );
+            @WebParam(name = "user_id") Integer user_id);
 
     @WebMethod
     public String useVoucher(
             @WebParam(name = "code") String code,
             @WebParam(name = "user_id") Integer user_id,
-            @WebParam(name = "amount") Integer amount
-
-    );
+            @WebParam(name = "amount") Integer amount,
+            @WebParam(name = "type") String type);
 
     @WebMethod
     public String[] getSpecifiedVouchers(
-            @WebParam(name = "code") String code
-    );
+            @WebParam(name = "code") String code);
 
     @WebMethod
     public String[] getAllVouchers(
 
     );
 
-
-
 }
diff --git a/src/main/java/org/toco/service/toco_service_impl.java b/src/main/java/org/toco/service/toco_service_impl.java
index 98c87d4fedc8ba12c9c82fda6da1b0ac019aa0be..bf54b789581f83e61b10ca155c6fd616be02a40f 100644
--- a/src/main/java/org/toco/service/toco_service_impl.java
+++ b/src/main/java/org/toco/service/toco_service_impl.java
@@ -3,7 +3,6 @@ package org.toco.service;
 import org.toco.model.*;
 import org.toco.entity.*;
 
-
 import javax.jws.WebService;
 import javax.annotation.Resource;
 import javax.xml.ws.WebServiceContext;
@@ -21,7 +20,7 @@ public class toco_service_impl implements toco_service {
 
     @Override
     public String addGems(Integer user_id, Integer gem, String type) {
-        if (validateApiKey()){
+        if (validateApiKey()) {
             userGems_Entity userGems = new userGems_Entity(user_id, gem);
             userGems_model userGemsModel = new userGems_model();
             transaction_model transactionModel = new transaction_model();
@@ -39,22 +38,21 @@ public class toco_service_impl implements toco_service {
                 transactionModel.insert(tan);
                 return "success";
             }
-        }
-        else {
-            addLoggging("User with id " + user_id + " tried to add " + gem + " gems but failed because of invalid api key");
+        } else {
+            addLoggging(
+                    "User with id " + user_id + " tried to add " + gem + " gems but failed because of invalid api key");
             return "failed";
         }
     }
 
     @Override
     public Integer getGems(Integer user_id) {
-        if(validateApiKey()){
+        if (validateApiKey()) {
             userGems_model userGemsModel = new userGems_model();
             Integer gems = userGemsModel.getUserGems(user_id);
             addLoggging("User with id " + user_id + " requested his gems");
             return gems;
-        }
-        else {
+        } else {
             addLoggging("User with id " + user_id + " tried to get his gems but failed because of invalid api key");
             return -1;
         }
@@ -62,86 +60,98 @@ public class toco_service_impl implements toco_service {
 
     @Override
     public String createTransaction(Integer user_id, Integer amount, String type, String email) {
-        if (validateApiKey()){
+        if (validateApiKey()) {
             userGems_model userGemsModel = new userGems_model();
             Integer userGems = userGemsModel.getUserGems(user_id);
             if (userGems >= amount) {
                 userGemsModel.update(new userGems_Entity(user_id, userGems - amount));
                 transaction_model transactionModel = new transaction_model();
                 transactionModel.insert(new transaction_entity(user_id, amount, type, "accepted", "0"));
-                addLoggging("User with id " + user_id + " created a transaction with amount " + amount + " and status ACCEPTED");
-                mail.sendMail(email,"Your transaction with " + amount + " gems has been accepted and will be processed immediately.");
+                addLoggging("User with id " + user_id + " created a transaction with amount " + amount
+                        + " and status ACCEPTED");
+                mail.sendMail(email, "Your transaction with " + amount
+                        + " gems has been accepted and will be processed immediately.");
                 return "success";
             } else {
                 transaction_model transactionModel = new transaction_model();
                 transactionModel.insert(new transaction_entity(user_id, amount, type, "rejected", "0"));
-                addLoggging("User with id " + user_id + " created a transaction with amount " + amount + " and status REJECTED");
+                addLoggging("User with id " + user_id + " created a transaction with amount " + amount
+                        + " and status REJECTED");
                 return "insufficient gems";
             }
-        }
-        else {
-            addLoggging("User with id " + user_id + " tried to create a transaction with amount " + amount + " but failed because of invalid api key");
+        } else {
+            addLoggging("User with id " + user_id + " tried to create a transaction with amount " + amount
+                    + " but failed because of invalid api key");
             return "failed";
         }
     }
 
     @Override
     public String[] getTransactions(Integer user_id) {
-        if(validateApiKey()){
+        if (validateApiKey()) {
             transaction_model transactionModel = new transaction_model();
             transaction_entity[] transactions = transactionModel.getTransaction(user_id);
-//            create transactions to a string with each transaction on a new line
+            // create transactions to a string with each transaction on a new line
             String[] ret = new String[transactionModel.getTransactionCount(user_id)];
             int len = transactionModel.getTransactionCount(user_id);
             for (int i = 0; i < len; i++) {
-                ret[i] =transactions[i].getAmount().toString()+", "+transactions[i].getImage()+", "+transactions[i].getStatus()+", "+transactions[i].getCreated_at();
+                ret[i] = transactions[i].getAmount().toString() + ", " + transactions[i].getImage() + ", "
+                        + transactions[i].getStatus() + ", " + transactions[i].getCreated_at();
             }
             addLoggging("User with id " + user_id + " requested his transactions");
             return ret;
-        }
-        else {
-            addLoggging("invalid api key for user"+user_id);
+        } else {
+            addLoggging("invalid api key for user" + user_id);
             return null;
         }
     }
 
     @Override
-    public String useVoucher(String voucher, Integer user_id, Integer amount) {
-        if(validateApiKey()){
+    public String useVoucher(String voucher, Integer user_id, Integer amount, String type) {
+        if (validateApiKey()) {
             voucher_model voucherModel = new voucher_model();
             userGems_model userGemsModel = new userGems_model();
             transaction_model transactionModel = new transaction_model();
-            voucher_entity voucherEntity = new voucher_entity(voucher,user_id,amount,"0");
-            voucherModel.insert(voucherEntity);
-            transactionModel.insert(new transaction_entity(user_id, amount, "Voucher Redeemed", "accepted", "0"));
-            if (userGemsModel.checkUser(user_id)) {
-                Integer currentGems = userGemsModel.getUserGems(user_id);
-                userGemsModel.update(new userGems_Entity(user_id, currentGems + amount));
+
+            if (!voucherModel.isVoucherAlreadyRedeemed(voucher, user_id)) {
+                voucher_entity voucherEntity = new voucher_entity(voucher, user_id, amount, "0");
+                voucherModel.insert(voucherEntity);
+                transactionModel.insert(new transaction_entity(user_id, amount, type, "accepted", "0"));
+
+                if (userGemsModel.checkUser(user_id)) {
+                    Integer currentGems = userGemsModel.getUserGems(user_id);
+                    userGemsModel.update(new userGems_Entity(user_id, currentGems + amount));
+                } else {
+                    userGemsModel.insert(new userGems_Entity(user_id, amount));
+                }
+
+                addLoggging("User with id " + user_id + " used voucher " + voucher + "with amount " + amount);
+                return "success";
             } else {
-                userGemsModel.insert(new userGems_Entity(user_id, amount));
+                addLoggging("User with id " + user_id + " tried to use a voucher with amount " + amount
+                        + " but failed because the voucher has already been redeemed");
+                return "voucher already redeemed";
             }
-            addLoggging("User with id " + user_id + " used voucher " + voucher + "with amount " + amount);
-            return "success";
-        }
-        else {
-            addLoggging("User with id " + user_id + " tried to use a voucher with amount " + amount + " but failed because of invalid api key");
-            return "invalid apikey";
+        } else {
+            addLoggging("User with id " + user_id + " tried to use a voucher with amount " + amount
+                    + " but failed because of an invalid API key");
+            return "invalid API key";
         }
     }
 
     @Override
-    public String[] getSpecifiedVouchers (String code){
-        if(validateApiKey()){
+    public String[] getSpecifiedVouchers(String code) {
+        if (validateApiKey()) {
             voucher_model voucherModel = new voucher_model();
             voucher_entity[] voucherEntity = voucherModel.getSpecifiedVoucher(code);
             Integer len = voucherModel.getSpecifiedCount(code);
             String[] ret = new String[len];
             for (int i = 0; i < len; i++) {
-                ret[i] = voucherEntity[i].getCode()+", "+voucherEntity[i].getAmount().toString()+", "+voucherEntity[i].getUser_id().toString()+", "+voucherEntity[i].getCreated_at();
+                ret[i] = voucherEntity[i].getCode() + ", " + voucherEntity[i].getAmount().toString() + ", "
+                        + voucherEntity[i].getUser_id().toString() + ", " + voucherEntity[i].getCreated_at();
             }
             return ret;
-        }
-        else {
+        } else {
             addLoggging("invalid api key");
             return null;
         }
@@ -149,17 +159,17 @@ public class toco_service_impl implements toco_service {
 
     @Override
     public String[] getAllVouchers() {
-        if(validateApiKey()){
+        if (validateApiKey()) {
             voucher_model voucherModel = new voucher_model();
             voucher_entity[] voucherEntity = voucherModel.getAllVouchers();
             Integer len = voucherModel.getAllCount();
             String[] ret = new String[len];
             for (int i = 0; i < len; i++) {
-                ret[i] = voucherEntity[i].getCode()+", "+voucherEntity[i].getAmount().toString()+", "+voucherEntity[i].getUser_id().toString()+", "+voucherEntity[i].getCreated_at();
+                ret[i] = voucherEntity[i].getCode() + ", " + voucherEntity[i].getAmount().toString() + ", "
+                        + voucherEntity[i].getUser_id().toString() + ", " + voucherEntity[i].getCreated_at();
             }
             return ret;
-        }
-        else {
+        } else {
             addLoggging("invalid api key");
             return null;
         }
@@ -179,7 +189,7 @@ public class toco_service_impl implements toco_service {
         }
     }
 
-    public void  addLoggging(String description) {
+    public void addLoggging(String description) {
         MessageContext mctx = wsctx.getMessageContext();
         HttpExchange req = (HttpExchange) mctx.get(JAXWSProperties.HTTP_EXCHANGE);
         InetSocketAddress remote = req.getRemoteAddress();