Skip to content
Merged
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
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
repos:
- repo: local
hooks:
- id: spotless-apply
name: Spotless Code Formatter (Apply)
entry: mvn spotless:apply
language: system
pass_filenames: false
stages: [pre-commit]
verbose: true

# some complex rules like missing parentheses in a if, loop statements for a single line are not applied by
# mvn spotless:apply so added another check that will block the commit
- id: spotless-check
name: Spotless Code Formatter (Check)
entry: mvn spotless:check
language: system
pass_filenames: false
stages: [pre-commit]
verbose: true
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PhonePe B2B Payment Gateway SDK for Java

[![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)
[![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)
![Java](https://img.shields.io/badge/Java-17%2B-orange)
[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](LICENSE)

Expand Down Expand Up @@ -36,7 +36,7 @@ Add the dependency to your project's POM file:
<dependency>
<groupId>com.phonepe</groupId>
<artifactId>pg-sdk-java</artifactId>
<version>2.1.7</version>
<version>2.1.8</version>
</dependency>
```

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

```gradle
dependencies {
implementation 'com.phonepe:pg-sdk-java:2.1.7'
implementation 'com.phonepe:pg-sdk-java:2.1.8'
}
```

Expand Down
380 changes: 380 additions & 0 deletions formatter.xml

Large diffs are not rendered by default.

69 changes: 68 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.phonepe</groupId>
<artifactId>pg-sdk-java</artifactId>
<version>2.1.7</version>
<version>2.1.8</version>
<name>B2B JAVA SDK</name>
<url>https://github.com/PhonePe/phonepe-pg-sdk-java</url>
<description>Phonepe PG JAVA SDK</description>
Expand Down Expand Up @@ -97,6 +97,11 @@
<name>Aditi Billore</name>
<email>[email protected]</email>
</developer>
<developer>
<id>Yogesh-Kamble</id>
<name>Yogesh Kamble</name>
<email>[email protected]</email>
</developer>
</developers>

<properties>
Expand Down Expand Up @@ -133,14 +138,51 @@
</properties>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.version}</version>
<configuration>
<ratchetFrom>origin/main</ratchetFrom>
<java>
<!-- Eclipse formatter with custom rules -->
<eclipse>
<file>${project.basedir}/formatter.xml</file>
<version>4.26</version>
</eclipse>
<includes>
<include>src/main/java/**/*.java</include>
<include>src/test/java/**/*.java</include>
Expand Down Expand Up @@ -170,6 +212,25 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
Expand Down Expand Up @@ -316,6 +377,12 @@
</repository>
</distributionManagement>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.sonatype.central</groupId>
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/com/phonepe/sdk/pg/common/constants/Headers.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,34 @@
*/
package com.phonepe.sdk.pg.common.constants;

import java.io.InputStream;
import java.util.Properties;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

@UtilityClass
@Slf4j
public class Headers {

private final Properties properties = new Properties();
private final String PROPERTIES_FILE_NAME = "/sdk.properties";

static {
try (InputStream input = Headers.class.getResourceAsStream(PROPERTIES_FILE_NAME)) {
if (input == null) {
log.error("Could not find {}", PROPERTIES_FILE_NAME);
} else {
properties.load(input);
}
} catch (Exception e) {
log.error("Failed to load SDK properties: {}", e.getMessage());
}
}

public static final String API_VERSION = "V2";
public static final String SUBSCRIPTION_API_VERSION = "2.1.7";
public static final String SUBSCRIPTION_API_VERSION = properties.getProperty("sdk.version");
public static final String INTEGRATION = "API";
public static final String SDK_VERSION = "2.1.7";
public static final String SDK_VERSION = properties.getProperty("sdk.version");
public static final String SDK_TYPE = "BACKEND_JAVA_SDK";
public static final String SOURCE = "x-source";
public static final String SOURCE_VERSION = "x-source-version";
Expand All @@ -32,4 +51,4 @@ public class Headers {
public static final String OAUTH_AUTHORIZATION = "Authorization";
public static final String CONTENT_TYPE = "Content-Type";
public static final String ACCEPT = "Accept";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private HttpUrl prepareHttpURL(String url) {
/**
* Executes the HTTP request and returns the response.
*
* @return <T> the response object
* @return the response object
*/
@SneakyThrows
public T execute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import lombok.SneakyThrows;

public class CustomCheckoutClient extends BaseClient {

private static final ConcurrentHashMap<String, CustomCheckoutClient> cachedInstances =
new ConcurrentHashMap<>();
private List<HttpHeaderPair> headers;

private CustomCheckoutClient(
Expand Down Expand Up @@ -102,20 +99,8 @@ public static CustomCheckoutClient getInstance(
boolean shouldPublishEvents)
throws PhonePeException {
final boolean shouldPublishInProd = shouldPublishEvents && env == Env.PRODUCTION;
final String requestedClientSHA =
CommonUtils.calculateSha256(
clientId,
clientSecret,
clientVersion,
env,
shouldPublishInProd,
FlowType.PG);

return cachedInstances.computeIfAbsent(
requestedClientSHA,
key ->
new CustomCheckoutClient(
clientId, clientSecret, clientVersion, env, shouldPublishInProd));
return new CustomCheckoutClient(
clientId, clientSecret, clientVersion, env, shouldPublishInProd);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,11 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import lombok.SneakyThrows;

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

private static final ConcurrentHashMap<String, StandardCheckoutClient> cachedInstances =
new ConcurrentHashMap<>();
private List<HttpHeaderPair> headers;

private StandardCheckoutClient(
Expand Down Expand Up @@ -103,20 +100,8 @@ public static StandardCheckoutClient getInstance(
boolean shouldPublishEvents)
throws PhonePeException {
final boolean shouldPublishInProd = shouldPublishEvents && env == Env.PRODUCTION;
final String requestedClientSHA =
CommonUtils.calculateSha256(
clientId,
clientSecret,
clientVersion,
env,
shouldPublishInProd,
FlowType.PG_CHECKOUT);

return cachedInstances.computeIfAbsent(
requestedClientSHA,
key ->
new StandardCheckoutClient(
clientId, clientSecret, clientVersion, env, shouldPublishInProd));
return new StandardCheckoutClient(
clientId, clientSecret, clientVersion, env, shouldPublishInProd);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class CreateSdkOrderRequest {
private PaymentFlow paymentFlow;
private Long expireAfter;
private List<InstrumentConstraint> constraints;
private Boolean disablePaymentRetry;

/**
* Builds SDK order Request
Expand All @@ -54,11 +55,13 @@ public CreateSdkOrderRequest(
MetaInfo metaInfo,
String message,
String redirectUrl,
Long expireAfter) {
Long expireAfter,
Boolean disablePaymentRetry) {
this.merchantOrderId = merchantOrderId;
this.amount = amount;
this.metaInfo = metaInfo;
this.expireAfter = expireAfter;
this.disablePaymentRetry = disablePaymentRetry;
MerchantUrls merchantUrls = MerchantUrls.builder().redirectUrl(redirectUrl).build();
this.setPaymentFlow(
PgCheckoutPaymentFlow.builder()
Expand All @@ -83,12 +86,14 @@ public CreateSdkOrderRequest(
long amount,
MetaInfo metaInfo,
List<InstrumentConstraint> constraints,
Long expireAfter) {
Long expireAfter,
Boolean disablePaymentRetry) {
this.merchantOrderId = merchantOrderId;
this.amount = amount;
this.metaInfo = metaInfo;
this.expireAfter = expireAfter;
this.constraints = constraints;
this.disablePaymentRetry = disablePaymentRetry;
this.setPaymentFlow(PgPaymentFlow.builder().build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@
import com.phonepe.sdk.pg.subscription.v2.models.response.SubscriptionStatusResponseV2;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import lombok.SneakyThrows;

public class SubscriptionClient extends BaseClient {

private static final ConcurrentHashMap<String, SubscriptionClient> cachedInstances =
new ConcurrentHashMap<>();
private List<HttpHeaderPair> headers;

private SubscriptionClient(
Expand Down Expand Up @@ -102,20 +99,8 @@ public static SubscriptionClient getInstance(
boolean shouldPublishEvents)
throws PhonePeException {
final boolean shouldPublishInProd = shouldPublishEvents && env == Env.PRODUCTION;
final String requestedClientSHA =
CommonUtils.calculateSha256(
clientId,
clientSecret,
clientVersion,
env,
shouldPublishInProd,
FlowType.SUBSCRIPTION);

return cachedInstances.computeIfAbsent(
requestedClientSHA,
key ->
new SubscriptionClient(
clientId, clientSecret, clientVersion, env, shouldPublishInProd));
return new SubscriptionClient(
clientId, clientSecret, clientVersion, env, shouldPublishInProd);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/sdk.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdk.version=${project.version}
Loading