lots of things to fix interaction with the api

parent a2972bea
......@@ -53,10 +53,14 @@ public class PaymentRequest {
public static void main(String[] args){
CubedPayAPI cubedpay = new CubedPayAPI("app_XXXXXXXXXXXXX", "oauth_XXXXXXXXXXXX");
cubedpay.getShopAPI().requestPayment("shop_XXXXXXXXXXX", "sale",
new Item("package_XXXXXXXXXX", 2)
).thenAccept(paymentRequest -> System.out.println("Send user to "+paymentRequest.getAuthorize().getRedirectTo()));
cubedpay.getShopAPI().getPackages(shopID, 1, 10)
.thenCompose(packages -> api.getShopAPI().createTransaction(shopID, "user@user.com",
new Item(packages.getData().get(0).getId(), 1)))
.thenAccept(transaction -> System.out.println("Payment Url: https://app.cubedpay.com/checkout/" + transaction.getId()))
.exceptionally(throwable -> {
throwable.printStackTrace();
return null;
});
cubedpay.shutdown();
}
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>co.melondev</groupId>
<artifactId>CubedPay</artifactId>
<version>0.4.2</version>
<version>0.4.3</version>
</parent>
<artifactId>CubedPay-bukkit</artifactId>
......@@ -21,7 +21,7 @@
<dependency>
<groupId>co.melondev</groupId>
<artifactId>CubedPay-common</artifactId>
<version>0.4.2</version>
<version>0.4.3</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
......
......@@ -6,7 +6,7 @@
<parent>
<groupId>co.melondev</groupId>
<artifactId>CubedPay</artifactId>
<version>0.4.2</version>
<version>0.4.3</version>
</parent>
<artifactId>CubedPay-common</artifactId>
......
......@@ -7,9 +7,11 @@ import co.melondev.cubedpay.envelope.APIEnvelopeTransformerConverterFactory;
import co.melondev.cubedpay.events.CubedAnnotationProcessor;
import co.melondev.cubedpay.events.CubedEvent;
import co.melondev.cubedpay.events.CubedEventRunnable;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializer;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import okhttp3.Dispatcher;
import okhttp3.OkHttpClient;
import okhttp3.ResponseBody;
......@@ -18,6 +20,7 @@ import retrofit2.Retrofit;
import retrofit2.adapter.java8.Java8CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.HashMap;
......@@ -46,6 +49,36 @@ public class CubedPayAPI {
ShopPage.Type.findById(json.getAsString()))
.registerTypeAdapter(ShopPackageRef.Type.class, (JsonDeserializer<ShopPackageRef.Type>) (json, typeOfT, context) ->
ShopPackageRef.Type.findById(json.getAsString()))
.registerTypeAdapterFactory(new TypeAdapterFactory() {
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
return type.getRawType() == boolean.class || type.getRawType() == Boolean.class ? (TypeAdapter<T>) new TypeAdapter<Boolean>() {
@Override
public Boolean read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
} else if (in.peek() == JsonToken.STRING) {
String value = in.nextString();
if (value.toLowerCase().equals("1")) {
return true;
}
if (value.toLowerCase().equals("0")) {
return false;
}
// support strings for compatibility with GSON 1.7
return Boolean.parseBoolean(value);
}
return in.nextBoolean();
}
@Override
public void write(JsonWriter out, Boolean value) throws IOException {
out.value((boolean) value);
}
} : null;
}
})
.create();
private CubedAnnotationProcessor annotationProcessor = new CubedAnnotationProcessor();
......
......@@ -153,7 +153,7 @@ public interface CubedPayShopAPI {
CompletableFuture<ShopSale> createSale(@Path("sid") String shopId, @Query("name") String name, @Query("amount") double amount, @Query("percent") boolean percent, @Query("active") boolean active, @Query("visible") boolean visible, @Query("banner") String banner, @Query("starts") long starts, @Query("ends") long ends);
@PATCH("/shop/{sid}/sale/{sale}")
CompletableFuture<ShopSale> updateSale(@Path("sid") String shopId, @Path("sale") String saleId, @Query(" name") String name, @Query("amount") double amount, @Query("percent") boolean percent, @Query("active") boolean active, @Query("visible") boolean visible, @Query("banner") String banner, @Query("starts") long starts, @Query("ends") long ends);
CompletableFuture<ShopSale> updateSale(@Path("sid") String shopId, @Path("sale") String saleId, @Query("name") String name, @Query("amount") double amount, @Query("percent") boolean percent, @Query("active") boolean active, @Query("visible") boolean visible, @Query("banner") String banner, @Query("starts") long starts, @Query("ends") long ends);
@DELETE("/shop/{sid}/sale/{sale}")
CompletableFuture<DeleteConfirmation> deleteSale(@Path("sid") String shopId, @Path("sale") String saleId);
......@@ -196,7 +196,7 @@ public interface CubedPayShopAPI {
//region Support
@GET("/shop/{sid}/ticket")
CompletableFuture<List<SupportTicket>> getSupportTickets(@Path("sid") String shopId, @Query("page") int page, @Query("perpage") int perpage);
CompletableFuture<Cursor<SupportTicket>> getSupportTickets(@Path("sid") String shopId, @Query("page") int page, @Query("perpage") int perpage);
@POST("/shop/{sid}/ticket/open")
CompletableFuture<SupportTicket> createSupportTicket(@Path("sid") String shopId, @Query("from_name") String user_name, @Query("from_email") String user_email, @Query("subject") String subject, @Query("body") String body);
......
......@@ -16,6 +16,7 @@ public class Shop {
private String time_zone = "";
private List<User> members = new ArrayList<>();
private List<Gateway> gateways = new ArrayList<>();
private ShopPlan plan;
public String getId() {
return id;
......@@ -61,6 +62,10 @@ public class Shop {
return gateways;
}
public ShopPlan getPlan() {
return plan;
}
@Override
public String toString() {
return "Shop{" +
......
......@@ -27,7 +27,7 @@ public class ShopPackage {
private UploadedImage icon;
private String description;
private String price;
@SerializedName("public")
@SerializedName("is_public")
private boolean isPublic;
private Sale sale;
......
......@@ -16,7 +16,8 @@ public class ShopPage {
}
public enum Display {
GRID;
GRID,
LIST;
public static Display findById(String id) {
return Arrays.stream(values()).filter(status -> status.name().equalsIgnoreCase(id))
......
package co.melondev.cubedpay.data;
/**
* @author theminecoder
*/
public class ShopPlan {
private String id;
public String getId() {
return id;
}
}
......@@ -48,4 +48,19 @@ public class ShopSale {
public String getBanner() {
return banner;
}
@Override
public String toString() {
return "ShopSale{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", starts='" + starts + '\'' +
", ends='" + ends + '\'' +
", active=" + active +
", amount=" + amount +
", percent=" + percent +
", visible=" + visible +
", banner='" + banner + '\'' +
'}';
}
}
......@@ -30,6 +30,10 @@ public class APIEnvelopeTransformerConverter<T> implements Converter<ResponseBod
throw new CubedPayException(500, "Server sent back invalid json:\n" + valueString);
}
// if (fullResponse.has("debug") && fullResponse.get("debug").isJsonObject()) {
// System.out.println("Cubed DEBUG: " + fullResponse.get("debug").toString());
// }
if (!fullResponse.getAsJsonPrimitive("success").getAsBoolean()) {
JsonObject errorObject = fullResponse.getAsJsonObject("return");
throw new CubedPayException(errorObject.getAsJsonPrimitive("code").getAsInt(),
......
......@@ -34,6 +34,9 @@ public class APIEnvelopeTransformerConverterFactory extends Factory {
if (type instanceof Class && (((Class) type).isPrimitive() || ((Class) type) == String.class)) {
return null;
}
if (type instanceof Class && ((Class) type).isEnum()) {
return (Converter<Object, String>) value -> ((Enum) value).name();
}
return gson::toJson;
}
}
......@@ -4,7 +4,7 @@
<groupId>co.melondev</groupId>
<artifactId>CubedPay</artifactId>
<version>0.4.2</version>
<version>0.4.3</version>
<packaging>pom</packaging>
<properties>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment