Skip to content

Commit bf7167a

Browse files
authored
Merge pull request #29 from PhonePe/formater_hook
singleton pattern removal and pre-commit hook
2 parents 0dd50cb + a35471d commit bf7167a

17 files changed

+882
-716
lines changed

.pre-commit-config.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: spotless-apply
5+
name: Spotless Code Formatter (Apply)
6+
entry: mvn spotless:apply
7+
language: system
8+
pass_filenames: false
9+
stages: [pre-commit]
10+
verbose: true
11+
12+
# some complex rules like missing parentheses in a if, loop statements for a single line are not applied by
13+
# mvn spotless:apply so added another check that will block the commit
14+
- id: spotless-check
15+
name: Spotless Code Formatter (Check)
16+
entry: mvn spotless:check
17+
language: system
18+
pass_filenames: false
19+
stages: [pre-commit]
20+
verbose: true

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# PhonePe B2B Payment Gateway SDK for Java
22

3-
[![Maven Central](https://img.shields.io/badge/Maven%20Central-v2.1.7-blue)](https://maven-badges.herokuapp.com/maven-central/com.phonepe/pg-sdk-java)
3+
[![Maven Central](https://img.shields.io/badge/Maven%20Central-v2.1.8-blue)](https://maven-badges.herokuapp.com/maven-central/com.phonepe/pg-sdk-java)
44
![Java](https://img.shields.io/badge/Java-17%2B-orange)
55
[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](LICENSE)
66

@@ -36,7 +36,7 @@ Add the dependency to your project's POM file:
3636
<dependency>
3737
<groupId>com.phonepe</groupId>
3838
<artifactId>pg-sdk-java</artifactId>
39-
<version>2.1.7</version>
39+
<version>2.1.8</version>
4040
</dependency>
4141
```
4242

@@ -46,7 +46,7 @@ Add the following to your project's build.gradle file:
4646

4747
```gradle
4848
dependencies {
49-
implementation 'com.phonepe:pg-sdk-java:2.1.7'
49+
implementation 'com.phonepe:pg-sdk-java:2.1.8'
5050
}
5151
```
5252

formatter.xml

Lines changed: 380 additions & 0 deletions
Large diffs are not rendered by default.

pom.xml

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

77
<groupId>com.phonepe</groupId>
88
<artifactId>pg-sdk-java</artifactId>
9-
<version>2.1.7</version>
9+
<version>2.1.8</version>
1010
<name>B2B JAVA SDK</name>
1111
<url>https://github.com/PhonePe/phonepe-pg-sdk-java</url>
1212
<description>Phonepe PG JAVA SDK</description>
@@ -97,6 +97,11 @@
9797
<name>Aditi Billore</name>
9898
<email>[email protected]</email>
9999
</developer>
100+
<developer>
101+
<id>Yogesh-Kamble</id>
102+
<name>Yogesh Kamble</name>
103+
<email>[email protected]</email>
104+
</developer>
100105
</developers>
101106

102107
<properties>
@@ -133,14 +138,51 @@
133138
</properties>
134139

135140
<build>
141+
<resources>
142+
<resource>
143+
<directory>src/main/resources</directory>
144+
<filtering>true</filtering>
145+
</resource>
146+
</resources>
136147
<plugins>
148+
<plugin>
149+
<groupId>org.apache.maven.plugins</groupId>
150+
<artifactId>maven-source-plugin</artifactId>
151+
<version>3.2.1</version>
152+
<executions>
153+
<execution>
154+
<id>attach-sources</id>
155+
<goals>
156+
<goal>jar-no-fork</goal>
157+
</goals>
158+
</execution>
159+
</executions>
160+
</plugin>
161+
<plugin>
162+
<groupId>org.apache.maven.plugins</groupId>
163+
<artifactId>maven-javadoc-plugin</artifactId>
164+
<version>3.4.0</version>
165+
<executions>
166+
<execution>
167+
<id>attach-javadocs</id>
168+
<goals>
169+
<goal>jar</goal>
170+
</goals>
171+
</execution>
172+
</executions>
173+
</plugin>
137174
<plugin>
138175
<groupId>com.diffplug.spotless</groupId>
139176
<artifactId>spotless-maven-plugin</artifactId>
140177
<version>${spotless.version}</version>
141178
<configuration>
142179
<ratchetFrom>origin/main</ratchetFrom>
143180
<java>
181+
<!-- Eclipse formatter with custom rules -->
182+
<eclipse>
183+
<file>${project.basedir}/formatter.xml</file>
184+
<version>4.26</version>
185+
</eclipse>
144186
<includes>
145187
<include>src/main/java/**/*.java</include>
146188
<include>src/test/java/**/*.java</include>
@@ -170,6 +212,25 @@
170212
</execution>
171213
</executions>
172214
</plugin>
215+
<plugin>
216+
<groupId>org.jacoco</groupId>
217+
<artifactId>jacoco-maven-plugin</artifactId>
218+
<version>0.8.11</version>
219+
<executions>
220+
<execution>
221+
<goals>
222+
<goal>prepare-agent</goal>
223+
</goals>
224+
</execution>
225+
<execution>
226+
<id>report</id>
227+
<phase>test</phase>
228+
<goals>
229+
<goal>report</goal>
230+
</goals>
231+
</execution>
232+
</executions>
233+
</plugin>
173234
</plugins>
174235
<pluginManagement>
175236
<plugins>
@@ -316,6 +377,12 @@
316377
</repository>
317378
</distributionManagement>
318379
<build>
380+
<resources>
381+
<resource>
382+
<directory>src/main/resources</directory>
383+
<filtering>true</filtering>
384+
</resource>
385+
</resources>
319386
<plugins>
320387
<plugin>
321388
<groupId>org.sonatype.central</groupId>

src/main/java/com/phonepe/sdk/pg/common/constants/Headers.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,34 @@
1515
*/
1616
package com.phonepe.sdk.pg.common.constants;
1717

18+
import java.io.InputStream;
19+
import java.util.Properties;
1820
import lombok.experimental.UtilityClass;
21+
import lombok.extern.slf4j.Slf4j;
1922

2023
@UtilityClass
24+
@Slf4j
2125
public class Headers {
2226

27+
private final Properties properties = new Properties();
28+
private final String PROPERTIES_FILE_NAME = "/sdk.properties";
29+
30+
static {
31+
try (InputStream input = Headers.class.getResourceAsStream(PROPERTIES_FILE_NAME)) {
32+
if (input == null) {
33+
log.error("Could not find {}", PROPERTIES_FILE_NAME);
34+
} else {
35+
properties.load(input);
36+
}
37+
} catch (Exception e) {
38+
log.error("Failed to load SDK properties: {}", e.getMessage());
39+
}
40+
}
41+
2342
public static final String API_VERSION = "V2";
24-
public static final String SUBSCRIPTION_API_VERSION = "2.1.7";
43+
public static final String SUBSCRIPTION_API_VERSION = properties.getProperty("sdk.version");
2544
public static final String INTEGRATION = "API";
26-
public static final String SDK_VERSION = "2.1.7";
45+
public static final String SDK_VERSION = properties.getProperty("sdk.version");
2746
public static final String SDK_TYPE = "BACKEND_JAVA_SDK";
2847
public static final String SOURCE = "x-source";
2948
public static final String SOURCE_VERSION = "x-source-version";
@@ -32,4 +51,4 @@ public class Headers {
3251
public static final String OAUTH_AUTHORIZATION = "Authorization";
3352
public static final String CONTENT_TYPE = "Content-Type";
3453
public static final String ACCEPT = "Accept";
35-
}
54+
}

src/main/java/com/phonepe/sdk/pg/common/http/HttpCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private HttpUrl prepareHttpURL(String url) {
9999
/**
100100
* Executes the HTTP request and returns the response.
101101
*
102-
* @return <T> the response object
102+
* @return the response object
103103
*/
104104
@SneakyThrows
105105
public T execute() {

src/main/java/com/phonepe/sdk/pg/payments/v2/CustomCheckoutClient.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,10 @@
4242
import java.util.ArrayList;
4343
import java.util.Collections;
4444
import java.util.List;
45-
import java.util.concurrent.ConcurrentHashMap;
4645
import lombok.SneakyThrows;
4746

4847
public class CustomCheckoutClient extends BaseClient {
4948

50-
private static final ConcurrentHashMap<String, CustomCheckoutClient> cachedInstances =
51-
new ConcurrentHashMap<>();
5249
private List<HttpHeaderPair> headers;
5350

5451
private CustomCheckoutClient(
@@ -102,20 +99,8 @@ public static CustomCheckoutClient getInstance(
10299
boolean shouldPublishEvents)
103100
throws PhonePeException {
104101
final boolean shouldPublishInProd = shouldPublishEvents && env == Env.PRODUCTION;
105-
final String requestedClientSHA =
106-
CommonUtils.calculateSha256(
107-
clientId,
108-
clientSecret,
109-
clientVersion,
110-
env,
111-
shouldPublishInProd,
112-
FlowType.PG);
113-
114-
return cachedInstances.computeIfAbsent(
115-
requestedClientSHA,
116-
key ->
117-
new CustomCheckoutClient(
118-
clientId, clientSecret, clientVersion, env, shouldPublishInProd));
102+
return new CustomCheckoutClient(
103+
clientId, clientSecret, clientVersion, env, shouldPublishInProd);
119104
}
120105

121106
/**

src/main/java/com/phonepe/sdk/pg/payments/v2/StandardCheckoutClient.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,11 @@
4242
import java.util.ArrayList;
4343
import java.util.Collections;
4444
import java.util.List;
45-
import java.util.concurrent.ConcurrentHashMap;
4645
import lombok.SneakyThrows;
4746

4847
/** The StandardCheckout client class provides methods for interacting with the PhonePe APIs. */
4948
public class StandardCheckoutClient extends BaseClient {
5049

51-
private static final ConcurrentHashMap<String, StandardCheckoutClient> cachedInstances =
52-
new ConcurrentHashMap<>();
5350
private List<HttpHeaderPair> headers;
5451

5552
private StandardCheckoutClient(
@@ -103,20 +100,8 @@ public static StandardCheckoutClient getInstance(
103100
boolean shouldPublishEvents)
104101
throws PhonePeException {
105102
final boolean shouldPublishInProd = shouldPublishEvents && env == Env.PRODUCTION;
106-
final String requestedClientSHA =
107-
CommonUtils.calculateSha256(
108-
clientId,
109-
clientSecret,
110-
clientVersion,
111-
env,
112-
shouldPublishInProd,
113-
FlowType.PG_CHECKOUT);
114-
115-
return cachedInstances.computeIfAbsent(
116-
requestedClientSHA,
117-
key ->
118-
new StandardCheckoutClient(
119-
clientId, clientSecret, clientVersion, env, shouldPublishInProd));
103+
return new StandardCheckoutClient(
104+
clientId, clientSecret, clientVersion, env, shouldPublishInProd);
120105
}
121106

122107
/**

src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/CreateSdkOrderRequest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class CreateSdkOrderRequest {
3535
private PaymentFlow paymentFlow;
3636
private Long expireAfter;
3737
private List<InstrumentConstraint> constraints;
38+
private Boolean disablePaymentRetry;
3839

3940
/**
4041
* Builds SDK order Request
@@ -54,11 +55,13 @@ public CreateSdkOrderRequest(
5455
MetaInfo metaInfo,
5556
String message,
5657
String redirectUrl,
57-
Long expireAfter) {
58+
Long expireAfter,
59+
Boolean disablePaymentRetry) {
5860
this.merchantOrderId = merchantOrderId;
5961
this.amount = amount;
6062
this.metaInfo = metaInfo;
6163
this.expireAfter = expireAfter;
64+
this.disablePaymentRetry = disablePaymentRetry;
6265
MerchantUrls merchantUrls = MerchantUrls.builder().redirectUrl(redirectUrl).build();
6366
this.setPaymentFlow(
6467
PgCheckoutPaymentFlow.builder()
@@ -83,12 +86,14 @@ public CreateSdkOrderRequest(
8386
long amount,
8487
MetaInfo metaInfo,
8588
List<InstrumentConstraint> constraints,
86-
Long expireAfter) {
89+
Long expireAfter,
90+
Boolean disablePaymentRetry) {
8791
this.merchantOrderId = merchantOrderId;
8892
this.amount = amount;
8993
this.metaInfo = metaInfo;
9094
this.expireAfter = expireAfter;
9195
this.constraints = constraints;
96+
this.disablePaymentRetry = disablePaymentRetry;
9297
this.setPaymentFlow(PgPaymentFlow.builder().build());
9398
}
9499
}

src/main/java/com/phonepe/sdk/pg/subscription/v2/SubscriptionClient.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,10 @@
4141
import com.phonepe.sdk.pg.subscription.v2.models.response.SubscriptionStatusResponseV2;
4242
import java.util.ArrayList;
4343
import java.util.List;
44-
import java.util.concurrent.ConcurrentHashMap;
4544
import lombok.SneakyThrows;
4645

4746
public class SubscriptionClient extends BaseClient {
4847

49-
private static final ConcurrentHashMap<String, SubscriptionClient> cachedInstances =
50-
new ConcurrentHashMap<>();
5148
private List<HttpHeaderPair> headers;
5249

5350
private SubscriptionClient(
@@ -102,20 +99,8 @@ public static SubscriptionClient getInstance(
10299
boolean shouldPublishEvents)
103100
throws PhonePeException {
104101
final boolean shouldPublishInProd = shouldPublishEvents && env == Env.PRODUCTION;
105-
final String requestedClientSHA =
106-
CommonUtils.calculateSha256(
107-
clientId,
108-
clientSecret,
109-
clientVersion,
110-
env,
111-
shouldPublishInProd,
112-
FlowType.SUBSCRIPTION);
113-
114-
return cachedInstances.computeIfAbsent(
115-
requestedClientSHA,
116-
key ->
117-
new SubscriptionClient(
118-
clientId, clientSecret, clientVersion, env, shouldPublishInProd));
102+
return new SubscriptionClient(
103+
clientId, clientSecret, clientVersion, env, shouldPublishInProd);
119104
}
120105

121106
/**

0 commit comments

Comments
 (0)