Skip to content

Commit 2626968

Browse files
author
Ian Saunders
committed
Support for notifications and amednemtsn
1 parent 33cff50 commit 2626968

22 files changed

Lines changed: 1050 additions & 4 deletions

src/main/java/net/billforward/BillForwardClient.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.Map;
1616
import java.util.Scanner;
1717

18+
import net.billforward.amendments.Amendment;
1819
import net.billforward.exception.APIConnectionException;
1920
import net.billforward.exception.APIException;
2021
import net.billforward.exception.AuthenticationException;
@@ -24,6 +25,7 @@
2425
import net.billforward.model.APIResponse;
2526
import net.billforward.model.gateways.APIConfiguration;
2627
import net.billforward.model.gateways.GatewayTypeMapping;
28+
import net.billforward.model.notifications.Notification;
2729
import net.billforward.net.BillForwardResponse;
2830

2931
import com.google.gson.FieldNamingPolicy;
@@ -90,11 +92,32 @@ public String getApiUrl() {
9092
for(GatewayTypeMapping mapping : mappings) {
9193
apiConfigAdapter.registerSubtype((Class)mapping.getApiType(), mapping.getName());
9294
}
95+
96+
/*
97+
* This is to support polymorphism in the different type of Amendments
98+
*/
99+
RuntimeTypeAdapterFactory<Amendment> amendmentConfigAdapter = RuntimeTypeAdapterFactory.of(Amendment.class, "@type");
100+
mappings = Amendment.getTypeMappings();
101+
for(GatewayTypeMapping mapping : mappings) {
102+
amendmentConfigAdapter.registerSubtype((Class)mapping.getApiType(), mapping.getName());
103+
}
104+
105+
/*
106+
* This is to support polymorphism in the different type of Notifications
107+
*/
108+
RuntimeTypeAdapterFactory<Notification> notificationConfigAdapter = RuntimeTypeAdapterFactory.of(Notification.class, "domain");
109+
mappings = Notification.getTypeMappings();
110+
for(GatewayTypeMapping mapping : mappings) {
111+
notificationConfigAdapter.registerSubtype((Class)mapping.getApiType(), mapping.getName());
112+
}
113+
93114
//2014-09-12T03:00:17Z
94115
GSON = new GsonBuilder()
95116
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
96117
.excludeFieldsWithoutExposeAnnotation()
97118
.registerTypeAdapterFactory(apiConfigAdapter)
119+
.registerTypeAdapterFactory(amendmentConfigAdapter)
120+
.registerTypeAdapterFactory(notificationConfigAdapter)
98121
.setFieldNamingPolicy(FieldNamingPolicy.IDENTITY)
99122
.create();
100123
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package net.billforward.amendments;
2+
3+
import java.util.ArrayList;
4+
import java.util.Date;
5+
import java.util.List;
6+
7+
import net.billforward.BillForwardClient;
8+
import net.billforward.model.InsertableEntity;
9+
import net.billforward.model.gateways.GatewayTypeMapping;
10+
11+
import com.google.gson.annotations.Expose;
12+
13+
public abstract class Amendment extends InsertableEntity<Amendment> {
14+
@Expose protected String id;
15+
@Expose protected String organizationID;
16+
@Expose protected String subscriptionID;
17+
@Expose protected Date actioningTime;
18+
@Expose protected Date actionedTime;
19+
@Expose protected String state;
20+
@Expose protected Date nextStatusCheckTime;
21+
@Expose protected Date nextOverdueCheckTime;
22+
@Expose protected Boolean deleted;
23+
@Expose protected Date created;
24+
@Expose protected Date updated;
25+
@Expose protected String changedBy;
26+
27+
public String getID() {
28+
return id;
29+
}
30+
31+
public String getSubscriptionID() {
32+
return subscriptionID;
33+
}
34+
35+
public void setSubscriptionID(String subscriptionID) {
36+
this.subscriptionID = subscriptionID;
37+
}
38+
39+
public Date getActioningTime() {
40+
return actioningTime;
41+
}
42+
43+
public void setActioningTime(Date actioningTime) {
44+
this.actioningTime = actioningTime;
45+
}
46+
47+
public Boolean getDeleted() {
48+
return deleted;
49+
}
50+
51+
public void setDeleted(Boolean deleted) {
52+
this.deleted = deleted;
53+
}
54+
55+
public String getOrganizationID() {
56+
return organizationID;
57+
}
58+
59+
public Date getActionedTime() {
60+
return actionedTime;
61+
}
62+
63+
public String getStateAsString() {
64+
return state;
65+
}
66+
67+
public AmendmentState getState() {
68+
return AmendmentState.valueOf(state);
69+
}
70+
71+
public Date getNextStatusCheckTime() {
72+
return nextStatusCheckTime;
73+
}
74+
75+
public Date getNextOverdueCheckTime() {
76+
return nextOverdueCheckTime;
77+
}
78+
79+
public Date getCreated() {
80+
return created;
81+
}
82+
83+
public Date getUpdated() {
84+
return updated;
85+
}
86+
87+
public String getChangedBy() {
88+
return changedBy;
89+
}
90+
91+
public Amendment(BillForwardClient client_) {
92+
super(client_);
93+
}
94+
95+
protected Amendment() {
96+
}
97+
98+
public enum AmendmentType {
99+
invoiceNextExecutionAttemptAmendment,
100+
cancellationAmendment,
101+
pricingComponentValueAmendment,
102+
amendmentDiscardAmendment,
103+
CompoundAmendment,
104+
FixedTermExpiryAmendment,
105+
GatewayMigrationAmendment,
106+
DefaultQuantityAmendment,
107+
InvoiceRecalculationAmendment,
108+
EndTrialAmendment,
109+
CreateSubscriptionChargeAmendment,
110+
InvoiceOutstandingChargesAmendment,
111+
IssueInvoiceAmendment;
112+
}
113+
114+
public enum AmendmentState {
115+
Pending,
116+
Succeeded,
117+
Failed,
118+
Discarded
119+
}
120+
121+
public static GatewayTypeMapping[] getTypeMappings() {
122+
List<GatewayTypeMapping> typeMappings = new ArrayList<GatewayTypeMapping>();
123+
typeMappings.add(new GatewayTypeMapping(InvoiceNextExecutionAttemptAmendment.class, InvoiceNextExecutionAttemptAmendment.class.getSimpleName()));
124+
typeMappings.add(new GatewayTypeMapping(InvoiceRecalculationAmendment.class, InvoiceRecalculationAmendment.class.getSimpleName()));
125+
typeMappings.add(new GatewayTypeMapping(IssueInvoiceAmendment.class, IssueInvoiceAmendment.class.getSimpleName()));
126+
typeMappings.add(new GatewayTypeMapping(CancellationAmendment.class, CancellationAmendment.class.getSimpleName()));
127+
128+
return typeMappings.toArray(new GatewayTypeMapping[]{});
129+
}
130+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package net.billforward.amendments;
2+
3+
import net.billforward.BillForwardClient;
4+
import net.billforward.exception.APIConnectionException;
5+
import net.billforward.exception.APIException;
6+
import net.billforward.exception.AuthenticationException;
7+
import net.billforward.exception.CardException;
8+
import net.billforward.exception.InvalidRequestException;
9+
import net.billforward.model.APIResponse;
10+
import net.billforward.model.ResourcePath;
11+
12+
import com.google.gson.annotations.Expose;
13+
import com.google.gson.annotations.SerializedName;
14+
import com.google.gson.reflect.TypeToken;
15+
16+
/**
17+
* Currently doesn't work on public API. JIRA Raised.
18+
*
19+
*/
20+
public class AmendmentDiscardAmendment extends Amendment {
21+
@SerializedName("@type")
22+
@Expose protected String amendmentType = AmendmentType.amendmentDiscardAmendment.toString();
23+
@Expose protected String amendmentToDiscardID;
24+
25+
public String getAmendmentToDiscardID() {
26+
return amendmentToDiscardID;
27+
}
28+
29+
public void setAmendmentToDiscardID(String amendmentToDiscardID) {
30+
this.amendmentToDiscardID = amendmentToDiscardID;
31+
}
32+
33+
public AmendmentDiscardAmendment(BillForwardClient client_) {
34+
super(client_);
35+
}
36+
37+
public AmendmentDiscardAmendment() {
38+
super();
39+
}
40+
41+
protected ResourcePath getResourcePath() {
42+
return resourcePath;
43+
}
44+
45+
protected static ResourcePath resourcePath;
46+
47+
protected static ResourcePath ResourcePath() {
48+
return resourcePath;
49+
}
50+
51+
static {
52+
resourcePath = new ResourcePath("amendments", "amendments", new TypeToken<APIResponse<AmendmentDiscardAmendment>>() {}.getType());
53+
}
54+
55+
public static AmendmentDiscardAmendment create(AmendmentDiscardAmendment amendment) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException {
56+
return create(amendment, ResourcePath())[0];
57+
}
58+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package net.billforward.amendments;
2+
3+
import net.billforward.BillForwardClient;
4+
import net.billforward.exception.APIConnectionException;
5+
import net.billforward.exception.APIException;
6+
import net.billforward.exception.AuthenticationException;
7+
import net.billforward.exception.CardException;
8+
import net.billforward.exception.InvalidRequestException;
9+
import net.billforward.model.APIResponse;
10+
import net.billforward.model.ResourcePath;
11+
12+
import com.google.gson.annotations.Expose;
13+
import com.google.gson.annotations.SerializedName;
14+
import com.google.gson.reflect.TypeToken;
15+
16+
public class CancellationAmendment extends Amendment {
17+
@SerializedName("@type")
18+
@Expose protected String amendmentType = AmendmentType.cancellationAmendment.toString();
19+
@Expose protected String source = "";
20+
@Expose protected String serviceEnd;
21+
@Expose protected SubscriptionCancellation subscriptionCancellation;
22+
23+
public String getSource() {
24+
return source;
25+
}
26+
27+
public void setSource(String source) {
28+
this.source = source;
29+
}
30+
31+
public String getServiceEndAsString() {
32+
return serviceEnd;
33+
}
34+
35+
public ServiceEndState getServiceEnd() {
36+
return ServiceEndState.valueOf(serviceEnd);
37+
}
38+
39+
public void setServiceEnd(ServiceEndState serviceEnd) {
40+
this.serviceEnd = serviceEnd.toString();
41+
}
42+
43+
public SubscriptionCancellation getSubscriptionCancellation() {
44+
return subscriptionCancellation;
45+
}
46+
47+
public CancellationAmendment(BillForwardClient client_) {
48+
super(client_);
49+
}
50+
51+
public CancellationAmendment() {
52+
super();
53+
}
54+
55+
protected ResourcePath getResourcePath() {
56+
return resourcePath;
57+
}
58+
59+
protected static ResourcePath resourcePath;
60+
61+
protected static ResourcePath ResourcePath() {
62+
return resourcePath;
63+
}
64+
65+
static {
66+
resourcePath = new ResourcePath("amendments", "amendments", new TypeToken<APIResponse<CancellationAmendment>>() {}.getType());
67+
}
68+
69+
public static CancellationAmendment create(CancellationAmendment amendment) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException {
70+
return create(amendment, ResourcePath())[0];
71+
}
72+
73+
public enum ServiceEndState {
74+
Immediate,
75+
AtPeriodEnd
76+
}
77+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package net.billforward.amendments;
2+
3+
import java.util.Date;
4+
5+
import net.billforward.BillForwardClient;
6+
import net.billforward.exception.APIConnectionException;
7+
import net.billforward.exception.APIException;
8+
import net.billforward.exception.AuthenticationException;
9+
import net.billforward.exception.CardException;
10+
import net.billforward.exception.InvalidRequestException;
11+
import net.billforward.model.APIResponse;
12+
import net.billforward.model.ResourcePath;
13+
14+
import com.google.gson.annotations.Expose;
15+
import com.google.gson.annotations.SerializedName;
16+
import com.google.gson.reflect.TypeToken;
17+
18+
public class InvoiceNextExecutionAttemptAmendment extends Amendment {
19+
@SerializedName("@type")
20+
@Expose protected String amendmentType = AmendmentType.invoiceNextExecutionAttemptAmendment.toString();
21+
@Expose String invoiceID;
22+
@Expose Date nextExecutionAttempt;
23+
24+
public String getAmendmentTypeAsString() {
25+
return amendmentType;
26+
}
27+
28+
public AmendmentType getAmendmentType() {
29+
return AmendmentType.valueOf(amendmentType);
30+
}
31+
32+
public String getInvoiceID() {
33+
return invoiceID;
34+
}
35+
36+
public void setInvoiceID(String invoiceID) {
37+
this.invoiceID = invoiceID;
38+
}
39+
40+
public Date getNextExecutionAttempt() {
41+
return nextExecutionAttempt;
42+
}
43+
44+
public void setNextExecutionAttempt(Date nextExecutionAttempt) {
45+
this.nextExecutionAttempt = nextExecutionAttempt;
46+
}
47+
48+
public InvoiceNextExecutionAttemptAmendment(BillForwardClient client_) {
49+
super(client_);
50+
}
51+
52+
public InvoiceNextExecutionAttemptAmendment() {
53+
super();
54+
}
55+
56+
protected ResourcePath getResourcePath() {
57+
return resourcePath;
58+
}
59+
60+
protected static ResourcePath resourcePath;
61+
62+
protected static ResourcePath ResourcePath() {
63+
return resourcePath;
64+
}
65+
66+
static {
67+
resourcePath = new ResourcePath("amendments", "amendments", new TypeToken<APIResponse<InvoiceNextExecutionAttemptAmendment>>() {}.getType());
68+
}
69+
70+
public static InvoiceNextExecutionAttemptAmendment create(InvoiceNextExecutionAttemptAmendment amendment) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException {
71+
return create(amendment, ResourcePath())[0];
72+
}
73+
}

0 commit comments

Comments
 (0)