Skip to content
Open
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
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.2.1-blue)](https://maven-badges.herokuapp.com/maven-central/com.phonepe/pg-sdk-java)
[![Maven Central](https://img.shields.io/badge/Maven%20Central-v2.2.4-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.2.3</version>
<version>2.2.4</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.2.3'
implementation 'com.phonepe:pg-sdk-java:2.2.4'
}
```

Expand Down
2 changes: 1 addition & 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.2.3</version>
<version>2.2.4</version>
<name>B2B JAVA SDK</name>
<url>https://github.com/PhonePe/phonepe-pg-sdk-java</url>
<description>Phonepe PG JAVA SDK</description>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2025 Original Author(s), PhonePe India Pvt. Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.phonepe.sdk.pg.common.models.response.paymentinstruments;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties(ignoreUnknown = true)
public class CreditLinePaymentInstrumentV2 extends PaymentInstrumentV2 {

private String maskedAccountNumber;
private String ifsc;
private String accountHolderName;
private String bankId;
private String providerAccountType;

public CreditLinePaymentInstrumentV2() {
super(PaymentInstrumentType.CREDIT_LINE);
}

@Builder
public CreditLinePaymentInstrumentV2(
String maskedAccountNumber,
String ifsc,
String accountHolderName,
String bankId,
String providerAccountType) {
super(PaymentInstrumentType.CREDIT_LINE);
this.maskedAccountNumber = maskedAccountNumber;
this.ifsc = ifsc;
this.accountHolderName = accountHolderName;
this.bankId = bankId;
this.providerAccountType = providerAccountType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
@JsonSubTypes.Type(name = "NET_BANKING", value = NetBankingPaymentInstrumentV2.class),
@JsonSubTypes.Type(name = "ACCOUNT", value = AccountPaymentInstrumentV2.class),
@JsonSubTypes.Type(name = "CREDIT_CARD", value = CreditCardPaymentInstrumentV2.class),
@JsonSubTypes.Type(name = "DEBIT_CARD", value = DebitCardPaymentInstrumentV2.class)
@JsonSubTypes.Type(name = "DEBIT_CARD", value = DebitCardPaymentInstrumentV2.class),
@JsonSubTypes.Type(name = "CREDIT_LINE", value = CreditLinePaymentInstrumentV2.class)
})
@NoArgsConstructor
@Data
Expand All @@ -41,6 +42,6 @@ public PaymentInstrumentV2(PaymentInstrumentType type) {
}

public enum PaymentInstrumentType {
WALLET, EGV, ACCOUNT, CREDIT_CARD, DEBIT_CARD, NET_BANKING
WALLET, EGV, ACCOUNT, CREDIT_CARD, DEBIT_CARD, NET_BANKING, CREDIT_LINE
}
}
69 changes: 69 additions & 0 deletions src/test/CallbackTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.phonepe.sdk.pg.common.models.response.PaymentDetail;
import com.phonepe.sdk.pg.common.models.response.paymentinstruments.AccountPaymentInstrumentV2;
import com.phonepe.sdk.pg.common.models.response.paymentinstruments.CreditCardPaymentInstrumentV2;
import com.phonepe.sdk.pg.common.models.response.paymentinstruments.CreditLinePaymentInstrumentV2;
import com.phonepe.sdk.pg.common.models.response.paymentinstruments.DebitCardPaymentInstrumentV2;
import com.phonepe.sdk.pg.common.models.response.paymentinstruments.EGVPaymentInstrumentV2;
import com.phonepe.sdk.pg.common.models.response.paymentinstruments.NetBankingPaymentInstrumentV2;
Expand Down Expand Up @@ -186,6 +187,74 @@ void testPG_ORDER_FAILED() {
Assertions.assertEquals(expected, actual);
}

@Test
void testPG_ORDER_COMPLETED_withCreditLineInstrument() {
String jsonString =
"{\"event\":\"pg.order.completed\",\"payload\":"
+ "{\"orderId\":\"OMOxx\",\"paymentDetails\":"
+ "[{\"paymentMode\":\"UPI_INTENT\",\"splitInstruments\":"
+ "[{\"rail\":{\"type\":\"UPI\",\"utr\":\"utr12313\","
+ "\"upiTransactionId\":\"upi12313\","
+ "\"vpa\":\"abcd@ybl\"},\"instrument\":{\"type\":\"CREDIT_LINE\","
+ "\"ifsc\":\"AABE0000000\",\"accountHolderName\":\"accountHolderName\","
+ "\"bankId\":\"bankId\",\"maskedAccountNumber\":\"121212121212\","
+ "\"providerAccountType\":\"providerAccountType\"},\"amount\":10000}]}]}}";

CallbackResponse expected =
CallbackResponse.builder()
.event("pg.order.completed")
.payload(
CallbackData.builder()
.orderId("OMOxx")
.paymentDetails(
Arrays.asList(
PaymentDetail.builder()
.paymentMode(
PgV2InstrumentType
.UPI_INTENT)
.splitInstruments(
Arrays.asList(
InstrumentCombo
.builder()
.instrument(
CreditLinePaymentInstrumentV2
.builder()
.ifsc(
"AABE0000000")
.accountHolderName(
"accountHolderName")
.bankId(
"bankId")
.maskedAccountNumber(
"121212121212")
.providerAccountType(
"providerAccountType")
.build())
.rail(
UpiPaymentRail
.builder()
.utr(
"utr12313")
.upiTransactionId(
"upi12313")
.vpa(
"abcd@ybl")
.build())
.amount(
10000)
.build()))
.build()))
.build())
.build();
CallbackResponse actual =
standardCheckoutClient.validateCallback(
"username",
"password",
"bc842c31a9e54efe320d30d948be61291f3ceee4766e36ab25fa65243cd76e0e",
jsonString);
Assertions.assertEquals(expected, actual);
}

@Test
void testPG_TRANSACTION_ATTEMPT_FAILED() {
String jsonString =
Expand Down
133 changes: 133 additions & 0 deletions src/test/CreditLinePaymentInstrumentV2Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* Copyright (c) 2025 Original Author(s), PhonePe India Pvt. Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.fasterxml.jackson.databind.ObjectMapper;
import com.phonepe.sdk.pg.common.models.response.paymentinstruments.AccountPaymentInstrumentV2;
import com.phonepe.sdk.pg.common.models.response.paymentinstruments.CreditLinePaymentInstrumentV2;
import com.phonepe.sdk.pg.common.models.response.paymentinstruments.PaymentInstrumentV2;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class CreditLinePaymentInstrumentV2Test {

private static CreditLinePaymentInstrumentV2 sample() {
return CreditLinePaymentInstrumentV2.builder()
.maskedAccountNumber("121212121212")
.ifsc("AABE0000000")
.accountHolderName("accountHolderName")
.bankId("bankId")
.providerAccountType("providerAccountType")
.build();
}

@Test
void typeIsCreditLine() {
Assertions.assertEquals(
PaymentInstrumentV2.PaymentInstrumentType.CREDIT_LINE, sample().getType());
Assertions.assertEquals(
PaymentInstrumentV2.PaymentInstrumentType.CREDIT_LINE,
new CreditLinePaymentInstrumentV2().getType());
}

@Test
void settersAndGetters() {
CreditLinePaymentInstrumentV2 instrument = new CreditLinePaymentInstrumentV2();
instrument.setMaskedAccountNumber("121212121212");
instrument.setIfsc("AABE0000000");
instrument.setAccountHolderName("accountHolderName");
instrument.setBankId("bankId");
instrument.setProviderAccountType("providerAccountType");

Assertions.assertEquals("121212121212", instrument.getMaskedAccountNumber());
Assertions.assertEquals("AABE0000000", instrument.getIfsc());
Assertions.assertEquals("accountHolderName", instrument.getAccountHolderName());
Assertions.assertEquals("bankId", instrument.getBankId());
Assertions.assertEquals("providerAccountType", instrument.getProviderAccountType());
Assertions.assertEquals(sample(), instrument);
}

@Test
void equalsAndHashCode() {
CreditLinePaymentInstrumentV2 base = sample();
CreditLinePaymentInstrumentV2 same = sample();

Assertions.assertEquals(base, base);
Assertions.assertEquals(base, same);
Assertions.assertEquals(base.hashCode(), same.hashCode());
Assertions.assertNotEquals(base, null);

Check warning on line 69 in src/test/CreditLinePaymentInstrumentV2Test.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Swap these 2 arguments so they are in the correct order: expected value, actual value.

See more on https://sonarcloud.io/project/issues?id=PhonePe_phonepe-pg-sdk-java&issues=AaF4GyKfmw1qsHGyefR-&open=AaF4GyKfmw1qsHGyefR-&pullRequest=49
Assertions.assertNotEquals(base, "string");

Check warning on line 70 in src/test/CreditLinePaymentInstrumentV2Test.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Swap these 2 arguments so they are in the correct order: expected value, actual value.

See more on https://sonarcloud.io/project/issues?id=PhonePe_phonepe-pg-sdk-java&issues=AaF4GyKfmw1qsHGyefR_&open=AaF4GyKfmw1qsHGyefR_&pullRequest=49
Assertions.assertNotEquals(base, AccountPaymentInstrumentV2.builder().build());

CreditLinePaymentInstrumentV2 other = sample();
other.setMaskedAccountNumber("other");
Assertions.assertNotEquals(base, other);
other = sample();
other.setIfsc("other");
Assertions.assertNotEquals(base, other);
other = sample();
other.setAccountHolderName("other");
Assertions.assertNotEquals(base, other);
other = sample();
other.setBankId("other");
Assertions.assertNotEquals(base, other);
other = sample();
other.setProviderAccountType("other");
Assertions.assertNotEquals(base, other);
}

@Test
void equalsAndHashCodeWithNullFields() {
CreditLinePaymentInstrumentV2 empty = CreditLinePaymentInstrumentV2.builder().build();
CreditLinePaymentInstrumentV2 anotherEmpty =
CreditLinePaymentInstrumentV2.builder().build();

Assertions.assertEquals(empty, anotherEmpty);
Assertions.assertEquals(empty.hashCode(), anotherEmpty.hashCode());
Assertions.assertNotEquals(empty, sample());
Assertions.assertNotEquals(sample(), empty);

CreditLinePaymentInstrumentV2 partial = CreditLinePaymentInstrumentV2.builder().build();
partial.setMaskedAccountNumber("121212121212");
Assertions.assertNotEquals(partial, sample());
partial.setIfsc("AABE0000000");
Assertions.assertNotEquals(partial, sample());
partial.setAccountHolderName("accountHolderName");
Assertions.assertNotEquals(partial, sample());
partial.setBankId("bankId");
Assertions.assertNotEquals(partial, sample());
partial.setProviderAccountType("providerAccountType");
Assertions.assertEquals(partial, sample());
}

@Test
void toStringContainsFields() {
String value = sample().toString();
Assertions.assertTrue(value.contains("providerAccountType"));
Assertions.assertTrue(value.contains("bankId"));
}

@Test
void deserializesCreditLineAndIgnoresUnknownProperties() throws Exception {
String json =
"{\"type\":\"CREDIT_LINE\",\"ifsc\":\"AABE0000000\",\"unknown\":\"x\","
+ "\"providerAccountType\":\"providerAccountType\"}";
PaymentInstrumentV2 actual = new ObjectMapper().readValue(json, PaymentInstrumentV2.class);

Assertions.assertTrue(actual instanceof CreditLinePaymentInstrumentV2);
CreditLinePaymentInstrumentV2 creditLine = (CreditLinePaymentInstrumentV2) actual;
Assertions.assertEquals("AABE0000000", creditLine.getIfsc());
Assertions.assertEquals("providerAccountType", creditLine.getProviderAccountType());
}
}
Loading
Loading