Skip to content

Commit 296d86c

Browse files
authored
Merge pull request #256 from mwarzybok-sumoheavy/feature/SP-579
SP-579 Java - Implement better refund exceptions
2 parents 3688226 + bf40111 commit 296d86c

File tree

135 files changed

+1717
-5735
lines changed

Some content is hidden

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

135 files changed

+1717
-5735
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.bitpay</groupId>
88
<artifactId>bitpay_sdk</artifactId>
9-
<version>9.0.2</version>
9+
<version>10.0.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>BitPay</name>

src/main/java/com/bitpay/sdk/Client.java

Lines changed: 263 additions & 331 deletions
Large diffs are not rendered by default.

src/main/java/com/bitpay/sdk/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class Config {
3434
/**
3535
* BitPay Plugin Info Version.
3636
*/
37-
public static final String BITPAY_PLUGIN_INFO = "BitPay_Java_Client_v9.0.2";
37+
public static final String BITPAY_PLUGIN_INFO = "BitPay_Java_Client_v10.0.0";
3838
/**
3939
* BitPay Api Frame.
4040
*/

src/main/java/com/bitpay/sdk/client/AuthorizationClient.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
package com.bitpay.sdk.client;
77

8-
import com.bitpay.sdk.exceptions.BitPayException;
8+
import com.bitpay.sdk.exceptions.BitPayApiException;
9+
import com.bitpay.sdk.exceptions.BitPayExceptionProvider;
10+
import com.bitpay.sdk.exceptions.BitPayGenericException;
911
import com.bitpay.sdk.model.Facade;
1012
import com.bitpay.sdk.model.Token;
1113
import com.bitpay.sdk.util.GuidGenerator;
@@ -16,7 +18,6 @@
1618
import java.util.Arrays;
1719
import java.util.List;
1820
import java.util.Objects;
19-
import org.apache.http.HttpResponse;
2021

2122
/**
2223
* The type Authorization client.
@@ -52,36 +53,34 @@ public AuthorizationClient(
5253
* Authorize (pair) this client with the server using the specified pairing code.
5354
*
5455
* @param pairingCode A code obtained from the server; typically from bitpay.com/api-tokens.
55-
* @throws BitPayException BitPayException class
56+
* @throws BitPayApiException BitPayApiException class
57+
* @throws BitPayGenericException BitPayGenericException class
5658
*/
57-
public void authorizeClient(String pairingCode) throws BitPayException {
59+
public void authorizeClient(String pairingCode) throws BitPayApiException, BitPayGenericException {
5860
Token token = new Token();
5961
token.setId(this.identity);
6062
token.setGuid(this.guidGenerator.execute());
6163
token.setPairingCode(pairingCode);
6264

6365
JsonMapper mapper = JsonMapperFactory.create();
6466

65-
String json;
67+
String json = null;
6668

6769
try {
6870
json = mapper.writeValueAsString(token);
6971
} catch (JsonProcessingException e) {
70-
throw new BitPayException(null, "failed to serialize Token object : " + e.getMessage());
72+
BitPayExceptionProvider.throwGenericExceptionWithMessage(
73+
"Failed to serialize Token object : " + e.getMessage());
7174
}
7275

73-
HttpResponse response = this.bitPayClient.post("tokens", json);
76+
String jsonResponse = this.bitPayClient.post("tokens", json);
7477

75-
List<Token> tokens;
78+
List<Token> tokens = null;
7679

7780
try {
78-
tokens = Arrays.asList(mapper.readValue(this.bitPayClient.responseToJsonString(response), Token[].class));
81+
tokens = Arrays.asList(mapper.readValue(jsonResponse, Token[].class));
7982
} catch (JsonProcessingException e) {
80-
throw new BitPayException(null,
81-
"failed to deserialize BitPay server response (Tokens) : " + e.getMessage());
82-
} catch (Exception e) {
83-
throw new BitPayException(null,
84-
"failed to deserialize BitPay server response (Tokens) : " + e.getMessage());
83+
BitPayExceptionProvider.throwDeserializeResourceException("Tokens", e.getMessage());
8584
}
8685

8786
for (Token t : tokens) {
@@ -94,12 +93,14 @@ public void authorizeClient(String pairingCode) throws BitPayException {
9493
*
9594
* @param facade Defines the level of API access being requested
9695
* @return A pairing code for claim at https://bitpay.com/dashboard/merchant/api-tokens.
97-
* @throws BitPayException BitPayException class
96+
* @throws BitPayGenericException BitPayGenericException class
97+
* @throws BitPayApiException BitPayApiException class
9898
*/
99-
public String authorizeClient(Facade facade) throws BitPayException {
99+
public String authorizeClient(Facade facade) throws BitPayApiException, BitPayGenericException {
100100
if (Objects.isNull(facade)) {
101-
throw new BitPayException(null, "missing required parameter");
101+
BitPayExceptionProvider.throwValidationException("Missing required parameter");
102102
}
103+
103104
Token token = new Token();
104105
token.setId(this.identity);
105106
token.setGuid(this.guidGenerator.execute());
@@ -108,32 +109,31 @@ public String authorizeClient(Facade facade) throws BitPayException {
108109

109110
JsonMapper mapper = JsonMapperFactory.create();
110111

111-
String json;
112+
String json = null;
112113

113114
try {
114115
json = mapper.writeValueAsString(token);
115116
} catch (JsonProcessingException e) {
116-
throw new BitPayException(null, "failed to serialize Token object : " + e.getMessage());
117+
BitPayExceptionProvider.throwSerializeResourceException("Token", e.getMessage());
117118
}
118119

119-
HttpResponse response = this.bitPayClient.post("tokens", json);
120+
String response = this.bitPayClient.post("tokens", json);
120121

121-
List<Token> tokens;
122+
List<Token> tokens = null;
122123

123124
try {
124-
tokens = Arrays.asList(mapper.readValue(this.bitPayClient.responseToJsonString(response), Token[].class));
125+
tokens = Arrays.asList(mapper.readValue(response, Token[].class));
125126

126127
// Expecting a single token resource.
127128
if (tokens.size() != 1) {
128-
throw new BitPayException(null, "failed to get token resource; expected 1 token, got " + tokens.size());
129+
BitPayExceptionProvider.throwDeserializeResourceException(
130+
"Token",
131+
"expected 1 token, got " + tokens.size()
132+
);
129133
}
130134

131135
} catch (JsonProcessingException e) {
132-
throw new BitPayException(null,
133-
"failed to deserialize BitPay server response (Tokens) : " + e.getMessage());
134-
} catch (Exception e) {
135-
throw new BitPayException(null,
136-
"failed to deserialize BitPay server response (Tokens) : " + e.getMessage());
136+
BitPayExceptionProvider.throwDeserializeResourceException("Tokens", e.getMessage());
137137
}
138138

139139
this.accessToken.put(tokens.get(0).getFacade(), tokens.get(0).getValue());

0 commit comments

Comments
 (0)