added payments, settings and shipping methods into the api
This commit is contained in:
parent
cf671d332e
commit
688433d9e6
@ -2,6 +2,7 @@ package me.gilo.woodroid;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import me.gilo.woodroid.models.PaymentGateway;
|
||||||
import me.gilo.woodroid.repo.*;
|
import me.gilo.woodroid.repo.*;
|
||||||
import me.gilo.woodroid.repo.order.OrderNoteRepository;
|
import me.gilo.woodroid.repo.order.OrderNoteRepository;
|
||||||
import me.gilo.woodroid.repo.order.RefundRepository;
|
import me.gilo.woodroid.repo.order.RefundRepository;
|
||||||
@ -36,6 +37,10 @@ public class Woocommerce {
|
|||||||
|
|
||||||
final CartRepository cartRepository;
|
final CartRepository cartRepository;
|
||||||
|
|
||||||
|
final PaymentGatewayRepository paymentGatewayRepository;
|
||||||
|
final SettingsRepository settingsRepository;
|
||||||
|
final ShippingMethodRepository shippingMethodRepository;
|
||||||
|
|
||||||
|
|
||||||
enum ApiVersion {
|
enum ApiVersion {
|
||||||
API_VERSION1{
|
API_VERSION1{
|
||||||
@ -81,6 +86,9 @@ public class Woocommerce {
|
|||||||
cartRepository = new CartRepository(cartBaseUrl, consumerKey, consumerSecret);
|
cartRepository = new CartRepository(cartBaseUrl, consumerKey, consumerSecret);
|
||||||
|
|
||||||
reviewRepository = new ReviewRepository(baseUrl, consumerKey, consumerSecret);
|
reviewRepository = new ReviewRepository(baseUrl, consumerKey, consumerSecret);
|
||||||
|
paymentGatewayRepository = new PaymentGatewayRepository(baseUrl, consumerKey, consumerSecret);
|
||||||
|
settingsRepository = new SettingsRepository(baseUrl, consumerKey, consumerSecret);
|
||||||
|
shippingMethodRepository = new ShippingMethodRepository(baseUrl, consumerKey, consumerSecret);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,6 +185,18 @@ public class Woocommerce {
|
|||||||
return reportsRepository;
|
return reportsRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PaymentGatewayRepository PaymentGatewayRepository() {
|
||||||
|
return paymentGatewayRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SettingsRepository SettingsRepository() {
|
||||||
|
return settingsRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShippingMethodRepository ShippingMethodRepository() {
|
||||||
|
return shippingMethodRepository;
|
||||||
|
}
|
||||||
|
|
||||||
public CartRepository CartRepository(Context context) {
|
public CartRepository CartRepository(Context context) {
|
||||||
cartRepository.turnOnCookies(context);
|
cartRepository.turnOnCookies(context);
|
||||||
return cartRepository;
|
return cartRepository;
|
||||||
|
|||||||
@ -0,0 +1,10 @@
|
|||||||
|
package me.gilo.woodroid.callback;
|
||||||
|
|
||||||
|
import android.arch.lifecycle.LiveData;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
import retrofit2.Response;
|
||||||
|
|
||||||
|
public interface WooCall<T> extends Call<T> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,18 +0,0 @@
|
|||||||
package me.gilo.woodroid.callback;
|
|
||||||
|
|
||||||
import android.arch.lifecycle.LiveData;
|
|
||||||
import retrofit2.Call;
|
|
||||||
import retrofit2.Callback;
|
|
||||||
import retrofit2.Response;
|
|
||||||
|
|
||||||
public class WooCallback<T> implements Callback<T> {
|
|
||||||
@Override
|
|
||||||
public void onResponse(Call<T> call, Response<T> response) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(Call<T> call, Throwable t) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
package me.gilo.woodroid.data.api;
|
||||||
|
|
||||||
|
|
||||||
|
import me.gilo.woodroid.callback.WooCall;
|
||||||
|
import me.gilo.woodroid.models.PaymentGateway;
|
||||||
|
import retrofit2.http.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface PaymentGatewayAPI {
|
||||||
|
|
||||||
|
|
||||||
|
@GET("payment_gateways/{id}")
|
||||||
|
WooCall<PaymentGateway> view(@Path("id") int id);
|
||||||
|
|
||||||
|
@GET("payment_gateways")
|
||||||
|
WooCall<List<PaymentGateway>> list();
|
||||||
|
|
||||||
|
@Headers("Content-Type: application/json")
|
||||||
|
@PUT("payment_gateways")
|
||||||
|
WooCall<PaymentGateway> update(@Path("id") String id, @Body PaymentGateway body);
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,10 +1,8 @@
|
|||||||
package me.gilo.woodroid.data.api;
|
package me.gilo.woodroid.data.api;
|
||||||
|
|
||||||
|
|
||||||
import me.gilo.woodroid.models.SettingGroup;
|
import me.gilo.woodroid.callback.WooCall;
|
||||||
import me.gilo.woodroid.models.SettingOption;
|
import me.gilo.woodroid.models.*;
|
||||||
import me.gilo.woodroid.models.TaxRate;
|
|
||||||
import me.gilo.woodroid.models.WebhookDelivery;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.http.*;
|
import retrofit2.http.*;
|
||||||
|
|
||||||
@ -15,17 +13,21 @@ import java.util.Map;
|
|||||||
public interface SettingsAPI {
|
public interface SettingsAPI {
|
||||||
|
|
||||||
@GET("settings")
|
@GET("settings")
|
||||||
Call<List<SettingGroup>> settings();
|
WooCall<List<SettingGroup>> settings();
|
||||||
|
|
||||||
@GET("settings/{group_id}/{id}")
|
@GET("settings/{group_id}/{id}")
|
||||||
Call<SettingOption> option(@Path("group_id") int group_id, @Path("id") int option_id);
|
WooCall<SettingOption> option(@Path("group_id") String group_id, @Path("id") String option_id);
|
||||||
|
|
||||||
@GET("settings/{id}")
|
@GET("settings/{id}")
|
||||||
Call<List<SettingOption>> options(@Path("id") int group_id);
|
WooCall<List<SettingOption>> options(@Path("id") String group_id);
|
||||||
|
|
||||||
@Headers("Content-Type: application/json")
|
@Headers("Content-Type: application/json")
|
||||||
@GET("settings/{group_id}/{id}")
|
@PUT("settings/{group_id}/{id}")
|
||||||
Call<SettingOption> update(@Path("group_id") int group_id, @Path("id") int option_id);
|
WooCall<SettingOption> update(
|
||||||
|
@Path("group_id") String group_id,
|
||||||
|
@Path("id") String option_id,
|
||||||
|
@Body SettingOption body
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,21 @@
|
|||||||
|
package me.gilo.woodroid.data.api;
|
||||||
|
|
||||||
|
|
||||||
|
import me.gilo.woodroid.callback.WooCall;
|
||||||
|
import me.gilo.woodroid.models.Coupon;
|
||||||
|
import me.gilo.woodroid.models.ShippingMethod;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.http.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface ShippingMethodAPI {
|
||||||
|
|
||||||
|
@GET("shipping_methods/{id}")
|
||||||
|
WooCall<ShippingMethod> view(@Path("id") String id);
|
||||||
|
|
||||||
|
@GET("shipping_methods")
|
||||||
|
WooCall<List<ShippingMethod>> list();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,88 @@
|
|||||||
|
package me.gilo.woodroid.models;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PaymentGateway {
|
||||||
|
|
||||||
|
String id;
|
||||||
|
String title;
|
||||||
|
String description;
|
||||||
|
int order;
|
||||||
|
boolean enabled;
|
||||||
|
String method_title;
|
||||||
|
String method_description;
|
||||||
|
String[] method_supports;
|
||||||
|
Map<String, PaymentGatewaySetting> settings;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOrder() {
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrder(int order) {
|
||||||
|
this.order = order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMethod_title() {
|
||||||
|
return method_title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMethod_title(String method_title) {
|
||||||
|
this.method_title = method_title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMethod_description() {
|
||||||
|
return method_description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMethod_description(String method_description) {
|
||||||
|
this.method_description = method_description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getMethod_supports() {
|
||||||
|
return method_supports;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMethod_supports(String[] method_supports) {
|
||||||
|
this.method_supports = method_supports;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, PaymentGatewaySetting> getSettings() {
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSettings(Map<String, PaymentGatewaySetting> settings) {
|
||||||
|
this.settings = settings;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,82 @@
|
|||||||
|
package me.gilo.woodroid.models;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PaymentGatewaySetting {
|
||||||
|
|
||||||
|
String id;
|
||||||
|
String label;
|
||||||
|
String description;
|
||||||
|
String type;
|
||||||
|
String value;
|
||||||
|
@JsonProperty("default")
|
||||||
|
String default_value;
|
||||||
|
String tip;
|
||||||
|
String placeholder;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLabel(String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDefault_value() {
|
||||||
|
return default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefault_value(String default_value) {
|
||||||
|
this.default_value = default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTip() {
|
||||||
|
return tip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTip(String tip) {
|
||||||
|
this.tip = tip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlaceholder() {
|
||||||
|
return placeholder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlaceholder(String placeholder) {
|
||||||
|
this.placeholder = placeholder;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
package me.gilo.woodroid.models;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
|
||||||
|
public class ShippingMethod {
|
||||||
|
private String id;
|
||||||
|
private String title;
|
||||||
|
private String descriptioon;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptioon() {
|
||||||
|
return descriptioon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptioon(String descriptioon) {
|
||||||
|
this.descriptioon = descriptioon;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package me.gilo.woodroid.repo;
|
||||||
|
|
||||||
|
import me.gilo.woodroid.callback.WooCall;
|
||||||
|
import me.gilo.woodroid.data.api.PaymentGatewayAPI;
|
||||||
|
import me.gilo.woodroid.models.PaymentGateway;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PaymentGatewayRepository extends WooRepository{
|
||||||
|
|
||||||
|
private final PaymentGatewayAPI apiService;
|
||||||
|
|
||||||
|
public PaymentGatewayRepository(String baseUrl, String consumerKey, String consumerSecret) {
|
||||||
|
super( baseUrl, consumerKey, consumerSecret);
|
||||||
|
apiService = retrofit.create(PaymentGatewayAPI.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WooCall<PaymentGateway> paymentGateway(int id) {
|
||||||
|
return apiService.view(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WooCall<List<PaymentGateway>> paymentGateways() {
|
||||||
|
return apiService.list();
|
||||||
|
}
|
||||||
|
|
||||||
|
public WooCall<PaymentGateway> update(String id, PaymentGateway paymentGateway) {
|
||||||
|
return apiService.update(id, paymentGateway);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
package me.gilo.woodroid.repo;
|
||||||
|
|
||||||
|
import me.gilo.woodroid.callback.WooCall;
|
||||||
|
import me.gilo.woodroid.data.api.SettingsAPI;
|
||||||
|
import me.gilo.woodroid.data.api.ShippingMethodAPI;
|
||||||
|
import me.gilo.woodroid.models.SettingGroup;
|
||||||
|
import me.gilo.woodroid.models.SettingOption;
|
||||||
|
import me.gilo.woodroid.models.ShippingMethod;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SettingsRepository extends WooRepository{
|
||||||
|
|
||||||
|
private final SettingsAPI apiService;
|
||||||
|
|
||||||
|
public SettingsRepository(String baseUrl, String consumerKey, String consumerSecret) {
|
||||||
|
super( baseUrl, consumerKey, consumerSecret);
|
||||||
|
apiService = retrofit.create(SettingsAPI.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WooCall<List<SettingGroup>> settings() {
|
||||||
|
return apiService.settings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public WooCall<SettingOption> option(String group_id, String option_id) {
|
||||||
|
return apiService.option(group_id, option_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WooCall<List<SettingOption>> options(String group_id) {
|
||||||
|
return apiService.options(group_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WooCall<SettingOption> updateOption(String group_id, String option_id, SettingOption option) {
|
||||||
|
return apiService.update(group_id, option_id, option);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
package me.gilo.woodroid.repo;
|
||||||
|
|
||||||
|
import me.gilo.woodroid.callback.WooCall;
|
||||||
|
import me.gilo.woodroid.data.api.PaymentGatewayAPI;
|
||||||
|
import me.gilo.woodroid.data.api.ShippingMethodAPI;
|
||||||
|
import me.gilo.woodroid.models.PaymentGateway;
|
||||||
|
import me.gilo.woodroid.models.ShippingMethod;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ShippingMethodRepository extends WooRepository{
|
||||||
|
|
||||||
|
private final ShippingMethodAPI apiService;
|
||||||
|
|
||||||
|
public ShippingMethodRepository(String baseUrl, String consumerKey, String consumerSecret) {
|
||||||
|
super( baseUrl, consumerKey, consumerSecret);
|
||||||
|
apiService = retrofit.create(ShippingMethodAPI.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WooCall<ShippingMethod> shippingMethod(String id) {
|
||||||
|
return apiService.view(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WooCall<List<ShippingMethod>> shippingMethods() {
|
||||||
|
return apiService.list();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user