Skip to content

Commit e295e00

Browse files
author
Ian Saunders
committed
Realtime pricing calc
1 parent da8a3f4 commit e295e00

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+572
-215
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ Add this dependency to your project's POM:
1717
<dependency>
1818
<groupId>net.billforward</groupId>
1919
<artifactId>billforward-java</artifactId>
20-
<version>1.2014.253</version>
20+
<version>1.2014.254</version>
2121
</dependency>
2222

2323
### Gradle users
2424

2525
Add this dependency to your project's build file:
2626

27-
compile "net.billforward:billforward-java:1.2014.253"
27+
compile "net.billforward:billforward-java:1.2014.254"
2828

2929
### Others
3030

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>net.billforward</groupId>
55
<artifactId>billforward-java</artifactId>
66
<packaging>jar</packaging>
7-
<version>1.2014.253</version>
7+
<version>1.2014.254</version>
88
<name>billforward-java</name>
99
<url>https://github.com/billforward/bf-java</url>
1010
<licenses>

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

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ public String getApiUrl() {
9090
for(GatewayTypeMapping mapping : mappings) {
9191
apiConfigAdapter.registerSubtype((Class)mapping.getApiType(), mapping.getName());
9292
}
93-
93+
//2014-09-12T03:00:17Z
9494
GSON = new GsonBuilder()
95-
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
95+
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
9696
.excludeFieldsWithoutExposeAnnotation()
9797
.registerTypeAdapterFactory(apiConfigAdapter)
9898
.setFieldNamingPolicy(FieldNamingPolicy.IDENTITY)
@@ -332,12 +332,44 @@ private BillForwardResponse makeURLConnectionRequest(RequestMethod method, Strin
332332
}
333333
}
334334

