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