3636use Adyen \Model \Checkout \Name ;
3737use Adyen \Model \Checkout \PaymentResponse ;
3838use Adyen \Service \Checkout \PaymentsApi ;
39+ use Adyen \Shopware \Handlers \AbstractPaymentMethodHandler ;
3940use Adyen \Shopware \Models \PaymentRequest as IntegrationPaymentRequest ;
4041use Adyen \Shopware \PaymentMethods \RatepayDirectdebitPaymentMethod ;
4142use Adyen \Shopware \PaymentMethods \RatepayPaymentMethod ;
43+ use Adyen \Shopware \Service \CaptureService ;
4244use Adyen \Shopware \Service \ClientService ;
4345use Adyen \Shopware \Service \ConfigurationService ;
4446use Adyen \Shopware \Service \Repository \SalesChannelRepository ;
@@ -86,6 +88,7 @@ class PaymentRequestService
8688 /**
8789 * @param ClientService $clientService
8890 * @param ConfigurationService $configurationService
91+ * @param CaptureService $captureService
8992 * @param Currency $currency
9093 * @param CheckoutStateDataValidator $checkoutStateDataValidator
9194 * @param RatePayDeviceFingerprintParamsProvider $ratePayFingerprintParamsProvider
@@ -97,6 +100,7 @@ class PaymentRequestService
97100 public function __construct (
98101 private readonly ClientService $ clientService ,
99102 private readonly ConfigurationService $ configurationService ,
103+ private readonly CaptureService $ captureService ,
100104 private readonly Currency $ currency ,
101105 private readonly CheckoutStateDataValidator $ checkoutStateDataValidator ,
102106 private readonly RatePayDeviceFingerprintParamsProvider $ ratePayFingerprintParamsProvider ,
@@ -119,6 +123,7 @@ public function __construct(
119123 * @param array $adyenOrderData
120124 * @param bool $isOpenInvoice
121125 * @param string $shopperInteraction
126+ * @param string $paymentMethodHandler
122127 *
123128 * @return IntegrationPaymentRequest
124129 */
@@ -131,7 +136,8 @@ public function buildPaymentRequestFromOrder(
131136 ?int $ partialAmount = null ,
132137 array $ adyenOrderData = [],
133138 bool $ isOpenInvoice = false ,
134- string $ shopperInteraction = self ::SHOPPER_INTERACTION_ECOMMERCE
139+ string $ shopperInteraction = self ::SHOPPER_INTERACTION_ECOMMERCE ,
140+ string $ paymentMethodHandler = AbstractPaymentMethodHandler::class
135141 ): IntegrationPaymentRequest {
136142 $ paymentRequest = new IntegrationPaymentRequest ($ stateData );
137143
@@ -209,12 +215,15 @@ public function buildPaymentRequestFromOrder(
209215 $ this ->salesChannelRepository ->getCurrentDomainUrl ($ salesChannelContext );
210216
211217 $ paymentRequest ->setOrigin ($ origin );
212- $ paymentRequest ->setAdditionalData ([
213- 'allow3DS2 ' => true ,
214- 'manualCapture ' => (bool )$ this ->configurationService ->isManualCaptureActive (
218+
219+ $ this ->setAdditionalRequestData (
220+ $ paymentRequest ,
221+ $ this ->captureService ->isManualCapture (
222+ $ paymentMethodHandler ,
215223 $ salesChannelContext ->getSalesChannel ()->getId ()
216224 ),
217- ]);
225+ $ isOpenInvoice
226+ );
218227 $ paymentRequest ->setChannel ('Web ' );
219228
220229 // Set order data for multi-payment scenarios
@@ -290,12 +299,14 @@ public function buildPaymentRequestFromCart(
290299 }
291300
292301 $ paymentRequest ->setOrigin ($ this ->salesChannelRepository ->getCurrentDomainUrl ($ salesChannelContext ));
293- $ paymentRequest ->setAdditionalData ([
294- 'allow3DS2 ' => true ,
295- 'manualCapture ' => (bool )$ this ->configurationService ->isManualCaptureActive (
302+
303+ // Express checkout never uses an open invoice method, so the manual capture setting decides on its own.
304+ $ this ->setAdditionalRequestData (
305+ $ paymentRequest ,
306+ (bool )$ this ->configurationService ->isManualCaptureActive (
296307 $ salesChannelContext ->getSalesChannel ()->getId ()
297- ),
298- ] );
308+ )
309+ );
299310 $ paymentRequest ->setChannel ('Web ' );
300311 $ paymentRequest ->setShopperInteraction (self ::SHOPPER_INTERACTION_ECOMMERCE );
301312
@@ -349,6 +360,29 @@ public function executePayment(
349360 }
350361 }
351362
363+ /**
364+ * @param IntegrationPaymentRequest $paymentRequest
365+ * @param bool $isManualCapture
366+ * @param bool $isOpenInvoice
367+ *
368+ * @return void
369+ */
370+ protected function setAdditionalRequestData (
371+ IntegrationPaymentRequest $ paymentRequest ,
372+ bool $ isManualCapture ,
373+ bool $ isOpenInvoice = false
374+ ): void {
375+ $ additionalData = ['allow3DS2 ' => true ];
376+
377+ if ($ isManualCapture ) {
378+ $ additionalData ['manualCapture ' ] = true ;
379+ } elseif ($ isOpenInvoice ) {
380+ $ paymentRequest ->setCaptureDelayHours (0 );
381+ }
382+
383+ $ paymentRequest ->setAdditionalData ($ additionalData );
384+ }
385+
352386 /**
353387 * Set browser info on payment request
354388 *
0 commit comments