diff --git a/changelog.txt b/changelog.txt index 17c03cb83..e8de50404 100644 --- a/changelog.txt +++ b/changelog.txt @@ -8,6 +8,7 @@ * Fix - Google Pay and Apple Pay Settings button from Connection tab have wrong links #2273 * Fix - Smart Buttons in Block Checkout not respecting the location setting (2830) #2278 * Fix - Disable Pay Upon Invoice if billing/shipping country not set #2281 +* Fix - Critical error on pay for order page when we try to pay with ACDC gateway #2321 * Enhancement - Enable shipping callback for WC subscriptions #2259 * Enhancement - Disable the shipping callback for "venmo" when vaulting is active #2269 * Enhancement - Improve "Could not retrieve order" error message #2271 diff --git a/modules/ppcp-blocks/resources/js/Components/card-fields.js b/modules/ppcp-blocks/resources/js/Components/card-fields.js index f7ff6c7e0..542d40bd3 100644 --- a/modules/ppcp-blocks/resources/js/Components/card-fields.js +++ b/modules/ppcp-blocks/resources/js/Components/card-fields.js @@ -25,6 +25,14 @@ export function CardFields({config, eventRegistration, emitResponse, components} } const hasSubscriptionProducts = cartHasSubscriptionProducts(config.scriptData); + useEffect(() => { + localStorage.removeItem('ppcp-save-card-payment'); + + if(hasSubscriptionProducts) { + localStorage.setItem('ppcp-save-card-payment', 'true'); + } + + }, [hasSubscriptionProducts]) useEffect( () => diff --git a/modules/ppcp-blocks/resources/js/card-fields-config.js b/modules/ppcp-blocks/resources/js/card-fields-config.js index 37d939a5f..6c0101c3b 100644 --- a/modules/ppcp-blocks/resources/js/card-fields-config.js +++ b/modules/ppcp-blocks/resources/js/card-fields-config.js @@ -35,7 +35,6 @@ export async function onApprove(data) { }) .then((response) => response.json()) .then((data) => { - console.log(data) localStorage.removeItem('ppcp-save-card-payment'); }) .catch((err) => { diff --git a/modules/ppcp-wc-gateway/src/Endpoint/CaptureCardPayment.php b/modules/ppcp-wc-gateway/src/Endpoint/CaptureCardPayment.php index bfb8b4bc4..a2289acee 100644 --- a/modules/ppcp-wc-gateway/src/Endpoint/CaptureCardPayment.php +++ b/modules/ppcp-wc-gateway/src/Endpoint/CaptureCardPayment.php @@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Endpoint; use Psr\Log\LoggerInterface; use RuntimeException; use stdClass; +use WC_Order; use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\RequestTrait; @@ -131,16 +132,25 @@ class CaptureCardPayment { /** * Creates PayPal order from the given card vault id. * - * @param string $vault_id Vault id. - * @param string $custom_id Custom id. - * @param string $invoice_id Invoice id. + * @param string $vault_id Vault id. + * @param string $custom_id Custom id. + * @param string $invoice_id Invoice id. + * @param WC_Order $wc_order The WC order. * @return stdClass * @throws RuntimeException When request fails. */ - public function create_order( string $vault_id, string $custom_id, string $invoice_id ): stdClass { + public function create_order( string $vault_id, string $custom_id, string $invoice_id, WC_Order $wc_order ): stdClass { $intent = $this->settings->has( 'intent' ) && strtoupper( (string) $this->settings->get( 'intent' ) ) === 'AUTHORIZE' ? 'AUTHORIZE' : 'CAPTURE'; $items = array( $this->purchase_unit_factory->from_wc_cart() ); + // phpcs:disable WordPress.Security.NonceVerification + $pay_for_order = wc_clean( wp_unslash( $_GET['pay_for_order'] ?? '' ) ); + $order_key = wc_clean( wp_unslash( $_GET['key'] ?? '' ) ); + // phpcs:enable + if ( $pay_for_order && $order_key === $wc_order->get_order_key() ) { + $items = array( $this->purchase_unit_factory->from_wc_order( $wc_order ) ); + } + $data = array( 'intent' => $intent, 'purchase_units' => array_map( diff --git a/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php b/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php index 6e21e70df..cea67537f 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php @@ -490,7 +490,7 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC { $custom_id = $wc_order->get_order_number(); $invoice_id = $this->prefix . $wc_order->get_order_number(); - $create_order = $this->capture_card_payment->create_order( $token->get_token(), $custom_id, $invoice_id ); + $create_order = $this->capture_card_payment->create_order( $token->get_token(), $custom_id, $invoice_id, $wc_order ); $order = $this->order_endpoint->order( $create_order->id ); $wc_order->update_meta_data( PayPalGateway::INTENT_META_KEY, $order->intent() ); diff --git a/readme.txt b/readme.txt index ac1315805..1542090d5 100644 --- a/readme.txt +++ b/readme.txt @@ -187,6 +187,7 @@ If you encounter issues with the PayPal buttons not appearing after an update, p * Fix - Google Pay and Apple Pay Settings button from Connection tab have wrong links #2273 * Fix - Smart Buttons in Block Checkout not respecting the location setting (2830) #2278 * Fix - Disable Pay Upon Invoice if billing/shipping country not set #2281 +* Fix - Critical error on pay for order page when we try to pay with ACDC gateway #2321 * Enhancement - Enable shipping callback for WC subscriptions #2259 * Enhancement - Disable the shipping callback for "venmo" when vaulting is active #2269 * Enhancement - Improve "Could not retrieve order" error message #2271