Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dependencies {
compile group: 'commons-codec', name: 'commons-codec', version: '1.11'
compile group: 'commons-logging', name: 'commons-logging', version: '1.2'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
compile group: 'joda-time', name: 'joda-time', version: '2.10.1'
}

jacocoTestReport {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/instamojo/wrapper/api/Instamojo.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.instamojo.wrapper.api;

import com.instamojo.wrapper.filter.PaymentRequestFilter;
import com.instamojo.wrapper.filter.PayoutFilter;
import com.instamojo.wrapper.exception.ConnectionException;
import com.instamojo.wrapper.exception.HTTPException;
import com.instamojo.wrapper.filter.PaymentRequestFilter;
import com.instamojo.wrapper.filter.PayoutFilter;
import com.instamojo.wrapper.model.*;
import com.instamojo.wrapper.response.ApiListResponse;

import java.util.List;
import java.util.Map;

/**
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/instamojo/wrapper/api/InstamojoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.instamojo.wrapper.response.ApiListResponse;
import com.instamojo.wrapper.response.ApiResponse;
import com.instamojo.wrapper.util.Constants;
import com.instamojo.wrapper.util.GsonWrapper;
import com.instamojo.wrapper.util.HttpUtils;
import org.apache.commons.codec.digest.HmacAlgorithms;
import org.apache.commons.codec.digest.HmacUtils;
Expand All @@ -18,7 +19,10 @@
import java.io.IOException;
import java.lang.reflect.Type;
import java.net.URISyntaxException;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class InstamojoImpl implements Instamojo {

Expand All @@ -28,7 +32,7 @@ public class InstamojoImpl implements Instamojo {

public InstamojoImpl(ApiContext context) {
this.context = context;
this.gson = new Gson();
this.gson = GsonWrapper.getGson();
}

@Override
Expand Down
21 changes: 10 additions & 11 deletions src/main/java/com/instamojo/wrapper/model/Invoice.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.instamojo.wrapper.model;

import com.google.gson.annotations.SerializedName;

import java.util.Date;
import org.joda.time.DateTime;

public class Invoice {

Expand All @@ -12,16 +11,16 @@ public class Invoice {
private String userUri;

@SerializedName("created_at")
private Date createdAt;
private DateTime createdAt;

@SerializedName("issue_date")
private Date issueDate;
private DateTime issueDate;

@SerializedName("file")
private String fileUrl;

@SerializedName("last_modified")
private Date modifiedAt;
private DateTime modifiedAt;

public String getId() {
return id;
Expand All @@ -39,19 +38,19 @@ public void setUserUri(String userUri) {
this.userUri = userUri;
}

public Date getCreatedAt() {
public DateTime getCreatedAt() {
return createdAt;
}

public void setCreatedAt(Date createdAt) {
public void setCreatedAt(DateTime createdAt) {
this.createdAt = createdAt;
}

public Date getIssueDate() {
public DateTime getIssueDate() {
return issueDate;
}

public void setIssueDate(Date issueDate) {
public void setIssueDate(DateTime issueDate) {
this.issueDate = issueDate;
}

Expand All @@ -63,11 +62,11 @@ public void setFileUrl(String fileUrl) {
this.fileUrl = fileUrl;
}

public Date getModifiedAt() {
public DateTime getModifiedAt() {
return modifiedAt;
}

public void setModifiedAt(Date modifiedAt) {
public void setModifiedAt(DateTime modifiedAt) {
this.modifiedAt = modifiedAt;
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/instamojo/wrapper/model/PaymentOrder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.instamojo.wrapper.model;

import com.google.gson.annotations.SerializedName;
import org.joda.time.DateTime;

import java.util.List;

Expand Down Expand Up @@ -68,7 +69,7 @@ public class PaymentOrder {
* The created at.
*/
@SerializedName("created_at")
private String createdAt;
private DateTime createdAt;

/**
* The resource uri.
Expand Down Expand Up @@ -288,7 +289,7 @@ public void setRedirectUrl(String redirectUrl) {
*
* @return the created at
*/
public String getCreatedAt() {
public DateTime getCreatedAt() {
return createdAt;
}

Expand All @@ -297,7 +298,7 @@ public String getCreatedAt() {
*
* @param createdAt the new created at
*/
public void setCreatedAt(String createdAt) {
public void setCreatedAt(DateTime createdAt) {
this.createdAt = createdAt;
}

Expand Down
26 changes: 13 additions & 13 deletions src/main/java/com/instamojo/wrapper/model/PaymentRequest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.instamojo.wrapper.model;

import com.google.gson.annotations.SerializedName;
import org.joda.time.DateTime;

import java.util.Date;
import java.util.List;

public class PaymentRequest {
Expand Down Expand Up @@ -50,10 +50,10 @@ public class PaymentRequest {
private String webhookUrl;

@SerializedName("scheduled_at")
private Date scheduledAt;
private DateTime scheduledAt;

@SerializedName("expires_at")
private Date expiresAt;
private DateTime expiresAt;

@SerializedName("allow_repeated_payments")
private Boolean allowRepeatedPayments;
Expand All @@ -71,10 +71,10 @@ public class PaymentRequest {
private Boolean markFulfilled;

@SerializedName("created_at")
private Date createdAt;
private DateTime createdAt;

@SerializedName("modified_at")
private Date modifiedAt;
private DateTime modifiedAt;

@SerializedName("resource_uri")
private String resourceUri;
Expand Down Expand Up @@ -207,19 +207,19 @@ public void setWebhookUrl(String webhookUrl) {
this.webhookUrl = webhookUrl;
}

public Date getScheduledAt() {
public DateTime getScheduledAt() {
return scheduledAt;
}

public void setScheduledAt(Date scheduledAt) {
public void setScheduledAt(DateTime scheduledAt) {
this.scheduledAt = scheduledAt;
}

public Date getExpiresAt() {
public DateTime getExpiresAt() {
return expiresAt;
}

public void setExpiresAt(Date expiresAt) {
public void setExpiresAt(DateTime expiresAt) {
this.expiresAt = expiresAt;
}

Expand Down Expand Up @@ -263,19 +263,19 @@ public void setMarkFulfilled(Boolean markFulfilled) {
this.markFulfilled = markFulfilled;
}

public Date getCreatedAt() {
public DateTime getCreatedAt() {
return createdAt;
}

public void setCreatedAt(Date createdAt) {
public void setCreatedAt(DateTime createdAt) {
this.createdAt = createdAt;
}

public Date getModifiedAt() {
public DateTime getModifiedAt() {
return modifiedAt;
}

public void setModifiedAt(Date modifiedAt) {
public void setModifiedAt(DateTime modifiedAt) {
this.modifiedAt = modifiedAt;
}

Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/instamojo/wrapper/model/Payout.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.instamojo.wrapper.model;

import com.google.gson.annotations.SerializedName;

import java.util.Date;
import org.joda.time.DateTime;

public class Payout {

Expand All @@ -13,7 +12,7 @@ public class Payout {
private Boolean status;

@SerializedName("paid_out_at")
private Date paidOutAt;
private DateTime paidOutAt;

private String currency;

Expand Down Expand Up @@ -71,11 +70,11 @@ public void setStatus(Boolean status) {
this.status = status;
}

public Date getPaidOutAt() {
public DateTime getPaidOutAt() {
return paidOutAt;
}

public void setPaidOutAt(Date paidOutAt) {
public void setPaidOutAt(DateTime paidOutAt) {
this.paidOutAt = paidOutAt;
}

Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/instamojo/wrapper/model/Refund.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.instamojo.wrapper.model;

import com.google.gson.annotations.SerializedName;

import java.util.Date;
import org.joda.time.DateTime;

/**
* The Class Refund.
Expand Down Expand Up @@ -31,7 +30,7 @@ public class Refund {
private Double totalAmount;

@SerializedName("created_at")
private Date createdAt;
private DateTime createdAt;

public String getId() {
return id;
Expand Down Expand Up @@ -89,11 +88,11 @@ public void setTotalAmount(Double totalAmount) {
this.totalAmount = totalAmount;
}

public Date getCreatedAt() {
public DateTime getCreatedAt() {
return createdAt;
}

public void setCreatedAt(Date createdAt) {
public void setCreatedAt(DateTime createdAt) {
this.createdAt = createdAt;
}

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/instamojo/wrapper/util/DateTimeUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.instamojo.wrapper.util;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.ISODateTimeFormat;

public class DateTimeUtils {

public static DateTime parseISODateTimeString(String datetime) {
return ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC).parseDateTime(datetime);
}

}
36 changes: 36 additions & 0 deletions src/main/java/com/instamojo/wrapper/util/GsonWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.instamojo.wrapper.util;

import com.google.gson.*;
import org.joda.time.DateTime;

import java.lang.reflect.Type;


final class DateTimeDeserializer implements JsonDeserializer<DateTime> {

@Override
public DateTime deserialize(JsonElement value, Type type, JsonDeserializationContext context) throws JsonParseException {
return value == null ? null : DateTimeUtils.parseISODateTimeString(value.getAsString());
}
}

final class DateTimeSerializer implements JsonSerializer<DateTime> {

@Override
public JsonElement serialize(DateTime dt, Type type, JsonSerializationContext context) throws JsonParseException {
return dt == null ? null : new JsonPrimitive(dt.toString());
}

}


public class GsonWrapper {

public static Gson getGson() {
return new GsonBuilder()
.registerTypeAdapter(DateTime.class, new DateTimeDeserializer())
.registerTypeAdapter(DateTime.class, new DateTimeSerializer())
.create();
}

}
5 changes: 1 addition & 4 deletions src/main/java/com/instamojo/wrapper/util/HttpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,8 @@ public static String post(String url, Map<String, String> customHeaders, String
}

private static boolean isErrorStatus(int statusCode) {
if (statusCode >= 400 && statusCode < 600) {
return true;
}
return statusCode >= 400 && statusCode < 600;

return false;
}

private static void populateHeaders(HttpRequestBase httpRequestBase, Map<String, String> customHeaders) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class InstamojoExample {

public static void main(String args[]) {
public static void main(String[] args) {

/*
* Get a reference to the instamojo api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.instamojo.wrapper.builder.PaymentOrderBuilder;
import com.instamojo.wrapper.exception.HTTPException;
import com.instamojo.wrapper.filter.PaymentRequestFilter;
import com.instamojo.wrapper.model.*;
import com.instamojo.wrapper.model.PaymentOrder;
import com.instamojo.wrapper.model.PaymentOrderResponse;
import com.instamojo.wrapper.model.PaymentRequest;
import com.instamojo.wrapper.response.ApiListResponse;
import com.instamojo.wrapper.util.TestConstants;
import org.junit.Before;
Expand Down
Loading