Skip to content

Commit 689b015

Browse files
authored
Merge pull request #30 from PhonePe/create_sdk_order_update
Added Additional Parameter in CreateSdkOrderRequest and StandardCheckoutPayRequest classes
2 parents bf7167a + aed5403 commit 689b015

File tree

7 files changed

+201
-7
lines changed

7 files changed

+201
-7
lines changed

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.8-blue)](https://maven-badges.herokuapp.com/maven-central/com.phonepe/pg-sdk-java)
3+
[![Maven Central](https://img.shields.io/badge/Maven%20Central-v2.2.0-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.8</version>
39+
<version>2.2.0</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.8'
49+
implementation 'com.phonepe:pg-sdk-java:2.2.0'
5050
}
5151
```
5252

pom.xml

Lines changed: 1 addition & 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.8</version>
9+
<version>2.2.0</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>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public CreateSdkOrderRequest(
5656
String message,
5757
String redirectUrl,
5858
Long expireAfter,
59-
Boolean disablePaymentRetry) {
59+
Boolean disablePaymentRetry,
60+
PaymentModeConfig paymentModeConfig) {
6061
this.merchantOrderId = merchantOrderId;
6162
this.amount = amount;
6263
this.metaInfo = metaInfo;
@@ -66,6 +67,7 @@ public CreateSdkOrderRequest(
6667
this.setPaymentFlow(
6768
PgCheckoutPaymentFlow.builder()
6869
.message(message)
70+
.paymentModeConfig(paymentModeConfig)
6971
.merchantUrls(merchantUrls)
7072
.build());
7173
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class StandardCheckoutPayRequest {
3131
private MetaInfo metaInfo;
3232
private PaymentFlow paymentFlow;
3333
private Long expireAfter;
34+
private Boolean disablePaymentRetry;
3435

3536
/**
3637
* Builds Standard Checkout Pay Request
@@ -49,7 +50,8 @@ public StandardCheckoutPayRequest(
4950
MetaInfo metaInfo,
5051
String message,
5152
Long expireAfter,
52-
PaymentModeConfig paymentModeConfig) {
53+
PaymentModeConfig paymentModeConfig,
54+
Boolean disablePaymentRetry) {
5355
this.merchantOrderId = merchantOrderId;
5456
this.amount = amount;
5557
this.metaInfo = metaInfo;
@@ -61,5 +63,6 @@ public StandardCheckoutPayRequest(
6163
.merchantUrls(merchantUrls)
6264
.paymentModeConfig(paymentModeConfig)
6365
.build());
66+
this.disablePaymentRetry = disablePaymentRetry;
6467
}
6568
}

src/test/CreateOrderTest.java

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,19 @@
1818
import com.google.common.collect.Maps;
1919
import com.phonepe.sdk.pg.common.exception.PhonePeException;
2020
import com.phonepe.sdk.pg.common.http.PhonePeResponse;
21+
import com.phonepe.sdk.pg.common.models.request.paymentmodeconstraints.CardPaymentModeConstraint;
22+
import com.phonepe.sdk.pg.common.models.request.paymentmodeconstraints.CardType;
23+
import com.phonepe.sdk.pg.common.models.request.paymentmodeconstraints.UpiIntentPaymentModeConstraint;
2124
import com.phonepe.sdk.pg.payments.v2.customcheckout.CustomCheckoutConstants;
2225
import com.phonepe.sdk.pg.payments.v2.models.request.CreateSdkOrderRequest;
26+
import com.phonepe.sdk.pg.payments.v2.models.request.PaymentModeConfig;
27+
import com.phonepe.sdk.pg.payments.v2.models.request.PgCheckoutPaymentFlow;
2328
import com.phonepe.sdk.pg.payments.v2.models.response.CreateSdkOrderResponse;
2429
import com.phonepe.sdk.pg.payments.v2.standardcheckout.StandardCheckoutConstants;
2530
import java.util.Collections;
31+
import java.util.List;
2632
import java.util.Map;
33+
import java.util.Set;
2734
import org.junit.jupiter.api.Assertions;
2835
import org.junit.jupiter.api.Test;
2936
import wiremock.org.apache.http.HttpStatus;
@@ -316,4 +323,85 @@ void testCreateOrderCustomCheckoutWithDisablePaymentRetryNull() {
316323
Assertions.assertEquals(actual, createSdkOrderResponse);
317324
Assertions.assertNull(createSdkOrderRequest.getDisablePaymentRetry());
318325
}
326+
327+
@Test
328+
void testCreateOrderWithPaymentModeConfig() {
329+
String redirectUrl = "https://google.com";
330+
PaymentModeConfig paymentModeConfig =
331+
PaymentModeConfig.builder()
332+
.enabledPaymentModes(List.of(
333+
CardPaymentModeConstraint.builder().cardTypes(Set.of(CardType.CREDIT_CARD)).build(),
334+
UpiIntentPaymentModeConstraint.builder().build()))
335+
.build();
336+
337+
CreateSdkOrderRequest createSdkOrderRequest =
338+
CreateSdkOrderRequest.StandardCheckoutBuilder()
339+
.merchantOrderId(merchantOrderId)
340+
.amount(amount)
341+
.redirectUrl(redirectUrl)
342+
.paymentModeConfig(paymentModeConfig)
343+
.build();
344+
final String url = StandardCheckoutConstants.CREATE_ORDER_API;
345+
CreateSdkOrderResponse createSdkOrderResponse =
346+
CreateSdkOrderResponse.builder()
347+
.expireAt(1432423)
348+
.orderId("orderId")
349+
.token("token")
350+
.state("PENDING")
351+
.build();
352+
353+
addStubForPostRequest(
354+
url,
355+
getHeaders(),
356+
createSdkOrderRequest,
357+
HttpStatus.SC_OK,
358+
Maps.newHashMap(),
359+
createSdkOrderResponse);
360+
361+
CreateSdkOrderResponse actual =
362+
standardCheckoutClient.createSdkOrder(createSdkOrderRequest);
363+
Assertions.assertEquals(actual, createSdkOrderResponse);
364+
PgCheckoutPaymentFlow pgCheckoutPaymentFlow = (PgCheckoutPaymentFlow)createSdkOrderRequest.getPaymentFlow();
365+
Assertions.assertNotNull(pgCheckoutPaymentFlow.getPaymentModeConfig());
366+
Assertions.assertEquals(
367+
paymentModeConfig.getEnabledPaymentModes(),
368+
pgCheckoutPaymentFlow.getPaymentModeConfig().getEnabledPaymentModes());
369+
Assertions.assertEquals(
370+
paymentModeConfig.getDisabledPaymentModes(),
371+
pgCheckoutPaymentFlow.getPaymentModeConfig().getDisabledPaymentModes());
372+
}
373+
374+
@Test
375+
void testCreateOrderWithNullPaymentModeConfig() {
376+
String redirectUrl = "https://google.com";
377+
378+
CreateSdkOrderRequest createSdkOrderRequest =
379+
CreateSdkOrderRequest.StandardCheckoutBuilder()
380+
.merchantOrderId(merchantOrderId)
381+
.amount(amount)
382+
.redirectUrl(redirectUrl)
383+
.build();
384+
final String url = StandardCheckoutConstants.CREATE_ORDER_API;
385+
CreateSdkOrderResponse createSdkOrderResponse =
386+
CreateSdkOrderResponse.builder()
387+
.expireAt(1432423)
388+
.orderId("orderId")
389+
.token("token")
390+
.state("PENDING")
391+
.build();
392+
393+
addStubForPostRequest(
394+
url,
395+
getHeaders(),
396+
createSdkOrderRequest,
397+
HttpStatus.SC_OK,
398+
Maps.newHashMap(),
399+
createSdkOrderResponse);
400+
401+
CreateSdkOrderResponse actual =
402+
standardCheckoutClient.createSdkOrder(createSdkOrderRequest);
403+
Assertions.assertEquals(actual, createSdkOrderResponse);
404+
PgCheckoutPaymentFlow pgCheckoutPaymentFlow = (PgCheckoutPaymentFlow)createSdkOrderRequest.getPaymentFlow();
405+
Assertions.assertNull(pgCheckoutPaymentFlow.getPaymentModeConfig());
406+
}
319407
}

src/test/PayTest.java

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,105 @@ void testCustomPay() {
162162
PgPaymentResponse actual = customCheckoutClient.pay(request);
163163
Assertions.assertEquals(pgPaymentResponse, actual);
164164
}
165+
166+
@SneakyThrows
167+
@Test
168+
void testStandardCheckoutPayWithDisablePaymentRetryTrue() {
169+
final String url = StandardCheckoutConstants.PAY_API;
170+
String redirectUrl = "https://redirectUrl.com";
171+
172+
StandardCheckoutPayRequest standardCheckoutPayRequest =
173+
StandardCheckoutPayRequest.builder()
174+
.merchantOrderId(merchantOrderId)
175+
.amount(amount)
176+
.disablePaymentRetry(true)
177+
.redirectUrl(redirectUrl)
178+
.build();
179+
StandardCheckoutPayResponse standardCheckoutResponse =
180+
StandardCheckoutPayResponse.builder()
181+
.orderId(String.valueOf(java.time.Instant.now().getEpochSecond()))
182+
.state("PENDING")
183+
.expireAt(java.time.Instant.now().getEpochSecond())
184+
.redirectUrl("https://google.com")
185+
.build();
186+
Map<String, String> headers = getHeaders();
187+
188+
addStubForPostRequest(
189+
url,
190+
headers,
191+
standardCheckoutPayRequest,
192+
HttpStatus.SC_OK,
193+
Maps.newHashMap(),
194+
standardCheckoutResponse);
195+
StandardCheckoutPayResponse actual = standardCheckoutClient.pay(standardCheckoutPayRequest);
196+
Assertions.assertEquals(standardCheckoutResponse, actual);
197+
Assertions.assertTrue(standardCheckoutPayRequest.getDisablePaymentRetry());
198+
}
199+
200+
@SneakyThrows
201+
@Test
202+
void testStandardCheckoutPayWithDisablePaymentRetryFalse() {
203+
final String url = StandardCheckoutConstants.PAY_API;
204+
String redirectUrl = "https://redirectUrl.com";
205+
206+
StandardCheckoutPayRequest standardCheckoutPayRequest =
207+
StandardCheckoutPayRequest.builder()
208+
.merchantOrderId(merchantOrderId)
209+
.amount(amount)
210+
.disablePaymentRetry(false)
211+
.redirectUrl(redirectUrl)
212+
.build();
213+
StandardCheckoutPayResponse standardCheckoutResponse =
214+
StandardCheckoutPayResponse.builder()
215+
.orderId(String.valueOf(java.time.Instant.now().getEpochSecond()))
216+
.state("PENDING")
217+
.expireAt(java.time.Instant.now().getEpochSecond())
218+
.redirectUrl("https://google.com")
219+
.build();
220+
Map<String, String> headers = getHeaders();
221+
222+
addStubForPostRequest(
223+
url,
224+
headers,
225+
standardCheckoutPayRequest,
226+
HttpStatus.SC_OK,
227+
Maps.newHashMap(),
228+
standardCheckoutResponse);
229+
StandardCheckoutPayResponse actual = standardCheckoutClient.pay(standardCheckoutPayRequest);
230+
Assertions.assertEquals(standardCheckoutResponse, actual);
231+
Assertions.assertFalse(standardCheckoutPayRequest.getDisablePaymentRetry());
232+
}
233+
234+
@SneakyThrows
235+
@Test
236+
void testStandardCheckoutPayWithDisablePaymentRetryNull() {
237+
final String url = StandardCheckoutConstants.PAY_API;
238+
String redirectUrl = "https://redirectUrl.com";
239+
240+
StandardCheckoutPayRequest standardCheckoutPayRequest =
241+
StandardCheckoutPayRequest.builder()
242+
.merchantOrderId(merchantOrderId)
243+
.amount(amount)
244+
.redirectUrl(redirectUrl)
245+
.build();
246+
StandardCheckoutPayResponse standardCheckoutResponse =
247+
StandardCheckoutPayResponse.builder()
248+
.orderId(String.valueOf(java.time.Instant.now().getEpochSecond()))
249+
.state("PENDING")
250+
.expireAt(java.time.Instant.now().getEpochSecond())
251+
.redirectUrl("https://google.com")
252+
.build();
253+
Map<String, String> headers = getHeaders();
254+
255+
addStubForPostRequest(
256+
url,
257+
headers,
258+
standardCheckoutPayRequest,
259+
HttpStatus.SC_OK,
260+
Maps.newHashMap(),
261+
standardCheckoutResponse);
262+
StandardCheckoutPayResponse actual = standardCheckoutClient.pay(standardCheckoutPayRequest);
263+
Assertions.assertEquals(standardCheckoutResponse, actual);
264+
Assertions.assertNull(standardCheckoutPayRequest.getDisablePaymentRetry());
265+
}
165266
}

src/test/headers/HeadersTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void testSDKVersionIsLoadedFromProperties() {
3434
}
3535

3636
/**
37-
* Test that SDK_VERSION follows semantic versioning format (e.g., 2.1.8)
37+
* Test that SDK_VERSION follows semantic versioning format
3838
*/
3939
@Test
4040
void testSDKVersionFormat() {

0 commit comments

Comments
 (0)