335-
public <T> APIResponse<T> request(RequestMethod method, String url, T obj, Type responseType) throws AuthenticationException,
336-
InvalidRequestException,
337-
APIConnectionException,
338-
CardException,
339-
APIException {
340335

336+
337+
public <TRequest, TResponse> TResponse requestUntyped(RequestMethod method, String url, TRequest obj, Type responseType) throws AuthenticationException,
338+
InvalidRequestException,
339+
APIConnectionException,
340+
CardException,
341+
APIException {
342+
url = String.format("%s/%s", apiUrl, url);
343+
String originalDNSCacheTTL = null;
344+
Boolean allowedToSetTTL = true;
345+
try {
346+
originalDNSCacheTTL = java.security.Security.getProperty(DNS_CACHE_TTL_PROPERTY_NAME);
347+
// disable DNS cache
348+
java.security.Security.setProperty(DNS_CACHE_TTL_PROPERTY_NAME, "0");
349+
} catch (SecurityException se) {
350+
allowedToSetTTL = false;
351+
}
352+
353+
try {
354+
return _requestUntyped(responseType, method, url, obj, apiKey);
355+
} finally {
356+
if (allowedToSetTTL) {
357+
if (originalDNSCacheTTL == null) {
358+
// value unspecified by implementation
359+
// DNS_CACHE_TTL_PROPERTY_NAME of -1 = cache forever
360+
java.security.Security.setProperty(DNS_CACHE_TTL_PROPERTY_NAME, "-1");
361+
} else {
362+
java.security.Security.setProperty(DNS_CACHE_TTL_PROPERTY_NAME, originalDNSCacheTTL);
363+
}
364+
}
365+
}
366+
}
367+
368+
public <T> APIResponse<T> request(RequestMethod method, String url, T obj, Type responseType) throws AuthenticationException,
369+
InvalidRequestException,
370+
APIConnectionException,
371+
CardException,
372+
APIException {
341373
url = String.format("%s/%s", apiUrl, url);
342374
String originalDNSCacheTTL = null;
343375
Boolean allowedToSetTTL = true;
@@ -364,6 +396,36 @@ public <T> APIResponse<T> request(RequestMethod method, String url, T obj, Type
364396
}
365397
}
366398

399+
400+
protected <TRequest, TResponse> TResponse _requestUntyped(Type responseType, RequestMethod method, String url, TRequest obj, String apiKey) throws AuthenticationException,
401+
InvalidRequestException, APIConnectionException, CardException,
402+
APIException {
403+
if ((apiKey == null || apiKey.length() == 0) && (apiKey == null || apiKey.length() == 0)) {
404+
throw new AuthenticationException(
405+
"No API key provided. (HINT: set your API key using 'BillForward.apiKey = <API-KEY>'. "
406+
+ "You can generate API keys from the BillForward web interface. "
407+
+ "See https://BillForward.com/api for details or email support@BillForward.com if you have questions.");
408+
}
409+
410+
String query = "";
411+
if(obj != null) {
412+
query = GSON.toJson(obj);
413+
}
414+
415+
BillForwardResponse response = makeURLConnectionRequest(method, url, query, apiKey);
416+
int rCode = response.getResponseCode();
417+
String rBody = response.getResponseBody();
418+
if (rCode < 200 || rCode >= 300) {
419+
handleAPIError(rBody, rCode);
420+
}
421+
422+
423+
TResponse acc = GSON.fromJson(rBody, responseType);
424+
return acc;
425+
}
426+
427+
428+
367429
protected <T> APIResponse<T> _request(Type responseType, RequestMethod method, String url, T obj, String apiKey) throws AuthenticationException,
368430
InvalidRequestException, APIConnectionException, CardException,
369431
APIException {

src/main/java/net/billforward/model/Account.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.billforward.model;
22

3+
import java.util.Date;
4+
35
import net.billforward.BillForwardClient;
46
import net.billforward.exception.APIConnectionException;
57
import net.billforward.exception.APIException;
@@ -23,8 +25,8 @@ public class Account extends MutableEntity<Account> {
2325
@Expose protected String userID;
2426
@Expose protected int successfulSubscriptions;
2527
@Expose protected boolean deleted;
26-
@Expose protected String created;
27-
@Expose protected String updated;
28+
@Expose protected Date created;
29+
@Expose protected Date updated;
2830
@Expose protected String changedBy;
2931
@Expose protected Profile profile;
3032
@Expose protected PaymentMethod[] paymentMethods;
@@ -83,14 +85,14 @@ public void setDeleted(boolean deleted) {
8385
/**
8486
* @return The UTC DateTime when the object was created.
8587
*/
86-
public String getCreated() {
88+
public Date getCreated() {
8789
return created;
8890
}
8991

9092
/**
9193
* @return The UTC DateTime when the object was last updated.
9294
*/
93-
public String getUpdated() {
95+
public Date getUpdated() {
9496
return updated;
9597
}
9698

@@ -125,6 +127,7 @@ public static Account create(Account account) throws AuthenticationException, In
125127

126128
public static Account getByID(String ID) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException {
127129
Account[] accs = getByID(ID, ResourcePath());
130+
if(accs == null || accs.length == 0) return null;
128131
return accs[0];
129132
}
130133

src/main/java/net/billforward/model/Address.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.billforward.model;
22

3+
import java.util.Date;
4+
35
import net.billforward.BillForwardClient;
46
import net.billforward.exception.APIConnectionException;
57
import net.billforward.exception.APIException;
@@ -24,9 +26,9 @@ public class Address extends MutableEntity<Address> {
2426
@Expose protected String landline = "";
2527
@Expose protected Boolean primaryAddress;
2628
@Expose protected Boolean deleted;
27-
@Expose protected String updated;
29+
@Expose protected Date updated;
2830
@Expose protected String changedBy;
29-
@Expose protected String created;
31+
@Expose protected Date created;
3032

3133
public String getID() {
3234
return id;
@@ -124,15 +126,15 @@ public void setDeleted(Boolean deleted) {
124126
this.deleted = deleted;
125127
}
126128

127-
public String getUpdated() {
129+
public Date getUpdated() {
128130
return updated;
129131
}
130132

131133
public String getChangedBy() {
132134
return changedBy;
133135
}
134136

135-
public String getCreated() {
137+
public Date getCreated() {
136138
return created;
137139
}
138140

src/main/java/net/billforward/model/Alias.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.billforward.model;
22

3+
import java.util.Date;
4+
35
import net.billforward.BillForwardClient;
46

57
import com.google.gson.annotations.Expose;
@@ -10,9 +12,9 @@ public class Alias extends BillingEntity {
1012
@Expose protected String organizationID;
1113
@Expose protected String alias;
1214
@Expose protected boolean deleted;
13-
@Expose protected String updated;
15+
@Expose protected Date updated;
1416
@Expose protected String changedBy;
15-
@Expose protected String created;
17+
@Expose protected Date created;
1618

1719
public String getID() {
1820
return id;

src/main/java/net/billforward/model/BillingEntity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package net.billforward.model;
22

3+
import java.lang.reflect.Array;
34
import java.lang.reflect.Field;
5+
import java.util.ArrayList;
46

57
import net.billforward.BillForwardClient;
68
import net.billforward.exception.APIConnectionException;

src/main/java/net/billforward/model/DunningLine.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.billforward.model;
22

3+
import java.util.Date;
4+
35
import net.billforward.BillForwardClient;
46

57
import com.google.gson.annotations.Expose;
@@ -11,9 +13,9 @@ public class DunningLine extends MutableEntity<DunningLine> {
1113
@Expose protected int attemptIx;
1214
@Expose protected int minutesDelay;
1315
@Expose protected boolean deleted;
14-
@Expose protected String updated;
16+
@Expose protected Date updated;
1517
@Expose protected String changedBy;
16-
@Expose protected String created;
18+
@Expose protected Date created;
1719
@Expose protected Organization organization;
1820

1921
public String getID() {

src/main/java/net/billforward/model/FixedTermDefinition.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.billforward.model;
22

33
import java.math.BigDecimal;
4+
import java.util.Date;
45

56
import net.billforward.BillForwardClient;
67

@@ -14,12 +15,12 @@ public class FixedTermDefinition extends MutableEntity<TaxationStrategy> {
1415
@Expose protected String expiryBehaviour;
1516
@Expose protected int firstTermPeriods;
1617
@Expose protected int subsequentTermPeriods;
17-
@Expose protected String productRatePlanAsOfTime;
18+
@Expose protected Date productRatePlanAsOfTime;
1819
@Expose protected BigDecimal uplift;
1920
@Expose protected Boolean deleted;
20-
@Expose protected String updated;
21+
@Expose protected Date updated;
2122
@Expose protected String changedBy;
22-
@Expose protected String created;
23+
@Expose protected Date created;
2324

2425
public String getID() {
2526
return id;

src/main/java/net/billforward/model/Invoice.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.billforward.model;
22

33
import java.math.BigDecimal;
4+
import java.util.Date;
45

56
import net.billforward.BillForwardClient;
67
import net.billforward.exception.APIConnectionException;
@@ -18,14 +19,14 @@ public class Invoice extends BillingEntity {
1819
@Expose protected String accountID;
1920
@Expose protected String organizationID;
2021
@Expose protected String state;
21-
@Expose protected String periodStart;
22-
@Expose protected String periodEnd;
22+
@Expose protected Date periodStart;
23+
@Expose protected Date periodEnd;
2324
@Expose protected Boolean deleted = false;
2425
@Expose protected int totalExecutionAttempts;
25-
@Expose protected String lastExecutionAttempt;
26-
@Expose protected String nextExecutionAttempt;
27-
@Expose protected String finalExecutionAttempt;
28-
@Expose protected String paymentReceived;
26+
@Expose protected Date lastExecutionAttempt;
27+
@Expose protected Date nextExecutionAttempt;
28+
@Expose protected Date finalExecutionAttempt;
29+
@Expose protected Date paymentReceived;
2930
@Expose protected String currency;
3031
@Expose protected BigDecimal costExcludingTax;
3132
@Expose protected BigDecimal invoiceCost;
@@ -37,9 +38,9 @@ public class Invoice extends BillingEntity {
3738
@Expose protected String managedBy;
3839
@Expose protected Boolean initialInvoice;
3940
@Expose protected int versionNumber;
40-
@Expose protected String updated;
41+
@Expose protected Date updated;
4142
@Expose protected String changedBy;
42-
@Expose protected String created;
43+
@Expose protected Date created;
4344

4445
protected InvoiceLine[] invoiceLines;
4546
protected InvoicePayment[] invoicePayments;
@@ -68,11 +69,11 @@ public InvoiceState getState() {
6869
return InvoiceState.valueOf(state);
6970
}
7071

71-
public String getPeriodStart() {
72+
public Date getPeriodStart() {
7273
return periodStart;
7374
}
7475

75-
public String getPeriodEnd() {
76+
public Date getPeriodEnd() {
7677
return periodEnd;
7778
}
7879

@@ -84,19 +85,19 @@ public int getTotalExecutionAttempts() {
8485
return totalExecutionAttempts;
8586
}
8687

87-
public String getLastExecutionAttempt() {
88+
public Date getLastExecutionAttempt() {
8889
return lastExecutionAttempt;
8990
}
9091

91-
public String getNextExecutionAttempt() {
92+
public Date getNextExecutionAttempt() {
9293
return nextExecutionAttempt;
9394
}
9495

95-
public String getFinalExecutionAttempt() {
96+
public Date getFinalExecutionAttempt() {
9697
return finalExecutionAttempt;
9798
}
9899

99-
public String getPaymentReceived() {
100+
public Date getPaymentReceived() {
100101
return paymentReceived;
101102
}
102103

@@ -148,15 +149,15 @@ public int getVersionNumber() {
148149
return versionNumber;
149150
}
150151

151-
public String getUpdated() {
152+
public Date getUpdated() {
152153
return updated;
153154
}
154155

155156
public String getChangedBy() {
156157
return changedBy;
157158
}
158159

159-
public String getCreated() {
160+
public Date getCreated() {
160161
return created;
161162
}
162163

0 commit comments

Comments
 (0)