From a7cae9b3e6fc05914cc2a8c5b416a57dc58c25a5 Mon Sep 17 00:00:00 2001 From: Crescenzo Rega Date: Mon, 4 Nov 2024 12:40:12 +0100 Subject: [PATCH] LPD-40881 Enable virtual items with no shipping address to be processed via Stripe --- .../stripe/AuthorizeRestController.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/workspaces/liferay-stripe-workspace/client-extensions/liferay-stripe-commerce-payment-integration/src/main/java/com/liferay/stripe/AuthorizeRestController.java b/workspaces/liferay-stripe-workspace/client-extensions/liferay-stripe-commerce-payment-integration/src/main/java/com/liferay/stripe/AuthorizeRestController.java index 09a9e56a9dbba1..f244aac05ecd76 100644 --- a/workspaces/liferay-stripe-workspace/client-extensions/liferay-stripe-commerce-payment-integration/src/main/java/com/liferay/stripe/AuthorizeRestController.java +++ b/workspaces/liferay-stripe-workspace/client-extensions/liferay-stripe-commerce-payment-integration/src/main/java/com/liferay/stripe/AuthorizeRestController.java @@ -128,7 +128,7 @@ private Session _createSession( String.class ).block())); - sessionCreateParams = SessionCreateParams.builder( + SessionCreateParams.Builder builder = SessionCreateParams.builder( ).addAllLineItem( _getLineItems( orderJSONObject.getString("currencyCode"), @@ -136,11 +136,6 @@ private Session _createSession( orderJSONObject.getJSONArray("orderItems")) ).addPaymentMethodType( SessionCreateParams.PaymentMethodType.CARD - ).addShippingOption( - _getShippingOption( - orderJSONObject.getString("currencyCode"), - orderJSONObject.getLong("shippingAmountValue"), - orderJSONObject.getString("shippingOption")) ).setCancelUrl( commercePaymentEntryJSONObject.getString("cancelURL") ).setCurrency( @@ -149,7 +144,17 @@ private Session _createSession( SessionCreateParams.Mode.PAYMENT ).setSuccessUrl( commercePaymentEntryJSONObject.getString("callbackURL") - ).build(); + ); + + if (orderJSONObject.getBoolean("shippable")) { + builder.addShippingOption( + _getShippingOption( + orderJSONObject.getString("currencyCode"), + orderJSONObject.getLong("shippingAmountValue"), + orderJSONObject.getString("shippingOption"))); + } + + sessionCreateParams = builder.build(); } else { sessionCreateParams = SessionCreateParams.builder(