Merge pull request #1595 from woocommerce/PCP-1906-capture-on-status-change-improvements

Apply Capture On Status Change only when order contains PayPal payment method (1906)
This commit is contained in:
Emili Castells 2023-09-08 09:54:42 +02:00 committed by GitHub
commit b4f8478920
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View file

@ -241,7 +241,7 @@ class RenewalHandler {
* @param \WC_Customer $customer The customer. * @param \WC_Customer $customer The customer.
* @param \WC_Order $wc_order The current WooCommerce order we want to process. * @param \WC_Order $wc_order The current WooCommerce order we want to process.
* *
* @return PaymentToken|null * @return PaymentToken|null|false
*/ */
private function get_token_for_customer( \WC_Customer $customer, \WC_Order $wc_order ) { private function get_token_for_customer( \WC_Customer $customer, \WC_Order $wc_order ) {
/** /**

View file

@ -44,4 +44,14 @@ class GatewayRepository {
} }
); );
} }
/**
* Indicates if a given gateway ID is registered.
*
* @param string $gateway_id The gateway ID.
* @return bool
*/
public function exists( string $gateway_id ): bool {
return in_array( $gateway_id, $this->ppcp_gateway_ids, true );
}
} }

View file

@ -33,6 +33,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Checkout\DisableGateways;
use WooCommerce\PayPalCommerce\WcGateway\Endpoint\ReturnUrlEndpoint; use WooCommerce\PayPalCommerce\WcGateway\Endpoint\ReturnUrlEndpoint;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException; use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\GatewayRepository;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCProductStatus; use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCProductStatus;
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus; use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus;
@ -356,6 +357,14 @@ class WCGatewayModule implements ModuleInterface {
return; return;
} }
$gateway_repository = $c->get( 'wcgateway.gateway-repository' );
assert( $gateway_repository instanceof GatewayRepository );
// Only allow to proceed if the payment method is one of our Gateways.
if ( ! $gateway_repository->exists( $wc_order->get_payment_method() ) ) {
return;
}
$intent = strtoupper( (string) $wc_order->get_meta( PayPalGateway::INTENT_META_KEY ) ); $intent = strtoupper( (string) $wc_order->get_meta( PayPalGateway::INTENT_META_KEY ) );
$captured = wc_string_to_bool( $wc_order->get_meta( AuthorizedPaymentsProcessor::CAPTURED_META_KEY ) ); $captured = wc_string_to_bool( $wc_order->get_meta( AuthorizedPaymentsProcessor::CAPTURED_META_KEY ) );
if ( $intent !== 'AUTHORIZE' || $captured ) { if ( $intent !== 'AUTHORIZE' || $captured ) {