From b49e4b954fb974b776ade1ef1f73422bf6b86c34 Mon Sep 17 00:00:00 2001 From: Yogesh Kamble Date: Tue, 17 Mar 2026 16:04:32 +0530 Subject: [PATCH] chore: apply spotless formatting across all Java source files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Force-applied Eclipse formatter (formatter.xml) to all 118 Java source files that were not yet compliant with the project's Spotless config. No logic changes — whitespace, indentation and import ordering only. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/main/java/com/phonepe/sdk/pg/Env.java | 34 +- .../com/phonepe/sdk/pg/common/BaseClient.java | 146 ++- .../phonepe/sdk/pg/common/CommonUtils.java | 82 +- .../pg/common/configs/CredentialConfig.java | 9 +- .../sdk/pg/common/constants/BaseUrl.java | 18 +- .../sdk/pg/common/constants/Headers.java | 52 +- .../sdk/pg/common/events/Constants.java | 16 +- .../pg/common/events/models/BaseEvent.java | 1063 +++++++++-------- .../pg/common/events/models/BulkEvent.java | 8 +- .../pg/common/events/models/EventData.java | 57 +- .../events/models/SubscriptionEventData.java | 6 +- .../events/models/enums/EventState.java | 4 +- .../common/events/models/enums/EventType.java | 43 +- .../common/events/models/enums/FlowType.java | 4 +- .../events/publisher/EventPublisher.java | 9 +- .../publisher/EventPublisherFactory.java | 72 +- .../publisher/QueuedEventPublisher.java | 256 ++-- .../queue/BoundedConcurrentLinkedQueue.java | 60 +- .../pg/common/events/queue/EventQueue.java | 27 +- .../sdk/pg/common/exception/BadRequest.java | 8 +- .../sdk/pg/common/exception/ClientError.java | 8 +- .../pg/common/exception/ExceptionMapper.java | 40 +- .../common/exception/ExpectationFailed.java | 10 +- .../pg/common/exception/ForbiddenAccess.java | 8 +- .../pg/common/exception/PhonePeException.java | 82 +- .../pg/common/exception/ResourceConflict.java | 8 +- .../sdk/pg/common/exception/ResourceGone.java | 8 +- .../pg/common/exception/ResourceInvalid.java | 8 +- .../pg/common/exception/ResourceNotFound.java | 8 +- .../sdk/pg/common/exception/ServerError.java | 8 +- .../pg/common/exception/TooManyRequest.java | 8 +- .../common/exception/UnauthorizedAccess.java | 10 +- .../sdk/pg/common/http/HttpHeaderPair.java | 4 +- .../sdk/pg/common/http/HttpMethodType.java | 3 +- .../sdk/pg/common/http/PhonePeResponse.java | 12 +- .../sdk/pg/common/models/MetaInfo.java | 10 +- .../sdk/pg/common/models/PaymentFlowType.java | 5 +- .../pg/common/models/PgV2InstrumentType.java | 9 +- .../models/request/AccountConstraint.java | 16 +- .../common/models/request/DeviceContext.java | 4 +- .../models/request/InstrumentConstraint.java | 8 +- .../pg/common/models/request/PaymentFlow.java | 2 +- .../models/request/PgPaymentRequest.java | 627 +++++----- .../common/models/request/RefundRequest.java | 6 +- .../request/instruments/BillingAddress.java | 12 +- .../instruments/CardPaymentV2Instrument.java | 26 +- .../instruments/CollectPaymentDetails.java | 2 +- .../CollectPaymentDetailsType.java | 3 +- .../CollectPaymentV2Instrument.java | 16 +- .../models/request/instruments/Expiry.java | 4 +- .../IntentPaymentV2Instrument.java | 18 +- .../NetBankingPaymentV2Instrument.java | 16 +- .../request/instruments/NewCardDetails.java | 12 +- .../instruments/PaymentV2Instrument.java | 10 +- .../PhoneNumberCollectPaymentDetails.java | 12 +- .../PpeIntenPaymentV2Instrument.java | 8 +- .../request/instruments/TokenDetails.java | 18 +- .../instruments/TokenPaymentV2Instrument.java | 22 +- .../instruments/UpiQrPaymentV2Instrument.java | 8 +- .../instruments/VpaCollectPaymentDetails.java | 12 +- .../CardPaymentModeConstraint.java | 12 +- .../paymentmodeconstraints/CardType.java | 3 +- .../NetBankingPaymentModeConstraint.java | 8 +- .../PaymentModeConstraint.java | 17 +- .../UpiCollectPaymentModeConstraint.java | 8 +- .../UpiIntentPaymentModeConstraint.java | 8 +- .../UpiQrPaymentModeConstraint.java | 8 +- .../common/models/response/CallbackData.java | 44 +- .../models/response/CallbackResponse.java | 4 +- .../models/response/InstrumentCombo.java | 6 +- .../models/response/OrderStatusResponse.java | 26 +- .../common/models/response/PaymentDetail.java | 20 +- .../models/response/PaymentFlowResponse.java | 22 +- .../models/response/PaymentRefundDetail.java | 20 +- .../models/response/PgPaymentResponse.java | 12 +- .../models/response/RefundResponse.java | 6 +- .../models/response/RefundStatusResponse.java | 12 +- .../AccountPaymentInstrumentV2.java | 32 +- .../CreditCardPaymentInstrumentV2.java | 32 +- .../DebitCardPaymentInstrumentV2.java | 32 +- .../EGVPaymentInstrumentV2.java | 22 +- .../NetBankingPaymentInstrumentV2.java | 32 +- .../PaymentInstrumentV2.java | 35 +- .../WalletPaymentInstrumentV2.java | 18 +- .../models/response/rails/PaymentRail.java | 29 +- .../models/response/rails/PgPaymentRail.java | 28 +- .../response/rails/PpiEgvPaymentRail.java | 8 +- .../response/rails/PpiWalletPaymentRail.java | 8 +- .../models/response/rails/UpiPaymentRail.java | 30 +- .../pg/common/tokenhandler/OAuthResponse.java | 32 +- .../common/tokenhandler/TokenConstants.java | 4 +- .../pg/common/tokenhandler/TokenService.java | 209 ++-- .../pg/payments/v2/CustomCheckoutClient.java | 704 +++++------ .../payments/v2/StandardCheckoutClient.java | 693 ++++++----- .../CustomCheckoutConstants.java | 14 +- .../models/request/CreateSdkOrderRequest.java | 135 +-- .../v2/models/request/MerchantUrls.java | 2 +- .../v2/models/request/PaymentModeConfig.java | 24 +- .../models/request/PgCheckoutPaymentFlow.java | 26 +- .../v2/models/request/PgPaymentFlow.java | 16 +- .../request/StandardCheckoutPayRequest.java | 86 +- .../response/CreateSdkOrderResponse.java | 8 +- .../response/StandardCheckoutPayResponse.java | 8 +- .../StandardCheckoutConstants.java | 14 +- .../subscription/v2/SubscriptionClient.java | 836 +++++++------ .../v2/SubscriptionConstants.java | 18 +- .../v2/models/request/AmountType.java | 3 +- .../v2/models/request/AuthWorkflowType.java | 3 +- .../v2/models/request/Frequency.java | 10 +- .../request/RedemptionRetryStrategy.java | 3 +- .../request/SubscriptionRedeemRequestV2.java | 8 +- .../SubscriptionRedemptionPaymentFlow.java | 26 +- .../request/SubscriptionSetupPaymentFlow.java | 50 +- .../SubscriptionRedeemResponseV2.java | 4 +- ...criptionRedemptionPaymentFlowResponse.java | 50 +- .../SubscriptionSetupPaymentFlowResponse.java | 56 +- .../SubscriptionStatusResponseV2.java | 20 +- 117 files changed, 3316 insertions(+), 3373 deletions(-) diff --git a/src/main/java/com/phonepe/sdk/pg/Env.java b/src/main/java/com/phonepe/sdk/pg/Env.java index f0dafe7..30dd11a 100644 --- a/src/main/java/com/phonepe/sdk/pg/Env.java +++ b/src/main/java/com/phonepe/sdk/pg/Env.java @@ -20,23 +20,23 @@ @Getter public enum Env { - SANDBOX( - BaseUrl.SANDBOX_PG_HOST_URL, - BaseUrl.SANDBOX_OAUTH_HOST_URL, - BaseUrl.SANDBOX_EVENTS_HOST_URL), - PRODUCTION( - BaseUrl.PRODUCTION_PG_HOST_URL, - BaseUrl.PRODUCTION_OAUTH_HOST_URL, - BaseUrl.PRODUCTION_EVENTS_HOST_URL), - TEST(BaseUrl.TESTING_URL, BaseUrl.TESTING_URL, BaseUrl.TESTING_URL); - private final String pgHostUrl; - private final String oAuthHostUrl; - private final String eventsHostUrl; + SANDBOX( + BaseUrl.SANDBOX_PG_HOST_URL, + BaseUrl.SANDBOX_OAUTH_HOST_URL, + BaseUrl.SANDBOX_EVENTS_HOST_URL), PRODUCTION( + BaseUrl.PRODUCTION_PG_HOST_URL, + BaseUrl.PRODUCTION_OAUTH_HOST_URL, + BaseUrl.PRODUCTION_EVENTS_HOST_URL), TEST(BaseUrl.TESTING_URL, BaseUrl.TESTING_URL, + BaseUrl.TESTING_URL); - Env(String pgHostUrl, String oAuthHostUrl, String eventsHostUrl) { - this.pgHostUrl = pgHostUrl; - this.oAuthHostUrl = oAuthHostUrl; - this.eventsHostUrl = eventsHostUrl; - } + private final String pgHostUrl; + private final String oAuthHostUrl; + private final String eventsHostUrl; + + Env(String pgHostUrl, String oAuthHostUrl, String eventsHostUrl) { + this.pgHostUrl = pgHostUrl; + this.oAuthHostUrl = oAuthHostUrl; + this.eventsHostUrl = eventsHostUrl; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/BaseClient.java b/src/main/java/com/phonepe/sdk/pg/common/BaseClient.java index fcb5529..3299fce 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/BaseClient.java +++ b/src/main/java/com/phonepe/sdk/pg/common/BaseClient.java @@ -39,84 +39,80 @@ @Getter public abstract class BaseClient { - private final ObjectMapper objectMapper; - private final OkHttpClient okHttpClient; - private final Env env; - private TokenService tokenService; - private CredentialConfig credentialConfig; - protected EventPublisherFactory eventPublisherFactory; - protected EventPublisher eventPublisher; - private boolean shouldPublishEvents; + private final ObjectMapper objectMapper; + private final OkHttpClient okHttpClient; + private final Env env; + private TokenService tokenService; + private CredentialConfig credentialConfig; + protected EventPublisherFactory eventPublisherFactory; + protected EventPublisher eventPublisher; + private boolean shouldPublishEvents; - protected BaseClient( - String clientId, - String clientSecret, - Integer clientVersion, - Env env, - boolean shouldPublishEvents) { - this.okHttpClient = new OkHttpClient(); - this.objectMapper = new ObjectMapper(); - this.env = env; - this.credentialConfig = - CredentialConfig.builder() - .clientId(clientId) - .clientSecret(clientSecret) - .clientVersion(clientVersion) - .build(); - this.shouldPublishEvents = shouldPublishEvents; - this.eventPublisherFactory = - new EventPublisherFactory( - this.getObjectMapper(), this.getOkHttpClient(), env.getEventsHostUrl()); - this.eventPublisher = this.eventPublisherFactory.getEventPublisher(shouldPublishEvents); - this.tokenService = - new TokenService( - this.okHttpClient, - this.objectMapper, - credentialConfig, - this.env, - this.eventPublisher); - this.eventPublisher.startPublishingEvents(tokenService::getAuthToken); - } + protected BaseClient( + String clientId, + String clientSecret, + Integer clientVersion, + Env env, + boolean shouldPublishEvents) { + this.okHttpClient = new OkHttpClient(); + this.objectMapper = new ObjectMapper(); + this.env = env; + this.credentialConfig = CredentialConfig.builder() + .clientId(clientId) + .clientSecret(clientSecret) + .clientVersion(clientVersion) + .build(); + this.shouldPublishEvents = shouldPublishEvents; + this.eventPublisherFactory = new EventPublisherFactory( + this.getObjectMapper(), this.getOkHttpClient(), env.getEventsHostUrl()); + this.eventPublisher = this.eventPublisherFactory.getEventPublisher(shouldPublishEvents); + this.tokenService = new TokenService( + this.okHttpClient, + this.objectMapper, + credentialConfig, + this.env, + this.eventPublisher); + this.eventPublisher.startPublishingEvents(tokenService::getAuthToken); + } - @SneakyThrows - protected T requestViaAuthRefresh( - HttpMethodType methodName, - R requestData, - String url, - Map queryParams, - TypeReference responseTypeReference, - List headers) { - List httpHeaders = new ArrayList<>(headers); - HttpCommand httpCommand = - HttpCommand.builder() - .client(this.okHttpClient) - .objectMapper(this.objectMapper) - .responseTypeReference(responseTypeReference) - .methodName(methodName) - .headers(addAuthHeader(httpHeaders)) - .requestData(requestData) - .hostURL(this.env.getPgHostUrl()) - .encodingType(APPLICATION_JSON) - .queryParams(queryParams) - .url(url) - .build(); + @SneakyThrows + protected T requestViaAuthRefresh( + HttpMethodType methodName, + R requestData, + String url, + Map queryParams, + TypeReference responseTypeReference, + List headers) { + List httpHeaders = new ArrayList<>(headers); + HttpCommand httpCommand = HttpCommand.builder() + .client(this.okHttpClient) + .objectMapper(this.objectMapper) + .responseTypeReference(responseTypeReference) + .methodName(methodName) + .headers(addAuthHeader(httpHeaders)) + .requestData(requestData) + .hostURL(this.env.getPgHostUrl()) + .encodingType(APPLICATION_JSON) + .queryParams(queryParams) + .url(url) + .build(); - try { - return httpCommand.execute(); - } catch (UnauthorizedAccess unauthorizedAccess) { - tokenService.forceRefreshToken(); - throw unauthorizedAccess; - } - } + try { + return httpCommand.execute(); + } catch (UnauthorizedAccess unauthorizedAccess) { + tokenService.forceRefreshToken(); + throw unauthorizedAccess; + } + } - @SneakyThrows - protected List addAuthHeader(List headers) { - headers.add( - HttpHeaderPair.builder() - .key(Headers.OAUTH_AUTHORIZATION) - .value(tokenService.getAuthToken()) - .build()); + @SneakyThrows + protected List addAuthHeader(List headers) { + headers.add( + HttpHeaderPair.builder() + .key(Headers.OAUTH_AUTHORIZATION) + .value(tokenService.getAuthToken()) + .build()); - return headers; - } + return headers; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/CommonUtils.java b/src/main/java/com/phonepe/sdk/pg/common/CommonUtils.java index 6e36503..a45d36f 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/CommonUtils.java +++ b/src/main/java/com/phonepe/sdk/pg/common/CommonUtils.java @@ -24,49 +24,49 @@ @UtilityClass public class CommonUtils { - /** - * Computes the SHA-256 hash of the provided data using the SHA-256 algorithm. - * - * @param args the objects to compute the hash for - * @return the computed hash as a string - */ - public String calculateSha256(Object... args) { - List listOfArgs = convertArgsToList(args); - String data = String.join(":", listOfArgs); - return shaHex(data, ShaAlgorithm.SHA256); - } + /** + * Computes the SHA-256 hash of the provided data using the SHA-256 algorithm. + * + * @param args the objects to compute the hash for + * @return the computed hash as a string + */ + public String calculateSha256(Object... args) { + List listOfArgs = convertArgsToList(args); + String data = String.join(":", listOfArgs); + return shaHex(data, ShaAlgorithm.SHA256); + } - public List convertArgsToList(Object... args) { - List list = new ArrayList<>(); - for (Object arg : args) { - list.add(arg.toString()); - } - return list; - } + public List convertArgsToList(Object... args) { + List list = new ArrayList<>(); + for (Object arg : args) { + list.add(arg.toString()); + } + return list; + } - /** - * Computes the SHA-256 hash of the provided data using the specified algorithm. - * - * @param data the data to compute the hash for - * @param algorithm the SHA algorithm to use (currently only supports SHA-256) - * @return the computed hash as a hexadecimal string - */ - public String shaHex(String data, ShaAlgorithm algorithm) { - switch (algorithm) { - case SHA256: - return DigestUtils.sha256Hex(data); - default: - return data; - } - } + /** + * Computes the SHA-256 hash of the provided data using the specified algorithm. + * + * @param data the data to compute the hash for + * @param algorithm the SHA algorithm to use (currently only supports SHA-256) + * @return the computed hash as a hexadecimal string + */ + public String shaHex(String data, ShaAlgorithm algorithm) { + switch (algorithm) { + case SHA256: + return DigestUtils.sha256Hex(data); + default: + return data; + } + } - /** Enum representing the supported SHA algorithms. Currently, only SHA-256 is supported. */ - private enum ShaAlgorithm { - SHA256; - } + /** Enum representing the supported SHA algorithms. Currently, only SHA-256 is supported. */ + private enum ShaAlgorithm { + SHA256; + } - public boolean isCallbackValid(String username, String password, String authorization) { - String sha256hash = calculateSha256(username, password); - return Objects.equals(sha256hash, authorization); - } + public boolean isCallbackValid(String username, String password, String authorization) { + String sha256hash = calculateSha256(username, password); + return Objects.equals(sha256hash, authorization); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/configs/CredentialConfig.java b/src/main/java/com/phonepe/sdk/pg/common/configs/CredentialConfig.java index 4e3d7f7..521478e 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/configs/CredentialConfig.java +++ b/src/main/java/com/phonepe/sdk/pg/common/configs/CredentialConfig.java @@ -27,9 +27,12 @@ @NoArgsConstructor public class CredentialConfig { - @NotBlank private String clientId; + @NotBlank + private String clientId; - @NotBlank private String clientSecret; + @NotBlank + private String clientSecret; - @NotBlank private Integer clientVersion; + @NotBlank + private Integer clientVersion; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/constants/BaseUrl.java b/src/main/java/com/phonepe/sdk/pg/common/constants/BaseUrl.java index 80d2c07..97a603b 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/constants/BaseUrl.java +++ b/src/main/java/com/phonepe/sdk/pg/common/constants/BaseUrl.java @@ -20,18 +20,14 @@ @UtilityClass public class BaseUrl { - public static final String PRODUCTION_PG_HOST_URL = "https://api.phonepe.com/apis/pg"; - public static final String SANDBOX_PG_HOST_URL = - "https://api-preprod.phonepe.com/apis/pg-sandbox"; + public static final String PRODUCTION_PG_HOST_URL = "https://api.phonepe.com/apis/pg"; + public static final String SANDBOX_PG_HOST_URL = "https://api-preprod.phonepe.com/apis/pg-sandbox"; - public static final String PRODUCTION_OAUTH_HOST_URL = - "https://api.phonepe.com/apis/identity-manager"; - public static final String SANDBOX_OAUTH_HOST_URL = - "https://api-preprod.phonepe.com/apis/pg-sandbox"; + public static final String PRODUCTION_OAUTH_HOST_URL = "https://api.phonepe.com/apis/identity-manager"; + public static final String SANDBOX_OAUTH_HOST_URL = "https://api-preprod.phonepe.com/apis/pg-sandbox"; - public static final String PRODUCTION_EVENTS_HOST_URL = - "https://api.phonepe.com/apis/pg-ingestion"; - public static final String SANDBOX_EVENTS_HOST_URL = "http://locahost"; + public static final String PRODUCTION_EVENTS_HOST_URL = "https://api.phonepe.com/apis/pg-ingestion"; + public static final String SANDBOX_EVENTS_HOST_URL = "http://locahost"; - public static final String TESTING_URL = "http://localhost:30419"; + public static final String TESTING_URL = "http://localhost:30419"; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/constants/Headers.java b/src/main/java/com/phonepe/sdk/pg/common/constants/Headers.java index d8c6e4b..0f2f842 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/constants/Headers.java +++ b/src/main/java/com/phonepe/sdk/pg/common/constants/Headers.java @@ -24,32 +24,32 @@ @Slf4j public class Headers { - private final Properties properties = new Properties(); - private final String PROPERTIES_FILE_NAME = "/sdk.properties"; + 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()); - } - } + 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 = properties.getProperty("sdk.version"); - public static final String INTEGRATION = "API"; - 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"; - public static final String SOURCE_PLATFORM = "x-source-platform"; - public static final String SOURCE_PLATFORM_VERSION = "x-source-platform-version"; - public static final String OAUTH_AUTHORIZATION = "Authorization"; - public static final String CONTENT_TYPE = "Content-Type"; - public static final String ACCEPT = "Accept"; - public static final String X_DEVICE_OS = "x-device-os"; + public static final String API_VERSION = "V2"; + public static final String SUBSCRIPTION_API_VERSION = properties.getProperty("sdk.version"); + public static final String INTEGRATION = "API"; + 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"; + public static final String SOURCE_PLATFORM = "x-source-platform"; + public static final String SOURCE_PLATFORM_VERSION = "x-source-platform-version"; + public static final String OAUTH_AUTHORIZATION = "Authorization"; + public static final String CONTENT_TYPE = "Content-Type"; + public static final String ACCEPT = "Accept"; + public static final String X_DEVICE_OS = "x-device-os"; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/events/Constants.java b/src/main/java/com/phonepe/sdk/pg/common/events/Constants.java index 9f0bb6c..9b60315 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/events/Constants.java +++ b/src/main/java/com/phonepe/sdk/pg/common/events/Constants.java @@ -20,13 +20,13 @@ @UtilityClass public class Constants { - public static final int MAX_EVENTS_IN_BATCH = 10; - public static final String SOURCE = "BACKEND_SDK"; - public static final String CLIENT_VERSION = "v2"; - public static final String AUTHORIZATION = "Authorization"; + public static final int MAX_EVENTS_IN_BATCH = 10; + public static final String SOURCE = "BACKEND_SDK"; + public static final String CLIENT_VERSION = "v2"; + public static final String AUTHORIZATION = "Authorization"; - public static final String EVENTS_ENDPOINT = "/client/v1/backend/events/batch"; - public static final int QUEUE_MAX_SIZE = 20000; // Should be greater than MAX_EVENTS_IN_BATCH - public static final int INITIAL_DELAY = 1; - public static final int DELAY = 1; + public static final String EVENTS_ENDPOINT = "/client/v1/backend/events/batch"; + public static final int QUEUE_MAX_SIZE = 20000; // Should be greater than MAX_EVENTS_IN_BATCH + public static final int INITIAL_DELAY = 1; + public static final int DELAY = 1; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/events/models/BaseEvent.java b/src/main/java/com/phonepe/sdk/pg/common/events/models/BaseEvent.java index 20f3f68..ba906ba 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/events/models/BaseEvent.java +++ b/src/main/java/com/phonepe/sdk/pg/common/events/models/BaseEvent.java @@ -42,534 +42,537 @@ @Builder public class BaseEvent { - private String merchantOrderId; - private EventType eventName; - private long eventTime; - private EventData data; - - /** Client initialization Event */ - public static BaseEvent buildInitClientEvent(FlowType flowType, EventType eventName) { - BaseEvent baseEvent = buildInitClientEvent(eventName); - baseEvent.data.setFlowType(flowType); - return baseEvent; - } - - /** Client initialization Event */ - public static BaseEvent buildInitClientEvent(EventType eventName) { - return BaseEvent.builder() - .eventName(eventName) - .eventTime(Instant.now().getEpochSecond()) - .data(EventData.builder().eventState(EventState.INITIATED).build()) - .build(); - } - - /** Pay Event Builder For Standard Checkout */ - public static BaseEvent buildStandardCheckoutPayEvent( - EventState eventState, - StandardCheckoutPayRequest standardCheckoutPayRequest, - String apiPath, - EventType eventName) { - return BaseEvent.builder() - .eventName(eventName) - .eventTime(Instant.now().getEpochSecond()) - .merchantOrderId(standardCheckoutPayRequest.getMerchantOrderId()) - .data( - EventData.builder() - .eventState(eventState) - .amount(standardCheckoutPayRequest.getAmount()) - .apiPath(apiPath) - .expireAfter(standardCheckoutPayRequest.getExpireAfter()) - .flowType(FlowType.PG_CHECKOUT) - .build()) - .build(); - } - - /** Pay Failure Event for Standard Checkout --> Exception is PhonePeException */ - public static BaseEvent buildStandardCheckoutPayEvent( - EventState eventState, - StandardCheckoutPayRequest standardCheckoutPayRequest, - String apiPath, - EventType eventName, - Exception exception) { - BaseEvent baseEvent = - buildStandardCheckoutPayEvent( - eventState, standardCheckoutPayRequest, apiPath, eventName); - return populateExceptionFields(baseEvent, exception); - } - - /** Pay Event Builder For Custom Checkout */ - public static BaseEvent buildCustomCheckoutPayEvent( - EventState eventState, - PgPaymentRequest pgPaymentRequest, - String apiPath, - EventType eventName) { - - // Extracting the instrument from the PgPaymentFlow - PgPaymentFlow pgPaymentFlow = (PgPaymentFlow) pgPaymentRequest.getPaymentFlow(); - - // Extracting the targetApp from the paymentMode in PgPaymentFlow - String targetApp = - Optional.ofNullable(pgPaymentFlow) - .map(PgPaymentFlow::getPaymentMode) - .filter( - paymentMode -> - paymentMode.getType().equals(PgV2InstrumentType.UPI_INTENT)) - .map(IntentPaymentV2Instrument.class::cast) - .map(IntentPaymentV2Instrument::getTargetApp) - .orElse(null); - - return BaseEvent.builder() - .eventName(eventName) - .eventTime(Instant.now().getEpochSecond()) - .merchantOrderId(pgPaymentRequest.getMerchantOrderId()) - .data( - EventData.builder() - .eventState(eventState) - .amount(pgPaymentRequest.getAmount()) - .apiPath(apiPath) - .deviceContext(pgPaymentRequest.getDeviceContext()) - .expireAfter(pgPaymentRequest.getExpireAfter()) - .targetApp(targetApp) - .paymentInstrument( - Optional.ofNullable(pgPaymentFlow) - .map(PgPaymentFlow::getPaymentMode) - .map(PaymentV2Instrument::getType) - .orElse(null)) - .flowType(FlowType.PG) - .build()) - .build(); - } - - /** Pay Failure Event for Custom Checkout --> Exception is PhonePeException */ - public static BaseEvent buildCustomCheckoutPayEvent( - EventState eventState, - PgPaymentRequest pgPaymentRequest, - String url, - EventType eventName, - Exception exception) { - BaseEvent baseEvent = - buildCustomCheckoutPayEvent(eventState, pgPaymentRequest, url, eventName); - return populateExceptionFields(baseEvent, exception); - } - - /** Order Status Event Builder */ - public static BaseEvent buildOrderStatusEvent( - EventState eventState, - String merchantOrderId, - String apiPath, - FlowType flowType, - EventType eventName) { - return BaseEvent.builder() - .eventName(eventName) - .eventTime(Instant.now().getEpochSecond()) - .merchantOrderId(merchantOrderId) - .data( - EventData.builder() - .eventState(eventState) - .flowType(flowType) - .apiPath(apiPath) - .build()) - .build(); - } - - /** Order Status Failure Event */ - public static BaseEvent buildOrderStatusEvent( - EventState eventState, - String merchantOrderId, - String apiPath, - FlowType flowType, - EventType eventName, - Exception exception) { - BaseEvent baseEvent = - buildOrderStatusEvent(eventState, merchantOrderId, apiPath, flowType, eventName); - return populateExceptionFields(baseEvent, exception); - } - - /** Refund Event Builder */ - public static BaseEvent buildRefundEvent( - EventState eventState, - RefundRequest refundRequest, - String apiPath, - FlowType flowType, - EventType eventName) { - return BaseEvent.builder() - .eventName(eventName) - .eventTime(Instant.now().getEpochSecond()) - .merchantOrderId(refundRequest.getOriginalMerchantOrderId()) - .data( - EventData.builder() - .merchantRefundId(refundRequest.getMerchantRefundId()) - .eventState(eventState) - .apiPath(apiPath) - .amount(refundRequest.getAmount()) - .originalMerchantOrderId(refundRequest.getOriginalMerchantOrderId()) - .flowType(flowType) - .build()) - .build(); - } - - /** Failure Event for Refund --> Exception is PhonePeException */ - public static BaseEvent buildRefundEvent( - EventState eventState, - RefundRequest refundRequest, - String apiPath, - FlowType flowType, - EventType eventName, - Exception exception) { - BaseEvent baseEvent = - buildRefundEvent(eventState, refundRequest, apiPath, flowType, eventName); - return populateExceptionFields(baseEvent, exception); - } - - /** Refund Status Event Builder */ - public static BaseEvent buildRefundStatusEvent( - EventState eventState, - String refundId, - String apiPath, - FlowType flowType, - EventType eventName) { - return BaseEvent.builder() - .eventName(eventName) - .eventTime(Instant.now().getEpochSecond()) - .data( - EventData.builder() - .merchantRefundId(refundId) - .eventState(eventState) - .apiPath(apiPath) - .flowType(flowType) - .build()) - .build(); - } - - /** Failure Event for Refund Status --> Exception is PhonePeException */ - public static BaseEvent buildRefundStatusEvent( - EventState eventState, - String refundId, - String apiPath, - FlowType flowType, - EventType eventName, - Exception exception) { - BaseEvent baseEvent = - buildRefundStatusEvent(eventState, refundId, apiPath, flowType, eventName); - return populateExceptionFields(baseEvent, exception); - } - - /** CreateSdkOrder Event Builder */ - public static BaseEvent buildCreateSdkOrderEvent( - EventState eventState, - CreateSdkOrderRequest createSdkOrderRequest, - String apiPath, - FlowType flowType, - EventType eventName) { - return BaseEvent.builder() - .merchantOrderId(createSdkOrderRequest.getMerchantOrderId()) - .eventName(eventName) - .eventTime(Instant.now().getEpochSecond()) - .data( - EventData.builder() - .amount(createSdkOrderRequest.getAmount()) - .eventState(eventState) - .apiPath(apiPath) - .expireAfter(createSdkOrderRequest.getExpireAfter()) - .flowType(flowType) - .build()) - .build(); - } - - /** Failure Event for CreateSdkOrder --> Exception is PhonePeException */ - public static BaseEvent buildCreateSdkOrderEvent( - EventState eventState, - CreateSdkOrderRequest createSdkOrderRequest, - String apiPath, - FlowType flowType, - EventType eventName, - Exception exception) { - BaseEvent baseEvent = - buildCreateSdkOrderEvent( - eventState, createSdkOrderRequest, apiPath, flowType, eventName); - return populateExceptionFields(baseEvent, exception); - } - - /** Transaction Status Event Builder */ - public static BaseEvent buildTransactionStatusEvent( - EventState eventState, - String transactionId, - String apiPath, - FlowType flowType, - EventType eventName) { - return BaseEvent.builder() - .eventName(eventName) - .eventTime(Instant.now().getEpochSecond()) - .data( - EventData.builder() - .eventState(eventState) - .transactionId(transactionId) - .apiPath(apiPath) - .flowType(flowType) - .build()) - .build(); - } - - /** Failure Event for Transaction Status --> Exception is PhonePeException */ - public static BaseEvent buildTransactionStatusEvent( - EventState eventState, - String transactionId, - String apiPath, - FlowType flowType, - EventType eventName, - Exception exception) { - BaseEvent baseEvent = - buildTransactionStatusEvent( - eventState, transactionId, apiPath, flowType, eventName); - return populateExceptionFields(baseEvent, exception); - } - - /** Subscription Setup Event Builder */ - public static BaseEvent buildSubscriptionSetupEvent( - EventState eventState, - PgPaymentRequest setupRequest, - String apiPath, - EventType eventName) { - // Extracting SubscriptionSetupPaymentFlow from the paymentFlow - SubscriptionSetupPaymentFlow setupPaymentFlow = - (SubscriptionSetupPaymentFlow) setupRequest.getPaymentFlow(); - - // Extracting targetApp if the paymentMode is UPI_INTENT - String targetApp = - Optional.ofNullable(setupPaymentFlow) - .map(SubscriptionSetupPaymentFlow::getPaymentMode) - .filter( - paymentMode -> - paymentMode.getType().equals(PgV2InstrumentType.UPI_INTENT)) - .map(IntentPaymentV2Instrument.class::cast) - .map(IntentPaymentV2Instrument::getTargetApp) - .orElse(null); - - return BaseEvent.builder() - .merchantOrderId(setupRequest.getMerchantOrderId()) - .eventTime(Instant.now().getEpochSecond()) - .eventName(eventName) - .data( - EventData.builder() - .eventState(eventState) - .apiPath(apiPath) - .flowType(FlowType.SUBSCRIPTION) - .paymentInstrument( - Optional.ofNullable(setupPaymentFlow) - .map(SubscriptionSetupPaymentFlow::getPaymentMode) - .map(PaymentV2Instrument::getType) - .orElse(null)) - .targetApp(targetApp) - .deviceContext(setupRequest.getDeviceContext()) - .amount(setupRequest.getAmount()) - .subscriptionEventData( - SubscriptionEventData.builder() - .orderExpireAt(setupRequest.getExpireAt()) - .subscriptionExpireAt( - Optional.ofNullable(setupPaymentFlow) - .map( - SubscriptionSetupPaymentFlow - ::getExpireAt) - .orElse(null)) - .merchantSubscriptionId( - Optional.ofNullable(setupPaymentFlow) - .map( - SubscriptionSetupPaymentFlow - ::getMerchantSubscriptionId) - .orElse(null)) - .build()) - .build()) - .build(); - } - - /** Failure Event for Subscription Setup */ - public static BaseEvent buildSubscriptionSetupEvent( - EventState eventState, - PgPaymentRequest setupRequest, - String apiPath, - EventType eventName, - Exception exception) { - BaseEvent event = buildSubscriptionSetupEvent(eventState, setupRequest, apiPath, eventName); - return populateExceptionFields(event, exception); - } - - /** Subscription Notify Event Builder */ - public static BaseEvent buildSubscriptionNotifyEvent( - EventState eventState, - PgPaymentRequest notifyRequest, - String apiPath, - EventType eventName) { - SubscriptionRedemptionPaymentFlow paymentFlow = - (SubscriptionRedemptionPaymentFlow) notifyRequest.getPaymentFlow(); - return BaseEvent.builder() - .eventName(eventName) - .eventTime(Instant.now().getEpochSecond()) - .merchantOrderId(notifyRequest.getMerchantOrderId()) - .data( - EventData.builder() - .eventState(eventState) - .apiPath(apiPath) - .amount(notifyRequest.getAmount()) - .flowType(FlowType.SUBSCRIPTION) - .subscriptionEventData( - SubscriptionEventData.builder() - .orderExpireAt(notifyRequest.getExpireAt()) - .merchantSubscriptionId( - paymentFlow.getMerchantSubscriptionId()) - .build()) - .build()) - .build(); - } - - /** Failure Event for Subscription Notify */ - public static BaseEvent buildSubscriptionNotifyEvent( - EventState eventState, - PgPaymentRequest notifyRequest, - String apiPath, - EventType eventName, - Exception exception) { - BaseEvent event = - buildSubscriptionNotifyEvent(eventState, notifyRequest, apiPath, eventName); - return populateExceptionFields(event, exception); - } - - public static BaseEvent buildSubscriptionRedeemEvent( - EventState eventState, String merchantOrderId, String apiPath, EventType eventName) { - return BaseEvent.builder() - .eventTime(Instant.now().getEpochSecond()) - .eventName(eventName) - .merchantOrderId(merchantOrderId) - .data( - EventData.builder() - .flowType(FlowType.SUBSCRIPTION) - .eventState(eventState) - .apiPath(apiPath) - .build()) - .build(); - } - - public static BaseEvent buildSubscriptionRedeemEvent( - EventState eventState, - String merchantOrderId, - String apiPath, - EventType eventName, - Exception exception) { - BaseEvent event = - buildSubscriptionRedeemEvent(eventState, merchantOrderId, apiPath, eventName); - return populateExceptionFields(event, exception); - } - - /** Order Status Event Builder */ - public static BaseEvent buildSubscriptionStatusEvent( - EventState eventState, - String merchantSubscriptionId, - String apiPath, - EventType eventName) { - return BaseEvent.builder() - .eventName(eventName) - .eventTime(Instant.now().getEpochSecond()) - .data( - EventData.builder() - .eventState(eventState) - .apiPath(apiPath) - .flowType(FlowType.SUBSCRIPTION) - .subscriptionEventData( - SubscriptionEventData.builder() - .merchantSubscriptionId(merchantSubscriptionId) - .build()) - .build()) - .build(); - } - - public static BaseEvent buildSubscriptionStatusEvent( - EventState eventState, - String merchantSubscriptionId, - String apiPath, - EventType eventName, - Exception exception) { - BaseEvent event = - buildSubscriptionStatusEvent( - eventState, merchantSubscriptionId, apiPath, eventName); - return populateExceptionFields(event, exception); - } - - public static BaseEvent buildSubscriptionCancelEvent( - EventState eventState, - String merchantSubscriptionId, - String apiPath, - EventType eventName) { - return BaseEvent.builder() - .eventTime(Instant.now().getEpochSecond()) - .eventName(eventName) - .data( - EventData.builder() - .eventState(eventState) - .apiPath(apiPath) - .flowType(FlowType.SUBSCRIPTION) - .subscriptionEventData( - SubscriptionEventData.builder() - .merchantSubscriptionId(merchantSubscriptionId) - .build()) - .build()) - .build(); - } - - public static BaseEvent buildSubscriptionCancelEvent( - EventState eventState, - String merchantSubscriptionId, - String apiPath, - EventType eventName, - Exception exception) { - BaseEvent event = - buildSubscriptionCancelEvent( - eventState, merchantSubscriptionId, apiPath, eventName); - return populateExceptionFields(event, exception); - } - - /** OAuth Event Builder for Cached Token Present */ - public static BaseEvent buildOAuthEvent( - long fetchAttemptTime, - String apiPath, - EventType eventName, - Exception exception, - long cachedTokenIssuedAt, - long cachedTokenExpiresAt) { - BaseEvent baseEvent = - BaseEvent.builder() - .eventName(eventName) - .eventTime(Instant.now().getEpochSecond()) - .data( - EventData.builder() - .tokenFetchAttemptTimestamp(fetchAttemptTime) - .apiPath(apiPath) - .eventState(EventState.FAILED) - .cachedTokenExpiresAt(cachedTokenExpiresAt) - .cachedTokenIssuedAt(cachedTokenIssuedAt) - .build()) - .build(); - return populateExceptionFields(baseEvent, exception); - } - - public static BaseEvent buildCallbackSerializationFailedEvent( - EventState eventState, FlowType flowType, EventType eventName, Exception exception) { - BaseEvent baseEvent = - BaseEvent.builder() - .eventName(eventName) - .eventTime(Instant.now().getEpochSecond()) - .data(EventData.builder().eventState(eventState).flowType(flowType).build()) - .build(); - return populateExceptionFields(baseEvent, exception); - } - - private static BaseEvent populateExceptionFields(BaseEvent baseEvent, Exception exception) { - baseEvent.data.setExceptionMessage(exception.getMessage()); - baseEvent.data.setExceptionClass(exception.getClass().getSimpleName()); - if (exception instanceof PhonePeException) { - PhonePeException phonePeException = (PhonePeException) exception; - baseEvent.data.setExceptionHttpStatusCode(phonePeException.getHttpStatusCode()); - baseEvent.data.setExceptionCode(phonePeException.getCode()); - baseEvent.data.setExceptionData(phonePeException.getData()); - } - return baseEvent; - } + private String merchantOrderId; + private EventType eventName; + private long eventTime; + private EventData data; + + /** Client initialization Event */ + public static BaseEvent buildInitClientEvent(FlowType flowType, EventType eventName) { + BaseEvent baseEvent = buildInitClientEvent(eventName); + baseEvent.data.setFlowType(flowType); + return baseEvent; + } + + /** Client initialization Event */ + public static BaseEvent buildInitClientEvent(EventType eventName) { + return BaseEvent.builder() + .eventName(eventName) + .eventTime(Instant.now() + .getEpochSecond()) + .data(EventData.builder() + .eventState(EventState.INITIATED) + .build()) + .build(); + } + + /** Pay Event Builder For Standard Checkout */ + public static BaseEvent buildStandardCheckoutPayEvent( + EventState eventState, + StandardCheckoutPayRequest standardCheckoutPayRequest, + String apiPath, + EventType eventName) { + return BaseEvent.builder() + .eventName(eventName) + .eventTime(Instant.now() + .getEpochSecond()) + .merchantOrderId(standardCheckoutPayRequest.getMerchantOrderId()) + .data( + EventData.builder() + .eventState(eventState) + .amount(standardCheckoutPayRequest.getAmount()) + .apiPath(apiPath) + .expireAfter(standardCheckoutPayRequest.getExpireAfter()) + .flowType(FlowType.PG_CHECKOUT) + .build()) + .build(); + } + + /** Pay Failure Event for Standard Checkout --> Exception is PhonePeException */ + public static BaseEvent buildStandardCheckoutPayEvent( + EventState eventState, + StandardCheckoutPayRequest standardCheckoutPayRequest, + String apiPath, + EventType eventName, + Exception exception) { + BaseEvent baseEvent = buildStandardCheckoutPayEvent( + eventState, standardCheckoutPayRequest, apiPath, eventName); + return populateExceptionFields(baseEvent, exception); + } + + /** Pay Event Builder For Custom Checkout */ + public static BaseEvent buildCustomCheckoutPayEvent( + EventState eventState, + PgPaymentRequest pgPaymentRequest, + String apiPath, + EventType eventName) { + + // Extracting the instrument from the PgPaymentFlow + PgPaymentFlow pgPaymentFlow = (PgPaymentFlow) pgPaymentRequest.getPaymentFlow(); + + // Extracting the targetApp from the paymentMode in PgPaymentFlow + String targetApp = Optional.ofNullable(pgPaymentFlow) + .map(PgPaymentFlow::getPaymentMode) + .filter( + paymentMode -> paymentMode.getType() + .equals(PgV2InstrumentType.UPI_INTENT)) + .map(IntentPaymentV2Instrument.class::cast) + .map(IntentPaymentV2Instrument::getTargetApp) + .orElse(null); + + return BaseEvent.builder() + .eventName(eventName) + .eventTime(Instant.now() + .getEpochSecond()) + .merchantOrderId(pgPaymentRequest.getMerchantOrderId()) + .data( + EventData.builder() + .eventState(eventState) + .amount(pgPaymentRequest.getAmount()) + .apiPath(apiPath) + .deviceContext(pgPaymentRequest.getDeviceContext()) + .expireAfter(pgPaymentRequest.getExpireAfter()) + .targetApp(targetApp) + .paymentInstrument( + Optional.ofNullable(pgPaymentFlow) + .map(PgPaymentFlow::getPaymentMode) + .map(PaymentV2Instrument::getType) + .orElse(null)) + .flowType(FlowType.PG) + .build()) + .build(); + } + + /** Pay Failure Event for Custom Checkout --> Exception is PhonePeException */ + public static BaseEvent buildCustomCheckoutPayEvent( + EventState eventState, + PgPaymentRequest pgPaymentRequest, + String url, + EventType eventName, + Exception exception) { + BaseEvent baseEvent = buildCustomCheckoutPayEvent(eventState, pgPaymentRequest, url, eventName); + return populateExceptionFields(baseEvent, exception); + } + + /** Order Status Event Builder */ + public static BaseEvent buildOrderStatusEvent( + EventState eventState, + String merchantOrderId, + String apiPath, + FlowType flowType, + EventType eventName) { + return BaseEvent.builder() + .eventName(eventName) + .eventTime(Instant.now() + .getEpochSecond()) + .merchantOrderId(merchantOrderId) + .data( + EventData.builder() + .eventState(eventState) + .flowType(flowType) + .apiPath(apiPath) + .build()) + .build(); + } + + /** Order Status Failure Event */ + public static BaseEvent buildOrderStatusEvent( + EventState eventState, + String merchantOrderId, + String apiPath, + FlowType flowType, + EventType eventName, + Exception exception) { + BaseEvent baseEvent = buildOrderStatusEvent(eventState, merchantOrderId, apiPath, flowType, eventName); + return populateExceptionFields(baseEvent, exception); + } + + /** Refund Event Builder */ + public static BaseEvent buildRefundEvent( + EventState eventState, + RefundRequest refundRequest, + String apiPath, + FlowType flowType, + EventType eventName) { + return BaseEvent.builder() + .eventName(eventName) + .eventTime(Instant.now() + .getEpochSecond()) + .merchantOrderId(refundRequest.getOriginalMerchantOrderId()) + .data( + EventData.builder() + .merchantRefundId(refundRequest.getMerchantRefundId()) + .eventState(eventState) + .apiPath(apiPath) + .amount(refundRequest.getAmount()) + .originalMerchantOrderId(refundRequest.getOriginalMerchantOrderId()) + .flowType(flowType) + .build()) + .build(); + } + + /** Failure Event for Refund --> Exception is PhonePeException */ + public static BaseEvent buildRefundEvent( + EventState eventState, + RefundRequest refundRequest, + String apiPath, + FlowType flowType, + EventType eventName, + Exception exception) { + BaseEvent baseEvent = buildRefundEvent(eventState, refundRequest, apiPath, flowType, eventName); + return populateExceptionFields(baseEvent, exception); + } + + /** Refund Status Event Builder */ + public static BaseEvent buildRefundStatusEvent( + EventState eventState, + String refundId, + String apiPath, + FlowType flowType, + EventType eventName) { + return BaseEvent.builder() + .eventName(eventName) + .eventTime(Instant.now() + .getEpochSecond()) + .data( + EventData.builder() + .merchantRefundId(refundId) + .eventState(eventState) + .apiPath(apiPath) + .flowType(flowType) + .build()) + .build(); + } + + /** Failure Event for Refund Status --> Exception is PhonePeException */ + public static BaseEvent buildRefundStatusEvent( + EventState eventState, + String refundId, + String apiPath, + FlowType flowType, + EventType eventName, + Exception exception) { + BaseEvent baseEvent = buildRefundStatusEvent(eventState, refundId, apiPath, flowType, eventName); + return populateExceptionFields(baseEvent, exception); + } + + /** CreateSdkOrder Event Builder */ + public static BaseEvent buildCreateSdkOrderEvent( + EventState eventState, + CreateSdkOrderRequest createSdkOrderRequest, + String apiPath, + FlowType flowType, + EventType eventName) { + return BaseEvent.builder() + .merchantOrderId(createSdkOrderRequest.getMerchantOrderId()) + .eventName(eventName) + .eventTime(Instant.now() + .getEpochSecond()) + .data( + EventData.builder() + .amount(createSdkOrderRequest.getAmount()) + .eventState(eventState) + .apiPath(apiPath) + .expireAfter(createSdkOrderRequest.getExpireAfter()) + .flowType(flowType) + .build()) + .build(); + } + + /** Failure Event for CreateSdkOrder --> Exception is PhonePeException */ + public static BaseEvent buildCreateSdkOrderEvent( + EventState eventState, + CreateSdkOrderRequest createSdkOrderRequest, + String apiPath, + FlowType flowType, + EventType eventName, + Exception exception) { + BaseEvent baseEvent = buildCreateSdkOrderEvent( + eventState, createSdkOrderRequest, apiPath, flowType, eventName); + return populateExceptionFields(baseEvent, exception); + } + + /** Transaction Status Event Builder */ + public static BaseEvent buildTransactionStatusEvent( + EventState eventState, + String transactionId, + String apiPath, + FlowType flowType, + EventType eventName) { + return BaseEvent.builder() + .eventName(eventName) + .eventTime(Instant.now() + .getEpochSecond()) + .data( + EventData.builder() + .eventState(eventState) + .transactionId(transactionId) + .apiPath(apiPath) + .flowType(flowType) + .build()) + .build(); + } + + /** Failure Event for Transaction Status --> Exception is PhonePeException */ + public static BaseEvent buildTransactionStatusEvent( + EventState eventState, + String transactionId, + String apiPath, + FlowType flowType, + EventType eventName, + Exception exception) { + BaseEvent baseEvent = buildTransactionStatusEvent( + eventState, transactionId, apiPath, flowType, eventName); + return populateExceptionFields(baseEvent, exception); + } + + /** Subscription Setup Event Builder */ + public static BaseEvent buildSubscriptionSetupEvent( + EventState eventState, + PgPaymentRequest setupRequest, + String apiPath, + EventType eventName) { + // Extracting SubscriptionSetupPaymentFlow from the paymentFlow + SubscriptionSetupPaymentFlow setupPaymentFlow = (SubscriptionSetupPaymentFlow) setupRequest.getPaymentFlow(); + + // Extracting targetApp if the paymentMode is UPI_INTENT + String targetApp = Optional.ofNullable(setupPaymentFlow) + .map(SubscriptionSetupPaymentFlow::getPaymentMode) + .filter( + paymentMode -> paymentMode.getType() + .equals(PgV2InstrumentType.UPI_INTENT)) + .map(IntentPaymentV2Instrument.class::cast) + .map(IntentPaymentV2Instrument::getTargetApp) + .orElse(null); + + return BaseEvent.builder() + .merchantOrderId(setupRequest.getMerchantOrderId()) + .eventTime(Instant.now() + .getEpochSecond()) + .eventName(eventName) + .data( + EventData.builder() + .eventState(eventState) + .apiPath(apiPath) + .flowType(FlowType.SUBSCRIPTION) + .paymentInstrument( + Optional.ofNullable(setupPaymentFlow) + .map(SubscriptionSetupPaymentFlow::getPaymentMode) + .map(PaymentV2Instrument::getType) + .orElse(null)) + .targetApp(targetApp) + .deviceContext(setupRequest.getDeviceContext()) + .amount(setupRequest.getAmount()) + .subscriptionEventData( + SubscriptionEventData.builder() + .orderExpireAt(setupRequest.getExpireAt()) + .subscriptionExpireAt( + Optional.ofNullable(setupPaymentFlow) + .map( + SubscriptionSetupPaymentFlow::getExpireAt) + .orElse(null)) + .merchantSubscriptionId( + Optional.ofNullable(setupPaymentFlow) + .map( + SubscriptionSetupPaymentFlow::getMerchantSubscriptionId) + .orElse(null)) + .build()) + .build()) + .build(); + } + + /** Failure Event for Subscription Setup */ + public static BaseEvent buildSubscriptionSetupEvent( + EventState eventState, + PgPaymentRequest setupRequest, + String apiPath, + EventType eventName, + Exception exception) { + BaseEvent event = buildSubscriptionSetupEvent(eventState, setupRequest, apiPath, eventName); + return populateExceptionFields(event, exception); + } + + /** Subscription Notify Event Builder */ + public static BaseEvent buildSubscriptionNotifyEvent( + EventState eventState, + PgPaymentRequest notifyRequest, + String apiPath, + EventType eventName) { + SubscriptionRedemptionPaymentFlow paymentFlow = (SubscriptionRedemptionPaymentFlow) notifyRequest + .getPaymentFlow(); + return BaseEvent.builder() + .eventName(eventName) + .eventTime(Instant.now() + .getEpochSecond()) + .merchantOrderId(notifyRequest.getMerchantOrderId()) + .data( + EventData.builder() + .eventState(eventState) + .apiPath(apiPath) + .amount(notifyRequest.getAmount()) + .flowType(FlowType.SUBSCRIPTION) + .subscriptionEventData( + SubscriptionEventData.builder() + .orderExpireAt(notifyRequest.getExpireAt()) + .merchantSubscriptionId( + paymentFlow.getMerchantSubscriptionId()) + .build()) + .build()) + .build(); + } + + /** Failure Event for Subscription Notify */ + public static BaseEvent buildSubscriptionNotifyEvent( + EventState eventState, + PgPaymentRequest notifyRequest, + String apiPath, + EventType eventName, + Exception exception) { + BaseEvent event = buildSubscriptionNotifyEvent(eventState, notifyRequest, apiPath, eventName); + return populateExceptionFields(event, exception); + } + + public static BaseEvent buildSubscriptionRedeemEvent( + EventState eventState, String merchantOrderId, String apiPath, EventType eventName) { + return BaseEvent.builder() + .eventTime(Instant.now() + .getEpochSecond()) + .eventName(eventName) + .merchantOrderId(merchantOrderId) + .data( + EventData.builder() + .flowType(FlowType.SUBSCRIPTION) + .eventState(eventState) + .apiPath(apiPath) + .build()) + .build(); + } + + public static BaseEvent buildSubscriptionRedeemEvent( + EventState eventState, + String merchantOrderId, + String apiPath, + EventType eventName, + Exception exception) { + BaseEvent event = buildSubscriptionRedeemEvent(eventState, merchantOrderId, apiPath, eventName); + return populateExceptionFields(event, exception); + } + + /** Order Status Event Builder */ + public static BaseEvent buildSubscriptionStatusEvent( + EventState eventState, + String merchantSubscriptionId, + String apiPath, + EventType eventName) { + return BaseEvent.builder() + .eventName(eventName) + .eventTime(Instant.now() + .getEpochSecond()) + .data( + EventData.builder() + .eventState(eventState) + .apiPath(apiPath) + .flowType(FlowType.SUBSCRIPTION) + .subscriptionEventData( + SubscriptionEventData.builder() + .merchantSubscriptionId(merchantSubscriptionId) + .build()) + .build()) + .build(); + } + + public static BaseEvent buildSubscriptionStatusEvent( + EventState eventState, + String merchantSubscriptionId, + String apiPath, + EventType eventName, + Exception exception) { + BaseEvent event = buildSubscriptionStatusEvent( + eventState, merchantSubscriptionId, apiPath, eventName); + return populateExceptionFields(event, exception); + } + + public static BaseEvent buildSubscriptionCancelEvent( + EventState eventState, + String merchantSubscriptionId, + String apiPath, + EventType eventName) { + return BaseEvent.builder() + .eventTime(Instant.now() + .getEpochSecond()) + .eventName(eventName) + .data( + EventData.builder() + .eventState(eventState) + .apiPath(apiPath) + .flowType(FlowType.SUBSCRIPTION) + .subscriptionEventData( + SubscriptionEventData.builder() + .merchantSubscriptionId(merchantSubscriptionId) + .build()) + .build()) + .build(); + } + + public static BaseEvent buildSubscriptionCancelEvent( + EventState eventState, + String merchantSubscriptionId, + String apiPath, + EventType eventName, + Exception exception) { + BaseEvent event = buildSubscriptionCancelEvent( + eventState, merchantSubscriptionId, apiPath, eventName); + return populateExceptionFields(event, exception); + } + + /** OAuth Event Builder for Cached Token Present */ + public static BaseEvent buildOAuthEvent( + long fetchAttemptTime, + String apiPath, + EventType eventName, + Exception exception, + long cachedTokenIssuedAt, + long cachedTokenExpiresAt) { + BaseEvent baseEvent = BaseEvent.builder() + .eventName(eventName) + .eventTime(Instant.now() + .getEpochSecond()) + .data( + EventData.builder() + .tokenFetchAttemptTimestamp(fetchAttemptTime) + .apiPath(apiPath) + .eventState(EventState.FAILED) + .cachedTokenExpiresAt(cachedTokenExpiresAt) + .cachedTokenIssuedAt(cachedTokenIssuedAt) + .build()) + .build(); + return populateExceptionFields(baseEvent, exception); + } + + public static BaseEvent buildCallbackSerializationFailedEvent( + EventState eventState, FlowType flowType, EventType eventName, Exception exception) { + BaseEvent baseEvent = BaseEvent.builder() + .eventName(eventName) + .eventTime(Instant.now() + .getEpochSecond()) + .data(EventData.builder() + .eventState(eventState) + .flowType(flowType) + .build()) + .build(); + return populateExceptionFields(baseEvent, exception); + } + + private static BaseEvent populateExceptionFields(BaseEvent baseEvent, Exception exception) { + baseEvent.data.setExceptionMessage(exception.getMessage()); + baseEvent.data.setExceptionClass(exception.getClass() + .getSimpleName()); + if (exception instanceof PhonePeException) { + PhonePeException phonePeException = (PhonePeException) exception; + baseEvent.data.setExceptionHttpStatusCode(phonePeException.getHttpStatusCode()); + baseEvent.data.setExceptionCode(phonePeException.getCode()); + baseEvent.data.setExceptionData(phonePeException.getData()); + } + return baseEvent; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/events/models/BulkEvent.java b/src/main/java/com/phonepe/sdk/pg/common/events/models/BulkEvent.java index c1154c7..7844064 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/events/models/BulkEvent.java +++ b/src/main/java/com/phonepe/sdk/pg/common/events/models/BulkEvent.java @@ -30,7 +30,9 @@ @Builder public class BulkEvent { - private List events; - @Default private String source = Constants.SOURCE; - @Default private String clientVersion = Headers.SDK_TYPE + ":" + Headers.SDK_VERSION; + private List events; + @Default + private String source = Constants.SOURCE; + @Default + private String clientVersion = Headers.SDK_TYPE + ":" + Headers.SDK_VERSION; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/events/models/EventData.java b/src/main/java/com/phonepe/sdk/pg/common/events/models/EventData.java index ebf5122..1d9c77a 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/events/models/EventData.java +++ b/src/main/java/com/phonepe/sdk/pg/common/events/models/EventData.java @@ -34,35 +34,38 @@ @NoArgsConstructor public class EventData { - // Product Type Detail (PG, PG_CHECKOUT) - private FlowType flowType; - @Default private String sdkType = Headers.SDK_TYPE; - @Default private String sdkVersion = Headers.SDK_VERSION; + // Product Type Detail (PG, PG_CHECKOUT) + private FlowType flowType; + @Default + private String sdkType = Headers.SDK_TYPE; + @Default + private String sdkVersion = Headers.SDK_VERSION; - // API Details - private String apiPath; - private Long amount; - private String targetApp; - private DeviceContext deviceContext; - private Long expireAfter; - private String merchantRefundId; - private String originalMerchantOrderId; - private String transactionId; - private EventState eventState; - private PgV2InstrumentType paymentInstrument; + // API Details + private String apiPath; + private Long amount; + private String targetApp; + private DeviceContext deviceContext; + private Long expireAfter; + private String merchantRefundId; + private String originalMerchantOrderId; + private String transactionId; + private EventState eventState; + private PgV2InstrumentType paymentInstrument; - // Token Details - private Long cachedTokenIssuedAt; - private Long cachedTokenExpiresAt; - private Long tokenFetchAttemptTimestamp; + // Token Details + private Long cachedTokenIssuedAt; + private Long cachedTokenExpiresAt; + private Long tokenFetchAttemptTimestamp; - // Subscription Details - @JsonUnwrapped private SubscriptionEventData subscriptionEventData; + // Subscription Details + @JsonUnwrapped + private SubscriptionEventData subscriptionEventData; - // Exception Data - private String exceptionClass; - private String exceptionMessage; - private String exceptionCode; - private Integer exceptionHttpStatusCode; - private Map exceptionData; + // Exception Data + private String exceptionClass; + private String exceptionMessage; + private String exceptionCode; + private Integer exceptionHttpStatusCode; + private Map exceptionData; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/events/models/SubscriptionEventData.java b/src/main/java/com/phonepe/sdk/pg/common/events/models/SubscriptionEventData.java index f67a1f5..eed3b24 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/events/models/SubscriptionEventData.java +++ b/src/main/java/com/phonepe/sdk/pg/common/events/models/SubscriptionEventData.java @@ -26,7 +26,7 @@ @NoArgsConstructor public class SubscriptionEventData { - private String merchantSubscriptionId; - private Long subscriptionExpireAt; - private Long orderExpireAt; + private String merchantSubscriptionId; + private Long subscriptionExpireAt; + private Long orderExpireAt; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/events/models/enums/EventState.java b/src/main/java/com/phonepe/sdk/pg/common/events/models/enums/EventState.java index 551d7f6..f59512b 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/events/models/enums/EventState.java +++ b/src/main/java/com/phonepe/sdk/pg/common/events/models/enums/EventState.java @@ -16,7 +16,5 @@ package com.phonepe.sdk.pg.common.events.models.enums; public enum EventState { - SUCCESS, - FAILED, - INITIATED, + SUCCESS, FAILED, INITIATED, } diff --git a/src/main/java/com/phonepe/sdk/pg/common/events/models/enums/EventType.java b/src/main/java/com/phonepe/sdk/pg/common/events/models/enums/EventType.java index c289a63..bbd43b3 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/events/models/enums/EventType.java +++ b/src/main/java/com/phonepe/sdk/pg/common/events/models/enums/EventType.java @@ -16,46 +16,33 @@ package com.phonepe.sdk.pg.common.events.models.enums; public enum EventType { - PAY_SUCCESS, - PAY_FAILED, + PAY_SUCCESS, PAY_FAILED, - REFUND_SUCCESS, - REFUND_FAILED, + REFUND_SUCCESS, REFUND_FAILED, - REFUND_STATUS_SUCCESS, - REFUND_STATUS_FAILED, + REFUND_STATUS_SUCCESS, REFUND_STATUS_FAILED, - ORDER_STATUS_SUCCESS, - ORDER_STATUS_FAILED, + ORDER_STATUS_SUCCESS, ORDER_STATUS_FAILED, - TRANSACTION_STATUS_SUCCESS, - TRANSACTION_STATUS_FAILED, + TRANSACTION_STATUS_SUCCESS, TRANSACTION_STATUS_FAILED, - CREATE_SDK_ORDER_SUCCESS, - CREATE_SDK_ORDER_FAILED, + CREATE_SDK_ORDER_SUCCESS, CREATE_SDK_ORDER_FAILED, - STANDARD_CHECKOUT_CLIENT_INITIALIZED, - CUSTOM_CHECKOUT_CLIENT_INITIALIZED, - TOKEN_SERVICE_INITIALIZED, + STANDARD_CHECKOUT_CLIENT_INITIALIZED, CUSTOM_CHECKOUT_CLIENT_INITIALIZED, TOKEN_SERVICE_INITIALIZED, - OAUTH_FETCH_FAILED_USED_CACHED_TOKEN, + OAUTH_FETCH_FAILED_USED_CACHED_TOKEN, - CALLBACK_SERIALIZATION_FAILED, + CALLBACK_SERIALIZATION_FAILED, - SUBSCRIPTION_CLIENT_INITIALIZED, + SUBSCRIPTION_CLIENT_INITIALIZED, - SETUP_SUCCESS, - SETUP_FAILED, + SETUP_SUCCESS, SETUP_FAILED, - NOTIFY_SUCCESS, - NOTIFY_FAILED, + NOTIFY_SUCCESS, NOTIFY_FAILED, - REDEEM_SUCCESS, - REDEEM_FAILED, + REDEEM_SUCCESS, REDEEM_FAILED, - CANCEL_SUCCESS, - CANCEL_FAILED, + CANCEL_SUCCESS, CANCEL_FAILED, - SUBSCRIPTION_STATUS_SUCCESS, - SUBSCRIPTION_STATUS_FAILED, + SUBSCRIPTION_STATUS_SUCCESS, SUBSCRIPTION_STATUS_FAILED, } diff --git a/src/main/java/com/phonepe/sdk/pg/common/events/models/enums/FlowType.java b/src/main/java/com/phonepe/sdk/pg/common/events/models/enums/FlowType.java index a8a2c48..dcd51e6 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/events/models/enums/FlowType.java +++ b/src/main/java/com/phonepe/sdk/pg/common/events/models/enums/FlowType.java @@ -16,7 +16,5 @@ package com.phonepe.sdk.pg.common.events.models.enums; public enum FlowType { - SUBSCRIPTION, - PG_CHECKOUT, - PG + SUBSCRIPTION, PG_CHECKOUT, PG } diff --git a/src/main/java/com/phonepe/sdk/pg/common/events/publisher/EventPublisher.java b/src/main/java/com/phonepe/sdk/pg/common/events/publisher/EventPublisher.java index 7ef3d9a..511bbfc 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/events/publisher/EventPublisher.java +++ b/src/main/java/com/phonepe/sdk/pg/common/events/publisher/EventPublisher.java @@ -20,9 +20,12 @@ public interface EventPublisher extends Runnable { - default void setAuthTokenSupplier(Supplier authTokenSuppplier) {} + default void setAuthTokenSupplier(Supplier authTokenSuppplier) { + } - default void startPublishingEvents(Supplier authTokenSupplier) {} + default void startPublishingEvents(Supplier authTokenSupplier) { + } - default void send(BaseEvent baseEvent) {} + default void send(BaseEvent baseEvent) { + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/events/publisher/EventPublisherFactory.java b/src/main/java/com/phonepe/sdk/pg/common/events/publisher/EventPublisherFactory.java index 905862e..4a52d1b 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/events/publisher/EventPublisherFactory.java +++ b/src/main/java/com/phonepe/sdk/pg/common/events/publisher/EventPublisherFactory.java @@ -25,42 +25,44 @@ @Builder public class EventPublisherFactory { - private final ObjectMapper objectMapper; - private final OkHttpClient okHttpClient; - private final String hostUrl; - private static EventPublisher cachedEventPublisher; + private final ObjectMapper objectMapper; + private final OkHttpClient okHttpClient; + private final String hostUrl; + private static EventPublisher cachedEventPublisher; - public EventPublisherFactory( - final ObjectMapper objectMapper, - final OkHttpClient okHttpClient, - final String hostUrl) { - this.objectMapper = objectMapper; - this.okHttpClient = okHttpClient; - this.hostUrl = hostUrl; - } + public EventPublisherFactory( + final ObjectMapper objectMapper, + final OkHttpClient okHttpClient, + final String hostUrl) { + this.objectMapper = objectMapper; + this.okHttpClient = okHttpClient; + this.hostUrl = hostUrl; + } - public static void setCachedEventPublisher(EventPublisher eventPublisher) { - EventPublisherFactory.cachedEventPublisher = eventPublisher; - } + public static void setCachedEventPublisher(EventPublisher eventPublisher) { + EventPublisherFactory.cachedEventPublisher = eventPublisher; + } - public EventPublisher getEventPublisher(boolean shouldPublishEvents) { - if (shouldPublishEvents) { - // For different clients, the eventSender should be same - if (Objects.isNull(cachedEventPublisher)) { - EventPublisherFactory.setCachedEventPublisher( - QueuedEventPublisher.builder() - .eventQueue( - new BoundedConcurrentLinkedQueue(Constants.QUEUE_MAX_SIZE)) - .objectMapper(this.objectMapper) - .hostUrl(this.hostUrl) - .okHttpClient(this.okHttpClient) - .build()); - } - return EventPublisherFactory.cachedEventPublisher; - } - return new EventPublisher() { - @Override - public void run() {} - }; - } + public EventPublisher getEventPublisher(boolean shouldPublishEvents) { + if (shouldPublishEvents) { + // For different clients, the eventSender should be same + if (Objects.isNull(cachedEventPublisher)) { + EventPublisherFactory.setCachedEventPublisher( + QueuedEventPublisher.builder() + .eventQueue( + new BoundedConcurrentLinkedQueue(Constants.QUEUE_MAX_SIZE)) + .objectMapper(this.objectMapper) + .hostUrl(this.hostUrl) + .okHttpClient(this.okHttpClient) + .build()); + } + return EventPublisherFactory.cachedEventPublisher; + } + return new EventPublisher() { + + @Override + public void run() { + } + }; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/events/publisher/QueuedEventPublisher.java b/src/main/java/com/phonepe/sdk/pg/common/events/publisher/QueuedEventPublisher.java index f01ce73..1446802 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/events/publisher/QueuedEventPublisher.java +++ b/src/main/java/com/phonepe/sdk/pg/common/events/publisher/QueuedEventPublisher.java @@ -42,128 +42,136 @@ @Slf4j public class QueuedEventPublisher implements EventPublisher { - private final ObjectMapper objectMapper; - private final OkHttpClient okHttpClient; - private final EventQueue eventQueue; - private final String hostUrl; - private Supplier authTokenSupplier; - protected ScheduledExecutorService scheduler; - - @Builder - public QueuedEventPublisher( - ObjectMapper objectMapper, - OkHttpClient okHttpClient, - EventQueue eventQueue, - String hostUrl) { - this.objectMapper = objectMapper; - this.okHttpClient = okHttpClient; - this.eventQueue = eventQueue; - this.hostUrl = hostUrl; - } - - @Override - public void setAuthTokenSupplier(Supplier authTokenSupplier) { - this.authTokenSupplier = authTokenSupplier; - } - - @Override - public void startPublishingEvents(Supplier authTokenSupplier) { - this.setAuthTokenSupplier(authTokenSupplier); - if (Objects.isNull(scheduler)) { - scheduler = Executors.newScheduledThreadPool(1); - this.scheduler.scheduleWithFixedDelay( - this, Constants.INITIAL_DELAY, Constants.DELAY, TimeUnit.SECONDS); - } - } - - @Override - public void send(BaseEvent event) { - this.eventQueue.add(event); - } - - private void sendBatchData() { - try { - if (this.eventQueue.isEmpty()) { - return; - } - log.info("Queue Size {}", this.eventQueue.size()); - - List> bulkEventBatch = createEventBatches(); - - for (List sdkEventList : bulkEventBatch) { - try { - sendBatchData(sdkEventList); - } catch (Exception exception) { - log.error("Error occurred sending events batch to backend", exception); - } - } - } catch (Exception exception) { - log.error("Error occurred sending events batch to backend", exception); - } - } - - private List> createEventBatches() { - final int CUR_QUEUE_SIZE = this.eventQueue.size(); - List> bulkEventBatch = new ArrayList<>(); - List currentBatch = new ArrayList<>(); - for (int numEventsProcessed = 0; - numEventsProcessed < CUR_QUEUE_SIZE; - numEventsProcessed++) { - BaseEvent event = this.eventQueue.poll(); - if (Objects.isNull(event)) { - break; - } - currentBatch.add(event); - if (currentBatch.size() == Constants.MAX_EVENTS_IN_BATCH) { - bulkEventBatch.add(currentBatch); - currentBatch = new ArrayList<>(); - } - } - if (!currentBatch.isEmpty()) { - bulkEventBatch.add(currentBatch); - } - - return bulkEventBatch; - } - - private List getHeaders() { - List headers = new ArrayList<>(); - headers.add(HttpHeaderPair.builder().key(Headers.ACCEPT).value(APPLICATION_JSON).build()); - headers.add( - HttpHeaderPair.builder() - .key(Constants.AUTHORIZATION) - .value(authTokenSupplier.get()) - .build()); - headers.add( - HttpHeaderPair.builder().key(Headers.CONTENT_TYPE).value(APPLICATION_JSON).build()); - return headers; - } - - @SneakyThrows - private void sendBatchData(List sdkEventList) { - BulkEvent bulkEvent = BulkEvent.builder().events(sdkEventList).build(); - List headers = getHeaders(); - HttpCommand httpCommand = buildHttpCommand(headers, bulkEvent); - httpCommand.execute(); - } - - private HttpCommand buildHttpCommand( - final List headers, BulkEvent bulkEvent) { - return HttpCommand.builder() - .methodName(HttpMethodType.POST) - .hostURL(this.hostUrl) - .url(Constants.EVENTS_ENDPOINT) - .client(this.okHttpClient) - .objectMapper(this.objectMapper) - .responseTypeReference(new TypeReference() {}) - .requestData(bulkEvent) - .encodingType(APPLICATION_JSON) - .headers(headers) - .build(); - } - - @Override - public void run() { - sendBatchData(); - } + private final ObjectMapper objectMapper; + private final OkHttpClient okHttpClient; + private final EventQueue eventQueue; + private final String hostUrl; + private Supplier authTokenSupplier; + protected ScheduledExecutorService scheduler; + + @Builder + public QueuedEventPublisher( + ObjectMapper objectMapper, + OkHttpClient okHttpClient, + EventQueue eventQueue, + String hostUrl) { + this.objectMapper = objectMapper; + this.okHttpClient = okHttpClient; + this.eventQueue = eventQueue; + this.hostUrl = hostUrl; + } + + @Override + public void setAuthTokenSupplier(Supplier authTokenSupplier) { + this.authTokenSupplier = authTokenSupplier; + } + + @Override + public void startPublishingEvents(Supplier authTokenSupplier) { + this.setAuthTokenSupplier(authTokenSupplier); + if (Objects.isNull(scheduler)) { + scheduler = Executors.newScheduledThreadPool(1); + this.scheduler.scheduleWithFixedDelay( + this, Constants.INITIAL_DELAY, Constants.DELAY, TimeUnit.SECONDS); + } + } + + @Override + public void send(BaseEvent event) { + this.eventQueue.add(event); + } + + private void sendBatchData() { + try { + if (this.eventQueue.isEmpty()) { + return; + } + log.info("Queue Size {}", this.eventQueue.size()); + + List> bulkEventBatch = createEventBatches(); + + for (List sdkEventList : bulkEventBatch) { + try { + sendBatchData(sdkEventList); + } catch (Exception exception) { + log.error("Error occurred sending events batch to backend", exception); + } + } + } catch (Exception exception) { + log.error("Error occurred sending events batch to backend", exception); + } + } + + private List> createEventBatches() { + final int CUR_QUEUE_SIZE = this.eventQueue.size(); + List> bulkEventBatch = new ArrayList<>(); + List currentBatch = new ArrayList<>(); + for (int numEventsProcessed = 0; + numEventsProcessed < CUR_QUEUE_SIZE; + numEventsProcessed++) { + BaseEvent event = this.eventQueue.poll(); + if (Objects.isNull(event)) { + break; + } + currentBatch.add(event); + if (currentBatch.size() == Constants.MAX_EVENTS_IN_BATCH) { + bulkEventBatch.add(currentBatch); + currentBatch = new ArrayList<>(); + } + } + if (!currentBatch.isEmpty()) { + bulkEventBatch.add(currentBatch); + } + + return bulkEventBatch; + } + + private List getHeaders() { + List headers = new ArrayList<>(); + headers.add(HttpHeaderPair.builder() + .key(Headers.ACCEPT) + .value(APPLICATION_JSON) + .build()); + headers.add( + HttpHeaderPair.builder() + .key(Constants.AUTHORIZATION) + .value(authTokenSupplier.get()) + .build()); + headers.add( + HttpHeaderPair.builder() + .key(Headers.CONTENT_TYPE) + .value(APPLICATION_JSON) + .build()); + return headers; + } + + @SneakyThrows + private void sendBatchData(List sdkEventList) { + BulkEvent bulkEvent = BulkEvent.builder() + .events(sdkEventList) + .build(); + List headers = getHeaders(); + HttpCommand httpCommand = buildHttpCommand(headers, bulkEvent); + httpCommand.execute(); + } + + private HttpCommand buildHttpCommand( + final List headers, BulkEvent bulkEvent) { + return HttpCommand.builder() + .methodName(HttpMethodType.POST) + .hostURL(this.hostUrl) + .url(Constants.EVENTS_ENDPOINT) + .client(this.okHttpClient) + .objectMapper(this.objectMapper) + .responseTypeReference(new TypeReference() {}) + .requestData(bulkEvent) + .encodingType(APPLICATION_JSON) + .headers(headers) + .build(); + } + + @Override + public void run() { + sendBatchData(); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/events/queue/BoundedConcurrentLinkedQueue.java b/src/main/java/com/phonepe/sdk/pg/common/events/queue/BoundedConcurrentLinkedQueue.java index 0a9390e..049e7e2 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/events/queue/BoundedConcurrentLinkedQueue.java +++ b/src/main/java/com/phonepe/sdk/pg/common/events/queue/BoundedConcurrentLinkedQueue.java @@ -27,40 +27,40 @@ @Slf4j public class BoundedConcurrentLinkedQueue implements EventQueue { - private ConcurrentLinkedQueue queue; - private int maxSize; + private ConcurrentLinkedQueue queue; + private int maxSize; - public BoundedConcurrentLinkedQueue(int maxSize) { - this.queue = new ConcurrentLinkedQueue<>(); - this.maxSize = maxSize; - } + public BoundedConcurrentLinkedQueue(int maxSize) { + this.queue = new ConcurrentLinkedQueue<>(); + this.maxSize = maxSize; + } - @Override - public void add(BaseEvent data) { - if (queue.size() < maxSize && Objects.nonNull(data)) { - queue.add(data); - } else { - log.error("Reached queue max size, skipping event {}", data.getEventName()); - } - } + @Override + public void add(BaseEvent data) { + if (queue.size() < maxSize && Objects.nonNull(data)) { + queue.add(data); + } else { + log.error("Reached queue max size, skipping event {}", data.getEventName()); + } + } - @Override - public boolean isEmpty() { - return queue.isEmpty(); - } + @Override + public boolean isEmpty() { + return queue.isEmpty(); + } - @Override - public int size() { - return queue.size(); - } + @Override + public int size() { + return queue.size(); + } - @Override - public BaseEvent poll() { - return queue.poll(); - } + @Override + public BaseEvent poll() { + return queue.poll(); + } - @Override - public ConcurrentLinkedQueue getQueue() { - return queue; - } + @Override + public ConcurrentLinkedQueue getQueue() { + return queue; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/events/queue/EventQueue.java b/src/main/java/com/phonepe/sdk/pg/common/events/queue/EventQueue.java index 1c2699f..254c163 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/events/queue/EventQueue.java +++ b/src/main/java/com/phonepe/sdk/pg/common/events/queue/EventQueue.java @@ -20,21 +20,22 @@ public interface EventQueue { - default void add(BaseEvent data) {} + default void add(BaseEvent data) { + } - default boolean isEmpty() { - return true; - } + default boolean isEmpty() { + return true; + } - default int size() { - return 0; - } + default int size() { + return 0; + } - default BaseEvent poll() { - return null; - } + default BaseEvent poll() { + return null; + } - default ConcurrentLinkedQueue getQueue() { - return null; - } + default ConcurrentLinkedQueue getQueue() { + return null; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/exception/BadRequest.java b/src/main/java/com/phonepe/sdk/pg/common/exception/BadRequest.java index e9e349b..c1c70c3 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/exception/BadRequest.java +++ b/src/main/java/com/phonepe/sdk/pg/common/exception/BadRequest.java @@ -19,8 +19,8 @@ public class BadRequest extends ClientError { - /** 400 Bad Request */ - public BadRequest(Integer responseCode, String message, PhonePeResponse phonePeResponse) { - super(responseCode, message, phonePeResponse); - } + /** 400 Bad Request */ + public BadRequest(Integer responseCode, String message, PhonePeResponse phonePeResponse) { + super(responseCode, message, phonePeResponse); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/exception/ClientError.java b/src/main/java/com/phonepe/sdk/pg/common/exception/ClientError.java index 0f541e8..fe4f1ec 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/exception/ClientError.java +++ b/src/main/java/com/phonepe/sdk/pg/common/exception/ClientError.java @@ -19,8 +19,8 @@ public class ClientError extends PhonePeException { - /** 4xx Client Error */ - public ClientError(Integer responseCode, String message, PhonePeResponse phonePeResponse) { - super(responseCode, message, phonePeResponse); - } + /** 4xx Client Error */ + public ClientError(Integer responseCode, String message, PhonePeResponse phonePeResponse) { + super(responseCode, message, phonePeResponse); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/exception/ExceptionMapper.java b/src/main/java/com/phonepe/sdk/pg/common/exception/ExceptionMapper.java index 2e7cd68..53f0782 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/exception/ExceptionMapper.java +++ b/src/main/java/com/phonepe/sdk/pg/common/exception/ExceptionMapper.java @@ -24,27 +24,25 @@ public class ExceptionMapper { - public static Map> codeToException = - Stream.of( - new AbstractMap.SimpleEntry<>(400, BadRequest.class), - new AbstractMap.SimpleEntry<>(401, UnauthorizedAccess.class), - new AbstractMap.SimpleEntry<>(403, ForbiddenAccess.class), - new AbstractMap.SimpleEntry<>(404, ResourceNotFound.class), - new AbstractMap.SimpleEntry<>(409, ResourceConflict.class), - new AbstractMap.SimpleEntry<>(410, ResourceGone.class), - new AbstractMap.SimpleEntry<>(417, ExpectationFailed.class), - new AbstractMap.SimpleEntry<>(422, ResourceInvalid.class), - new AbstractMap.SimpleEntry<>(429, TooManyRequest.class)) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + public static Map> codeToException = Stream.of( + new AbstractMap.SimpleEntry<>(400, BadRequest.class), + new AbstractMap.SimpleEntry<>(401, UnauthorizedAccess.class), + new AbstractMap.SimpleEntry<>(403, ForbiddenAccess.class), + new AbstractMap.SimpleEntry<>(404, ResourceNotFound.class), + new AbstractMap.SimpleEntry<>(409, ResourceConflict.class), + new AbstractMap.SimpleEntry<>(410, ResourceGone.class), + new AbstractMap.SimpleEntry<>(417, ExpectationFailed.class), + new AbstractMap.SimpleEntry<>(422, ResourceInvalid.class), + new AbstractMap.SimpleEntry<>(429, TooManyRequest.class)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - @SneakyThrows - public static void prepareCodeToException( - int responseCode, String message, PhonePeResponse phonePeResponse) { + @SneakyThrows + public static void prepareCodeToException( + int responseCode, String message, PhonePeResponse phonePeResponse) { - Class exceptionClass = codeToException.get(responseCode); - throw (Throwable) - exceptionClass - .getDeclaredConstructor(Integer.class, String.class, PhonePeResponse.class) - .newInstance(responseCode, message, phonePeResponse); - } + Class exceptionClass = codeToException.get(responseCode); + throw (Throwable) exceptionClass + .getDeclaredConstructor(Integer.class, String.class, PhonePeResponse.class) + .newInstance(responseCode, message, phonePeResponse); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/exception/ExpectationFailed.java b/src/main/java/com/phonepe/sdk/pg/common/exception/ExpectationFailed.java index 4d1368c..5286cd5 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/exception/ExpectationFailed.java +++ b/src/main/java/com/phonepe/sdk/pg/common/exception/ExpectationFailed.java @@ -19,9 +19,9 @@ public class ExpectationFailed extends ClientError { - /** 417 Expectation failed */ - public ExpectationFailed( - Integer responseCode, String message, PhonePeResponse phonePeResponse) { - super(responseCode, message, phonePeResponse); - } + /** 417 Expectation failed */ + public ExpectationFailed( + Integer responseCode, String message, PhonePeResponse phonePeResponse) { + super(responseCode, message, phonePeResponse); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/exception/ForbiddenAccess.java b/src/main/java/com/phonepe/sdk/pg/common/exception/ForbiddenAccess.java index 6582cf4..6241735 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/exception/ForbiddenAccess.java +++ b/src/main/java/com/phonepe/sdk/pg/common/exception/ForbiddenAccess.java @@ -19,8 +19,8 @@ public class ForbiddenAccess extends ClientError { - /** 403 Forbidden */ - public ForbiddenAccess(Integer responseCode, String message, PhonePeResponse phonePeResponse) { - super(responseCode, message, phonePeResponse); - } + /** 403 Forbidden */ + public ForbiddenAccess(Integer responseCode, String message, PhonePeResponse phonePeResponse) { + super(responseCode, message, phonePeResponse); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/exception/PhonePeException.java b/src/main/java/com/phonepe/sdk/pg/common/exception/PhonePeException.java index fd0a303..81c459e 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/exception/PhonePeException.java +++ b/src/main/java/com/phonepe/sdk/pg/common/exception/PhonePeException.java @@ -24,50 +24,48 @@ @Setter public class PhonePeException extends RuntimeException { - private Integer httpStatusCode; - private String message; - private transient Map data; - private String code; + private Integer httpStatusCode; + private String message; + private transient Map data; + private String code; - public PhonePeException(String message) { - this.message = message; - } + public PhonePeException(String message) { + this.message = message; + } - public PhonePeException(Integer httpStatusCode, String message) { - this.httpStatusCode = httpStatusCode; - this.message = message; - } + public PhonePeException(Integer httpStatusCode, String message) { + this.httpStatusCode = httpStatusCode; + this.message = message; + } - public PhonePeException( - Integer httpStatusCode, String message, PhonePeResponse phonePeResponse) { - this.httpStatusCode = httpStatusCode; - this.message = message; - if (phonePeResponse != null) { - this.message = - phonePeResponse.getMessage() != null ? phonePeResponse.getMessage() : message; - this.data = phonePeResponse.getData(); - this.code = - phonePeResponse.getErrorCode() != null - ? phonePeResponse.getErrorCode() - : phonePeResponse.getCode(); - // keeping only the `errorCode` field for auth exception (ignoring code) - } - } + public PhonePeException( + Integer httpStatusCode, String message, PhonePeResponse phonePeResponse) { + this.httpStatusCode = httpStatusCode; + this.message = message; + if (phonePeResponse != null) { + this.message = phonePeResponse.getMessage() != null ? phonePeResponse.getMessage() : message; + this.data = phonePeResponse.getData(); + this.code = phonePeResponse.getErrorCode() != null + ? phonePeResponse.getErrorCode() + : phonePeResponse.getCode(); + // keeping only the `errorCode` field for auth exception (ignoring code) + } + } - public String toString() { - return getClass() - + "\n" - + "httpStatusCode: " - + httpStatusCode - + "\n" - + "message: " - + message - + "\n" - + "data: " - + data - + "\n" - + "code : " - + code - + "\n"; - } + public String toString() { + return getClass() + + "\n" + + "httpStatusCode: " + + httpStatusCode + + "\n" + + "message: " + + message + + "\n" + + "data: " + + data + + "\n" + + "code : " + + code + + "\n"; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/exception/ResourceConflict.java b/src/main/java/com/phonepe/sdk/pg/common/exception/ResourceConflict.java index af316f3..879c573 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/exception/ResourceConflict.java +++ b/src/main/java/com/phonepe/sdk/pg/common/exception/ResourceConflict.java @@ -19,8 +19,8 @@ public class ResourceConflict extends ClientError { - /** 409 Conflict */ - public ResourceConflict(Integer responseCode, String message, PhonePeResponse phonePeResponse) { - super(responseCode, message, phonePeResponse); - } + /** 409 Conflict */ + public ResourceConflict(Integer responseCode, String message, PhonePeResponse phonePeResponse) { + super(responseCode, message, phonePeResponse); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/exception/ResourceGone.java b/src/main/java/com/phonepe/sdk/pg/common/exception/ResourceGone.java index 4d27a7e..6c83da7 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/exception/ResourceGone.java +++ b/src/main/java/com/phonepe/sdk/pg/common/exception/ResourceGone.java @@ -19,8 +19,8 @@ public class ResourceGone extends ClientError { - /** 410 Gone */ - public ResourceGone(Integer responseCode, String message, PhonePeResponse phonePeResponse) { - super(responseCode, message, phonePeResponse); - } + /** 410 Gone */ + public ResourceGone(Integer responseCode, String message, PhonePeResponse phonePeResponse) { + super(responseCode, message, phonePeResponse); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/exception/ResourceInvalid.java b/src/main/java/com/phonepe/sdk/pg/common/exception/ResourceInvalid.java index 810d9b9..1effe6e 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/exception/ResourceInvalid.java +++ b/src/main/java/com/phonepe/sdk/pg/common/exception/ResourceInvalid.java @@ -19,8 +19,8 @@ public class ResourceInvalid extends ClientError { - /** 422 Invalid */ - public ResourceInvalid(Integer responseCode, String message, PhonePeResponse phonePeResponse) { - super(responseCode, message, phonePeResponse); - } + /** 422 Invalid */ + public ResourceInvalid(Integer responseCode, String message, PhonePeResponse phonePeResponse) { + super(responseCode, message, phonePeResponse); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/exception/ResourceNotFound.java b/src/main/java/com/phonepe/sdk/pg/common/exception/ResourceNotFound.java index 4610eb2..e0ccb69 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/exception/ResourceNotFound.java +++ b/src/main/java/com/phonepe/sdk/pg/common/exception/ResourceNotFound.java @@ -19,9 +19,9 @@ public class ResourceNotFound extends ClientError { - /** 404 Not Found */ - public ResourceNotFound(Integer responseCode, String message, PhonePeResponse phonePeResponse) { + /** 404 Not Found */ + public ResourceNotFound(Integer responseCode, String message, PhonePeResponse phonePeResponse) { - super(responseCode, message, phonePeResponse); - } + super(responseCode, message, phonePeResponse); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/exception/ServerError.java b/src/main/java/com/phonepe/sdk/pg/common/exception/ServerError.java index 51e0e3a..6f32cd1 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/exception/ServerError.java +++ b/src/main/java/com/phonepe/sdk/pg/common/exception/ServerError.java @@ -19,8 +19,8 @@ public class ServerError extends PhonePeException { - /** 5xx Server Error */ - public ServerError(Integer responseCode, String message, PhonePeResponse phonePeResponse) { - super(responseCode, message, phonePeResponse); - } + /** 5xx Server Error */ + public ServerError(Integer responseCode, String message, PhonePeResponse phonePeResponse) { + super(responseCode, message, phonePeResponse); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/exception/TooManyRequest.java b/src/main/java/com/phonepe/sdk/pg/common/exception/TooManyRequest.java index ea3e6a9..acf5256 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/exception/TooManyRequest.java +++ b/src/main/java/com/phonepe/sdk/pg/common/exception/TooManyRequest.java @@ -19,8 +19,8 @@ public class TooManyRequest extends ClientError { - // Too Many Request - public TooManyRequest(Integer responseCode, String message, PhonePeResponse phonePeResponse) { - super(responseCode, message, phonePeResponse); - } + // Too Many Request + public TooManyRequest(Integer responseCode, String message, PhonePeResponse phonePeResponse) { + super(responseCode, message, phonePeResponse); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/exception/UnauthorizedAccess.java b/src/main/java/com/phonepe/sdk/pg/common/exception/UnauthorizedAccess.java index 3114336..5901451 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/exception/UnauthorizedAccess.java +++ b/src/main/java/com/phonepe/sdk/pg/common/exception/UnauthorizedAccess.java @@ -19,9 +19,9 @@ public class UnauthorizedAccess extends ClientError { - /** 401 Unauthorized */ - public UnauthorizedAccess( - Integer responseCode, String message, PhonePeResponse phonePeResponse) { - super(responseCode, message, phonePeResponse); - } + /** 401 Unauthorized */ + public UnauthorizedAccess( + Integer responseCode, String message, PhonePeResponse phonePeResponse) { + super(responseCode, message, phonePeResponse); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/http/HttpHeaderPair.java b/src/main/java/com/phonepe/sdk/pg/common/http/HttpHeaderPair.java index 7a04b78..69ef242 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/http/HttpHeaderPair.java +++ b/src/main/java/com/phonepe/sdk/pg/common/http/HttpHeaderPair.java @@ -26,6 +26,6 @@ @NoArgsConstructor public class HttpHeaderPair { - private String key; - private String value; + private String key; + private String value; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/http/HttpMethodType.java b/src/main/java/com/phonepe/sdk/pg/common/http/HttpMethodType.java index 907613c..1411fab 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/http/HttpMethodType.java +++ b/src/main/java/com/phonepe/sdk/pg/common/http/HttpMethodType.java @@ -16,6 +16,5 @@ package com.phonepe.sdk.pg.common.http; public enum HttpMethodType { - GET, - POST + GET, POST } diff --git a/src/main/java/com/phonepe/sdk/pg/common/http/PhonePeResponse.java b/src/main/java/com/phonepe/sdk/pg/common/http/PhonePeResponse.java index 47ccf75..6ecd79c 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/http/PhonePeResponse.java +++ b/src/main/java/com/phonepe/sdk/pg/common/http/PhonePeResponse.java @@ -30,12 +30,12 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class PhonePeResponse { - private boolean success; - private String code; - private String message; + private boolean success; + private String code; + private String message; - @JsonAlias({"data", "context"}) - private Map data; + @JsonAlias({"data", "context"}) + private Map data; - private String errorCode; + private String errorCode; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/MetaInfo.java b/src/main/java/com/phonepe/sdk/pg/common/models/MetaInfo.java index ddd0172..72babb2 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/MetaInfo.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/MetaInfo.java @@ -31,9 +31,9 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class MetaInfo { - private String udf1; - private String udf2; - private String udf3; - private String udf4; - private String udf5; + private String udf1; + private String udf2; + private String udf3; + private String udf4; + private String udf5; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/PaymentFlowType.java b/src/main/java/com/phonepe/sdk/pg/common/models/PaymentFlowType.java index 8f7d6aa..e86e875 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/PaymentFlowType.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/PaymentFlowType.java @@ -16,8 +16,5 @@ package com.phonepe.sdk.pg.common.models; public enum PaymentFlowType { - PG, - PG_CHECKOUT, - SUBSCRIPTION_SETUP, - SUBSCRIPTION_REDEMPTION, + PG, PG_CHECKOUT, SUBSCRIPTION_SETUP, SUBSCRIPTION_REDEMPTION, } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/PgV2InstrumentType.java b/src/main/java/com/phonepe/sdk/pg/common/models/PgV2InstrumentType.java index d5bf954..97b6397 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/PgV2InstrumentType.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/PgV2InstrumentType.java @@ -16,12 +16,5 @@ package com.phonepe.sdk.pg.common.models; public enum PgV2InstrumentType { - UPI_COLLECT, - UPI_INTENT, - PPE_INTENT, - UPI_QR, - CARD, - TOKEN, - NET_BANKING, - UPI_AUTO_PAY + UPI_COLLECT, UPI_INTENT, PPE_INTENT, UPI_QR, CARD, TOKEN, NET_BANKING, UPI_AUTO_PAY } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/AccountConstraint.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/AccountConstraint.java index d02f1e0..3378f7e 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/AccountConstraint.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/AccountConstraint.java @@ -26,13 +26,13 @@ @JsonInclude(Include.NON_NULL) public class AccountConstraint extends InstrumentConstraint { - private String accountNumber; - private String ifsc; + private String accountNumber; + private String ifsc; - @Builder - public AccountConstraint(String accountNumber, String ifsc) { - super(PaymentInstrumentType.ACCOUNT); - this.accountNumber = accountNumber; - this.ifsc = ifsc; - } + @Builder + public AccountConstraint(String accountNumber, String ifsc) { + super(PaymentInstrumentType.ACCOUNT); + this.accountNumber = accountNumber; + this.ifsc = ifsc; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/DeviceContext.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/DeviceContext.java index 933e052..e2392a7 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/DeviceContext.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/DeviceContext.java @@ -27,6 +27,6 @@ @JsonInclude(Include.NON_NULL) public class DeviceContext { - private String deviceOS; - private String merchantCallBackScheme; + private String deviceOS; + private String merchantCallBackScheme; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/InstrumentConstraint.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/InstrumentConstraint.java index c29b171..911ae92 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/InstrumentConstraint.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/InstrumentConstraint.java @@ -29,9 +29,9 @@ @JsonIgnoreProperties(ignoreUnknown = true) public abstract class InstrumentConstraint { - private PaymentInstrumentType type; + private PaymentInstrumentType type; - public enum PaymentInstrumentType { - ACCOUNT; - } + public enum PaymentInstrumentType { + ACCOUNT; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/PaymentFlow.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/PaymentFlow.java index 2ad95e7..4e87d3a 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/PaymentFlow.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/PaymentFlow.java @@ -30,5 +30,5 @@ @JsonIgnoreProperties(ignoreUnknown = true) public abstract class PaymentFlow { - private PaymentFlowType type; + private PaymentFlowType type; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/PgPaymentRequest.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/PgPaymentRequest.java index f382093..e9b48d1 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/PgPaymentRequest.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/PgPaymentRequest.java @@ -46,337 +46,332 @@ @JsonInclude(Include.NON_NULL) public class PgPaymentRequest { - private String merchantOrderId; + private String merchantOrderId; - private Long amount; + private Long amount; - private MetaInfo metaInfo; + private MetaInfo metaInfo; - private PaymentFlow paymentFlow; + private PaymentFlow paymentFlow; - private List constraints; + private List constraints; - private DeviceContext deviceContext; - private Long expireAfter; - private Long expireAt; + private DeviceContext deviceContext; + private Long expireAfter; + private Long expireAt; - // The "x-device-os" request header is currently required only for UPI COLLECT transactions. - // Once the COLLECT payment instrument is fully disabled, as per the guidelines, - // this header will no longer be necessary, even for iOS devices. - // To streamline the request structure and avoid unnecessary complexity, - // this header is now being incorporated directly into the request builder - // instead of being managed as a separate value. - @JsonIgnore - private String deviceOS; + // The "x-device-os" request header is currently required only for UPI COLLECT transactions. + // Once the COLLECT payment instrument is fully disabled, as per the guidelines, + // this header will no longer be necessary, even for iOS devices. + // To streamline the request structure and avoid unnecessary complexity, + // this header is now being incorporated directly into the request builder + // instead of being managed as a separate value. + @JsonIgnore + private String deviceOS; - private PgPaymentRequest( - String merchantOrderId, - Long amount, - MetaInfo metaInfo, - List constraints, - Long expireAfter) { - this.merchantOrderId = merchantOrderId; - this.amount = amount; - this.metaInfo = metaInfo; - this.constraints = constraints; - this.expireAfter = expireAfter; - } + private PgPaymentRequest( + String merchantOrderId, + Long amount, + MetaInfo metaInfo, + List constraints, + Long expireAfter) { + this.merchantOrderId = merchantOrderId; + this.amount = amount; + this.metaInfo = metaInfo; + this.constraints = constraints; + this.expireAfter = expireAfter; + } - @Builder( - builderClassName = "UpiIntentPayRequestBuilder", builderMethodName = "UpiIntentPayRequestBuilder") - public PgPaymentRequest( - String merchantOrderId, - long amount, - MetaInfo metaInfo, - List constraints, - String deviceOS, - String merchantCallBackScheme, - String targetApp, - Long expireAfter) { - this(merchantOrderId, amount, metaInfo, constraints, expireAfter); - this.deviceContext = DeviceContext.builder() - .deviceOS(deviceOS) - .merchantCallBackScheme(merchantCallBackScheme) - .build(); - this.paymentFlow = PgPaymentFlow.builder() - .paymentMode( - IntentPaymentV2Instrument.builder() - .targetApp(targetApp) - .build()) - .build(); - } + @Builder( + builderClassName = "UpiIntentPayRequestBuilder", builderMethodName = "UpiIntentPayRequestBuilder") + public PgPaymentRequest( + String merchantOrderId, + long amount, + MetaInfo metaInfo, + List constraints, + String deviceOS, + String merchantCallBackScheme, + String targetApp, + Long expireAfter) { + this(merchantOrderId, amount, metaInfo, constraints, expireAfter); + this.deviceContext = DeviceContext.builder() + .deviceOS(deviceOS) + .merchantCallBackScheme(merchantCallBackScheme) + .build(); + this.paymentFlow = PgPaymentFlow.builder() + .paymentMode( + IntentPaymentV2Instrument.builder() + .targetApp(targetApp) + .build()) + .build(); + } - @Builder( - builderClassName = "UpiCollectPayViaVpaRequestBuilder", builderMethodName = - "UpiCollectPayViaVpaRequestBuilder") - public PgPaymentRequest( - long amount, - String merchantOrderId, - MetaInfo metaInfo, - List constraints, - String vpa, - String message, - Long expireAfter, - String deviceOS) { - this(merchantOrderId, amount, metaInfo, constraints, expireAfter); - this.deviceOS = deviceOS; - this.paymentFlow = PgPaymentFlow.builder() - .paymentMode( - CollectPaymentV2Instrument.builder() - .details( - VpaCollectPaymentDetails.builder() - .vpa(vpa) - .build()) - .message(message) - .build()) - .build(); - } + @Builder( + builderClassName = "UpiCollectPayViaVpaRequestBuilder", builderMethodName = "UpiCollectPayViaVpaRequestBuilder") + public PgPaymentRequest( + long amount, + String merchantOrderId, + MetaInfo metaInfo, + List constraints, + String vpa, + String message, + Long expireAfter, + String deviceOS) { + this(merchantOrderId, amount, metaInfo, constraints, expireAfter); + this.deviceOS = deviceOS; + this.paymentFlow = PgPaymentFlow.builder() + .paymentMode( + CollectPaymentV2Instrument.builder() + .details( + VpaCollectPaymentDetails.builder() + .vpa(vpa) + .build()) + .message(message) + .build()) + .build(); + } - @Builder( - builderClassName = "UpiCollectPayViaPhoneNumberRequestBuilder", builderMethodName = - "UpiCollectPayViaPhoneNumberRequestBuilder") - public PgPaymentRequest( - long amount, - MetaInfo metaInfo, - String merchantOrderId, - String phoneNumber, - List constraints, - String message, - Long expireAfter, - String deviceOS) { - this(merchantOrderId, amount, metaInfo, constraints, expireAfter); - this.deviceOS = deviceOS; - this.paymentFlow = PgPaymentFlow.builder() - .paymentMode( - CollectPaymentV2Instrument.builder() - .details( - PhoneNumberCollectPaymentDetails.builder() - .phoneNumber(phoneNumber) - .build()) - .message(message) - .build()) - .build(); - } + @Builder( + builderClassName = "UpiCollectPayViaPhoneNumberRequestBuilder", builderMethodName = "UpiCollectPayViaPhoneNumberRequestBuilder") + public PgPaymentRequest( + long amount, + MetaInfo metaInfo, + String merchantOrderId, + String phoneNumber, + List constraints, + String message, + Long expireAfter, + String deviceOS) { + this(merchantOrderId, amount, metaInfo, constraints, expireAfter); + this.deviceOS = deviceOS; + this.paymentFlow = PgPaymentFlow.builder() + .paymentMode( + CollectPaymentV2Instrument.builder() + .details( + PhoneNumberCollectPaymentDetails.builder() + .phoneNumber(phoneNumber) + .build()) + .message(message) + .build()) + .build(); + } - @Builder(builderClassName = "UpiQrRequestBuilder", builderMethodName = "UpiQrRequestBuilder") - public PgPaymentRequest( - long amount, - MetaInfo metaInfo, - String merchantOrderId, - List constraints, - Long expireAfter) { - this(merchantOrderId, amount, metaInfo, constraints, expireAfter); - this.paymentFlow = PgPaymentFlow.builder() - .paymentMode(UpiQrPaymentV2Instrument.builder() - .build()) - .build(); - } + @Builder(builderClassName = "UpiQrRequestBuilder", builderMethodName = "UpiQrRequestBuilder") + public PgPaymentRequest( + long amount, + MetaInfo metaInfo, + String merchantOrderId, + List constraints, + Long expireAfter) { + this(merchantOrderId, amount, metaInfo, constraints, expireAfter); + this.paymentFlow = PgPaymentFlow.builder() + .paymentMode(UpiQrPaymentV2Instrument.builder() + .build()) + .build(); + } - @Builder( - builderClassName = "NetBankingPayRequestBuilder", builderMethodName = "NetBankingPayRequestBuilder") - public PgPaymentRequest( - long amount, - MetaInfo metaInfo, - List constraints, - String merchantOrderId, - String bankId, - String merchantUserId, - String redirectUrl, - Long expireAfter) { - this(merchantOrderId, amount, metaInfo, constraints, expireAfter); - this.paymentFlow = PgPaymentFlow.builder() - .paymentMode( - NetBankingPaymentV2Instrument.builder() - .bankId(bankId) - .merchantUserId(merchantUserId) - .build()) - .merchantUrls(MerchantUrls.builder() - .redirectUrl(redirectUrl) - .build()) - .build(); - } + @Builder( + builderClassName = "NetBankingPayRequestBuilder", builderMethodName = "NetBankingPayRequestBuilder") + public PgPaymentRequest( + long amount, + MetaInfo metaInfo, + List constraints, + String merchantOrderId, + String bankId, + String merchantUserId, + String redirectUrl, + Long expireAfter) { + this(merchantOrderId, amount, metaInfo, constraints, expireAfter); + this.paymentFlow = PgPaymentFlow.builder() + .paymentMode( + NetBankingPaymentV2Instrument.builder() + .bankId(bankId) + .merchantUserId(merchantUserId) + .build()) + .merchantUrls(MerchantUrls.builder() + .redirectUrl(redirectUrl) + .build()) + .build(); + } - @Builder( - builderClassName = "TokenPayRequestBuilder", builderMethodName = "TokenPayRequestBuilder") - public PgPaymentRequest( - String merchantOrderId, - long amount, - long encryptionKeyId, - String authMode, - String encryptedToken, - String encryptedCvv, - String cryptogram, - String panSuffix, - String expiryMonth, - String expiryYear, - String redirectUrl, - String cardHolderName, - String merchantUserId, - MetaInfo metaInfo, - List constraints, - Long expireAfter) { - this(merchantOrderId, amount, metaInfo, constraints, expireAfter); - this.paymentFlow = PgPaymentFlow.builder() - .paymentMode( - TokenPaymentV2Instrument.builder() - .merchantUserId(merchantUserId) - .authMode(authMode) - .tokenDetails( - TokenDetails.builder() - .cardHolderName(cardHolderName) - .cryptogram(cryptogram) - .encryptedCvv(encryptedCvv) - .encryptedToken(encryptedToken) - .encryptionKeyId(encryptionKeyId) - .panSuffix(panSuffix) - .expiry( - Expiry.builder() - .month(expiryMonth) - .year(expiryYear) - .build()) - .build()) - .build()) - .merchantUrls(MerchantUrls.builder() - .redirectUrl(redirectUrl) - .build()) - .build(); - } + @Builder( + builderClassName = "TokenPayRequestBuilder", builderMethodName = "TokenPayRequestBuilder") + public PgPaymentRequest( + String merchantOrderId, + long amount, + long encryptionKeyId, + String authMode, + String encryptedToken, + String encryptedCvv, + String cryptogram, + String panSuffix, + String expiryMonth, + String expiryYear, + String redirectUrl, + String cardHolderName, + String merchantUserId, + MetaInfo metaInfo, + List constraints, + Long expireAfter) { + this(merchantOrderId, amount, metaInfo, constraints, expireAfter); + this.paymentFlow = PgPaymentFlow.builder() + .paymentMode( + TokenPaymentV2Instrument.builder() + .merchantUserId(merchantUserId) + .authMode(authMode) + .tokenDetails( + TokenDetails.builder() + .cardHolderName(cardHolderName) + .cryptogram(cryptogram) + .encryptedCvv(encryptedCvv) + .encryptedToken(encryptedToken) + .encryptionKeyId(encryptionKeyId) + .panSuffix(panSuffix) + .expiry( + Expiry.builder() + .month(expiryMonth) + .year(expiryYear) + .build()) + .build()) + .build()) + .merchantUrls(MerchantUrls.builder() + .redirectUrl(redirectUrl) + .build()) + .build(); + } - @Builder( - builderClassName = "CardPayRequestBuilder", builderMethodName = "CardPayRequestBuilder") - public PgPaymentRequest( - String merchantOrderId, - long amount, - long encryptionKeyId, - String authMode, - String encryptedCardNumber, - String encryptedCvv, - String expiryMonth, - String expiryYear, - String cardHolderName, - String merchantUserId, - MetaInfo metaInfo, - List constraints, - String redirectUrl, - Long expireAfter) { - this(merchantOrderId, amount, metaInfo, constraints, expireAfter); - this.paymentFlow = PgPaymentFlow.builder() - .paymentMode( - CardPaymentV2Instrument.builder() - .merchantUserId(merchantUserId) - .authMode(authMode) - .cardDetails( - NewCardDetails.builder() - .cardHolderName(cardHolderName) - .encryptedCvv(encryptedCvv) - .encryptionKeyId(encryptionKeyId) - .encryptedCardNumber(encryptedCardNumber) - .expiry( - Expiry.builder() - .month(expiryMonth) - .year(expiryYear) - .build()) - .build()) - .build()) - .merchantUrls(MerchantUrls.builder() - .redirectUrl(redirectUrl) - .build()) - .build(); - } + @Builder( + builderClassName = "CardPayRequestBuilder", builderMethodName = "CardPayRequestBuilder") + public PgPaymentRequest( + String merchantOrderId, + long amount, + long encryptionKeyId, + String authMode, + String encryptedCardNumber, + String encryptedCvv, + String expiryMonth, + String expiryYear, + String cardHolderName, + String merchantUserId, + MetaInfo metaInfo, + List constraints, + String redirectUrl, + Long expireAfter) { + this(merchantOrderId, amount, metaInfo, constraints, expireAfter); + this.paymentFlow = PgPaymentFlow.builder() + .paymentMode( + CardPaymentV2Instrument.builder() + .merchantUserId(merchantUserId) + .authMode(authMode) + .cardDetails( + NewCardDetails.builder() + .cardHolderName(cardHolderName) + .encryptedCvv(encryptedCvv) + .encryptionKeyId(encryptionKeyId) + .encryptedCardNumber(encryptedCardNumber) + .expiry( + Expiry.builder() + .month(expiryMonth) + .year(expiryYear) + .build()) + .build()) + .build()) + .merchantUrls(MerchantUrls.builder() + .redirectUrl(redirectUrl) + .build()) + .build(); + } - @Builder( - builderClassName = "SubscriptionSetupUpiIntentBuilder", builderMethodName = - "SubscriptionSetupUpiIntentBuilder") - public PgPaymentRequest( - String merchantOrderId, - String merchantSubscriptionId, - Long amount, - String deviceOS, - String merchantCallbackScheme, - String targetApp, - AuthWorkflowType authWorkflowType, - Long subscriptionExpireAt, - Long orderExpireAt, - AmountType amountType, - Frequency frequency, - MetaInfo metaInfo, - Long maxAmount, - List constraints) { - this(merchantOrderId, amount, metaInfo, constraints, null); - this.expireAt = orderExpireAt; - this.deviceContext = DeviceContext.builder() - .deviceOS(deviceOS) - .merchantCallBackScheme(merchantCallbackScheme) - .build(); - this.paymentFlow = SubscriptionSetupPaymentFlow.builder() - .merchantSubscriptionId(merchantSubscriptionId) - .amountType(amountType) - .authWorkflowType(authWorkflowType) - .expireAt(subscriptionExpireAt) - .frequency(frequency) - .maxAmount(maxAmount) - .paymentMode( - IntentPaymentV2Instrument.builder() - .targetApp(targetApp) - .build()) - .build(); - } + @Builder( + builderClassName = "SubscriptionSetupUpiIntentBuilder", builderMethodName = "SubscriptionSetupUpiIntentBuilder") + public PgPaymentRequest( + String merchantOrderId, + String merchantSubscriptionId, + Long amount, + String deviceOS, + String merchantCallbackScheme, + String targetApp, + AuthWorkflowType authWorkflowType, + Long subscriptionExpireAt, + Long orderExpireAt, + AmountType amountType, + Frequency frequency, + MetaInfo metaInfo, + Long maxAmount, + List constraints) { + this(merchantOrderId, amount, metaInfo, constraints, null); + this.expireAt = orderExpireAt; + this.deviceContext = DeviceContext.builder() + .deviceOS(deviceOS) + .merchantCallBackScheme(merchantCallbackScheme) + .build(); + this.paymentFlow = SubscriptionSetupPaymentFlow.builder() + .merchantSubscriptionId(merchantSubscriptionId) + .amountType(amountType) + .authWorkflowType(authWorkflowType) + .expireAt(subscriptionExpireAt) + .frequency(frequency) + .maxAmount(maxAmount) + .paymentMode( + IntentPaymentV2Instrument.builder() + .targetApp(targetApp) + .build()) + .build(); + } - @Builder( - builderClassName = "SubscriptionSetupUpiCollectBuilder", builderMethodName = - "SubscriptionSetupUpiCollectBuilder") - public PgPaymentRequest( - String merchantOrderId, - String merchantSubscriptionId, - Long amount, - AuthWorkflowType authWorkflowType, - Long subscriptionExpireAt, - Long orderExpireAt, - AmountType amountType, - Frequency frequency, - MetaInfo metaInfo, - Long maxAmount, - String vpa, - String message, - List constraints) { - this(merchantOrderId, amount, metaInfo, constraints, null); - this.expireAt = orderExpireAt; - this.paymentFlow = SubscriptionSetupPaymentFlow.builder() - .merchantSubscriptionId(merchantSubscriptionId) - .amountType(amountType) - .authWorkflowType(authWorkflowType) - .expireAt(subscriptionExpireAt) - .frequency(frequency) - .maxAmount(maxAmount) - .paymentMode( - CollectPaymentV2Instrument.builder() - .details( - VpaCollectPaymentDetails.builder() - .vpa(vpa) - .build()) - .message(message) - .build()) - .build(); - } + @Builder( + builderClassName = "SubscriptionSetupUpiCollectBuilder", builderMethodName = "SubscriptionSetupUpiCollectBuilder") + public PgPaymentRequest( + String merchantOrderId, + String merchantSubscriptionId, + Long amount, + AuthWorkflowType authWorkflowType, + Long subscriptionExpireAt, + Long orderExpireAt, + AmountType amountType, + Frequency frequency, + MetaInfo metaInfo, + Long maxAmount, + String vpa, + String message, + List constraints) { + this(merchantOrderId, amount, metaInfo, constraints, null); + this.expireAt = orderExpireAt; + this.paymentFlow = SubscriptionSetupPaymentFlow.builder() + .merchantSubscriptionId(merchantSubscriptionId) + .amountType(amountType) + .authWorkflowType(authWorkflowType) + .expireAt(subscriptionExpireAt) + .frequency(frequency) + .maxAmount(maxAmount) + .paymentMode( + CollectPaymentV2Instrument.builder() + .details( + VpaCollectPaymentDetails.builder() + .vpa(vpa) + .build()) + .message(message) + .build()) + .build(); + } - @Builder( - builderClassName = "SubscriptionNotifyRequestBuilder", builderMethodName = - "SubscriptionNotifyRequestBuilder") - public PgPaymentRequest( - String merchantOrderId, - Long amount, - Long expireAt, - MetaInfo metaInfo, - String merchantSubscriptionId, - boolean autoDebit, - RedemptionRetryStrategy redemptionRetryStrategy, - List constraints) { - this(merchantOrderId, amount, metaInfo, constraints, null); - this.expireAt = expireAt; - this.paymentFlow = SubscriptionRedemptionPaymentFlow.builder() - .redemptionRetryStrategy(redemptionRetryStrategy) - .autoDebit(autoDebit) - .merchantSubscriptionId(merchantSubscriptionId) - .build(); - } + @Builder( + builderClassName = "SubscriptionNotifyRequestBuilder", builderMethodName = "SubscriptionNotifyRequestBuilder") + public PgPaymentRequest( + String merchantOrderId, + Long amount, + Long expireAt, + MetaInfo metaInfo, + String merchantSubscriptionId, + boolean autoDebit, + RedemptionRetryStrategy redemptionRetryStrategy, + List constraints) { + this(merchantOrderId, amount, metaInfo, constraints, null); + this.expireAt = expireAt; + this.paymentFlow = SubscriptionRedemptionPaymentFlow.builder() + .redemptionRetryStrategy(redemptionRetryStrategy) + .autoDebit(autoDebit) + .merchantSubscriptionId(merchantSubscriptionId) + .build(); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/RefundRequest.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/RefundRequest.java index ec176a9..69a1edf 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/RefundRequest.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/RefundRequest.java @@ -25,7 +25,7 @@ @JsonInclude(Include.NON_NULL) public class RefundRequest { - private String merchantRefundId; - private String originalMerchantOrderId; - private long amount; + private String merchantRefundId; + private String originalMerchantOrderId; + private long amount; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/BillingAddress.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/BillingAddress.java index 26dad70..4774c2a 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/BillingAddress.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/BillingAddress.java @@ -25,10 +25,10 @@ @JsonInclude(Include.NON_NULL) public class BillingAddress { - private String line1; - private String line2; - private String city; - private String state; - private String zip; - private String country; + private String line1; + private String line2; + private String city; + private String state; + private String zip; + private String country; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/CardPaymentV2Instrument.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/CardPaymentV2Instrument.java index a0cb3f1..700fb9a 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/CardPaymentV2Instrument.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/CardPaymentV2Instrument.java @@ -27,18 +27,18 @@ @JsonInclude(Include.NON_NULL) public class CardPaymentV2Instrument extends PaymentV2Instrument { - private String authMode; - private NewCardDetails cardDetails; - private boolean savedCard; - private String merchantUserId; + private String authMode; + private NewCardDetails cardDetails; + private boolean savedCard; + private String merchantUserId; - @Builder - public CardPaymentV2Instrument( - String authMode, String merchantUserId, NewCardDetails cardDetails, boolean savedCard) { - super(PgV2InstrumentType.CARD); - this.authMode = authMode; - this.cardDetails = cardDetails; - this.savedCard = savedCard; - this.merchantUserId = merchantUserId; - } + @Builder + public CardPaymentV2Instrument( + String authMode, String merchantUserId, NewCardDetails cardDetails, boolean savedCard) { + super(PgV2InstrumentType.CARD); + this.authMode = authMode; + this.cardDetails = cardDetails; + this.savedCard = savedCard; + this.merchantUserId = merchantUserId; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/CollectPaymentDetails.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/CollectPaymentDetails.java index c00f411..dc2ab4c 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/CollectPaymentDetails.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/CollectPaymentDetails.java @@ -24,5 +24,5 @@ @Getter public abstract class CollectPaymentDetails { - CollectPaymentDetailsType type; + CollectPaymentDetailsType type; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/CollectPaymentDetailsType.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/CollectPaymentDetailsType.java index b7a11b3..93fc995 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/CollectPaymentDetailsType.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/CollectPaymentDetailsType.java @@ -16,6 +16,5 @@ package com.phonepe.sdk.pg.common.models.request.instruments; public enum CollectPaymentDetailsType { - VPA, - PHONE_NUMBER + VPA, PHONE_NUMBER } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/CollectPaymentV2Instrument.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/CollectPaymentV2Instrument.java index ea840bf..fff8774 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/CollectPaymentV2Instrument.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/CollectPaymentV2Instrument.java @@ -27,13 +27,13 @@ @JsonInclude(Include.NON_NULL) public class CollectPaymentV2Instrument extends PaymentV2Instrument { - private CollectPaymentDetails details; - private String message; + private CollectPaymentDetails details; + private String message; - @Builder - public CollectPaymentV2Instrument(CollectPaymentDetails details, String message) { - super(PgV2InstrumentType.UPI_COLLECT); - this.details = details; - this.message = message; - } + @Builder + public CollectPaymentV2Instrument(CollectPaymentDetails details, String message) { + super(PgV2InstrumentType.UPI_COLLECT); + this.details = details; + this.message = message; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/Expiry.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/Expiry.java index 3f7e84d..f405b18 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/Expiry.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/Expiry.java @@ -25,6 +25,6 @@ @Builder public class Expiry { - private String month; - private String year; + private String month; + private String year; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/IntentPaymentV2Instrument.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/IntentPaymentV2Instrument.java index 3418d48..85a3fcd 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/IntentPaymentV2Instrument.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/IntentPaymentV2Instrument.java @@ -27,15 +27,15 @@ @JsonInclude(Include.NON_NULL) public class IntentPaymentV2Instrument extends PaymentV2Instrument { - private String targetApp; + private String targetApp; - public IntentPaymentV2Instrument() { - super(PgV2InstrumentType.UPI_INTENT); - } + public IntentPaymentV2Instrument() { + super(PgV2InstrumentType.UPI_INTENT); + } - @Builder - public IntentPaymentV2Instrument(String targetApp) { - super(PgV2InstrumentType.UPI_INTENT); - this.targetApp = targetApp; - } + @Builder + public IntentPaymentV2Instrument(String targetApp) { + super(PgV2InstrumentType.UPI_INTENT); + this.targetApp = targetApp; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/NetBankingPaymentV2Instrument.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/NetBankingPaymentV2Instrument.java index 51fbaf3..4d75a54 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/NetBankingPaymentV2Instrument.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/NetBankingPaymentV2Instrument.java @@ -27,13 +27,13 @@ @JsonInclude(Include.NON_NULL) public class NetBankingPaymentV2Instrument extends PaymentV2Instrument { - private String bankId; - private String merchantUserId; + private String bankId; + private String merchantUserId; - @Builder - public NetBankingPaymentV2Instrument(String bankId, String merchantUserId) { - super(PgV2InstrumentType.NET_BANKING); - this.bankId = bankId; - this.merchantUserId = merchantUserId; - } + @Builder + public NetBankingPaymentV2Instrument(String bankId, String merchantUserId) { + super(PgV2InstrumentType.NET_BANKING); + this.bankId = bankId; + this.merchantUserId = merchantUserId; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/NewCardDetails.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/NewCardDetails.java index 0f198ae..c2e5626 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/NewCardDetails.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/NewCardDetails.java @@ -22,10 +22,10 @@ @Data public class NewCardDetails { - private String encryptedCardNumber; - private Long encryptionKeyId; - private String cardHolderName; - private Expiry expiry; - private String encryptedCvv; - private BillingAddress billingAddress; + private String encryptedCardNumber; + private Long encryptionKeyId; + private String cardHolderName; + private Expiry expiry; + private String encryptedCvv; + private BillingAddress billingAddress; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/PaymentV2Instrument.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/PaymentV2Instrument.java index 58e1382..26cea8a 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/PaymentV2Instrument.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/PaymentV2Instrument.java @@ -27,10 +27,10 @@ @Getter public abstract class PaymentV2Instrument { - private PgV2InstrumentType type; - private List instrumentConstraints; + private PgV2InstrumentType type; + private List instrumentConstraints; - public PaymentV2Instrument(PgV2InstrumentType type) { - this.type = type; - } + public PaymentV2Instrument(PgV2InstrumentType type) { + this.type = type; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/PhoneNumberCollectPaymentDetails.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/PhoneNumberCollectPaymentDetails.java index 3316a89..66ef196 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/PhoneNumberCollectPaymentDetails.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/PhoneNumberCollectPaymentDetails.java @@ -26,11 +26,11 @@ @JsonInclude(Include.NON_NULL) public class PhoneNumberCollectPaymentDetails extends CollectPaymentDetails { - private String phoneNumber; + private String phoneNumber; - @Builder - public PhoneNumberCollectPaymentDetails(String phoneNumber) { - super(CollectPaymentDetailsType.PHONE_NUMBER); - this.phoneNumber = phoneNumber; - } + @Builder + public PhoneNumberCollectPaymentDetails(String phoneNumber) { + super(CollectPaymentDetailsType.PHONE_NUMBER); + this.phoneNumber = phoneNumber; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/PpeIntenPaymentV2Instrument.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/PpeIntenPaymentV2Instrument.java index 85c019d..0d62520 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/PpeIntenPaymentV2Instrument.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/PpeIntenPaymentV2Instrument.java @@ -27,8 +27,8 @@ @JsonInclude(Include.NON_NULL) public class PpeIntenPaymentV2Instrument extends PaymentV2Instrument { - @Builder - public PpeIntenPaymentV2Instrument() { - super(PgV2InstrumentType.PPE_INTENT); - } + @Builder + public PpeIntenPaymentV2Instrument() { + super(PgV2InstrumentType.PPE_INTENT); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/TokenDetails.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/TokenDetails.java index 3f9f0ee..d5aa694 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/TokenDetails.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/TokenDetails.java @@ -25,13 +25,13 @@ @Builder public class TokenDetails { - private String encryptedToken; - private String encryptedCvv; - private long encryptionKeyId; - private Expiry expiry; - private String cryptogram; - private String panSuffix; - private String cardHolderName; - private String eci; - private String atc; + private String encryptedToken; + private String encryptedCvv; + private long encryptionKeyId; + private Expiry expiry; + private String cryptogram; + private String panSuffix; + private String cardHolderName; + private String eci; + private String atc; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/TokenPaymentV2Instrument.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/TokenPaymentV2Instrument.java index ee48868..0124e52 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/TokenPaymentV2Instrument.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/TokenPaymentV2Instrument.java @@ -27,16 +27,16 @@ @JsonInclude(Include.NON_NULL) public class TokenPaymentV2Instrument extends PaymentV2Instrument { - private String authMode; - private TokenDetails tokenDetails; - private String merchantUserId; + private String authMode; + private TokenDetails tokenDetails; + private String merchantUserId; - @Builder - public TokenPaymentV2Instrument( - String authMode, TokenDetails tokenDetails, String merchantUserId) { - super(PgV2InstrumentType.TOKEN); - this.authMode = authMode; - this.tokenDetails = tokenDetails; - this.merchantUserId = merchantUserId; - } + @Builder + public TokenPaymentV2Instrument( + String authMode, TokenDetails tokenDetails, String merchantUserId) { + super(PgV2InstrumentType.TOKEN); + this.authMode = authMode; + this.tokenDetails = tokenDetails; + this.merchantUserId = merchantUserId; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/UpiQrPaymentV2Instrument.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/UpiQrPaymentV2Instrument.java index 3cd5816..827dfb7 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/UpiQrPaymentV2Instrument.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/UpiQrPaymentV2Instrument.java @@ -27,8 +27,8 @@ @JsonInclude(Include.NON_NULL) public class UpiQrPaymentV2Instrument extends PaymentV2Instrument { - @Builder - public UpiQrPaymentV2Instrument() { - super(PgV2InstrumentType.UPI_QR); - } + @Builder + public UpiQrPaymentV2Instrument() { + super(PgV2InstrumentType.UPI_QR); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/VpaCollectPaymentDetails.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/VpaCollectPaymentDetails.java index 8de18fa..2f4a264 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/VpaCollectPaymentDetails.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/instruments/VpaCollectPaymentDetails.java @@ -26,11 +26,11 @@ @JsonInclude(Include.NON_NULL) public class VpaCollectPaymentDetails extends CollectPaymentDetails { - private String vpa; + private String vpa; - @Builder - public VpaCollectPaymentDetails(String vpa) { - super(CollectPaymentDetailsType.VPA); - this.vpa = vpa; - } + @Builder + public VpaCollectPaymentDetails(String vpa) { + super(CollectPaymentDetailsType.VPA); + this.vpa = vpa; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/CardPaymentModeConstraint.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/CardPaymentModeConstraint.java index 592a2ef..a8fb21e 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/CardPaymentModeConstraint.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/CardPaymentModeConstraint.java @@ -30,11 +30,11 @@ @JsonInclude(Include.NON_NULL) public class CardPaymentModeConstraint extends PaymentModeConstraint { - private final Set cardTypes; + private final Set cardTypes; - @Builder - public CardPaymentModeConstraint(Set cardTypes) { - super(PgV2InstrumentType.CARD); - this.cardTypes = cardTypes; - } + @Builder + public CardPaymentModeConstraint(Set cardTypes) { + super(PgV2InstrumentType.CARD); + this.cardTypes = cardTypes; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/CardType.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/CardType.java index b7ec616..f3099f6 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/CardType.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/CardType.java @@ -16,6 +16,5 @@ package com.phonepe.sdk.pg.common.models.request.paymentmodeconstraints; public enum CardType { - CREDIT_CARD, - DEBIT_CARD + CREDIT_CARD, DEBIT_CARD } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/NetBankingPaymentModeConstraint.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/NetBankingPaymentModeConstraint.java index 3c5f5cc..3d9594e 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/NetBankingPaymentModeConstraint.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/NetBankingPaymentModeConstraint.java @@ -29,8 +29,8 @@ @JsonInclude(Include.NON_NULL) public class NetBankingPaymentModeConstraint extends PaymentModeConstraint { - @Builder - public NetBankingPaymentModeConstraint() { - super(PgV2InstrumentType.NET_BANKING); - } + @Builder + public NetBankingPaymentModeConstraint() { + super(PgV2InstrumentType.NET_BANKING); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/PaymentModeConstraint.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/PaymentModeConstraint.java index e923e70..2f0d3fd 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/PaymentModeConstraint.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/PaymentModeConstraint.java @@ -27,18 +27,15 @@ @NoArgsConstructor @AllArgsConstructor @JsonTypeInfo( - use = JsonTypeInfo.Id.NAME, - include = As.EXISTING_PROPERTY, - property = "type", - visible = true) + use = JsonTypeInfo.Id.NAME, include = As.EXISTING_PROPERTY, property = "type", visible = true) @JsonSubTypes({ - @JsonSubTypes.Type(value = CardPaymentModeConstraint.class, name = "CARD"), - @JsonSubTypes.Type(value = NetBankingPaymentModeConstraint.class, name = "NET_BANKING"), - @JsonSubTypes.Type(value = UpiIntentPaymentModeConstraint.class, name = "UPI_INTENT"), - @JsonSubTypes.Type(value = UpiQrPaymentModeConstraint.class, name = "UPI_QR"), - @JsonSubTypes.Type(value = UpiCollectPaymentModeConstraint.class, name = "UPI_COLLECT") + @JsonSubTypes.Type(value = CardPaymentModeConstraint.class, name = "CARD"), + @JsonSubTypes.Type(value = NetBankingPaymentModeConstraint.class, name = "NET_BANKING"), + @JsonSubTypes.Type(value = UpiIntentPaymentModeConstraint.class, name = "UPI_INTENT"), + @JsonSubTypes.Type(value = UpiQrPaymentModeConstraint.class, name = "UPI_QR"), + @JsonSubTypes.Type(value = UpiCollectPaymentModeConstraint.class, name = "UPI_COLLECT") }) public abstract class PaymentModeConstraint { - protected PgV2InstrumentType type; + protected PgV2InstrumentType type; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/UpiCollectPaymentModeConstraint.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/UpiCollectPaymentModeConstraint.java index 21506e4..83e8913 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/UpiCollectPaymentModeConstraint.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/UpiCollectPaymentModeConstraint.java @@ -29,8 +29,8 @@ @JsonInclude(Include.NON_NULL) public class UpiCollectPaymentModeConstraint extends PaymentModeConstraint { - @Builder - public UpiCollectPaymentModeConstraint() { - super(PgV2InstrumentType.UPI_COLLECT); - } + @Builder + public UpiCollectPaymentModeConstraint() { + super(PgV2InstrumentType.UPI_COLLECT); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/UpiIntentPaymentModeConstraint.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/UpiIntentPaymentModeConstraint.java index 61b82b7..946e2dd 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/UpiIntentPaymentModeConstraint.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/UpiIntentPaymentModeConstraint.java @@ -29,8 +29,8 @@ @JsonInclude(Include.NON_NULL) public class UpiIntentPaymentModeConstraint extends PaymentModeConstraint { - @Builder - public UpiIntentPaymentModeConstraint() { - super(PgV2InstrumentType.UPI_INTENT); - } + @Builder + public UpiIntentPaymentModeConstraint() { + super(PgV2InstrumentType.UPI_INTENT); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/UpiQrPaymentModeConstraint.java b/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/UpiQrPaymentModeConstraint.java index fd37f8b..cc1395e 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/UpiQrPaymentModeConstraint.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/request/paymentmodeconstraints/UpiQrPaymentModeConstraint.java @@ -29,8 +29,8 @@ @JsonInclude(Include.NON_NULL) public class UpiQrPaymentModeConstraint extends PaymentModeConstraint { - @Builder - public UpiQrPaymentModeConstraint() { - super(PgV2InstrumentType.UPI_QR); - } + @Builder + public UpiQrPaymentModeConstraint() { + super(PgV2InstrumentType.UPI_QR); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/CallbackData.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/CallbackData.java index 484405b..20920af 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/CallbackData.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/CallbackData.java @@ -33,26 +33,26 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class CallbackData { - private String orderId; - private String merchantId; - private String merchantRefundId; - private String originalMerchantOrderId; - private String refundId; - private String merchantOrderId; - private String state; - private Long amount; - private Long expireAt; - private String errorCode; - private String detailedErrorCode; - private MetaInfo metaInfo; - private String merchantSubscriptionId; - private String subscriptionId; - private AuthWorkflowType authWorkflowType; - private AmountType amountType; - private Long maxAmount; - private Frequency frequency; - private Long pauseStartDate; - private Long pauseEndDate; - private PaymentFlowResponse paymentFlow; - private List paymentDetails; + private String orderId; + private String merchantId; + private String merchantRefundId; + private String originalMerchantOrderId; + private String refundId; + private String merchantOrderId; + private String state; + private Long amount; + private Long expireAt; + private String errorCode; + private String detailedErrorCode; + private MetaInfo metaInfo; + private String merchantSubscriptionId; + private String subscriptionId; + private AuthWorkflowType authWorkflowType; + private AmountType amountType; + private Long maxAmount; + private Frequency frequency; + private Long pauseStartDate; + private Long pauseEndDate; + private PaymentFlowResponse paymentFlow; + private List paymentDetails; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/CallbackResponse.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/CallbackResponse.java index 045bd11..3cd24ed 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/CallbackResponse.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/CallbackResponse.java @@ -28,6 +28,6 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class CallbackResponse { - String event; - CallbackData payload; + String event; + CallbackData payload; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/InstrumentCombo.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/InstrumentCombo.java index 8ade535..8d9e5b5 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/InstrumentCombo.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/InstrumentCombo.java @@ -30,7 +30,7 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class InstrumentCombo { - private PaymentInstrumentV2 instrument; - private PaymentRail rail; - private long amount; + private PaymentInstrumentV2 instrument; + private PaymentRail rail; + private long amount; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/OrderStatusResponse.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/OrderStatusResponse.java index 9c083fa..b419f04 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/OrderStatusResponse.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/OrderStatusResponse.java @@ -30,17 +30,17 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class OrderStatusResponse { - private String merchantId; - private String merchantOrderId; - private String orderId; - private String state; - private long amount; - private PaymentFlowResponse paymentFlow; - private long payableAmount; - private long feeAmount; - private long expireAt; - private String errorCode; - private String detailedErrorCode; - private MetaInfo metaInfo; - private List paymentDetails; + private String merchantId; + private String merchantOrderId; + private String orderId; + private String state; + private long amount; + private PaymentFlowResponse paymentFlow; + private long payableAmount; + private long feeAmount; + private long expireAt; + private String errorCode; + private String detailedErrorCode; + private MetaInfo metaInfo; + private List paymentDetails; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/PaymentDetail.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/PaymentDetail.java index 298a33b..8413519 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/PaymentDetail.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/PaymentDetail.java @@ -30,14 +30,14 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class PaymentDetail { - private String transactionId; - private PgV2InstrumentType paymentMode; - private long timestamp; - private long amount; - private long payableAmount; - private long feeAmount; - private String state; - private String errorCode; - private String detailedErrorCode; - private List splitInstruments; + private String transactionId; + private PgV2InstrumentType paymentMode; + private long timestamp; + private long amount; + private long payableAmount; + private long feeAmount; + private String state; + private String errorCode; + private String detailedErrorCode; + private List splitInstruments; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/PaymentFlowResponse.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/PaymentFlowResponse.java index 182c44e..89f961c 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/PaymentFlowResponse.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/PaymentFlowResponse.java @@ -24,24 +24,20 @@ import lombok.NoArgsConstructor; @JsonTypeInfo( - use = JsonTypeInfo.Id.NAME, - include = JsonTypeInfo.As.EXISTING_PROPERTY, - property = "type") + use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type") @JsonSubTypes({ - @JsonSubTypes.Type( - name = "SUBSCRIPTION_SETUP", - value = SubscriptionSetupPaymentFlowResponse.class), - @JsonSubTypes.Type( - name = "SUBSCRIPTION_REDEMPTION", - value = SubscriptionRedemptionPaymentFlowResponse.class), + @JsonSubTypes.Type( + name = "SUBSCRIPTION_SETUP", value = SubscriptionSetupPaymentFlowResponse.class), + @JsonSubTypes.Type( + name = "SUBSCRIPTION_REDEMPTION", value = SubscriptionRedemptionPaymentFlowResponse.class), }) @NoArgsConstructor @Data public class PaymentFlowResponse { - private PaymentFlowType type; + private PaymentFlowType type; - public PaymentFlowResponse(PaymentFlowType type) { - this.type = type; - } + public PaymentFlowResponse(PaymentFlowType type) { + this.type = type; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/PaymentRefundDetail.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/PaymentRefundDetail.java index ed36aa7..e139316 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/PaymentRefundDetail.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/PaymentRefundDetail.java @@ -32,14 +32,14 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class PaymentRefundDetail { - private String transactionId; - private PgV2InstrumentType paymentMode; - private long timestamp; - private long amount; - private String state; - private String errorCode; - private String detailedErrorCode; - private PaymentInstrumentV2 instrument; - private PaymentRail rail; - private List splitInstruments; + private String transactionId; + private PgV2InstrumentType paymentMode; + private long timestamp; + private long amount; + private String state; + private String errorCode; + private String detailedErrorCode; + private PaymentInstrumentV2 instrument; + private PaymentRail rail; + private List splitInstruments; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/PgPaymentResponse.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/PgPaymentResponse.java index 7f361d0..c1372e4 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/PgPaymentResponse.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/PgPaymentResponse.java @@ -28,10 +28,10 @@ @NoArgsConstructor public class PgPaymentResponse { - private String orderId; - private String state; - private long expireAt; - private String redirectUrl; - private String intentUrl; - private String qrData; + private String orderId; + private String state; + private long expireAt; + private String redirectUrl; + private String intentUrl; + private String qrData; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/RefundResponse.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/RefundResponse.java index 2b070aa..491c221 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/RefundResponse.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/RefundResponse.java @@ -28,7 +28,7 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class RefundResponse { - private String refundId; - private long amount; - private String state; + private String refundId; + private long amount; + private String state; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/RefundStatusResponse.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/RefundStatusResponse.java index 3a982b6..1a39b43 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/RefundStatusResponse.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/RefundStatusResponse.java @@ -29,10 +29,10 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class RefundStatusResponse { - private String merchantId; - private String merchantRefundId; - private String originalMerchantOrderId; - private long amount; - private String state; - private List paymentDetails; + private String merchantId; + private String merchantRefundId; + private String originalMerchantOrderId; + private long amount; + private String state; + private List paymentDetails; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/AccountPaymentInstrumentV2.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/AccountPaymentInstrumentV2.java index 084191f..d7a958b 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/AccountPaymentInstrumentV2.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/AccountPaymentInstrumentV2.java @@ -25,22 +25,22 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class AccountPaymentInstrumentV2 extends PaymentInstrumentV2 { - private String maskedAccountNumber; - private String ifsc; - private String accountHolderName; - private String accountType; + private String maskedAccountNumber; + private String ifsc; + private String accountHolderName; + private String accountType; - public AccountPaymentInstrumentV2() { - super(PaymentInstrumentType.ACCOUNT); - } + public AccountPaymentInstrumentV2() { + super(PaymentInstrumentType.ACCOUNT); + } - @Builder - public AccountPaymentInstrumentV2( - String maskedAccountNumber, String ifsc, String accountHolderName, String accountType) { - super(PaymentInstrumentType.ACCOUNT); - this.maskedAccountNumber = maskedAccountNumber; - this.ifsc = ifsc; - this.accountHolderName = accountHolderName; - this.accountType = accountType; - } + @Builder + public AccountPaymentInstrumentV2( + String maskedAccountNumber, String ifsc, String accountHolderName, String accountType) { + super(PaymentInstrumentType.ACCOUNT); + this.maskedAccountNumber = maskedAccountNumber; + this.ifsc = ifsc; + this.accountHolderName = accountHolderName; + this.accountType = accountType; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/CreditCardPaymentInstrumentV2.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/CreditCardPaymentInstrumentV2.java index 0b97bfb..f6d38f9 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/CreditCardPaymentInstrumentV2.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/CreditCardPaymentInstrumentV2.java @@ -25,22 +25,22 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class CreditCardPaymentInstrumentV2 extends PaymentInstrumentV2 { - private String bankTransactionId; - private String bankId; - private String brn; - private String arn; + private String bankTransactionId; + private String bankId; + private String brn; + private String arn; - public CreditCardPaymentInstrumentV2() { - super(PaymentInstrumentType.CREDIT_CARD); - } + public CreditCardPaymentInstrumentV2() { + super(PaymentInstrumentType.CREDIT_CARD); + } - @Builder - public CreditCardPaymentInstrumentV2( - String bankTransactionId, String bankId, String brn, String arn) { - super(PaymentInstrumentType.CREDIT_CARD); - this.bankTransactionId = bankTransactionId; - this.bankId = bankId; - this.brn = brn; - this.arn = arn; - } + @Builder + public CreditCardPaymentInstrumentV2( + String bankTransactionId, String bankId, String brn, String arn) { + super(PaymentInstrumentType.CREDIT_CARD); + this.bankTransactionId = bankTransactionId; + this.bankId = bankId; + this.brn = brn; + this.arn = arn; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/DebitCardPaymentInstrumentV2.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/DebitCardPaymentInstrumentV2.java index 168d833..aab2f05 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/DebitCardPaymentInstrumentV2.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/DebitCardPaymentInstrumentV2.java @@ -25,22 +25,22 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class DebitCardPaymentInstrumentV2 extends PaymentInstrumentV2 { - private String bankTransactionId; - private String bankId; - private String brn; - private String arn; + private String bankTransactionId; + private String bankId; + private String brn; + private String arn; - public DebitCardPaymentInstrumentV2() { - super(PaymentInstrumentType.DEBIT_CARD); - } + public DebitCardPaymentInstrumentV2() { + super(PaymentInstrumentType.DEBIT_CARD); + } - @Builder - public DebitCardPaymentInstrumentV2( - String bankTransactionId, String bankId, String brn, String arn) { - super(PaymentInstrumentType.DEBIT_CARD); - this.bankTransactionId = bankTransactionId; - this.bankId = bankId; - this.brn = brn; - this.arn = arn; - } + @Builder + public DebitCardPaymentInstrumentV2( + String bankTransactionId, String bankId, String brn, String arn) { + super(PaymentInstrumentType.DEBIT_CARD); + this.bankTransactionId = bankTransactionId; + this.bankId = bankId; + this.brn = brn; + this.arn = arn; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/EGVPaymentInstrumentV2.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/EGVPaymentInstrumentV2.java index dccd3e1..c936c65 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/EGVPaymentInstrumentV2.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/EGVPaymentInstrumentV2.java @@ -25,17 +25,17 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class EGVPaymentInstrumentV2 extends PaymentInstrumentV2 { - private String cardNumber; - private String programId; + private String cardNumber; + private String programId; - public EGVPaymentInstrumentV2() { - super(PaymentInstrumentType.EGV); - } + public EGVPaymentInstrumentV2() { + super(PaymentInstrumentType.EGV); + } - @Builder - public EGVPaymentInstrumentV2(String cardNumber, String programId) { - super(PaymentInstrumentType.EGV); - this.cardNumber = cardNumber; - this.programId = programId; - } + @Builder + public EGVPaymentInstrumentV2(String cardNumber, String programId) { + super(PaymentInstrumentType.EGV); + this.cardNumber = cardNumber; + this.programId = programId; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/NetBankingPaymentInstrumentV2.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/NetBankingPaymentInstrumentV2.java index 2c8e70c..a2e1763 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/NetBankingPaymentInstrumentV2.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/NetBankingPaymentInstrumentV2.java @@ -25,22 +25,22 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class NetBankingPaymentInstrumentV2 extends PaymentInstrumentV2 { - private String bankTransactionId; - private String bankId; - private String brn; - private String arn; + private String bankTransactionId; + private String bankId; + private String brn; + private String arn; - public NetBankingPaymentInstrumentV2() { - super(PaymentInstrumentType.NET_BANKING); - } + public NetBankingPaymentInstrumentV2() { + super(PaymentInstrumentType.NET_BANKING); + } - @Builder - public NetBankingPaymentInstrumentV2( - String bankTransactionId, String bankId, String brn, String arn) { - super(PaymentInstrumentType.NET_BANKING); - this.bankTransactionId = bankTransactionId; - this.bankId = bankId; - this.brn = brn; - this.arn = arn; - } + @Builder + public NetBankingPaymentInstrumentV2( + String bankTransactionId, String bankId, String brn, String arn) { + super(PaymentInstrumentType.NET_BANKING); + this.bankTransactionId = bankTransactionId; + this.bankId = bankId; + this.brn = brn; + this.arn = arn; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/PaymentInstrumentV2.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/PaymentInstrumentV2.java index 35f7add..9acf3b3 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/PaymentInstrumentV2.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/PaymentInstrumentV2.java @@ -21,33 +21,26 @@ import lombok.NoArgsConstructor; @JsonTypeInfo( - use = JsonTypeInfo.Id.NAME, - include = JsonTypeInfo.As.EXISTING_PROPERTY, - property = "type") + use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type") @JsonSubTypes({ - @JsonSubTypes.Type(name = "WALLET", value = WalletPaymentInstrumentV2.class), - @JsonSubTypes.Type(name = "EGV", value = EGVPaymentInstrumentV2.class), - @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 = "WALLET", value = WalletPaymentInstrumentV2.class), + @JsonSubTypes.Type(name = "EGV", value = EGVPaymentInstrumentV2.class), + @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) }) @NoArgsConstructor @Data public abstract class PaymentInstrumentV2 { - private PaymentInstrumentType type; + private PaymentInstrumentType type; - public PaymentInstrumentV2(PaymentInstrumentType type) { - this.type = type; - } + public PaymentInstrumentV2(PaymentInstrumentType type) { + this.type = type; + } - public enum PaymentInstrumentType { - WALLET, - EGV, - ACCOUNT, - CREDIT_CARD, - DEBIT_CARD, - NET_BANKING - } + public enum PaymentInstrumentType { + WALLET, EGV, ACCOUNT, CREDIT_CARD, DEBIT_CARD, NET_BANKING + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/WalletPaymentInstrumentV2.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/WalletPaymentInstrumentV2.java index def647d..a59867c 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/WalletPaymentInstrumentV2.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/paymentinstruments/WalletPaymentInstrumentV2.java @@ -25,15 +25,15 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class WalletPaymentInstrumentV2 extends PaymentInstrumentV2 { - private String walletId; + private String walletId; - public WalletPaymentInstrumentV2() { - super(PaymentInstrumentType.WALLET); - } + public WalletPaymentInstrumentV2() { + super(PaymentInstrumentType.WALLET); + } - @Builder - public WalletPaymentInstrumentV2(String walletId) { - super(PaymentInstrumentType.WALLET); - this.walletId = walletId; - } + @Builder + public WalletPaymentInstrumentV2(String walletId) { + super(PaymentInstrumentType.WALLET); + this.walletId = walletId; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/PaymentRail.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/PaymentRail.java index 23c60be..ea0944c 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/PaymentRail.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/PaymentRail.java @@ -21,29 +21,24 @@ import lombok.NoArgsConstructor; @JsonTypeInfo( - use = JsonTypeInfo.Id.NAME, - include = JsonTypeInfo.As.EXISTING_PROPERTY, - property = "type") + use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type") @JsonSubTypes({ - @JsonSubTypes.Type(name = "UPI", value = UpiPaymentRail.class), - @JsonSubTypes.Type(name = "PG", value = PgPaymentRail.class), - @JsonSubTypes.Type(name = "PPI_WALLET", value = PpiWalletPaymentRail.class), - @JsonSubTypes.Type(name = "PPI_EGV", value = PpiEgvPaymentRail.class) + @JsonSubTypes.Type(name = "UPI", value = UpiPaymentRail.class), + @JsonSubTypes.Type(name = "PG", value = PgPaymentRail.class), + @JsonSubTypes.Type(name = "PPI_WALLET", value = PpiWalletPaymentRail.class), + @JsonSubTypes.Type(name = "PPI_EGV", value = PpiEgvPaymentRail.class) }) @NoArgsConstructor @Data public abstract class PaymentRail { - private PaymentRailType type; + private PaymentRailType type; - public PaymentRail(PaymentRailType type) { - this.type = type; - } + public PaymentRail(PaymentRailType type) { + this.type = type; + } - public enum PaymentRailType { - UPI, - PG, - PPI_WALLET, - PPI_EGV - } + public enum PaymentRailType { + UPI, PG, PPI_WALLET, PPI_EGV + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/PgPaymentRail.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/PgPaymentRail.java index dbc0511..dd768ea 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/PgPaymentRail.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/PgPaymentRail.java @@ -25,20 +25,20 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class PgPaymentRail extends PaymentRail { - private String transactionId; - private String authorizationCode; - private String serviceTransactionId; + private String transactionId; + private String authorizationCode; + private String serviceTransactionId; - public PgPaymentRail() { - super(PaymentRailType.PG); - } + public PgPaymentRail() { + super(PaymentRailType.PG); + } - @Builder - public PgPaymentRail( - String transactionId, String authorizationCode, String serviceTransactionId) { - super(PaymentRailType.PG); - this.transactionId = transactionId; - this.authorizationCode = authorizationCode; - this.serviceTransactionId = serviceTransactionId; - } + @Builder + public PgPaymentRail( + String transactionId, String authorizationCode, String serviceTransactionId) { + super(PaymentRailType.PG); + this.transactionId = transactionId; + this.authorizationCode = authorizationCode; + this.serviceTransactionId = serviceTransactionId; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/PpiEgvPaymentRail.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/PpiEgvPaymentRail.java index e0592dc..2130cb6 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/PpiEgvPaymentRail.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/PpiEgvPaymentRail.java @@ -25,8 +25,8 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class PpiEgvPaymentRail extends PaymentRail { - @Builder - public PpiEgvPaymentRail() { - super(PaymentRailType.PPI_EGV); - } + @Builder + public PpiEgvPaymentRail() { + super(PaymentRailType.PPI_EGV); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/PpiWalletPaymentRail.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/PpiWalletPaymentRail.java index 6c8abae..051d083 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/PpiWalletPaymentRail.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/PpiWalletPaymentRail.java @@ -25,8 +25,8 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class PpiWalletPaymentRail extends PaymentRail { - @Builder - public PpiWalletPaymentRail() { - super(PaymentRailType.PPI_WALLET); - } + @Builder + public PpiWalletPaymentRail() { + super(PaymentRailType.PPI_WALLET); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/UpiPaymentRail.java b/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/UpiPaymentRail.java index ea3ef2e..3c2f395 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/UpiPaymentRail.java +++ b/src/main/java/com/phonepe/sdk/pg/common/models/response/rails/UpiPaymentRail.java @@ -25,21 +25,21 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class UpiPaymentRail extends PaymentRail { - private String utr; - private String upiTransactionId; - private String vpa; - private String umn; + private String utr; + private String upiTransactionId; + private String vpa; + private String umn; - public UpiPaymentRail() { - super(PaymentRailType.UPI); - } + public UpiPaymentRail() { + super(PaymentRailType.UPI); + } - @Builder - public UpiPaymentRail(String utr, String upiTransactionId, String vpa, String umn) { - super(PaymentRailType.UPI); - this.vpa = vpa; - this.utr = utr; - this.upiTransactionId = upiTransactionId; - this.umn = umn; - } + @Builder + public UpiPaymentRail(String utr, String upiTransactionId, String vpa, String umn) { + super(PaymentRailType.UPI); + this.vpa = vpa; + this.utr = utr; + this.upiTransactionId = upiTransactionId; + this.umn = umn; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/common/tokenhandler/OAuthResponse.java b/src/main/java/com/phonepe/sdk/pg/common/tokenhandler/OAuthResponse.java index f87c62a..8d00a88 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/tokenhandler/OAuthResponse.java +++ b/src/main/java/com/phonepe/sdk/pg/common/tokenhandler/OAuthResponse.java @@ -29,27 +29,27 @@ @AllArgsConstructor public class OAuthResponse { - @JsonAlias("access_token") - private String accessToken; + @JsonAlias("access_token") + private String accessToken; - @JsonAlias("encrypted_access_token") - private String encryptedAccessToken; + @JsonAlias("encrypted_access_token") + private String encryptedAccessToken; - @JsonAlias("refresh_token") - private String refreshToken; + @JsonAlias("refresh_token") + private String refreshToken; - @JsonAlias("expires_in") - private int expiresIn; + @JsonAlias("expires_in") + private int expiresIn; - @JsonAlias("issued_at") - private long issuedAt; + @JsonAlias("issued_at") + private long issuedAt; - @JsonAlias("expires_at") - private long expiresAt; + @JsonAlias("expires_at") + private long expiresAt; - @JsonAlias("session_expires_at") - private long sessionExpiresAt; + @JsonAlias("session_expires_at") + private long sessionExpiresAt; - @JsonAlias("token_type") - private String tokenType; + @JsonAlias("token_type") + private String tokenType; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/tokenhandler/TokenConstants.java b/src/main/java/com/phonepe/sdk/pg/common/tokenhandler/TokenConstants.java index 8907463..aa6de6c 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/tokenhandler/TokenConstants.java +++ b/src/main/java/com/phonepe/sdk/pg/common/tokenhandler/TokenConstants.java @@ -17,6 +17,6 @@ public class TokenConstants { - public static final String OAUTH_GET_TOKEN = "/v1/oauth/token"; - public static final String OAUTH_GRANT_TYPE = "client_credentials"; + public static final String OAUTH_GET_TOKEN = "/v1/oauth/token"; + public static final String OAUTH_GRANT_TYPE = "client_credentials"; } diff --git a/src/main/java/com/phonepe/sdk/pg/common/tokenhandler/TokenService.java b/src/main/java/com/phonepe/sdk/pg/common/tokenhandler/TokenService.java index ae8b528..ab32a93 100644 --- a/src/main/java/com/phonepe/sdk/pg/common/tokenhandler/TokenService.java +++ b/src/main/java/com/phonepe/sdk/pg/common/tokenhandler/TokenService.java @@ -41,116 +41,121 @@ @Slf4j public class TokenService { - private OkHttpClient okHttpClient; - private ObjectMapper objectMapper; - private CredentialConfig credentialConfig; - private Env env; - @Setter private OAuthResponse oAuthResponse; - private EventPublisher eventPublisher; + private OkHttpClient okHttpClient; + private ObjectMapper objectMapper; + private CredentialConfig credentialConfig; + private Env env; + @Setter + private OAuthResponse oAuthResponse; + private EventPublisher eventPublisher; - public TokenService( - OkHttpClient okHttpClient, - ObjectMapper objectMapper, - CredentialConfig credentialConfig, - Env env, - EventPublisher eventPublisher) { - this.okHttpClient = okHttpClient; - this.objectMapper = objectMapper; - this.credentialConfig = credentialConfig; - this.env = env; - this.eventPublisher = eventPublisher; - this.eventPublisher.send( - BaseEvent.buildInitClientEvent(EventType.TOKEN_SERVICE_INITIALIZED)); - } + public TokenService( + OkHttpClient okHttpClient, + ObjectMapper objectMapper, + CredentialConfig credentialConfig, + Env env, + EventPublisher eventPublisher) { + this.okHttpClient = okHttpClient; + this.objectMapper = objectMapper; + this.credentialConfig = credentialConfig; + this.env = env; + this.eventPublisher = eventPublisher; + this.eventPublisher.send( + BaseEvent.buildInitClientEvent(EventType.TOKEN_SERVICE_INITIALIZED)); + } - private List prepareRequestHeaders() { - return Arrays.asList( - HttpHeaderPair.builder() - .key(Headers.CONTENT_TYPE) - .value(APPLICATION_FORM_URLENCODED) - .build(), - HttpHeaderPair.builder().key(Headers.ACCEPT).value(APPLICATION_JSON).build()); - } + private List prepareRequestHeaders() { + return Arrays.asList( + HttpHeaderPair.builder() + .key(Headers.CONTENT_TYPE) + .value(APPLICATION_FORM_URLENCODED) + .build(), + HttpHeaderPair.builder() + .key(Headers.ACCEPT) + .value(APPLICATION_JSON) + .build()); + } - public String formatCachedToken() { - return oAuthResponse.getTokenType() + " " + oAuthResponse.getAccessToken(); - } + public String formatCachedToken() { + return oAuthResponse.getTokenType() + " " + oAuthResponse.getAccessToken(); + } - public long getCurrentTime() { - return java.time.Instant.now().getEpochSecond(); - } + public long getCurrentTime() { + return java.time.Instant.now() + .getEpochSecond(); + } - @SneakyThrows - public synchronized String getAuthToken() { - if (isCachedTokenValid()) { - log.debug("Returning cached token"); - return formatCachedToken(); - } - try { - this.setOAuthResponse(fetchTokenFromPhonePe()); - } catch (Exception exception) { - if (Objects.isNull(oAuthResponse)) { - log.error( - "No cached token, error occurred while fetching new token {}", - exception.toString()); - throw exception; - } - log.info( - "Returning cached token, error occurred while fetching new token {}", - exception.toString()); - eventPublisher.send( - BaseEvent.buildOAuthEvent( - getCurrentTime(), - TokenConstants.OAUTH_GET_TOKEN, - EventType.OAUTH_FETCH_FAILED_USED_CACHED_TOKEN, - exception, - oAuthResponse.getIssuedAt(), - oAuthResponse.getExpiresAt())); - } - return formatCachedToken(); - } + @SneakyThrows + public synchronized String getAuthToken() { + if (isCachedTokenValid()) { + log.debug("Returning cached token"); + return formatCachedToken(); + } + try { + this.setOAuthResponse(fetchTokenFromPhonePe()); + } catch (Exception exception) { + if (Objects.isNull(oAuthResponse)) { + log.error( + "No cached token, error occurred while fetching new token {}", + exception.toString()); + throw exception; + } + log.info( + "Returning cached token, error occurred while fetching new token {}", + exception.toString()); + eventPublisher.send( + BaseEvent.buildOAuthEvent( + getCurrentTime(), + TokenConstants.OAUTH_GET_TOKEN, + EventType.OAUTH_FETCH_FAILED_USED_CACHED_TOKEN, + exception, + oAuthResponse.getIssuedAt(), + oAuthResponse.getExpiresAt())); + } + return formatCachedToken(); + } - private synchronized boolean isCachedTokenValid() { - if (Objects.isNull(oAuthResponse)) { - return false; - } - long issuedAt = oAuthResponse.getIssuedAt(); - long expireAt = oAuthResponse.getExpiresAt(); - long currentTime = getCurrentTime(); - long reloadTime = issuedAt + (expireAt - issuedAt) / 2; - return currentTime < reloadTime; - } + private synchronized boolean isCachedTokenValid() { + if (Objects.isNull(oAuthResponse)) { + return false; + } + long issuedAt = oAuthResponse.getIssuedAt(); + long expireAt = oAuthResponse.getExpiresAt(); + long currentTime = getCurrentTime(); + long reloadTime = issuedAt + (expireAt - issuedAt) / 2; + return currentTime < reloadTime; + } - public void forceRefreshToken() { - log.debug("Force Refreshing Token"); - this.setOAuthResponse(fetchTokenFromPhonePe()); - } + public void forceRefreshToken() { + log.debug("Force Refreshing Token"); + this.setOAuthResponse(fetchTokenFromPhonePe()); + } - @SneakyThrows - public synchronized OAuthResponse fetchTokenFromPhonePe() { - final FormBody formBody = prepareFormBody(this.credentialConfig); + @SneakyThrows + public synchronized OAuthResponse fetchTokenFromPhonePe() { + final FormBody formBody = prepareFormBody(this.credentialConfig); - final String url = TokenConstants.OAUTH_GET_TOKEN; - return HttpCommand.builder() - .client(okHttpClient) - .objectMapper(objectMapper) - .responseTypeReference(new TypeReference() {}) - .methodName(HttpMethodType.POST) - .headers(prepareRequestHeaders()) - .requestData(formBody) - .hostURL(this.env.getOAuthHostUrl()) - .url(url) - .encodingType(APPLICATION_FORM_URLENCODED) - .build() - .execute(); - } + final String url = TokenConstants.OAUTH_GET_TOKEN; + return HttpCommand.builder() + .client(okHttpClient) + .objectMapper(objectMapper) + .responseTypeReference(new TypeReference() {}) + .methodName(HttpMethodType.POST) + .headers(prepareRequestHeaders()) + .requestData(formBody) + .hostURL(this.env.getOAuthHostUrl()) + .url(url) + .encodingType(APPLICATION_FORM_URLENCODED) + .build() + .execute(); + } - private FormBody prepareFormBody(CredentialConfig credentialConfig) { - return new FormBody.Builder() - .add("client_id", credentialConfig.getClientId()) - .add("client_secret", credentialConfig.getClientSecret()) - .add("grant_type", TokenConstants.OAUTH_GRANT_TYPE) - .add("client_version", String.valueOf(credentialConfig.getClientVersion())) - .build(); - } + private FormBody prepareFormBody(CredentialConfig credentialConfig) { + return new FormBody.Builder() + .add("client_id", credentialConfig.getClientId()) + .add("client_secret", credentialConfig.getClientSecret()) + .add("grant_type", TokenConstants.OAUTH_GRANT_TYPE) + .add("client_version", String.valueOf(credentialConfig.getClientVersion())) + .build(); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/payments/v2/CustomCheckoutClient.java b/src/main/java/com/phonepe/sdk/pg/payments/v2/CustomCheckoutClient.java index 029401d..05e44c6 100644 --- a/src/main/java/com/phonepe/sdk/pg/payments/v2/CustomCheckoutClient.java +++ b/src/main/java/com/phonepe/sdk/pg/payments/v2/CustomCheckoutClient.java @@ -46,368 +46,368 @@ public class CustomCheckoutClient extends BaseClient { - private List headers; + private List headers; - private CustomCheckoutClient( - final String clientId, - final String clientSecret, - final Integer clientVersion, - final Env env, - boolean shouldPublishEvents) { - super(clientId, clientSecret, clientVersion, env, shouldPublishEvents); - this.eventPublisher.send( - BaseEvent.buildInitClientEvent( - FlowType.PG, EventType.CUSTOM_CHECKOUT_CLIENT_INITIALIZED)); - this.prepareHeaders(); - } + private CustomCheckoutClient( + final String clientId, + final String clientSecret, + final Integer clientVersion, + final Env env, + boolean shouldPublishEvents) { + super(clientId, clientSecret, clientVersion, env, shouldPublishEvents); + this.eventPublisher.send( + BaseEvent.buildInitClientEvent( + FlowType.PG, EventType.CUSTOM_CHECKOUT_CLIENT_INITIALIZED)); + this.prepareHeaders(); + } - /** - * Generates a CustomCheckout Client for interacting with the PhonePe APIs - * - * @param clientId Unique client-id assigned to merchant by PhonePe - * @param clientSecret Secret provided by PhonePe - * @param clientVersion The client version used for secure transactions - * @param env Set to `Env.SANDBOX` for the SANDBOX environment or `Env.PRODUCTION` for the production - * environment. - * @return CustomCheckoutClient object for interacting with the PhonePe APIs - */ - public static CustomCheckoutClient getInstance( - final String clientId, - final String clientSecret, - final Integer clientVersion, - final Env env) throws PhonePeException { - return getInstance(clientId, clientSecret, clientVersion, env, true); - } + /** + * Generates a CustomCheckout Client for interacting with the PhonePe APIs + * + * @param clientId Unique client-id assigned to merchant by PhonePe + * @param clientSecret Secret provided by PhonePe + * @param clientVersion The client version used for secure transactions + * @param env Set to `Env.SANDBOX` for the SANDBOX environment or `Env.PRODUCTION` for the production + * environment. + * @return CustomCheckoutClient object for interacting with the PhonePe APIs + */ + public static CustomCheckoutClient getInstance( + final String clientId, + final String clientSecret, + final Integer clientVersion, + final Env env) throws PhonePeException { + return getInstance(clientId, clientSecret, clientVersion, env, true); + } - /** - * Generates a CustomCheckout Client for interacting with the PhonePe APIs - * - * @param clientId received at the time of onboarding - * @param clientSecret received at the time of onboarding - * @param clientVersion received at the time of onboarding - * @param env environment to be used by the merchant - * @param shouldPublishEvents When true, events are sent to PhonePe providing smoother experience - * @return CustomCheckoutClient object for interacting with the PhonePe APIs - */ - public static CustomCheckoutClient getInstance( - final String clientId, - final String clientSecret, - final Integer clientVersion, - final Env env, - boolean shouldPublishEvents) throws PhonePeException { - final boolean shouldPublishInProd = shouldPublishEvents && env == Env.PRODUCTION; - return new CustomCheckoutClient( - clientId, clientSecret, clientVersion, env, shouldPublishInProd); - } + /** + * Generates a CustomCheckout Client for interacting with the PhonePe APIs + * + * @param clientId received at the time of onboarding + * @param clientSecret received at the time of onboarding + * @param clientVersion received at the time of onboarding + * @param env environment to be used by the merchant + * @param shouldPublishEvents When true, events are sent to PhonePe providing smoother experience + * @return CustomCheckoutClient object for interacting with the PhonePe APIs + */ + public static CustomCheckoutClient getInstance( + final String clientId, + final String clientSecret, + final Integer clientVersion, + final Env env, + boolean shouldPublishEvents) throws PhonePeException { + final boolean shouldPublishInProd = shouldPublishEvents && env == Env.PRODUCTION; + return new CustomCheckoutClient( + clientId, clientSecret, clientVersion, env, shouldPublishInProd); + } - /** - * Initiate a Pay Order - * - * @param pgPaymentRequest Request Object Build using CustomCheckoutPayRequest Builder's - * @return CustomCheckoutPayResponse contains checkout page url and related details - */ - @SneakyThrows - public PgPaymentResponse pay(PgPaymentRequest pgPaymentRequest) { - String url = CustomCheckoutConstants.PAY_API; - try { - List requestHeaders = headers; - if (pgPaymentRequest.getDeviceOS() != null && !pgPaymentRequest.getDeviceOS() - .isBlank()) { - requestHeaders = new ArrayList<>(headers); - requestHeaders.add( - HttpHeaderPair.builder() - .key(Headers.X_DEVICE_OS) - .value(pgPaymentRequest.getDeviceOS()) - .build()); - } - PgPaymentResponse pgPaymentResponse = requestViaAuthRefresh( - HttpMethodType.POST, - pgPaymentRequest, - url, - null, - new TypeReference() {}, - requestHeaders); - this.eventPublisher.send( - BaseEvent.buildCustomCheckoutPayEvent( - EventState.SUCCESS, pgPaymentRequest, url, EventType.PAY_SUCCESS)); - return pgPaymentResponse; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildCustomCheckoutPayEvent( - EventState.FAILED, - pgPaymentRequest, - url, - EventType.PAY_FAILED, - exception)); - throw exception; - } - } + /** + * Initiate a Pay Order + * + * @param pgPaymentRequest Request Object Build using CustomCheckoutPayRequest Builder's + * @return CustomCheckoutPayResponse contains checkout page url and related details + */ + @SneakyThrows + public PgPaymentResponse pay(PgPaymentRequest pgPaymentRequest) { + String url = CustomCheckoutConstants.PAY_API; + try { + List requestHeaders = headers; + if (pgPaymentRequest.getDeviceOS() != null && !pgPaymentRequest.getDeviceOS() + .isBlank()) { + requestHeaders = new ArrayList<>(headers); + requestHeaders.add( + HttpHeaderPair.builder() + .key(Headers.X_DEVICE_OS) + .value(pgPaymentRequest.getDeviceOS()) + .build()); + } + PgPaymentResponse pgPaymentResponse = requestViaAuthRefresh( + HttpMethodType.POST, + pgPaymentRequest, + url, + null, + new TypeReference() {}, + requestHeaders); + this.eventPublisher.send( + BaseEvent.buildCustomCheckoutPayEvent( + EventState.SUCCESS, pgPaymentRequest, url, EventType.PAY_SUCCESS)); + return pgPaymentResponse; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildCustomCheckoutPayEvent( + EventState.FAILED, + pgPaymentRequest, + url, + EventType.PAY_FAILED, + exception)); + throw exception; + } + } - /** - * Gets the status of the order - * - * @param merchantOrderId Order id generated by merchant - * @return OrderStatusResponse Response with order and transaction details - */ - @SneakyThrows - public OrderStatusResponse getOrderStatus(String merchantOrderId) { - return getOrderStatus(merchantOrderId, false); - } + /** + * Gets the status of the order + * + * @param merchantOrderId Order id generated by merchant + * @return OrderStatusResponse Response with order and transaction details + */ + @SneakyThrows + public OrderStatusResponse getOrderStatus(String merchantOrderId) { + return getOrderStatus(merchantOrderId, false); + } - /** - * Gets status of an order - * - * @param merchantOrderId Order id generated by merchant - * @param details true -> order status has all attempt details under paymentDetails list false -> order - * status has only latest attempt details under paymentDetails list - * @return OrderStatusResponse Response with order and transaction details - */ - @SneakyThrows - public OrderStatusResponse getOrderStatus(String merchantOrderId, boolean details) { - String url = String.format(CustomCheckoutConstants.ORDER_STATUS_API, merchantOrderId); - try { - OrderStatusResponse orderStatusResponse = requestViaAuthRefresh( - HttpMethodType.GET, - null, - url, - Collections.singletonMap( - CustomCheckoutConstants.ORDER_DETAILS, - Boolean.toString(details)), - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildOrderStatusEvent( - EventState.SUCCESS, - merchantOrderId, - url, - FlowType.PG, - EventType.ORDER_STATUS_SUCCESS)); - return orderStatusResponse; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildOrderStatusEvent( - EventState.FAILED, - merchantOrderId, - url, - FlowType.PG, - EventType.ORDER_STATUS_FAILED, - exception)); - throw exception; - } - } + /** + * Gets status of an order + * + * @param merchantOrderId Order id generated by merchant + * @param details true -> order status has all attempt details under paymentDetails list false -> order + * status has only latest attempt details under paymentDetails list + * @return OrderStatusResponse Response with order and transaction details + */ + @SneakyThrows + public OrderStatusResponse getOrderStatus(String merchantOrderId, boolean details) { + String url = String.format(CustomCheckoutConstants.ORDER_STATUS_API, merchantOrderId); + try { + OrderStatusResponse orderStatusResponse = requestViaAuthRefresh( + HttpMethodType.GET, + null, + url, + Collections.singletonMap( + CustomCheckoutConstants.ORDER_DETAILS, + Boolean.toString(details)), + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildOrderStatusEvent( + EventState.SUCCESS, + merchantOrderId, + url, + FlowType.PG, + EventType.ORDER_STATUS_SUCCESS)); + return orderStatusResponse; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildOrderStatusEvent( + EventState.FAILED, + merchantOrderId, + url, + FlowType.PG, + EventType.ORDER_STATUS_FAILED, + exception)); + throw exception; + } + } - /** - * Initiate refund of an order - * - * @param refundRequest Request object build using RefundRequest builder - * @return RefundResponse contains refund details for an order - */ - @SneakyThrows - public RefundResponse refund(RefundRequest refundRequest) { - String url = CustomCheckoutConstants.REFUND_API; - try { - RefundResponse refundResponse = requestViaAuthRefresh( - HttpMethodType.POST, - refundRequest, - url, - null, - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildRefundEvent( - EventState.SUCCESS, - refundRequest, - url, - FlowType.PG, - EventType.REFUND_SUCCESS)); - return refundResponse; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildRefundEvent( - EventState.FAILED, - refundRequest, - url, - FlowType.PG, - EventType.REFUND_FAILED, - exception)); - throw exception; - } - } + /** + * Initiate refund of an order + * + * @param refundRequest Request object build using RefundRequest builder + * @return RefundResponse contains refund details for an order + */ + @SneakyThrows + public RefundResponse refund(RefundRequest refundRequest) { + String url = CustomCheckoutConstants.REFUND_API; + try { + RefundResponse refundResponse = requestViaAuthRefresh( + HttpMethodType.POST, + refundRequest, + url, + null, + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildRefundEvent( + EventState.SUCCESS, + refundRequest, + url, + FlowType.PG, + EventType.REFUND_SUCCESS)); + return refundResponse; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildRefundEvent( + EventState.FAILED, + refundRequest, + url, + FlowType.PG, + EventType.REFUND_FAILED, + exception)); + throw exception; + } + } - /** - * Create order token for SDK integrated order requests - * - * @param createSdkOrderRequest Request object build using CreateSdkOrderRequest builder - * @return CreateSdkOrderResponse contains token details to be consumed by the UI - */ - @SneakyThrows - public CreateSdkOrderResponse createSdkOrder(CreateSdkOrderRequest createSdkOrderRequest) { - String url = CustomCheckoutConstants.CREATE_ORDER_API; - try { - CreateSdkOrderResponse createSdkOrderResponse = requestViaAuthRefresh( - HttpMethodType.POST, - createSdkOrderRequest, - url, - null, - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildCreateSdkOrderEvent( - EventState.SUCCESS, - createSdkOrderRequest, - url, - FlowType.PG, - EventType.CREATE_SDK_ORDER_SUCCESS)); - return createSdkOrderResponse; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildCreateSdkOrderEvent( - EventState.FAILED, - createSdkOrderRequest, - url, - FlowType.PG, - EventType.CREATE_SDK_ORDER_FAILED, - exception)); - throw exception; - } - } + /** + * Create order token for SDK integrated order requests + * + * @param createSdkOrderRequest Request object build using CreateSdkOrderRequest builder + * @return CreateSdkOrderResponse contains token details to be consumed by the UI + */ + @SneakyThrows + public CreateSdkOrderResponse createSdkOrder(CreateSdkOrderRequest createSdkOrderRequest) { + String url = CustomCheckoutConstants.CREATE_ORDER_API; + try { + CreateSdkOrderResponse createSdkOrderResponse = requestViaAuthRefresh( + HttpMethodType.POST, + createSdkOrderRequest, + url, + null, + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildCreateSdkOrderEvent( + EventState.SUCCESS, + createSdkOrderRequest, + url, + FlowType.PG, + EventType.CREATE_SDK_ORDER_SUCCESS)); + return createSdkOrderResponse; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildCreateSdkOrderEvent( + EventState.FAILED, + createSdkOrderRequest, + url, + FlowType.PG, + EventType.CREATE_SDK_ORDER_FAILED, + exception)); + throw exception; + } + } - /** - * Get status of a transaction attempt - * - * @param transactionId Transaction attempt id generated by PhonePe - * @return OrderStatusResponse Response with order and transaction details - * @throws PhonePeException if any error occurs during the process - */ - @SneakyThrows - public OrderStatusResponse getTransactionStatus(String transactionId) { - final String url = String.format(CustomCheckoutConstants.TRANSACTION_STATUS_API, transactionId); - try { - OrderStatusResponse orderStatusResponse = requestViaAuthRefresh( - HttpMethodType.GET, - null, - url, - null, - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildTransactionStatusEvent( - EventState.SUCCESS, - transactionId, - url, - FlowType.PG, - EventType.TRANSACTION_STATUS_SUCCESS)); - return orderStatusResponse; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildTransactionStatusEvent( - EventState.FAILED, - transactionId, - url, - FlowType.PG, - EventType.TRANSACTION_STATUS_FAILED, - exception)); - throw exception; - } - } + /** + * Get status of a transaction attempt + * + * @param transactionId Transaction attempt id generated by PhonePe + * @return OrderStatusResponse Response with order and transaction details + * @throws PhonePeException if any error occurs during the process + */ + @SneakyThrows + public OrderStatusResponse getTransactionStatus(String transactionId) { + final String url = String.format(CustomCheckoutConstants.TRANSACTION_STATUS_API, transactionId); + try { + OrderStatusResponse orderStatusResponse = requestViaAuthRefresh( + HttpMethodType.GET, + null, + url, + null, + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildTransactionStatusEvent( + EventState.SUCCESS, + transactionId, + url, + FlowType.PG, + EventType.TRANSACTION_STATUS_SUCCESS)); + return orderStatusResponse; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildTransactionStatusEvent( + EventState.FAILED, + transactionId, + url, + FlowType.PG, + EventType.TRANSACTION_STATUS_FAILED, + exception)); + throw exception; + } + } - /** - * Get status of refund - * - * @param refundId Merchant Refund id for which you need the status - * @return RefundStatusResponse Refund status details - * @throws PhonePeException if any error occurs during the process - */ - @SneakyThrows - public RefundStatusResponse getRefundStatus(String refundId) { - final String url = String.format(CustomCheckoutConstants.REFUND_STATUS_API, refundId); - try { - RefundStatusResponse refundStatusResponse = requestViaAuthRefresh( - HttpMethodType.GET, - null, - url, - null, - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildRefundStatusEvent( - EventState.SUCCESS, - refundId, - url, - FlowType.PG, - EventType.REFUND_STATUS_SUCCESS)); - return refundStatusResponse; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildRefundStatusEvent( - EventState.FAILED, - refundId, - url, - FlowType.PG, - EventType.REFUND_STATUS_FAILED, - exception)); - throw exception; - } - } + /** + * Get status of refund + * + * @param refundId Merchant Refund id for which you need the status + * @return RefundStatusResponse Refund status details + * @throws PhonePeException if any error occurs during the process + */ + @SneakyThrows + public RefundStatusResponse getRefundStatus(String refundId) { + final String url = String.format(CustomCheckoutConstants.REFUND_STATUS_API, refundId); + try { + RefundStatusResponse refundStatusResponse = requestViaAuthRefresh( + HttpMethodType.GET, + null, + url, + null, + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildRefundStatusEvent( + EventState.SUCCESS, + refundId, + url, + FlowType.PG, + EventType.REFUND_STATUS_SUCCESS)); + return refundStatusResponse; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildRefundStatusEvent( + EventState.FAILED, + refundId, + url, + FlowType.PG, + EventType.REFUND_STATUS_FAILED, + exception)); + throw exception; + } + } - /** - * Validate if the callback is valid - * - * @param username username set by the merchant on the dashboard - * @param password password set by the merchant on the dashboard - * @param authorization String data under `authorization` key of response headers - * @param responseBody Callback response body - * @return CallbackResponse Deserialized callback body - * @throws PhonePeException when callback is not valid - */ - @SneakyThrows - public CallbackResponse validateCallback( - String username, String password, String authorization, String responseBody) { - if (!CommonUtils.isCallbackValid(username, password, authorization)) { - throw new PhonePeException(417, "Invalid Callback"); - } - try { - return getObjectMapper().readValue(responseBody, CallbackResponse.class); - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildCallbackSerializationFailedEvent( - EventState.FAILED, - FlowType.PG, - EventType.CALLBACK_SERIALIZATION_FAILED, - exception)); - throw exception; - } - } + /** + * Validate if the callback is valid + * + * @param username username set by the merchant on the dashboard + * @param password password set by the merchant on the dashboard + * @param authorization String data under `authorization` key of response headers + * @param responseBody Callback response body + * @return CallbackResponse Deserialized callback body + * @throws PhonePeException when callback is not valid + */ + @SneakyThrows + public CallbackResponse validateCallback( + String username, String password, String authorization, String responseBody) { + if (!CommonUtils.isCallbackValid(username, password, authorization)) { + throw new PhonePeException(417, "Invalid Callback"); + } + try { + return getObjectMapper().readValue(responseBody, CallbackResponse.class); + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildCallbackSerializationFailedEvent( + EventState.FAILED, + FlowType.PG, + EventType.CALLBACK_SERIALIZATION_FAILED, + exception)); + throw exception; + } + } - /** - * Prepares the headers for CustomCheckout Client - */ - private void prepareHeaders() { - this.headers = new ArrayList<>(); - headers.add( - HttpHeaderPair.builder() - .key(Headers.CONTENT_TYPE) - .value(APPLICATION_JSON) - .build()); - headers.add( - HttpHeaderPair.builder() - .key(Headers.SOURCE) - .value(Headers.INTEGRATION) - .build()); - headers.add( - HttpHeaderPair.builder() - .key(Headers.SOURCE_VERSION) - .value(Headers.API_VERSION) - .build()); - headers.add( - HttpHeaderPair.builder() - .key(Headers.SOURCE_PLATFORM) - .value(Headers.SDK_TYPE) - .build()); - headers.add( - HttpHeaderPair.builder() - .key(Headers.SOURCE_PLATFORM_VERSION) - .value(Headers.SDK_VERSION) - .build()); - } + /** + * Prepares the headers for CustomCheckout Client + */ + private void prepareHeaders() { + this.headers = new ArrayList<>(); + headers.add( + HttpHeaderPair.builder() + .key(Headers.CONTENT_TYPE) + .value(APPLICATION_JSON) + .build()); + headers.add( + HttpHeaderPair.builder() + .key(Headers.SOURCE) + .value(Headers.INTEGRATION) + .build()); + headers.add( + HttpHeaderPair.builder() + .key(Headers.SOURCE_VERSION) + .value(Headers.API_VERSION) + .build()); + headers.add( + HttpHeaderPair.builder() + .key(Headers.SOURCE_PLATFORM) + .value(Headers.SDK_TYPE) + .build()); + headers.add( + HttpHeaderPair.builder() + .key(Headers.SOURCE_PLATFORM_VERSION) + .value(Headers.SDK_VERSION) + .build()); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/payments/v2/StandardCheckoutClient.java b/src/main/java/com/phonepe/sdk/pg/payments/v2/StandardCheckoutClient.java index a22405c..d2758df 100644 --- a/src/main/java/com/phonepe/sdk/pg/payments/v2/StandardCheckoutClient.java +++ b/src/main/java/com/phonepe/sdk/pg/payments/v2/StandardCheckoutClient.java @@ -47,365 +47,360 @@ /** The StandardCheckout client class provides methods for interacting with the PhonePe APIs. */ public class StandardCheckoutClient extends BaseClient { - private List headers; + private List headers; - private StandardCheckoutClient( - final String clientId, - final String clientSecret, - final Integer clientVersion, - final Env env, - boolean shouldPublishEvents) { - super(clientId, clientSecret, clientVersion, env, shouldPublishEvents); - this.eventPublisher.send( - BaseEvent.buildInitClientEvent( - FlowType.PG_CHECKOUT, EventType.STANDARD_CHECKOUT_CLIENT_INITIALIZED)); - this.prepareHeaders(); - } + private StandardCheckoutClient( + final String clientId, + final String clientSecret, + final Integer clientVersion, + final Env env, + boolean shouldPublishEvents) { + super(clientId, clientSecret, clientVersion, env, shouldPublishEvents); + this.eventPublisher.send( + BaseEvent.buildInitClientEvent( + FlowType.PG_CHECKOUT, EventType.STANDARD_CHECKOUT_CLIENT_INITIALIZED)); + this.prepareHeaders(); + } - /** - * Generates a StandardCheckout Client for interacting with the PhonePe APIs - * - * @param clientId Unique client-id assigned to merchant by PhonePe - * @param clientSecret Secret provided by PhonePe - * @param clientVersion The client version used for secure transactions - * @param env Set to `Env.SANDBOX` for the SANDBOX environment or `Env.PRODUCTION` for the - * production environment. - * @return StandardCheckoutClient object for interacting with the PhonePe APIs - */ - public static StandardCheckoutClient getInstance( - final String clientId, - final String clientSecret, - final Integer clientVersion, - final Env env) - throws PhonePeException { - return getInstance(clientId, clientSecret, clientVersion, env, true); - } + /** + * Generates a StandardCheckout Client for interacting with the PhonePe APIs + * + * @param clientId Unique client-id assigned to merchant by PhonePe + * @param clientSecret Secret provided by PhonePe + * @param clientVersion The client version used for secure transactions + * @param env Set to `Env.SANDBOX` for the SANDBOX environment or `Env.PRODUCTION` for the + * production environment. + * @return StandardCheckoutClient object for interacting with the PhonePe APIs + */ + public static StandardCheckoutClient getInstance( + final String clientId, + final String clientSecret, + final Integer clientVersion, + final Env env) throws PhonePeException { + return getInstance(clientId, clientSecret, clientVersion, env, true); + } - /** - * Generates a StandardCheckout Client for interacting with the PhonePe APIs - * - * @param clientId received at the time of onboarding - * @param clientSecret received at the time of onboarding - * @param clientVersion received at the time of onboarding - * @param env environment to be used by the merchant - * @param shouldPublishEvents When true, events are sent to PhonePe providing smoother - * experience - * @return StandardCheckoutClient object for interacting with the PhonePe APIs - */ - public static StandardCheckoutClient getInstance( - final String clientId, - final String clientSecret, - final Integer clientVersion, - final Env env, - boolean shouldPublishEvents) - throws PhonePeException { - final boolean shouldPublishInProd = shouldPublishEvents && env == Env.PRODUCTION; - return new StandardCheckoutClient( - clientId, clientSecret, clientVersion, env, shouldPublishInProd); - } + /** + * Generates a StandardCheckout Client for interacting with the PhonePe APIs + * + * @param clientId received at the time of onboarding + * @param clientSecret received at the time of onboarding + * @param clientVersion received at the time of onboarding + * @param env environment to be used by the merchant + * @param shouldPublishEvents When true, events are sent to PhonePe providing smoother + * experience + * @return StandardCheckoutClient object for interacting with the PhonePe APIs + */ + public static StandardCheckoutClient getInstance( + final String clientId, + final String clientSecret, + final Integer clientVersion, + final Env env, + boolean shouldPublishEvents) throws PhonePeException { + final boolean shouldPublishInProd = shouldPublishEvents && env == Env.PRODUCTION; + return new StandardCheckoutClient( + clientId, clientSecret, clientVersion, env, shouldPublishInProd); + } - /** - * Initiate a Pay Order - * - * @param standardCheckoutPayRequest Request Object Build using StandardCheckoutPayRequest - * Builder - * @return StandardCheckoutPayResponse contains checkout page url and related details - */ - @SneakyThrows - public StandardCheckoutPayResponse pay(StandardCheckoutPayRequest standardCheckoutPayRequest) { - String url = StandardCheckoutConstants.PAY_API; - try { - StandardCheckoutPayResponse standardCheckoutPayResponse = - requestViaAuthRefresh( - HttpMethodType.POST, - standardCheckoutPayRequest, - url, - null, - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildStandardCheckoutPayEvent( - EventState.SUCCESS, - standardCheckoutPayRequest, - url, - EventType.PAY_SUCCESS)); - return standardCheckoutPayResponse; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildStandardCheckoutPayEvent( - EventState.FAILED, - standardCheckoutPayRequest, - url, - EventType.PAY_FAILED, - exception)); - throw exception; - } - } + /** + * Initiate a Pay Order + * + * @param standardCheckoutPayRequest Request Object Build using StandardCheckoutPayRequest + * Builder + * @return StandardCheckoutPayResponse contains checkout page url and related details + */ + @SneakyThrows + public StandardCheckoutPayResponse pay(StandardCheckoutPayRequest standardCheckoutPayRequest) { + String url = StandardCheckoutConstants.PAY_API; + try { + StandardCheckoutPayResponse standardCheckoutPayResponse = requestViaAuthRefresh( + HttpMethodType.POST, + standardCheckoutPayRequest, + url, + null, + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildStandardCheckoutPayEvent( + EventState.SUCCESS, + standardCheckoutPayRequest, + url, + EventType.PAY_SUCCESS)); + return standardCheckoutPayResponse; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildStandardCheckoutPayEvent( + EventState.FAILED, + standardCheckoutPayRequest, + url, + EventType.PAY_FAILED, + exception)); + throw exception; + } + } - /** - * Gets the status of the order - * - * @param merchantOrderId Order id generated by merchant - * @return OrderStatusResponse Response with order and transaction details - */ - @SneakyThrows - public OrderStatusResponse getOrderStatus(String merchantOrderId) { - return getOrderStatus(merchantOrderId, false); - } + /** + * Gets the status of the order + * + * @param merchantOrderId Order id generated by merchant + * @return OrderStatusResponse Response with order and transaction details + */ + @SneakyThrows + public OrderStatusResponse getOrderStatus(String merchantOrderId) { + return getOrderStatus(merchantOrderId, false); + } - /** - * Gets the status of an order - * - * @param merchantOrderId Order id generated by merchant - * @param details true -> order status has all attempt details under paymentDetails list false - * -> order status has only latest attempt details under paymentDetails list - * @return OrderStatusResponse Response with order and transaction details - */ - @SneakyThrows - public OrderStatusResponse getOrderStatus(String merchantOrderId, boolean details) { - final String url = - String.format(StandardCheckoutConstants.ORDER_STATUS_API, merchantOrderId); - try { - OrderStatusResponse orderStatusResponse = - requestViaAuthRefresh( - HttpMethodType.GET, - null, - url, - Collections.singletonMap( - StandardCheckoutConstants.ORDER_DETAILS, - Boolean.toString(details)), - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildOrderStatusEvent( - EventState.SUCCESS, - merchantOrderId, - url, - FlowType.PG_CHECKOUT, - EventType.ORDER_STATUS_SUCCESS)); - return orderStatusResponse; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildOrderStatusEvent( - EventState.FAILED, - merchantOrderId, - url, - FlowType.PG_CHECKOUT, - EventType.ORDER_STATUS_FAILED, - exception)); - throw exception; - } - } + /** + * Gets the status of an order + * + * @param merchantOrderId Order id generated by merchant + * @param details true -> order status has all attempt details under paymentDetails list false + * -> order status has only latest attempt details under paymentDetails list + * @return OrderStatusResponse Response with order and transaction details + */ + @SneakyThrows + public OrderStatusResponse getOrderStatus(String merchantOrderId, boolean details) { + final String url = String.format(StandardCheckoutConstants.ORDER_STATUS_API, merchantOrderId); + try { + OrderStatusResponse orderStatusResponse = requestViaAuthRefresh( + HttpMethodType.GET, + null, + url, + Collections.singletonMap( + StandardCheckoutConstants.ORDER_DETAILS, + Boolean.toString(details)), + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildOrderStatusEvent( + EventState.SUCCESS, + merchantOrderId, + url, + FlowType.PG_CHECKOUT, + EventType.ORDER_STATUS_SUCCESS)); + return orderStatusResponse; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildOrderStatusEvent( + EventState.FAILED, + merchantOrderId, + url, + FlowType.PG_CHECKOUT, + EventType.ORDER_STATUS_FAILED, + exception)); + throw exception; + } + } - /** - * Initiate refund of an order - * - * @param refundRequest Request object build using RefundRequest builder - * @return RefundResponse contains refund details for an order - */ - @SneakyThrows - public RefundResponse refund(RefundRequest refundRequest) { - final String url = StandardCheckoutConstants.REFUND_API; - try { - RefundResponse refundResponse = - requestViaAuthRefresh( - HttpMethodType.POST, - refundRequest, - url, - null, - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildRefundEvent( - EventState.SUCCESS, - refundRequest, - url, - FlowType.PG_CHECKOUT, - EventType.REFUND_SUCCESS)); - return refundResponse; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildRefundEvent( - EventState.FAILED, - refundRequest, - url, - FlowType.PG_CHECKOUT, - EventType.REFUND_FAILED, - exception)); - throw exception; - } - } + /** + * Initiate refund of an order + * + * @param refundRequest Request object build using RefundRequest builder + * @return RefundResponse contains refund details for an order + */ + @SneakyThrows + public RefundResponse refund(RefundRequest refundRequest) { + final String url = StandardCheckoutConstants.REFUND_API; + try { + RefundResponse refundResponse = requestViaAuthRefresh( + HttpMethodType.POST, + refundRequest, + url, + null, + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildRefundEvent( + EventState.SUCCESS, + refundRequest, + url, + FlowType.PG_CHECKOUT, + EventType.REFUND_SUCCESS)); + return refundResponse; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildRefundEvent( + EventState.FAILED, + refundRequest, + url, + FlowType.PG_CHECKOUT, + EventType.REFUND_FAILED, + exception)); + throw exception; + } + } - /** - * Create order token for SDK integrated order requests - * - * @param createSdkOrderRequest Request object build using SdkOrderRequest builder - * @return CreateSdkOrderResponse contains token details to be consumed by the UI - */ - @SneakyThrows - public CreateSdkOrderResponse createSdkOrder(CreateSdkOrderRequest createSdkOrderRequest) { - final String url = StandardCheckoutConstants.CREATE_ORDER_API; - try { - CreateSdkOrderResponse createSdkOrderResponse = - requestViaAuthRefresh( - HttpMethodType.POST, - createSdkOrderRequest, - url, - null, - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildCreateSdkOrderEvent( - EventState.SUCCESS, - createSdkOrderRequest, - url, - FlowType.PG_CHECKOUT, - EventType.CREATE_SDK_ORDER_SUCCESS)); - return createSdkOrderResponse; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildCreateSdkOrderEvent( - EventState.FAILED, - createSdkOrderRequest, - url, - FlowType.PG_CHECKOUT, - EventType.CREATE_SDK_ORDER_FAILED, - exception)); - throw exception; - } - } + /** + * Create order token for SDK integrated order requests + * + * @param createSdkOrderRequest Request object build using SdkOrderRequest builder + * @return CreateSdkOrderResponse contains token details to be consumed by the UI + */ + @SneakyThrows + public CreateSdkOrderResponse createSdkOrder(CreateSdkOrderRequest createSdkOrderRequest) { + final String url = StandardCheckoutConstants.CREATE_ORDER_API; + try { + CreateSdkOrderResponse createSdkOrderResponse = requestViaAuthRefresh( + HttpMethodType.POST, + createSdkOrderRequest, + url, + null, + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildCreateSdkOrderEvent( + EventState.SUCCESS, + createSdkOrderRequest, + url, + FlowType.PG_CHECKOUT, + EventType.CREATE_SDK_ORDER_SUCCESS)); + return createSdkOrderResponse; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildCreateSdkOrderEvent( + EventState.FAILED, + createSdkOrderRequest, + url, + FlowType.PG_CHECKOUT, + EventType.CREATE_SDK_ORDER_FAILED, + exception)); + throw exception; + } + } - /** - * Get status of a transaction attempt - * - * @param transactionId Transaction attempt id generated by PhonePe - * @return OrderStatusResponse Response with order and transaction details - */ - @SneakyThrows - public OrderStatusResponse getTransactionStatus(String transactionId) { - final String url = - String.format(StandardCheckoutConstants.TRANSACTION_STATUS_API, transactionId); - try { - OrderStatusResponse orderStatusResponse = - requestViaAuthRefresh( - HttpMethodType.GET, - null, - url, - null, - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildTransactionStatusEvent( - EventState.SUCCESS, - transactionId, - url, - FlowType.PG_CHECKOUT, - EventType.TRANSACTION_STATUS_SUCCESS)); - return orderStatusResponse; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildTransactionStatusEvent( - EventState.FAILED, - transactionId, - url, - FlowType.PG_CHECKOUT, - EventType.TRANSACTION_STATUS_FAILED, - exception)); - throw exception; - } - } + /** + * Get status of a transaction attempt + * + * @param transactionId Transaction attempt id generated by PhonePe + * @return OrderStatusResponse Response with order and transaction details + */ + @SneakyThrows + public OrderStatusResponse getTransactionStatus(String transactionId) { + final String url = String.format(StandardCheckoutConstants.TRANSACTION_STATUS_API, transactionId); + try { + OrderStatusResponse orderStatusResponse = requestViaAuthRefresh( + HttpMethodType.GET, + null, + url, + null, + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildTransactionStatusEvent( + EventState.SUCCESS, + transactionId, + url, + FlowType.PG_CHECKOUT, + EventType.TRANSACTION_STATUS_SUCCESS)); + return orderStatusResponse; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildTransactionStatusEvent( + EventState.FAILED, + transactionId, + url, + FlowType.PG_CHECKOUT, + EventType.TRANSACTION_STATUS_FAILED, + exception)); + throw exception; + } + } - /** - * Get status of refund - * - * @param refundId Merchant Refund id for which you need the status - * @return RefundStatusResponse Refund status details - * @throws PhonePeException if any error occurs during the process - */ - @SneakyThrows - public RefundStatusResponse getRefundStatus(String refundId) { - final String url = String.format(StandardCheckoutConstants.REFUND_STATUS_API, refundId); - try { - RefundStatusResponse refundStatusResponse = - requestViaAuthRefresh( - HttpMethodType.GET, - null, - url, - null, - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildRefundStatusEvent( - EventState.SUCCESS, - refundId, - url, - FlowType.PG_CHECKOUT, - EventType.REFUND_STATUS_SUCCESS)); - return refundStatusResponse; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildRefundStatusEvent( - EventState.FAILED, - refundId, - url, - FlowType.PG_CHECKOUT, - EventType.REFUND_STATUS_FAILED, - exception)); - throw exception; - } - } + /** + * Get status of refund + * + * @param refundId Merchant Refund id for which you need the status + * @return RefundStatusResponse Refund status details + * @throws PhonePeException if any error occurs during the process + */ + @SneakyThrows + public RefundStatusResponse getRefundStatus(String refundId) { + final String url = String.format(StandardCheckoutConstants.REFUND_STATUS_API, refundId); + try { + RefundStatusResponse refundStatusResponse = requestViaAuthRefresh( + HttpMethodType.GET, + null, + url, + null, + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildRefundStatusEvent( + EventState.SUCCESS, + refundId, + url, + FlowType.PG_CHECKOUT, + EventType.REFUND_STATUS_SUCCESS)); + return refundStatusResponse; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildRefundStatusEvent( + EventState.FAILED, + refundId, + url, + FlowType.PG_CHECKOUT, + EventType.REFUND_STATUS_FAILED, + exception)); + throw exception; + } + } - /** - * Validate if the callback is valid - * - * @param username username set by the merchant on the dashboard - * @param password password set by the merchant on the dashboard - * @param authorization String data under `authorization` key of response headers - * @param responseBody Callback response body - * @return CallbackResponse Deserialized callback body - * @throws PhonePeException when callback is not valid - */ - @SneakyThrows - public CallbackResponse validateCallback( - String username, String password, String authorization, String responseBody) - throws PhonePeException { - if (!CommonUtils.isCallbackValid(username, password, authorization)) { - throw new PhonePeException(417, "Invalid Callback"); - } - try { - return getObjectMapper().readValue(responseBody, CallbackResponse.class); - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildCallbackSerializationFailedEvent( - EventState.FAILED, - FlowType.PG_CHECKOUT, - EventType.CALLBACK_SERIALIZATION_FAILED, - exception)); - throw exception; - } - } + /** + * Validate if the callback is valid + * + * @param username username set by the merchant on the dashboard + * @param password password set by the merchant on the dashboard + * @param authorization String data under `authorization` key of response headers + * @param responseBody Callback response body + * @return CallbackResponse Deserialized callback body + * @throws PhonePeException when callback is not valid + */ + @SneakyThrows + public CallbackResponse validateCallback( + String username, String password, String authorization, String responseBody) throws PhonePeException { + if (!CommonUtils.isCallbackValid(username, password, authorization)) { + throw new PhonePeException(417, "Invalid Callback"); + } + try { + return getObjectMapper().readValue(responseBody, CallbackResponse.class); + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildCallbackSerializationFailedEvent( + EventState.FAILED, + FlowType.PG_CHECKOUT, + EventType.CALLBACK_SERIALIZATION_FAILED, + exception)); + throw exception; + } + } - /** Prepares the headers for StandardCheckout Client */ - private void prepareHeaders() { - this.headers = new ArrayList<>(); - headers.add( - HttpHeaderPair.builder().key(Headers.CONTENT_TYPE).value(APPLICATION_JSON).build()); - headers.add( - HttpHeaderPair.builder().key(Headers.SOURCE).value(Headers.INTEGRATION).build()); - headers.add( - HttpHeaderPair.builder() - .key(Headers.SOURCE_VERSION) - .value(Headers.API_VERSION) - .build()); - headers.add( - HttpHeaderPair.builder() - .key(Headers.SOURCE_PLATFORM) - .value(Headers.SDK_TYPE) - .build()); - headers.add( - HttpHeaderPair.builder() - .key(Headers.SOURCE_PLATFORM_VERSION) - .value(Headers.SDK_VERSION) - .build()); - } + /** Prepares the headers for StandardCheckout Client */ + private void prepareHeaders() { + this.headers = new ArrayList<>(); + headers.add( + HttpHeaderPair.builder() + .key(Headers.CONTENT_TYPE) + .value(APPLICATION_JSON) + .build()); + headers.add( + HttpHeaderPair.builder() + .key(Headers.SOURCE) + .value(Headers.INTEGRATION) + .build()); + headers.add( + HttpHeaderPair.builder() + .key(Headers.SOURCE_VERSION) + .value(Headers.API_VERSION) + .build()); + headers.add( + HttpHeaderPair.builder() + .key(Headers.SOURCE_PLATFORM) + .value(Headers.SDK_TYPE) + .build()); + headers.add( + HttpHeaderPair.builder() + .key(Headers.SOURCE_PLATFORM_VERSION) + .value(Headers.SDK_VERSION) + .build()); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/payments/v2/customcheckout/CustomCheckoutConstants.java b/src/main/java/com/phonepe/sdk/pg/payments/v2/customcheckout/CustomCheckoutConstants.java index de22ad5..d3655d9 100644 --- a/src/main/java/com/phonepe/sdk/pg/payments/v2/customcheckout/CustomCheckoutConstants.java +++ b/src/main/java/com/phonepe/sdk/pg/payments/v2/customcheckout/CustomCheckoutConstants.java @@ -17,15 +17,15 @@ public class CustomCheckoutConstants { - public static final String PAY_API = "/payments/v2/pay"; + public static final String PAY_API = "/payments/v2/pay"; - public static final String ORDER_STATUS_API = "/payments/v2/order/%s/status"; - public static final String ORDER_DETAILS = "details"; + public static final String ORDER_STATUS_API = "/payments/v2/order/%s/status"; + public static final String ORDER_DETAILS = "details"; - public static final String REFUND_API = "/payments/v2/refund"; - public static final String REFUND_STATUS_API = "/payments/v2/refund/%s/status"; + public static final String REFUND_API = "/payments/v2/refund"; + public static final String REFUND_STATUS_API = "/payments/v2/refund/%s/status"; - public static final String TRANSACTION_STATUS_API = "/payments/v2/transaction/%s/status"; + public static final String TRANSACTION_STATUS_API = "/payments/v2/transaction/%s/status"; - public static final String CREATE_ORDER_API = "/payments/v2/sdk/order"; + public static final String CREATE_ORDER_API = "/payments/v2/sdk/order"; } diff --git a/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/CreateSdkOrderRequest.java b/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/CreateSdkOrderRequest.java index 158ba6e..512c1b7 100644 --- a/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/CreateSdkOrderRequest.java +++ b/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/CreateSdkOrderRequest.java @@ -29,73 +29,74 @@ @JsonInclude(Include.NON_NULL) public class CreateSdkOrderRequest { - private String merchantOrderId; - private long amount; - private MetaInfo metaInfo; - private PaymentFlow paymentFlow; - private Long expireAfter; - private List constraints; - private Boolean disablePaymentRetry; + private String merchantOrderId; + private long amount; + private MetaInfo metaInfo; + private PaymentFlow paymentFlow; + private Long expireAfter; + private List constraints; + private Boolean disablePaymentRetry; - /** - * Builds SDK order Request - * - * @param amount Order amount in paisa - * @param merchantOrderId The unique order ID generated by the merchant - * @param metaInfo Merchant defined meta info to store additional information - * @param message Payment message shown in APP for collect requests - * @param redirectUrl URL where user will be redirected after success/failed payment - */ - @Builder( - builderClassName = "StandardCheckoutBuilder", - builderMethodName = "StandardCheckoutBuilder") - public CreateSdkOrderRequest( - long amount, - @NotNull String merchantOrderId, - MetaInfo metaInfo, - String message, - String redirectUrl, - Long expireAfter, - Boolean disablePaymentRetry, - PaymentModeConfig paymentModeConfig) { - 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() - .message(message) - .paymentModeConfig(paymentModeConfig) - .merchantUrls(merchantUrls) - .build()); - } + /** + * Builds SDK order Request + * + * @param amount Order amount in paisa + * @param merchantOrderId The unique order ID generated by the merchant + * @param metaInfo Merchant defined meta info to store additional information + * @param message Payment message shown in APP for collect requests + * @param redirectUrl URL where user will be redirected after success/failed payment + */ + @Builder( + builderClassName = "StandardCheckoutBuilder", builderMethodName = "StandardCheckoutBuilder") + public CreateSdkOrderRequest( + long amount, + @NotNull String merchantOrderId, + MetaInfo metaInfo, + String message, + String redirectUrl, + Long expireAfter, + Boolean disablePaymentRetry, + PaymentModeConfig paymentModeConfig) { + 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() + .message(message) + .paymentModeConfig(paymentModeConfig) + .merchantUrls(merchantUrls) + .build()); + } - /** - * Builds SDK order Request - * - * @param amount Order amount in paisa - * @param merchantOrderId The unique order ID generated by the merchant - * @param metaInfo Merchant defined meta info to store additional information - * @param constraints Different type of constraints that must be applied to the payment - */ - @Builder( - builderClassName = "CustomCheckoutBuilder", - builderMethodName = "CustomCheckoutBuilder") - public CreateSdkOrderRequest( - @NotNull String merchantOrderId, - long amount, - MetaInfo metaInfo, - List constraints, - 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()); - } + /** + * Builds SDK order Request + * + * @param amount Order amount in paisa + * @param merchantOrderId The unique order ID generated by the merchant + * @param metaInfo Merchant defined meta info to store additional information + * @param constraints Different type of constraints that must be applied to the payment + */ + @Builder( + builderClassName = "CustomCheckoutBuilder", builderMethodName = "CustomCheckoutBuilder") + public CreateSdkOrderRequest( + @NotNull String merchantOrderId, + long amount, + MetaInfo metaInfo, + List constraints, + 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()); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/MerchantUrls.java b/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/MerchantUrls.java index 3f38d3d..8575e98 100644 --- a/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/MerchantUrls.java +++ b/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/MerchantUrls.java @@ -25,5 +25,5 @@ @JsonInclude(Include.NON_NULL) public class MerchantUrls { - private String redirectUrl; + private String redirectUrl; } diff --git a/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/PaymentModeConfig.java b/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/PaymentModeConfig.java index 297a770..b9cc78d 100644 --- a/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/PaymentModeConfig.java +++ b/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/PaymentModeConfig.java @@ -27,18 +27,18 @@ @JsonInclude(Include.NON_NULL) public class PaymentModeConfig { - List enabledPaymentModes; - List disabledPaymentModes; + List enabledPaymentModes; + List disabledPaymentModes; - PaymentModeConfig( - List enabledPaymentModes, - List disabledPaymentModes) { - this.enabledPaymentModes = enabledPaymentModes; - this.disabledPaymentModes = disabledPaymentModes; - } + PaymentModeConfig( + List enabledPaymentModes, + List disabledPaymentModes) { + this.enabledPaymentModes = enabledPaymentModes; + this.disabledPaymentModes = disabledPaymentModes; + } - public PaymentModeConfig() { - this.enabledPaymentModes = null; - this.disabledPaymentModes = null; - } + public PaymentModeConfig() { + this.enabledPaymentModes = null; + this.disabledPaymentModes = null; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/PgCheckoutPaymentFlow.java b/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/PgCheckoutPaymentFlow.java index 1c7c408..6727f66 100644 --- a/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/PgCheckoutPaymentFlow.java +++ b/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/PgCheckoutPaymentFlow.java @@ -28,18 +28,18 @@ @JsonInclude(Include.NON_NULL) public class PgCheckoutPaymentFlow extends PaymentFlow { - private String message; - private MerchantUrls merchantUrls; - private PaymentModeConfig paymentModeConfig; + private String message; + private MerchantUrls merchantUrls; + private PaymentModeConfig paymentModeConfig; - @Builder - public PgCheckoutPaymentFlow( - final String message, - final MerchantUrls merchantUrls, - final PaymentModeConfig paymentModeConfig) { - super(PaymentFlowType.PG_CHECKOUT); - this.message = message; - this.merchantUrls = merchantUrls; - this.paymentModeConfig = paymentModeConfig; - } + @Builder + public PgCheckoutPaymentFlow( + final String message, + final MerchantUrls merchantUrls, + final PaymentModeConfig paymentModeConfig) { + super(PaymentFlowType.PG_CHECKOUT); + this.message = message; + this.merchantUrls = merchantUrls; + this.paymentModeConfig = paymentModeConfig; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/PgPaymentFlow.java b/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/PgPaymentFlow.java index 236bf67..2bb2a1f 100644 --- a/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/PgPaymentFlow.java +++ b/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/PgPaymentFlow.java @@ -29,13 +29,13 @@ @JsonInclude(Include.NON_NULL) public class PgPaymentFlow extends PaymentFlow { - private PaymentV2Instrument paymentMode; - private MerchantUrls merchantUrls; + private PaymentV2Instrument paymentMode; + private MerchantUrls merchantUrls; - @Builder - public PgPaymentFlow(final PaymentV2Instrument paymentMode, final MerchantUrls merchantUrls) { - super(PaymentFlowType.PG); - this.paymentMode = paymentMode; - this.merchantUrls = merchantUrls; - } + @Builder + public PgPaymentFlow(final PaymentV2Instrument paymentMode, final MerchantUrls merchantUrls) { + super(PaymentFlowType.PG); + this.paymentMode = paymentMode; + this.merchantUrls = merchantUrls; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/StandardCheckoutPayRequest.java b/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/StandardCheckoutPayRequest.java index b6e10f9..8fb372d 100644 --- a/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/StandardCheckoutPayRequest.java +++ b/src/main/java/com/phonepe/sdk/pg/payments/v2/models/request/StandardCheckoutPayRequest.java @@ -26,48 +26,48 @@ @JsonInclude(Include.NON_NULL) public class StandardCheckoutPayRequest { - private String merchantOrderId; - private long amount; - private MetaInfo metaInfo; - private PaymentFlow paymentFlow; - private Long expireAfter; - private Boolean disablePaymentRetry; - private PrefillUserLoginDetails prefillUserLoginDetails; + private String merchantOrderId; + private long amount; + private MetaInfo metaInfo; + private PaymentFlow paymentFlow; + private Long expireAfter; + private Boolean disablePaymentRetry; + private PrefillUserLoginDetails prefillUserLoginDetails; - /** - * Builds Standard Checkout Pay Request - * - * @param merchantOrderId The unique order ID generated by the merchant - * @param amount Order amount in paisa - * @param redirectUrl URL where user will be redirected after success/failed payment - * @param metaInfo Merchant defined meta info to store additional information - * @param message Payment message shown in APP for collect requests - */ - @Builder - public StandardCheckoutPayRequest( - String merchantOrderId, - long amount, - String redirectUrl, - MetaInfo metaInfo, - String message, - Long expireAfter, - PaymentModeConfig paymentModeConfig, - Boolean disablePaymentRetry, - PrefillUserLoginDetails prefillUserLoginDetails) { - this.merchantOrderId = merchantOrderId; - this.amount = amount; - this.metaInfo = metaInfo; - this.expireAfter = expireAfter; - MerchantUrls merchantUrls = MerchantUrls.builder() - .redirectUrl(redirectUrl) - .build(); - this.setPaymentFlow( - PgCheckoutPaymentFlow.builder() - .message(message) - .merchantUrls(merchantUrls) - .paymentModeConfig(paymentModeConfig) - .build()); - this.disablePaymentRetry = disablePaymentRetry; - this.prefillUserLoginDetails = prefillUserLoginDetails; - } + /** + * Builds Standard Checkout Pay Request + * + * @param merchantOrderId The unique order ID generated by the merchant + * @param amount Order amount in paisa + * @param redirectUrl URL where user will be redirected after success/failed payment + * @param metaInfo Merchant defined meta info to store additional information + * @param message Payment message shown in APP for collect requests + */ + @Builder + public StandardCheckoutPayRequest( + String merchantOrderId, + long amount, + String redirectUrl, + MetaInfo metaInfo, + String message, + Long expireAfter, + PaymentModeConfig paymentModeConfig, + Boolean disablePaymentRetry, + PrefillUserLoginDetails prefillUserLoginDetails) { + this.merchantOrderId = merchantOrderId; + this.amount = amount; + this.metaInfo = metaInfo; + this.expireAfter = expireAfter; + MerchantUrls merchantUrls = MerchantUrls.builder() + .redirectUrl(redirectUrl) + .build(); + this.setPaymentFlow( + PgCheckoutPaymentFlow.builder() + .message(message) + .merchantUrls(merchantUrls) + .paymentModeConfig(paymentModeConfig) + .build()); + this.disablePaymentRetry = disablePaymentRetry; + this.prefillUserLoginDetails = prefillUserLoginDetails; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/payments/v2/models/response/CreateSdkOrderResponse.java b/src/main/java/com/phonepe/sdk/pg/payments/v2/models/response/CreateSdkOrderResponse.java index c509e2f..8dcb43c 100644 --- a/src/main/java/com/phonepe/sdk/pg/payments/v2/models/response/CreateSdkOrderResponse.java +++ b/src/main/java/com/phonepe/sdk/pg/payments/v2/models/response/CreateSdkOrderResponse.java @@ -28,8 +28,8 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class CreateSdkOrderResponse { - private String orderId; - private String state; - private long expireAt; - private String token; + private String orderId; + private String state; + private long expireAt; + private String token; } diff --git a/src/main/java/com/phonepe/sdk/pg/payments/v2/models/response/StandardCheckoutPayResponse.java b/src/main/java/com/phonepe/sdk/pg/payments/v2/models/response/StandardCheckoutPayResponse.java index 88c64c6..0300ca8 100644 --- a/src/main/java/com/phonepe/sdk/pg/payments/v2/models/response/StandardCheckoutPayResponse.java +++ b/src/main/java/com/phonepe/sdk/pg/payments/v2/models/response/StandardCheckoutPayResponse.java @@ -28,8 +28,8 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class StandardCheckoutPayResponse { - private String orderId; - private String state; - private long expireAt; - private String redirectUrl; + private String orderId; + private String state; + private long expireAt; + private String redirectUrl; } diff --git a/src/main/java/com/phonepe/sdk/pg/payments/v2/standardcheckout/StandardCheckoutConstants.java b/src/main/java/com/phonepe/sdk/pg/payments/v2/standardcheckout/StandardCheckoutConstants.java index 213862f..0cccc62 100644 --- a/src/main/java/com/phonepe/sdk/pg/payments/v2/standardcheckout/StandardCheckoutConstants.java +++ b/src/main/java/com/phonepe/sdk/pg/payments/v2/standardcheckout/StandardCheckoutConstants.java @@ -20,11 +20,11 @@ @UtilityClass public class StandardCheckoutConstants { - public static final String PAY_API = "/checkout/v2/pay"; - public static final String CREATE_ORDER_API = "/checkout/v2/sdk/order"; - public static final String ORDER_STATUS_API = "/checkout/v2/order/%s/status"; - public static final String TRANSACTION_STATUS_API = "/checkout/v2/transaction/%s/status"; - public static final String REFUND_API = "/payments/v2/refund"; - public static final String REFUND_STATUS_API = "/payments/v2/refund/%s/status"; - public static final String ORDER_DETAILS = "details"; + public static final String PAY_API = "/checkout/v2/pay"; + public static final String CREATE_ORDER_API = "/checkout/v2/sdk/order"; + public static final String ORDER_STATUS_API = "/checkout/v2/order/%s/status"; + public static final String TRANSACTION_STATUS_API = "/checkout/v2/transaction/%s/status"; + public static final String REFUND_API = "/payments/v2/refund"; + public static final String REFUND_STATUS_API = "/payments/v2/refund/%s/status"; + public static final String ORDER_DETAILS = "details"; } diff --git a/src/main/java/com/phonepe/sdk/pg/subscription/v2/SubscriptionClient.java b/src/main/java/com/phonepe/sdk/pg/subscription/v2/SubscriptionClient.java index 165f65c..f720677 100644 --- a/src/main/java/com/phonepe/sdk/pg/subscription/v2/SubscriptionClient.java +++ b/src/main/java/com/phonepe/sdk/pg/subscription/v2/SubscriptionClient.java @@ -45,439 +45,433 @@ public class SubscriptionClient extends BaseClient { - private List headers; + private List headers; - private SubscriptionClient( - String clientId, - String clientSecret, - Integer clientVersion, - Env env, - boolean shouldPublishEvents) { - super(clientId, clientSecret, clientVersion, env, shouldPublishEvents); - this.eventPublisher.send( - BaseEvent.buildInitClientEvent( - FlowType.SUBSCRIPTION, EventType.SUBSCRIPTION_CLIENT_INITIALIZED)); - this.prepareHeaders(); - } + private SubscriptionClient( + String clientId, + String clientSecret, + Integer clientVersion, + Env env, + boolean shouldPublishEvents) { + super(clientId, clientSecret, clientVersion, env, shouldPublishEvents); + this.eventPublisher.send( + BaseEvent.buildInitClientEvent( + FlowType.SUBSCRIPTION, EventType.SUBSCRIPTION_CLIENT_INITIALIZED)); + this.prepareHeaders(); + } - /** - * Generates a Subscription Client for interacting with the PhonePe APIs - * - * @param clientId Unique client-id assigned to merchant by PhonePe - * @param clientSecret Secret provided by PhonePe - * @param clientVersion The client version used for secure transactions - * @param env Set to `Env.SANDBOX` for the SANDBOX environment or `Env.PRODUCTION` for the - * production environment. - * @return SubscriptionClient object for interacting with the PhonePe APIs - */ - public static SubscriptionClient getInstance( - final String clientId, - final String clientSecret, - final Integer clientVersion, - final Env env) - throws PhonePeException { - return getInstance(clientId, clientSecret, clientVersion, env, true); - } + /** + * Generates a Subscription Client for interacting with the PhonePe APIs + * + * @param clientId Unique client-id assigned to merchant by PhonePe + * @param clientSecret Secret provided by PhonePe + * @param clientVersion The client version used for secure transactions + * @param env Set to `Env.SANDBOX` for the SANDBOX environment or `Env.PRODUCTION` for the + * production environment. + * @return SubscriptionClient object for interacting with the PhonePe APIs + */ + public static SubscriptionClient getInstance( + final String clientId, + final String clientSecret, + final Integer clientVersion, + final Env env) throws PhonePeException { + return getInstance(clientId, clientSecret, clientVersion, env, true); + } - /** - * Generates a Subscription Client for interacting with the PhonePe Subscription APIs - * - * @param clientId Unique client-id assigned to merchant by PhonePe - * @param clientSecret Secret provided by PhonePe - * @param clientVersion The client version used for secure transactions - * @param env Set to `Env.SANDBOX` for the SANDBOX environment or `Env.PRODUCTION` for the - * production environment. - * @param shouldPublishEvents When true, events are sent to PhonePe providing smoother - * experience - * @return SubscriptionClient object for interacting with the PhonePe APIs - */ - public static SubscriptionClient getInstance( - final String clientId, - final String clientSecret, - final Integer clientVersion, - final Env env, - boolean shouldPublishEvents) - throws PhonePeException { - final boolean shouldPublishInProd = shouldPublishEvents && env == Env.PRODUCTION; - return new SubscriptionClient( - clientId, clientSecret, clientVersion, env, shouldPublishInProd); - } + /** + * Generates a Subscription Client for interacting with the PhonePe Subscription APIs + * + * @param clientId Unique client-id assigned to merchant by PhonePe + * @param clientSecret Secret provided by PhonePe + * @param clientVersion The client version used for secure transactions + * @param env Set to `Env.SANDBOX` for the SANDBOX environment or `Env.PRODUCTION` for the + * production environment. + * @param shouldPublishEvents When true, events are sent to PhonePe providing smoother + * experience + * @return SubscriptionClient object for interacting with the PhonePe APIs + */ + public static SubscriptionClient getInstance( + final String clientId, + final String clientSecret, + final Integer clientVersion, + final Env env, + boolean shouldPublishEvents) throws PhonePeException { + final boolean shouldPublishInProd = shouldPublishEvents && env == Env.PRODUCTION; + return new SubscriptionClient( + clientId, clientSecret, clientVersion, env, shouldPublishInProd); + } - /** - * Setup the subscription based on the given merchant requirements - * - * @param request Request built using PgPaymentRequest Builder's. 1. Payment via UPI_INTENT -> - * use PgPaymentRequest.SubscriptionSetupUpiIntentBuilder() 2. Payment via UPI_COLLECT -> - * use PgPaymentRequest.SubscriptionSetupUpiCollectBuilder() - * @return PgPaymentResponse which contains the state of the requested setup - */ - @SneakyThrows - public PgPaymentResponse setup(PgPaymentRequest request) { - final String url = SubscriptionConstants.SETUP_API; - try { - PgPaymentResponse response = - requestViaAuthRefresh( - HttpMethodType.POST, - request, - url, - null, - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildSubscriptionSetupEvent( - EventState.SUCCESS, request, url, EventType.SETUP_SUCCESS)); - return response; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildSubscriptionSetupEvent( - EventState.FAILED, request, url, EventType.SETUP_FAILED, exception)); - throw exception; - } - } + /** + * Setup the subscription based on the given merchant requirements + * + * @param request Request built using PgPaymentRequest Builder's. 1. Payment via UPI_INTENT -> + * use PgPaymentRequest.SubscriptionSetupUpiIntentBuilder() 2. Payment via UPI_COLLECT -> + * use PgPaymentRequest.SubscriptionSetupUpiCollectBuilder() + * @return PgPaymentResponse which contains the state of the requested setup + */ + @SneakyThrows + public PgPaymentResponse setup(PgPaymentRequest request) { + final String url = SubscriptionConstants.SETUP_API; + try { + PgPaymentResponse response = requestViaAuthRefresh( + HttpMethodType.POST, + request, + url, + null, + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildSubscriptionSetupEvent( + EventState.SUCCESS, request, url, EventType.SETUP_SUCCESS)); + return response; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildSubscriptionSetupEvent( + EventState.FAILED, request, url, EventType.SETUP_FAILED, exception)); + throw exception; + } + } - /** - * Used to send the notify information from the PhonePe - * - * @param request Request built using PgPaymentRequest.SubscriptionNotifyRequestBuilder() - * @return PgPaymentResponse which contains the state of the requested notify - */ - @SneakyThrows - public PgPaymentResponse notify(PgPaymentRequest request) { - final String url = SubscriptionConstants.NOTIFY_API; - try { - PgPaymentResponse response = - requestViaAuthRefresh( - HttpMethodType.POST, - request, - url, - null, - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildSubscriptionNotifyEvent( - EventState.SUCCESS, request, url, EventType.NOTIFY_SUCCESS)); - return response; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildSubscriptionNotifyEvent( - EventState.FAILED, request, url, EventType.NOTIFY_FAILED, exception)); - throw exception; - } - } + /** + * Used to send the notify information from the PhonePe + * + * @param request Request built using PgPaymentRequest.SubscriptionNotifyRequestBuilder() + * @return PgPaymentResponse which contains the state of the requested notify + */ + @SneakyThrows + public PgPaymentResponse notify(PgPaymentRequest request) { + final String url = SubscriptionConstants.NOTIFY_API; + try { + PgPaymentResponse response = requestViaAuthRefresh( + HttpMethodType.POST, + request, + url, + null, + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildSubscriptionNotifyEvent( + EventState.SUCCESS, request, url, EventType.NOTIFY_SUCCESS)); + return response; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildSubscriptionNotifyEvent( + EventState.FAILED, request, url, EventType.NOTIFY_FAILED, exception)); + throw exception; + } + } - /** - * Used to redeem the subscription for the given ID - * - * @param merchantOrderId Same ID used at the time of making a notify request - * @return SubscriptionRedeemResponseV2 which contains the state for the request made - */ - @SneakyThrows - public SubscriptionRedeemResponseV2 redeem(String merchantOrderId) { - final String url = SubscriptionConstants.REDEEM_API; - try { - SubscriptionRedeemRequestV2 request = new SubscriptionRedeemRequestV2(merchantOrderId); - SubscriptionRedeemResponseV2 response = - requestViaAuthRefresh( - HttpMethodType.POST, - request, - url, - null, - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildSubscriptionRedeemEvent( - EventState.SUCCESS, merchantOrderId, url, EventType.REDEEM_SUCCESS)); - return response; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildSubscriptionRedeemEvent( - EventState.FAILED, - merchantOrderId, - url, - EventType.REDEEM_FAILED, - exception)); - throw exception; - } - } + /** + * Used to redeem the subscription for the given ID + * + * @param merchantOrderId Same ID used at the time of making a notify request + * @return SubscriptionRedeemResponseV2 which contains the state for the request made + */ + @SneakyThrows + public SubscriptionRedeemResponseV2 redeem(String merchantOrderId) { + final String url = SubscriptionConstants.REDEEM_API; + try { + SubscriptionRedeemRequestV2 request = new SubscriptionRedeemRequestV2(merchantOrderId); + SubscriptionRedeemResponseV2 response = requestViaAuthRefresh( + HttpMethodType.POST, + request, + url, + null, + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildSubscriptionRedeemEvent( + EventState.SUCCESS, merchantOrderId, url, EventType.REDEEM_SUCCESS)); + return response; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildSubscriptionRedeemEvent( + EventState.FAILED, + merchantOrderId, + url, + EventType.REDEEM_FAILED, + exception)); + throw exception; + } + } - /** - * Gets the status of the subscription - * - * @param merchantSubscriptionId Subscription ID generated by the merchant - * @return SubscriptionStatusResponseV2 which contains the entire status of the given - * subscription ID - */ - @SneakyThrows - public SubscriptionStatusResponseV2 getSubscriptionStatus(String merchantSubscriptionId) { - final String url = - String.format( - SubscriptionConstants.SUBSCRIPTION_STATUS_API, merchantSubscriptionId); - try { - SubscriptionStatusResponseV2 response = - requestViaAuthRefresh( - HttpMethodType.GET, - null, - url, - null, - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildSubscriptionStatusEvent( - EventState.SUCCESS, - merchantSubscriptionId, - url, - EventType.SUBSCRIPTION_STATUS_SUCCESS)); - return response; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildSubscriptionStatusEvent( - EventState.FAILED, - merchantSubscriptionId, - url, - EventType.SUBSCRIPTION_STATUS_FAILED, - exception)); - throw exception; - } - } + /** + * Gets the status of the subscription + * + * @param merchantSubscriptionId Subscription ID generated by the merchant + * @return SubscriptionStatusResponseV2 which contains the entire status of the given + * subscription ID + */ + @SneakyThrows + public SubscriptionStatusResponseV2 getSubscriptionStatus(String merchantSubscriptionId) { + final String url = String.format( + SubscriptionConstants.SUBSCRIPTION_STATUS_API, merchantSubscriptionId); + try { + SubscriptionStatusResponseV2 response = requestViaAuthRefresh( + HttpMethodType.GET, + null, + url, + null, + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildSubscriptionStatusEvent( + EventState.SUCCESS, + merchantSubscriptionId, + url, + EventType.SUBSCRIPTION_STATUS_SUCCESS)); + return response; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildSubscriptionStatusEvent( + EventState.FAILED, + merchantSubscriptionId, + url, + EventType.SUBSCRIPTION_STATUS_FAILED, + exception)); + throw exception; + } + } - /** - * Gets the status for the order - * - * @param merchantOrderId Order ID generated by the merchant - * @return OrderStatusResponse which contains the entire status of the given order ID - */ - @SneakyThrows - public OrderStatusResponse getOrderStatus(String merchantOrderId) { - final String url = String.format(SubscriptionConstants.ORDER_STATUS_API, merchantOrderId); - try { - OrderStatusResponse response = - requestViaAuthRefresh( - HttpMethodType.GET, - null, - url, - null, - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildOrderStatusEvent( - EventState.SUCCESS, - merchantOrderId, - url, - FlowType.SUBSCRIPTION, - EventType.ORDER_STATUS_SUCCESS)); - return response; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildOrderStatusEvent( - EventState.FAILED, - merchantOrderId, - url, - FlowType.SUBSCRIPTION, - EventType.ORDER_STATUS_FAILED, - exception)); - throw exception; - } - } + /** + * Gets the status for the order + * + * @param merchantOrderId Order ID generated by the merchant + * @return OrderStatusResponse which contains the entire status of the given order ID + */ + @SneakyThrows + public OrderStatusResponse getOrderStatus(String merchantOrderId) { + final String url = String.format(SubscriptionConstants.ORDER_STATUS_API, merchantOrderId); + try { + OrderStatusResponse response = requestViaAuthRefresh( + HttpMethodType.GET, + null, + url, + null, + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildOrderStatusEvent( + EventState.SUCCESS, + merchantOrderId, + url, + FlowType.SUBSCRIPTION, + EventType.ORDER_STATUS_SUCCESS)); + return response; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildOrderStatusEvent( + EventState.FAILED, + merchantOrderId, + url, + FlowType.SUBSCRIPTION, + EventType.ORDER_STATUS_FAILED, + exception)); + throw exception; + } + } - /** - * Cancels/Stops the subscription for the given subscription ID - * - * @param merchantSubscriptionId Subscription ID generated by the merchant - */ - @SneakyThrows - public void cancelSubscription(String merchantSubscriptionId) { - final String url = String.format(SubscriptionConstants.CANCEL_API, merchantSubscriptionId); - try { - requestViaAuthRefresh( - HttpMethodType.POST, null, url, null, new TypeReference() {}, headers); - this.eventPublisher.send( - BaseEvent.buildSubscriptionCancelEvent( - EventState.SUCCESS, - merchantSubscriptionId, - url, - EventType.CANCEL_SUCCESS)); - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildSubscriptionCancelEvent( - EventState.FAILED, - merchantSubscriptionId, - url, - EventType.CANCEL_FAILED, - exception)); - throw exception; - } - } + /** + * Cancels/Stops the subscription for the given subscription ID + * + * @param merchantSubscriptionId Subscription ID generated by the merchant + */ + @SneakyThrows + public void cancelSubscription(String merchantSubscriptionId) { + final String url = String.format(SubscriptionConstants.CANCEL_API, merchantSubscriptionId); + try { + requestViaAuthRefresh( + HttpMethodType.POST, null, url, null, new TypeReference() {}, headers); + this.eventPublisher.send( + BaseEvent.buildSubscriptionCancelEvent( + EventState.SUCCESS, + merchantSubscriptionId, + url, + EventType.CANCEL_SUCCESS)); + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildSubscriptionCancelEvent( + EventState.FAILED, + merchantSubscriptionId, + url, + EventType.CANCEL_FAILED, + exception)); + throw exception; + } + } - /** - * Gets status of the given particular transaction ID - * - * @param transactionId Generated by the PhonePe Side - * @return OrderStatusResponse which contains the status of the particular transaction in the - * paymentDetails attribute - */ - @SneakyThrows - public OrderStatusResponse getTransactionStatus(String transactionId) { - final String url = - String.format(SubscriptionConstants.TRANSACTION_STATUS_API, transactionId); - try { - OrderStatusResponse response = - requestViaAuthRefresh( - HttpMethodType.GET, - null, - url, - null, - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildTransactionStatusEvent( - EventState.SUCCESS, - transactionId, - url, - FlowType.SUBSCRIPTION, - EventType.TRANSACTION_STATUS_SUCCESS)); - return response; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildTransactionStatusEvent( - EventState.FAILED, - transactionId, - url, - FlowType.SUBSCRIPTION, - EventType.TRANSACTION_STATUS_FAILED, - exception)); - throw exception; - } - } + /** + * Gets status of the given particular transaction ID + * + * @param transactionId Generated by the PhonePe Side + * @return OrderStatusResponse which contains the status of the particular transaction in the + * paymentDetails attribute + */ + @SneakyThrows + public OrderStatusResponse getTransactionStatus(String transactionId) { + final String url = String.format(SubscriptionConstants.TRANSACTION_STATUS_API, transactionId); + try { + OrderStatusResponse response = requestViaAuthRefresh( + HttpMethodType.GET, + null, + url, + null, + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildTransactionStatusEvent( + EventState.SUCCESS, + transactionId, + url, + FlowType.SUBSCRIPTION, + EventType.TRANSACTION_STATUS_SUCCESS)); + return response; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildTransactionStatusEvent( + EventState.FAILED, + transactionId, + url, + FlowType.SUBSCRIPTION, + EventType.TRANSACTION_STATUS_FAILED, + exception)); + throw exception; + } + } - /** - * Initiate refund of an order - * - * @param refundRequest Request object build using RefundRequest builder - * @return RefundResponse contains refund details for an order - */ - @SneakyThrows - public RefundResponse refund(RefundRequest refundRequest) { - final String url = SubscriptionConstants.REFUND_API; - try { - RefundResponse refundResponse = - requestViaAuthRefresh( - HttpMethodType.POST, - refundRequest, - url, - null, - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildRefundEvent( - EventState.SUCCESS, - refundRequest, - url, - FlowType.SUBSCRIPTION, - EventType.REFUND_SUCCESS)); - return refundResponse; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildRefundEvent( - EventState.FAILED, - refundRequest, - url, - FlowType.SUBSCRIPTION, - EventType.REFUND_FAILED, - exception)); - throw exception; - } - } + /** + * Initiate refund of an order + * + * @param refundRequest Request object build using RefundRequest builder + * @return RefundResponse contains refund details for an order + */ + @SneakyThrows + public RefundResponse refund(RefundRequest refundRequest) { + final String url = SubscriptionConstants.REFUND_API; + try { + RefundResponse refundResponse = requestViaAuthRefresh( + HttpMethodType.POST, + refundRequest, + url, + null, + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildRefundEvent( + EventState.SUCCESS, + refundRequest, + url, + FlowType.SUBSCRIPTION, + EventType.REFUND_SUCCESS)); + return refundResponse; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildRefundEvent( + EventState.FAILED, + refundRequest, + url, + FlowType.SUBSCRIPTION, + EventType.REFUND_FAILED, + exception)); + throw exception; + } + } - /** - * Get status of the refund initiated - * - * @param refundId Merchant Refund id for which you need the status - * @return RefundStatusResponse Refund status details - * @throws PhonePeException if any error occurs during the process - */ - @SneakyThrows - public RefundStatusResponse getRefundStatus(String refundId) { - final String url = String.format(SubscriptionConstants.REFUND_STATUS_API, refundId); - try { - RefundStatusResponse refundStatusResponse = - requestViaAuthRefresh( - HttpMethodType.GET, - null, - url, - null, - new TypeReference() {}, - headers); - this.eventPublisher.send( - BaseEvent.buildRefundStatusEvent( - EventState.SUCCESS, - refundId, - url, - FlowType.SUBSCRIPTION, - EventType.REFUND_STATUS_SUCCESS)); - return refundStatusResponse; - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildRefundStatusEvent( - EventState.FAILED, - refundId, - url, - FlowType.SUBSCRIPTION, - EventType.REFUND_STATUS_FAILED, - exception)); - throw exception; - } - } + /** + * Get status of the refund initiated + * + * @param refundId Merchant Refund id for which you need the status + * @return RefundStatusResponse Refund status details + * @throws PhonePeException if any error occurs during the process + */ + @SneakyThrows + public RefundStatusResponse getRefundStatus(String refundId) { + final String url = String.format(SubscriptionConstants.REFUND_STATUS_API, refundId); + try { + RefundStatusResponse refundStatusResponse = requestViaAuthRefresh( + HttpMethodType.GET, + null, + url, + null, + new TypeReference() {}, + headers); + this.eventPublisher.send( + BaseEvent.buildRefundStatusEvent( + EventState.SUCCESS, + refundId, + url, + FlowType.SUBSCRIPTION, + EventType.REFUND_STATUS_SUCCESS)); + return refundStatusResponse; + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildRefundStatusEvent( + EventState.FAILED, + refundId, + url, + FlowType.SUBSCRIPTION, + EventType.REFUND_STATUS_FAILED, + exception)); + throw exception; + } + } - /** - * Validate if the callback is valid - * - * @param username username set by the merchant on the dashboard - * @param password password set by the merchant on the dashboard - * @param authorization String data under `authorization` key of response headers - * @param responseBody Callback response body - * @return CallbackResponse Deserialized callback body - * @throws PhonePeException when callback is not valid - */ - @SneakyThrows - public CallbackResponse validateCallback( - String username, String password, String authorization, String responseBody) { - if (!CommonUtils.isCallbackValid(username, password, authorization)) { - throw new PhonePeException(417, "Invalid Callback"); - } - try { - return getObjectMapper().readValue(responseBody, CallbackResponse.class); - } catch (Exception exception) { - this.eventPublisher.send( - BaseEvent.buildCallbackSerializationFailedEvent( - EventState.FAILED, - FlowType.SUBSCRIPTION, - EventType.CALLBACK_SERIALIZATION_FAILED, - exception)); - throw exception; - } - } + /** + * Validate if the callback is valid + * + * @param username username set by the merchant on the dashboard + * @param password password set by the merchant on the dashboard + * @param authorization String data under `authorization` key of response headers + * @param responseBody Callback response body + * @return CallbackResponse Deserialized callback body + * @throws PhonePeException when callback is not valid + */ + @SneakyThrows + public CallbackResponse validateCallback( + String username, String password, String authorization, String responseBody) { + if (!CommonUtils.isCallbackValid(username, password, authorization)) { + throw new PhonePeException(417, "Invalid Callback"); + } + try { + return getObjectMapper().readValue(responseBody, CallbackResponse.class); + } catch (Exception exception) { + this.eventPublisher.send( + BaseEvent.buildCallbackSerializationFailedEvent( + EventState.FAILED, + FlowType.SUBSCRIPTION, + EventType.CALLBACK_SERIALIZATION_FAILED, + exception)); + throw exception; + } + } - /** Prepares the headers for Subscription Client */ - private void prepareHeaders() { - this.headers = new ArrayList<>(); - headers.add( - HttpHeaderPair.builder().key(Headers.CONTENT_TYPE).value(APPLICATION_JSON).build()); - headers.add( - HttpHeaderPair.builder().key(Headers.SOURCE).value(Headers.INTEGRATION).build()); - headers.add( - HttpHeaderPair.builder() - .key(Headers.SOURCE_VERSION) - .value(Headers.SUBSCRIPTION_API_VERSION) - .build()); - headers.add( - HttpHeaderPair.builder() - .key(Headers.SOURCE_PLATFORM) - .value(Headers.SDK_TYPE) - .build()); - headers.add( - HttpHeaderPair.builder() - .key(Headers.SOURCE_PLATFORM_VERSION) - .value(Headers.SDK_VERSION) - .build()); - } + /** Prepares the headers for Subscription Client */ + private void prepareHeaders() { + this.headers = new ArrayList<>(); + headers.add( + HttpHeaderPair.builder() + .key(Headers.CONTENT_TYPE) + .value(APPLICATION_JSON) + .build()); + headers.add( + HttpHeaderPair.builder() + .key(Headers.SOURCE) + .value(Headers.INTEGRATION) + .build()); + headers.add( + HttpHeaderPair.builder() + .key(Headers.SOURCE_VERSION) + .value(Headers.SUBSCRIPTION_API_VERSION) + .build()); + headers.add( + HttpHeaderPair.builder() + .key(Headers.SOURCE_PLATFORM) + .value(Headers.SDK_TYPE) + .build()); + headers.add( + HttpHeaderPair.builder() + .key(Headers.SOURCE_PLATFORM_VERSION) + .value(Headers.SDK_VERSION) + .build()); + } } diff --git a/src/main/java/com/phonepe/sdk/pg/subscription/v2/SubscriptionConstants.java b/src/main/java/com/phonepe/sdk/pg/subscription/v2/SubscriptionConstants.java index 0febd7a..423e1ed 100644 --- a/src/main/java/com/phonepe/sdk/pg/subscription/v2/SubscriptionConstants.java +++ b/src/main/java/com/phonepe/sdk/pg/subscription/v2/SubscriptionConstants.java @@ -20,13 +20,13 @@ @UtilityClass public class SubscriptionConstants { - public static final String SETUP_API = "/subscriptions/v2/setup"; - public static final String NOTIFY_API = "/subscriptions/v2/notify"; - public static final String REDEEM_API = "/subscriptions/v2/redeem"; - public static final String SUBSCRIPTION_STATUS_API = "/subscriptions/v2/%s/status"; - public static final String ORDER_STATUS_API = "/subscriptions/v2/order/%s/status"; - public static final String CANCEL_API = "/subscriptions/v2/%s/cancel"; - public static final String TRANSACTION_STATUS_API = "/subscriptions/v2/transaction/%s/status"; - public static final String REFUND_API = "/payments/v2/refund"; - public static final String REFUND_STATUS_API = "/payments/v2/refund/%s/status"; + public static final String SETUP_API = "/subscriptions/v2/setup"; + public static final String NOTIFY_API = "/subscriptions/v2/notify"; + public static final String REDEEM_API = "/subscriptions/v2/redeem"; + public static final String SUBSCRIPTION_STATUS_API = "/subscriptions/v2/%s/status"; + public static final String ORDER_STATUS_API = "/subscriptions/v2/order/%s/status"; + public static final String CANCEL_API = "/subscriptions/v2/%s/cancel"; + public static final String TRANSACTION_STATUS_API = "/subscriptions/v2/transaction/%s/status"; + public static final String REFUND_API = "/payments/v2/refund"; + public static final String REFUND_STATUS_API = "/payments/v2/refund/%s/status"; } diff --git a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/AmountType.java b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/AmountType.java index ffdd970..da8e7dc 100644 --- a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/AmountType.java +++ b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/AmountType.java @@ -16,6 +16,5 @@ package com.phonepe.sdk.pg.subscription.v2.models.request; public enum AmountType { - FIXED, - VARIABLE; + FIXED, VARIABLE; } diff --git a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/AuthWorkflowType.java b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/AuthWorkflowType.java index 0adb948..db72254 100644 --- a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/AuthWorkflowType.java +++ b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/AuthWorkflowType.java @@ -16,6 +16,5 @@ package com.phonepe.sdk.pg.subscription.v2.models.request; public enum AuthWorkflowType { - PENNY_DROP, - TRANSACTION, + PENNY_DROP, TRANSACTION, } diff --git a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/Frequency.java b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/Frequency.java index b595d2f..a308722 100644 --- a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/Frequency.java +++ b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/Frequency.java @@ -16,13 +16,5 @@ package com.phonepe.sdk.pg.subscription.v2.models.request; public enum Frequency { - DAILY, - WEEKLY, - MONTHLY, - YEARLY, - FORTNIGHTLY, - BIMONTHLY, - ON_DEMAND, - QUARTERLY, - HALFYEARLY + DAILY, WEEKLY, MONTHLY, YEARLY, FORTNIGHTLY, BIMONTHLY, ON_DEMAND, QUARTERLY, HALFYEARLY } diff --git a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/RedemptionRetryStrategy.java b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/RedemptionRetryStrategy.java index 569b678..0b683fe 100644 --- a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/RedemptionRetryStrategy.java +++ b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/RedemptionRetryStrategy.java @@ -16,6 +16,5 @@ package com.phonepe.sdk.pg.subscription.v2.models.request; public enum RedemptionRetryStrategy { - CUSTOM, - STANDARD; + CUSTOM, STANDARD; } diff --git a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/SubscriptionRedeemRequestV2.java b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/SubscriptionRedeemRequestV2.java index b9db87d..b288d72 100644 --- a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/SubscriptionRedeemRequestV2.java +++ b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/SubscriptionRedeemRequestV2.java @@ -23,9 +23,9 @@ @JsonInclude(Include.NON_NULL) public class SubscriptionRedeemRequestV2 { - private String merchantOrderId; + private String merchantOrderId; - public SubscriptionRedeemRequestV2(String merchantOrderId) { - this.merchantOrderId = merchantOrderId; - } + public SubscriptionRedeemRequestV2(String merchantOrderId) { + this.merchantOrderId = merchantOrderId; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/SubscriptionRedemptionPaymentFlow.java b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/SubscriptionRedemptionPaymentFlow.java index f2fe8a5..0a0149f 100644 --- a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/SubscriptionRedemptionPaymentFlow.java +++ b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/SubscriptionRedemptionPaymentFlow.java @@ -28,18 +28,18 @@ @JsonInclude(Include.NON_NULL) public class SubscriptionRedemptionPaymentFlow extends PaymentFlow { - private String merchantSubscriptionId; - private RedemptionRetryStrategy redemptionRetryStrategy; - private boolean autoDebit; + private String merchantSubscriptionId; + private RedemptionRetryStrategy redemptionRetryStrategy; + private boolean autoDebit; - @Builder - public SubscriptionRedemptionPaymentFlow( - String merchantSubscriptionId, - RedemptionRetryStrategy redemptionRetryStrategy, - boolean autoDebit) { - super(PaymentFlowType.SUBSCRIPTION_REDEMPTION); - this.merchantSubscriptionId = merchantSubscriptionId; - this.redemptionRetryStrategy = redemptionRetryStrategy; - this.autoDebit = autoDebit; - } + @Builder + public SubscriptionRedemptionPaymentFlow( + String merchantSubscriptionId, + RedemptionRetryStrategy redemptionRetryStrategy, + boolean autoDebit) { + super(PaymentFlowType.SUBSCRIPTION_REDEMPTION); + this.merchantSubscriptionId = merchantSubscriptionId; + this.redemptionRetryStrategy = redemptionRetryStrategy; + this.autoDebit = autoDebit; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/SubscriptionSetupPaymentFlow.java b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/SubscriptionSetupPaymentFlow.java index 06d9a73..0fdf08e 100644 --- a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/SubscriptionSetupPaymentFlow.java +++ b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/request/SubscriptionSetupPaymentFlow.java @@ -29,30 +29,30 @@ @JsonInclude(Include.NON_NULL) public class SubscriptionSetupPaymentFlow extends PaymentFlow { - private String merchantSubscriptionId; - private AuthWorkflowType authWorkflowType; - private AmountType amountType; - private Long maxAmount; - private Frequency frequency; - private Long expireAt; - private PaymentV2Instrument paymentMode; + private String merchantSubscriptionId; + private AuthWorkflowType authWorkflowType; + private AmountType amountType; + private Long maxAmount; + private Frequency frequency; + private Long expireAt; + private PaymentV2Instrument paymentMode; - @Builder - public SubscriptionSetupPaymentFlow( - String merchantSubscriptionId, - AuthWorkflowType authWorkflowType, - AmountType amountType, - Long maxAmount, - Frequency frequency, - Long expireAt, - PaymentV2Instrument paymentMode) { - super(PaymentFlowType.SUBSCRIPTION_SETUP); - this.merchantSubscriptionId = merchantSubscriptionId; - this.authWorkflowType = authWorkflowType; - this.amountType = amountType; - this.maxAmount = maxAmount; - this.frequency = frequency; - this.expireAt = expireAt; - this.paymentMode = paymentMode; - } + @Builder + public SubscriptionSetupPaymentFlow( + String merchantSubscriptionId, + AuthWorkflowType authWorkflowType, + AmountType amountType, + Long maxAmount, + Frequency frequency, + Long expireAt, + PaymentV2Instrument paymentMode) { + super(PaymentFlowType.SUBSCRIPTION_SETUP); + this.merchantSubscriptionId = merchantSubscriptionId; + this.authWorkflowType = authWorkflowType; + this.amountType = amountType; + this.maxAmount = maxAmount; + this.frequency = frequency; + this.expireAt = expireAt; + this.paymentMode = paymentMode; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/response/SubscriptionRedeemResponseV2.java b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/response/SubscriptionRedeemResponseV2.java index 463abfc..3aa2471 100644 --- a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/response/SubscriptionRedeemResponseV2.java +++ b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/response/SubscriptionRedeemResponseV2.java @@ -28,6 +28,6 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class SubscriptionRedeemResponseV2 { - private String transactionId; - private String state; + private String transactionId; + private String state; } diff --git a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/response/SubscriptionRedemptionPaymentFlowResponse.java b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/response/SubscriptionRedemptionPaymentFlowResponse.java index 8829f68..a937d6f 100644 --- a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/response/SubscriptionRedemptionPaymentFlowResponse.java +++ b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/response/SubscriptionRedemptionPaymentFlowResponse.java @@ -28,31 +28,31 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class SubscriptionRedemptionPaymentFlowResponse extends PaymentFlowResponse { - private String merchantSubscriptionId; - private RedemptionRetryStrategy redemptionRetryStrategy; - private boolean autoDebit; - private Long validAfter; - private Long validUpto; - private Long notifiedAt; + private String merchantSubscriptionId; + private RedemptionRetryStrategy redemptionRetryStrategy; + private boolean autoDebit; + private Long validAfter; + private Long validUpto; + private Long notifiedAt; - public SubscriptionRedemptionPaymentFlowResponse() { - super(PaymentFlowType.SUBSCRIPTION_REDEMPTION); - } + public SubscriptionRedemptionPaymentFlowResponse() { + super(PaymentFlowType.SUBSCRIPTION_REDEMPTION); + } - @Builder - public SubscriptionRedemptionPaymentFlowResponse( - String merchantSubscriptionId, - RedemptionRetryStrategy redemptionRetryStrategy, - boolean autoDebit, - Long validAfter, - Long validUpto, - Long notifiedAt) { - super(PaymentFlowType.SUBSCRIPTION_REDEMPTION); - this.merchantSubscriptionId = merchantSubscriptionId; - this.redemptionRetryStrategy = redemptionRetryStrategy; - this.autoDebit = autoDebit; - this.validAfter = validAfter; - this.validUpto = validUpto; - this.notifiedAt = notifiedAt; - } + @Builder + public SubscriptionRedemptionPaymentFlowResponse( + String merchantSubscriptionId, + RedemptionRetryStrategy redemptionRetryStrategy, + boolean autoDebit, + Long validAfter, + Long validUpto, + Long notifiedAt) { + super(PaymentFlowType.SUBSCRIPTION_REDEMPTION); + this.merchantSubscriptionId = merchantSubscriptionId; + this.redemptionRetryStrategy = redemptionRetryStrategy; + this.autoDebit = autoDebit; + this.validAfter = validAfter; + this.validUpto = validUpto; + this.notifiedAt = notifiedAt; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/response/SubscriptionSetupPaymentFlowResponse.java b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/response/SubscriptionSetupPaymentFlowResponse.java index 4afdace..a75e9bb 100644 --- a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/response/SubscriptionSetupPaymentFlowResponse.java +++ b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/response/SubscriptionSetupPaymentFlowResponse.java @@ -30,34 +30,34 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class SubscriptionSetupPaymentFlowResponse extends PaymentFlowResponse { - private String merchantSubscriptionId; - private AuthWorkflowType authWorkflowType; - private AmountType amountType; - private Long maxAmount; - private Frequency frequency; - private Long expireAt; - private String subscriptionId; + private String merchantSubscriptionId; + private AuthWorkflowType authWorkflowType; + private AmountType amountType; + private Long maxAmount; + private Frequency frequency; + private Long expireAt; + private String subscriptionId; - public SubscriptionSetupPaymentFlowResponse() { - super(PaymentFlowType.SUBSCRIPTION_SETUP); - } + public SubscriptionSetupPaymentFlowResponse() { + super(PaymentFlowType.SUBSCRIPTION_SETUP); + } - @Builder - public SubscriptionSetupPaymentFlowResponse( - String merchantSubscriptionId, - AuthWorkflowType authWorkflowType, - AmountType amountType, - Long maxAmount, - Frequency frequency, - Long expireAt, - String subscriptionId) { - super(PaymentFlowType.SUBSCRIPTION_SETUP); - this.merchantSubscriptionId = merchantSubscriptionId; - this.authWorkflowType = authWorkflowType; - this.amountType = amountType; - this.maxAmount = maxAmount; - this.frequency = frequency; - this.expireAt = expireAt; - this.subscriptionId = subscriptionId; - } + @Builder + public SubscriptionSetupPaymentFlowResponse( + String merchantSubscriptionId, + AuthWorkflowType authWorkflowType, + AmountType amountType, + Long maxAmount, + Frequency frequency, + Long expireAt, + String subscriptionId) { + super(PaymentFlowType.SUBSCRIPTION_SETUP); + this.merchantSubscriptionId = merchantSubscriptionId; + this.authWorkflowType = authWorkflowType; + this.amountType = amountType; + this.maxAmount = maxAmount; + this.frequency = frequency; + this.expireAt = expireAt; + this.subscriptionId = subscriptionId; + } } diff --git a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/response/SubscriptionStatusResponseV2.java b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/response/SubscriptionStatusResponseV2.java index af2f2b5..087c8eb 100644 --- a/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/response/SubscriptionStatusResponseV2.java +++ b/src/main/java/com/phonepe/sdk/pg/subscription/v2/models/response/SubscriptionStatusResponseV2.java @@ -31,14 +31,14 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class SubscriptionStatusResponseV2 { - private String merchantSubscriptionId; - private String subscriptionId; - private String state; - private AuthWorkflowType authWorkflowType; - private AmountType amountType; - private Long maxAmount; - private Frequency frequency; - private Long expireAt; - private Long pauseStartDate; - private Long pauseEndDate; + private String merchantSubscriptionId; + private String subscriptionId; + private String state; + private AuthWorkflowType authWorkflowType; + private AmountType amountType; + private Long maxAmount; + private Frequency frequency; + private Long expireAt; + private Long pauseStartDate; + private Long pauseEndDate; }