| @@ -13,9 +13,9 @@ | ||
| 13 | 13 | protected $gateway; |
| 14 | 14 | |
| 15 | 15 | protected $allowed_country_codes; |
| 16 | 16 | |
| 17 | - public function initialize() | |
| 17 | + public function initialize(): void | |
| 18 | 18 | { |
| 19 | 19 | if (class_exists('WC_Blocks_Utils')) { |
| 20 | 20 | if (\WC_Blocks_Utils::has_block_in_page(wc_get_page_id('checkout'), 'woocommerce/checkout') || |
| 21 | 21 | \WC_Blocks_Utils::has_block_in_page(wc_get_page_id('cart'), 'woocommerce/cart') |
| @@ -84,9 +84,13 @@ | ||
| 84 | 84 | // Remove tokenization from supported features if outside allowed amount range |
| 85 | 85 | $features = array_diff($features, ['tokenization']); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - return $features; | |
| 88 | + // array_diff() preserves original keys, leaving gaps; a PHP array with non-sequential | |
| 89 | + // keys is JSON-encoded as an object, but WC Blocks' registerPaymentMethod() requires | |
| 90 | + // supports.features to be a plain array (or undefined), or it throws and the whole | |
| 91 | + // checkout payment-methods list fails to render. | |
| 92 | + return array_values($features); | |
| 89 | 93 | } |
| 90 | 94 | |
| 91 | 95 | /** |
| 92 | 96 | * Returns an associative array of data to be exposed for the payment method's client side. |
| @@ -112,7 +116,8 @@ | ||
| 112 | 116 | 'title' => $this->gateway->title, |
| 113 | 117 | 'description' => $this->gateway->description, |
| 114 | 118 | 'allowed_country_codes' => $this->allowed_country_codes, |
| 115 | 119 | 'save_card' => $save_card, |
| 120 | + 'wp_nonce' => wp_create_nonce('woocommerce-process_checkout'), | |
| 116 | 121 | ]; |
| 117 | 122 | } |
| 118 | 123 | } |