From 3f89e7237a44acecbd2c239a1d56a55ce8713f59 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Mon, 3 Aug 2026 12:23:24 +0500 Subject: [PATCH 1/9] Include new parameters in session and authorize to support MarketPay integration --- assets/js/applepay.js | 7 +- classes/core/ApplePay.php | 61 +++++++++++- composer.json | 2 +- composer.lock | 165 +++++++++++++++------------------ includes/AltapayFormFields.php | 7 ++ views/paymentClass.tpl | 2 + 6 files changed, 153 insertions(+), 91 deletions(-) diff --git a/assets/js/applepay.js b/assets/js/applepay.js index 0ee037ff..bb37cd24 100644 --- a/assets/js/applepay.js +++ b/assets/js/applepay.js @@ -138,7 +138,11 @@ function onApplePayButtonClicked(applepay_obj, createSession, wc_checkout_form, ajax_nonce: applepay_obj.nonce, action: 'validate_merchant', validation_url: event.validationURL, - terminal: applepay_obj.terminal + terminal: applepay_obj.terminal, + applepay_payment_method: applepay_obj.applepay_payment_method, + order_id: order_id, + amount: applepay_obj.subtotal, + currency: applepay_obj.currency }, function (res) { if (res.success === true) { @@ -185,6 +189,7 @@ function onApplePayButtonClicked(applepay_obj, createSession, wc_checkout_form, action: 'card_wallet_authorize', provider_data: JSON.stringify( event.payment.token ), terminal: applepay_obj.terminal, + applepay_payment_method: applepay_obj.applepay_payment_method, order_id: order_id }, function (res) { diff --git a/classes/core/ApplePay.php b/classes/core/ApplePay.php index 0e4e76fc..86c61f5a 100644 --- a/classes/core/ApplePay.php +++ b/classes/core/ApplePay.php @@ -86,6 +86,27 @@ public function altapay_load_apple_pay_script() { ); } + /** + * Whether the Apple Pay has the legacy flow enabled. + * + * @param string $payment_method. + * @return bool + */ + private function is_legacy_apple_pay_flow( $payment_method ) { + + if ( ! $payment_method ) { + return true; + } + + $settings = get_option( 'woocommerce_' . $payment_method . '_settings' ); + + if ( ! is_array( $settings ) ) { + return true; + } + + return ( $settings['apple_pay_legacy_flow'] ?? 'yes' ) === 'yes'; + } + /** * Validate Apple Pay Session * @@ -100,16 +121,42 @@ public function applepay_validate_merchant() { $terminal = isset( $_POST['terminal'] ) ? sanitize_text_field( wp_unslash( $_POST['terminal'] ) ) : ''; $validation_url = isset( $_POST['validation_url'] ) ? sanitize_text_field( wp_unslash( $_POST['validation_url'] ) ) : ''; + $applepay_payment_method = isset( $_POST['applepay_payment_method'] ) ? sanitize_text_field( wp_unslash( $_POST['applepay_payment_method'] ) ) : ''; + $order_id = isset( $_POST['order_id'] ) ? absint( $_POST['order_id'] ) : 0; + $order = $order_id ? wc_get_order( $order_id ) : false; $request = new CardWalletSession( $this->getAuth() ); $request->setTerminal( $terminal ) ->setValidationUrl( $validation_url ) ->setDomain( $_SERVER['HTTP_HOST'] ); + if ( ! $this->is_legacy_apple_pay_flow( $applepay_payment_method ) ) { + $request->setShopOrderId( $_POST['order_id'] ) + ->setAmount( (float) $_POST['amount'] ) + ->setCurrency( $_POST['currency'] ) + ->setApplePayRequestData( [ + 'validationUrl' => $validation_url, + 'domain' => $_SERVER['HTTP_HOST'] + ] ); + } + try { $response = $request->call(); if ( $response->Result === 'Success' ) { - wp_send_json_success( $response->ApplePaySession, 200 ); + if ( isset( $response->ApplePaySession ) ) { + wp_send_json_success( $response->ApplePaySession, 200 ); + } elseif ( isset( $response->WalletData->Session ) ) { + $transaction = ! empty( $response->Transactions ) ? reset( $response->Transactions ) : null; + + if ( $order && isset( $transaction->PaymentId ) ) { + $order->update_meta_data( 'altapay_payment_id', $transaction->PaymentId ); + $order->save(); + } + wp_send_json_success( $response->WalletData->Session, 200 ); + } else { + wc_add_notice( __( 'Payment failed.', 'altapay' ), 'error' ); + wp_send_json_error( array( 'redirect' => wc_get_cart_url() ) ); + } } else { wc_add_notice( __( 'Payment failed.', 'altapay' ), 'error' ); wp_send_json_error( array( 'redirect' => wc_get_cart_url() ) ); @@ -134,9 +181,16 @@ public function applepay_card_wallet_authorize() { $provider_data = isset( $_POST['provider_data'] ) ? sanitize_text_field( wp_unslash( $_POST['provider_data'] ) ) : ''; $terminal = isset( $_POST['terminal'] ) ? sanitize_text_field( wp_unslash( $_POST['terminal'] ) ) : ''; + $applepay_payment_method = isset( $_POST['applepay_payment_method'] ) ? sanitize_text_field( wp_unslash( $_POST['applepay_payment_method'] ) ) : ''; $order_id = isset( $_POST['order_id'] ) ? sanitize_text_field( wp_unslash( $_POST['order_id'] ) ) : ''; $order = wc_get_order( $order_id ); + $legacy_flow = $this->is_legacy_apple_pay_flow( $applepay_payment_method ); + + if ( ! $legacy_flow ) { + $altapay_payment_id = $order->get_meta( 'altapay_payment_id' ); + } + $payment_gateways = WC()->payment_gateways()->payment_gateways(); $payment_method = $order->get_payment_method(); @@ -162,6 +216,10 @@ public function applepay_card_wallet_authorize() { ->setOrderLines( $order_lines ) ->setSaleReconciliationIdentifier( wp_generate_uuid4() ); + if ( ! $legacy_flow ) { + $request->setPaymentId( $altapay_payment_id ); + } + $payment_type = 'payment'; foreach ( $payment_gateways as $key => $payment_gateway ) { @@ -233,6 +291,7 @@ public function applepay_woocommerce_after_checkout_form() { 'subtotal' => WC()->cart->get_total( 'edit' ), 'terminal' => $payment_gateway->terminal, 'apply_pay_label' => $payment_gateway->apple_pay_label, + 'apple_pay_legacy_flow' => $payment_gateway->apple_pay_legacy_flow, 'apple_pay_supported_networks' => $payment_gateway->get_option('apple_pay_supported_networks'), 'applepay_payment_method' => $payment_gateway->id ); diff --git a/composer.json b/composer.json index 0b28f80a..ebe15cdf 100755 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ }, "require": { "php": "^7.4 || ^8.0", - "altapay/api-php":"^3.5.9", + "altapay/api-php":"^3.6.1", "eftec/bladeone":"^4.4", "humbug/php-scoper": "0.17.5" }, diff --git a/composer.lock b/composer.lock index 927d68a8..786473a9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7aef1851ad280240ea498159f57c12ac", + "content-hash": "4a7755314d876e5608b5735dd509db60", "packages": [ { "name": "altapay/api-php", - "version": "3.5.9", + "version": "3.6.1", "source": { "type": "git", "url": "https://github.com/AltaPay/api-php.git", - "reference": "9459d5f5f2d0a1bbed07d88328f67130a5d39b62" + "reference": "d9dea2b34a810d2726bb0e11312f66fc1c56cebb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/AltaPay/api-php/zipball/9459d5f5f2d0a1bbed07d88328f67130a5d39b62", - "reference": "9459d5f5f2d0a1bbed07d88328f67130a5d39b62", + "url": "https://api.github.com/repos/AltaPay/api-php/zipball/d9dea2b34a810d2726bb0e11312f66fc1c56cebb", + "reference": "d9dea2b34a810d2726bb0e11312f66fc1c56cebb", "shasum": "" }, "require": { @@ -58,9 +58,9 @@ ], "support": { "issues": "https://github.com/AltaPay/api-php/issues", - "source": "https://github.com/AltaPay/api-php/tree/3.5.9" + "source": "https://github.com/AltaPay/api-php/tree/3.6.1" }, - "time": "2026-05-12T08:50:55+00:00" + "time": "2026-07-23T16:20:18+00:00" }, { "name": "composer/package-versions-deprecated", @@ -133,6 +133,7 @@ "type": "tidelift" } ], + "abandoned": true, "time": "2022-01-17T14:14:24+00:00" }, { @@ -280,25 +281,26 @@ }, { "name": "guzzlehttp/guzzle", - "version": "7.10.0", + "version": "7.15.2", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "b51ac707cfa420b7bfd4e4d5e510ba8008e822b4" + "reference": "744101956d78b7c1384d0cbf379db13e859167bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/b51ac707cfa420b7bfd4e4d5e510ba8008e822b4", - "reference": "b51ac707cfa420b7bfd4e4d5e510ba8008e822b4", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/744101956d78b7c1384d0cbf379db13e859167bf", + "reference": "744101956d78b7c1384d0cbf379db13e859167bf", "shasum": "" }, "require": { "ext-json": "*", - "guzzlehttp/promises": "^2.3", - "guzzlehttp/psr7": "^2.8", + "guzzlehttp/promises": "^2.5.1", + "guzzlehttp/psr7": "^2.13", "php": "^7.2.5 || ^8.0", "psr/http-client": "^1.0", - "symfony/deprecation-contracts": "^2.2 || ^3.0" + "symfony/deprecation-contracts": "^2.5 || ^3.0", + "symfony/polyfill-php80": "^1.25" }, "provide": { "psr/http-client-implementation": "1.0" @@ -306,9 +308,10 @@ "require-dev": { "bamarni/composer-bin-plugin": "^1.8.2", "ext-curl": "*", - "guzzle/client-integration-tests": "3.0.2", + "guzzle/client-integration-tests": "3.0.3", + "guzzlehttp/test-server": "^0.7", "php-http/message-factory": "^1.1", - "phpunit/phpunit": "^8.5.39 || ^9.6.20", + "phpunit/phpunit": "^8.5.52 || ^9.6.34", "psr/log": "^1.1 || ^2.0 || ^3.0" }, "suggest": { @@ -386,7 +389,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.10.0" + "source": "https://github.com/guzzle/guzzle/tree/7.15.2" }, "funding": [ { @@ -402,28 +405,29 @@ "type": "tidelift" } ], - "time": "2025-08-23T22:36:01+00:00" + "time": "2026-07-26T23:23:20+00:00" }, { "name": "guzzlehttp/promises", - "version": "2.3.0", + "version": "2.5.1", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "481557b130ef3790cf82b713667b43030dc9c957" + "reference": "9ad1e4fc607446a055b95870c7f668e93b5cff29" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/481557b130ef3790cf82b713667b43030dc9c957", - "reference": "481557b130ef3790cf82b713667b43030dc9c957", + "url": "https://api.github.com/repos/guzzle/promises/zipball/9ad1e4fc607446a055b95870c7f668e93b5cff29", + "reference": "9ad1e4fc607446a055b95870c7f668e93b5cff29", "shasum": "" }, "require": { - "php": "^7.2.5 || ^8.0" + "php": "^7.2.5 || ^8.0", + "symfony/deprecation-contracts": "^2.5 || ^3.0" }, "require-dev": { "bamarni/composer-bin-plugin": "^1.8.2", - "phpunit/phpunit": "^8.5.44 || ^9.6.25" + "phpunit/phpunit": "^8.5.52 || ^9.6.34" }, "type": "library", "extra": { @@ -469,7 +473,7 @@ ], "support": { "issues": "https://github.com/guzzle/promises/issues", - "source": "https://github.com/guzzle/promises/tree/2.3.0" + "source": "https://github.com/guzzle/promises/tree/2.5.1" }, "funding": [ { @@ -485,27 +489,29 @@ "type": "tidelift" } ], - "time": "2025-08-22T14:34:08+00:00" + "time": "2026-07-08T15:48:39+00:00" }, { "name": "guzzlehttp/psr7", - "version": "2.9.0", + "version": "2.13.0", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "7d0ed42f28e42d61352a7a79de682e5e67fec884" + "reference": "dad89620b7a6edb60c15858442eb2e408b45d8f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/7d0ed42f28e42d61352a7a79de682e5e67fec884", - "reference": "7d0ed42f28e42d61352a7a79de682e5e67fec884", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/dad89620b7a6edb60c15858442eb2e408b45d8f4", + "reference": "dad89620b7a6edb60c15858442eb2e408b45d8f4", "shasum": "" }, "require": { "php": "^7.2.5 || ^8.0", "psr/http-factory": "^1.0", "psr/http-message": "^1.1 || ^2.0", - "ralouphie/getallheaders": "^3.0" + "ralouphie/getallheaders": "^3.0", + "symfony/deprecation-contracts": "^2.5 || ^3.0", + "symfony/polyfill-php80": "^1.25" }, "provide": { "psr/http-factory-implementation": "1.0", @@ -513,9 +519,9 @@ }, "require-dev": { "bamarni/composer-bin-plugin": "^1.8.2", - "http-interop/http-factory-tests": "0.9.0", + "http-interop/http-factory-tests": "1.1.0", "jshttp/mime-db": "1.54.0.1", - "phpunit/phpunit": "^8.5.44 || ^9.6.25" + "phpunit/phpunit": "^8.5.52 || ^9.6.34" }, "suggest": { "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" @@ -586,7 +592,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.9.0" + "source": "https://github.com/guzzle/psr7/tree/2.13.0" }, "funding": [ { @@ -602,7 +608,7 @@ "type": "tidelift" } ], - "time": "2026-03-10T16:41:02+00:00" + "time": "2026-07-16T22:23:49+00:00" }, { "name": "humbug/php-scoper", @@ -1700,16 +1706,16 @@ }, { "name": "symfony/polyfill-intl-grapheme", - "version": "v1.37.0", + "version": "v1.41.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "4864388bfbd3001ce88e234fab652acd91fdc57e" + "reference": "bb899c1db0aa8127dc3afe8cda4a67eb24915f8d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/4864388bfbd3001ce88e234fab652acd91fdc57e", - "reference": "4864388bfbd3001ce88e234fab652acd91fdc57e", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/bb899c1db0aa8127dc3afe8cda4a67eb24915f8d", + "reference": "bb899c1db0aa8127dc3afe8cda4a67eb24915f8d", "shasum": "" }, "require": { @@ -1758,7 +1764,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.37.0" + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.41.0" }, "funding": [ { @@ -1778,20 +1784,20 @@ "type": "tidelift" } ], - "time": "2026-04-26T13:13:48+00:00" + "time": "2026-07-28T08:25:59+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.37.0", + "version": "v1.38.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "3833d7255cc303546435cb650316bff708a1c75c" + "reference": "2d446c214bdbe5b71bde5011b060a05fece3ae6b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/3833d7255cc303546435cb650316bff708a1c75c", - "reference": "3833d7255cc303546435cb650316bff708a1c75c", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/2d446c214bdbe5b71bde5011b060a05fece3ae6b", + "reference": "2d446c214bdbe5b71bde5011b060a05fece3ae6b", "shasum": "" }, "require": { @@ -1843,7 +1849,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.37.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.38.0" }, "funding": [ { @@ -1863,20 +1869,20 @@ "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2026-05-25T13:48:31+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.37.0", + "version": "v1.38.2", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "6a21eb99c6973357967f6ce3708cd55a6bec6315" + "reference": "d3d318bad5e7a1bfbd026009c8bfb8d8f99ae6b6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6a21eb99c6973357967f6ce3708cd55a6bec6315", - "reference": "6a21eb99c6973357967f6ce3708cd55a6bec6315", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d3d318bad5e7a1bfbd026009c8bfb8d8f99ae6b6", + "reference": "d3d318bad5e7a1bfbd026009c8bfb8d8f99ae6b6", "shasum": "" }, "require": { @@ -1928,7 +1934,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.37.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.38.2" }, "funding": [ { @@ -1948,7 +1954,7 @@ "type": "tidelift" } ], - "time": "2026-04-10T17:25:58+00:00" + "time": "2026-05-27T06:59:30+00:00" }, { "name": "symfony/polyfill-php80", @@ -2036,16 +2042,16 @@ }, { "name": "symfony/polyfill-php81", - "version": "v1.37.0", + "version": "v1.38.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php81.git", - "reference": "4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c" + "reference": "6bfb9c766cacffbc8e118cb87217d08ed84e5cd7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c", - "reference": "4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c", + "url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/6bfb9c766cacffbc8e118cb87217d08ed84e5cd7", + "reference": "6bfb9c766cacffbc8e118cb87217d08ed84e5cd7", "shasum": "" }, "require": { @@ -2092,7 +2098,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php81/tree/v1.37.0" + "source": "https://github.com/symfony/polyfill-php81/tree/v1.38.1" }, "funding": [ { @@ -2112,7 +2118,7 @@ "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2026-05-26T12:45:58+00:00" }, { "name": "symfony/service-contracts", @@ -3176,30 +3182,29 @@ "type": "github" } ], - "abandoned": true, "time": "2020-08-04T08:28:15+00:00" }, { "name": "phpunit/phpunit", - "version": "8.5.52", + "version": "8.5.53", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "1015741814413c156abb0f53d7db7bbd03c6e858" + "reference": "17cd4291b0ef645b6d21e5ddb6f497694c5e9bcd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1015741814413c156abb0f53d7db7bbd03c6e858", - "reference": "1015741814413c156abb0f53d7db7bbd03c6e858", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/17cd4291b0ef645b6d21e5ddb6f497694c5e9bcd", + "reference": "17cd4291b0ef645b6d21e5ddb6f497694c5e9bcd", "shasum": "" }, "require": { "doctrine/instantiator": "^1.5.0", "ext-dom": "*", + "ext-filter": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", - "ext-xml": "*", "ext-xmlwriter": "*", "myclabs/deep-copy": "^1.13.4", "phar-io/manifest": "^2.0.4", @@ -3259,31 +3264,15 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/8.5.52" + "source": "https://github.com/sebastianbergmann/phpunit/tree/8.5.53" }, "funding": [ { - "url": "https://phpunit.de/sponsors.html", - "type": "custom" - }, - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - }, - { - "url": "https://liberapay.com/sebastianbergmann", - "type": "liberapay" - }, - { - "url": "https://thanks.dev/u/gh/sebastianbergmann", - "type": "thanks_dev" - }, - { - "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit", - "type": "tidelift" + "url": "https://phpunit.de/sponsoring.html", + "type": "other" } ], - "time": "2026-01-27T05:20:18+00:00" + "time": "2026-07-06T14:29:25+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -4178,12 +4167,12 @@ ], "aliases": [], "minimum-stability": "dev", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": true, "prefer-lowest": false, "platform": { "php": "^7.4 || ^8.0" }, - "platform-dev": [], - "plugin-api-version": "2.2.0" + "platform-dev": {}, + "plugin-api-version": "2.6.0" } diff --git a/includes/AltapayFormFields.php b/includes/AltapayFormFields.php index 6f504b8f..412df3ce 100755 --- a/includes/AltapayFormFields.php +++ b/includes/AltapayFormFields.php @@ -77,6 +77,13 @@ 'default' => 'no', 'desc_tip' => true, ), + 'apple_pay_legacy_flow' => array( + 'title' => __( 'Legacy Apple Pay flow', 'altapay' ), + 'type' => 'checkbox', + 'label' => __( 'Supports legacy ApplePay flow.', 'altapay' ), + 'default' => 'yes', + 'desc_tip' => true, + ), 'apple_pay_label' => array( 'title' => __( 'Apple Pay form label', 'altapay' ), 'type' => 'text', diff --git a/views/paymentClass.tpl b/views/paymentClass.tpl index bc9bc90a..6db1c586 100644 --- a/views/paymentClass.tpl +++ b/views/paymentClass.tpl @@ -49,6 +49,7 @@ class WC_Gateway_{key} extends WC_Payment_Gateway { public $payment_action = ''; public $is_apple_pay; + public $apple_pay_legacy_flow; public $apple_pay_label; public $apple_pay_supported_networks; public $secret; @@ -68,6 +69,7 @@ class WC_Gateway_{key} extends WC_Payment_Gateway { $this->token = $this->get_option( 'token' ); $this->payment_action = $this->get_option( 'payment_action' ); $this->is_apple_pay = $this->get_option( 'is_apple_pay' ); + $this->apple_pay_legacy_flow = $this->get_option( 'apple_pay_legacy_flow' ); $this->apple_pay_label = $this->get_option( 'apple_pay_label' ); $this->apple_pay_supported_networks = $this->get_option( 'apple_pay_supported_networks' ); $this->secret = $this->get_option( 'secret' ); From 82df2620b779c3744bf98e3b133ca3681920785d Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Mon, 3 Aug 2026 12:37:32 +0500 Subject: [PATCH 2/9] Refactor ApplePay response handling to improve readability and maintainability --- classes/core/ApplePay.php | 52 +++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/classes/core/ApplePay.php b/classes/core/ApplePay.php index 86c61f5a..44951e24 100644 --- a/classes/core/ApplePay.php +++ b/classes/core/ApplePay.php @@ -142,31 +142,45 @@ public function applepay_validate_merchant() { try { $response = $request->call(); - if ( $response->Result === 'Success' ) { - if ( isset( $response->ApplePaySession ) ) { - wp_send_json_success( $response->ApplePaySession, 200 ); - } elseif ( isset( $response->WalletData->Session ) ) { - $transaction = ! empty( $response->Transactions ) ? reset( $response->Transactions ) : null; - - if ( $order && isset( $transaction->PaymentId ) ) { - $order->update_meta_data( 'altapay_payment_id', $transaction->PaymentId ); - $order->save(); - } - wp_send_json_success( $response->WalletData->Session, 200 ); - } else { - wc_add_notice( __( 'Payment failed.', 'altapay' ), 'error' ); - wp_send_json_error( array( 'redirect' => wc_get_cart_url() ) ); - } - } else { - wc_add_notice( __( 'Payment failed.', 'altapay' ), 'error' ); - wp_send_json_error( array( 'redirect' => wc_get_cart_url() ) ); - } + $this->send_validate_merchant_response( $response, $order ); } catch ( \Exception $e ) { wc_add_notice( __( 'Payment failed:', 'altapay' ) . ' ' . $e->getMessage(), 'error' ); wp_send_json_error( array( 'redirect' => wc_get_cart_url() ) ); } } + /** + * Send the AJAX response for a CardWalletSession result. + * + * @param object $response + * @param WC_Order|false $order + * @return void + */ + private function send_validate_merchant_response( $response, $order ) { + + if ( $response->Result !== 'Success' ) { + wc_add_notice( __( 'Payment failed.', 'altapay' ), 'error' ); + wp_send_json_error( array( 'redirect' => wc_get_cart_url() ) ); + } + + if ( isset( $response->ApplePaySession ) ) { + wp_send_json_success( $response->ApplePaySession, 200 ); + } + + if ( isset( $response->WalletData->Session ) ) { + $transaction = ! empty( $response->Transactions ) ? reset( $response->Transactions ) : null; + + if ( $order && isset( $transaction->PaymentId ) ) { + $order->update_meta_data( 'altapay_payment_id', $transaction->PaymentId ); + $order->save(); + } + wp_send_json_success( $response->WalletData->Session, 200 ); + } + + wc_add_notice( __( 'Payment failed.', 'altapay' ), 'error' ); + wp_send_json_error( array( 'redirect' => wc_get_cart_url() ) ); + } + /** * Call CardWalletAuthorize API * From 3bc4ac2150e81381e6a0ac5c612da27318433e39 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Mon, 3 Aug 2026 12:55:45 +0500 Subject: [PATCH 3/9] Improve code readability --- classes/core/ApplePay.php | 100 ++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 36 deletions(-) diff --git a/classes/core/ApplePay.php b/classes/core/ApplePay.php index 44951e24..e8e1fce6 100644 --- a/classes/core/ApplePay.php +++ b/classes/core/ApplePay.php @@ -92,7 +92,7 @@ public function altapay_load_apple_pay_script() { * @param string $payment_method. * @return bool */ - private function is_legacy_apple_pay_flow( $payment_method ) { + private function isLegacyApplePayFlow( $payment_method ) { if ( ! $payment_method ) { return true; @@ -130,7 +130,7 @@ public function applepay_validate_merchant() { ->setValidationUrl( $validation_url ) ->setDomain( $_SERVER['HTTP_HOST'] ); - if ( ! $this->is_legacy_apple_pay_flow( $applepay_payment_method ) ) { + if ( ! $this->isLegacyApplePayFlow( $applepay_payment_method ) ) { $request->setShopOrderId( $_POST['order_id'] ) ->setAmount( (float) $_POST['amount'] ) ->setCurrency( $_POST['currency'] ) @@ -142,7 +142,7 @@ public function applepay_validate_merchant() { try { $response = $request->call(); - $this->send_validate_merchant_response( $response, $order ); + $this->sendValidateMerchantResponse( $response, $order ); } catch ( \Exception $e ) { wc_add_notice( __( 'Payment failed:', 'altapay' ) . ' ' . $e->getMessage(), 'error' ); wp_send_json_error( array( 'redirect' => wc_get_cart_url() ) ); @@ -156,7 +156,7 @@ public function applepay_validate_merchant() { * @param WC_Order|false $order * @return void */ - private function send_validate_merchant_response( $response, $order ) { + private function sendValidateMerchantResponse( $response, $order ) { if ( $response->Result !== 'Success' ) { wc_add_notice( __( 'Payment failed.', 'altapay' ), 'error' ); @@ -199,7 +199,7 @@ public function applepay_card_wallet_authorize() { $order_id = isset( $_POST['order_id'] ) ? sanitize_text_field( wp_unslash( $_POST['order_id'] ) ) : ''; $order = wc_get_order( $order_id ); - $legacy_flow = $this->is_legacy_apple_pay_flow( $applepay_payment_method ); + $legacy_flow = $this->isLegacyApplePayFlow( $applepay_payment_method ); if ( ! $legacy_flow ) { $altapay_payment_id = $order->get_meta( 'altapay_payment_id' ); @@ -234,6 +234,29 @@ public function applepay_card_wallet_authorize() { $request->setPaymentId( $altapay_payment_id ); } + $payment_type = $this->determinePaymentType( $payment_gateways, $payment_method ); + + $request->setType( $payment_type ); + + try { + $response = $request->call(); + $this->sendCardWalletAuthorizeResponse( $response, $order, $order_id, $payment_type ); + } catch ( \Exception $e ) { + $order->add_order_note( __( 'Payment failed: ' . $e->getMessage() ) ); + wc_add_notice( __( 'Payment failed:', 'altapay' ) . ' ' . $e->getMessage(), 'error' ); + wp_send_json_error( array( 'redirect' => wc_get_cart_url() ) ); + } + } + + /** + * Whether the gateway used for this order is set to authorize-and-capture. + * + * @param array $payment_gateways + * @param string $payment_method + * @return string + */ + private function determinePaymentType( $payment_gateways, $payment_method ) { + $payment_type = 'payment'; foreach ( $payment_gateways as $key => $payment_gateway ) { @@ -245,43 +268,48 @@ public function applepay_card_wallet_authorize() { } } - $request->setType( $payment_type ); - - try { - $response = $request->call(); + return $payment_type; + } - $transactions = json_decode( wp_json_encode( $response->Transactions ), true ); - $latest_transaction = $this->getLatestTransaction( $transactions, $payment_type ); - $transaction = $transactions[ $latest_transaction ]; - $txn_id = $transaction['TransactionId']; + /** + * Send the AJAX response for a CardWalletAuthorize result. + * + * @param object $response + * @param WC_Order $order + * @param string $order_id + * @param string $payment_type + * @return void + */ + private function sendCardWalletAuthorizeResponse( $response, $order, $order_id, $payment_type ) { - $order->add_order_note( __( "Gateway Order ID: $order_id", 'altapay' ) ); - if ( $response->Result === 'Success' ) { - $order->set_transaction_id( $txn_id ); - $order->add_order_note( __( 'Apple Pay payment completed', 'altapay' ) ); - $order->payment_complete(); + $transactions = json_decode( wp_json_encode( $response->Transactions ), true ); + $latest_transaction = $this->getLatestTransaction( $transactions, $payment_type ); + $transaction = $transactions[ $latest_transaction ]; + $txn_id = $transaction['TransactionId']; - $reconciliation = new Core\AltapayReconciliation(); - foreach ( $transaction['ReconciliationIdentifiers'] as $val ) { - $reconciliation->saveReconciliationIdentifier( $order_id, $txn_id, $val['Id'], $val['Type'] ); - } + $order->add_order_note( __( "Gateway Order ID: $order_id", 'altapay' ) ); - wp_send_json_success( - array( - 'redirect' => $order->get_checkout_order_received_url(), - ), - 200 - ); - } else { - $order->add_order_note( __( 'Payment failed.' ) ); - wc_add_notice( __( 'Payment failed.', 'altapay' ), 'error' ); - wp_send_json_error( array( 'redirect' => wc_get_cart_url() ) ); - } - } catch ( \Exception $e ) { - $order->add_order_note( __( 'Payment failed: ' . $e->getMessage() ) ); - wc_add_notice( __( 'Payment failed:', 'altapay' ) . ' ' . $e->getMessage(), 'error' ); + if ( $response->Result !== 'Success' ) { + $order->add_order_note( __( 'Payment failed.' ) ); + wc_add_notice( __( 'Payment failed.', 'altapay' ), 'error' ); wp_send_json_error( array( 'redirect' => wc_get_cart_url() ) ); } + + $order->set_transaction_id( $txn_id ); + $order->add_order_note( __( 'Apple Pay payment completed', 'altapay' ) ); + $order->payment_complete(); + + $reconciliation = new Core\AltapayReconciliation(); + foreach ( $transaction['ReconciliationIdentifiers'] as $val ) { + $reconciliation->saveReconciliationIdentifier( $order_id, $txn_id, $val['Id'], $val['Type'] ); + } + + wp_send_json_success( + array( + 'redirect' => $order->get_checkout_order_received_url(), + ), + 200 + ); } /** From 7757f62f3ac49427c84ff0e38eec90d9b990084a Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Mon, 3 Aug 2026 13:04:03 +0500 Subject: [PATCH 4/9] Update compatibility information for WordPress and WooCommerce in readme and wiki --- altapay.php | 2 +- readme.txt | 4 ++-- wiki.md | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/altapay.php b/altapay.php index 3b5a6883..5852b9af 100755 --- a/altapay.php +++ b/altapay.php @@ -10,7 +10,7 @@ * Version: 3.8.7 * Name: SDM_Altapay * WC requires at least: 3.9.0 - * WC tested up to: 10.7.0 + * WC tested up to: 10.9.4 * * @package Altapay */ diff --git a/readme.txt b/readme.txt index c041dbe5..a8ca9c10 100644 --- a/readme.txt +++ b/readme.txt @@ -3,11 +3,11 @@ Contributors: altapay_integrations Tags: AltaPay, Gateway, Payments, WooCommerce, Payment Card Industry Requires PHP: 7.4 Requires at least: 5.0 -Tested up to: 6.9.4 +Tested up to: 7.0.2 Stable tag: 3.8.7 License: MIT WC requires at least: 3.9.0 -WC tested up to: 10.7.0 +WC tested up to: 10.9.4 License URI: http://www.gnu.org/licenses/gpl-2.0.html A plugin that integrates your WooCommerce web shop to the AltaPay payments gateway. diff --git a/wiki.md b/wiki.md index f095fe74..08c623ac 100644 --- a/wiki.md +++ b/wiki.md @@ -316,14 +316,14 @@ The new credentials can now be used as the API Username and API Password in your ## Supported versions Minimum system requirements are: -- WordPress min. 5.0 – max. 6.9.4 -- WooCommerce min. 3.9.0 – max. 10.7.0 +- WordPress min. 5.0 – max. 7.0.2 +- WooCommerce min. 3.9.0 – max. 10.9.4 - PHP 7.4 and above - PHP-bcmath library installed. - PHP-curl MUST be enabled. The latest tested version is: -- WordPress 6.9.4, WooCommerce 10.7.0 and PHP 8.4 +- WordPress 7.0.2, WooCommerce 10.9.4 and PHP 8.4 ## Troubleshooting From 128a5d9109c8836d4bc118328f05adafe1166e71 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Mon, 3 Aug 2026 17:27:45 +0500 Subject: [PATCH 5/9] Add error logging for missing order in process_payment method --- views/paymentClass.tpl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/views/paymentClass.tpl b/views/paymentClass.tpl index 6db1c586..b78bab44 100644 --- a/views/paymentClass.tpl +++ b/views/paymentClass.tpl @@ -423,7 +423,14 @@ class WC_Gateway_{key} extends WC_Payment_Gateway { } } - $order = wc_get_order( $order_id ); + $order = wc_get_order( $order_id ); + if ( ! $order ) { + wc_get_logger()->error( + 'Could not find order for callback. order_id: ' . $order_id, + array( 'source' => 'altapay' ) + ); + exit; + } $transaction_id = $order->get_transaction_id(); $agreement_id = $type === 'subscriptionAndCharge' || $type === 'subscription' ? $txnId : ''; $transaction = array(); From b8df1e75052337816b78076597c66d7db4acecb0 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Fri, 7 Aug 2026 11:05:02 +0500 Subject: [PATCH 6/9] Update version and release notes --- CHANGELOG.md | 3 +++ altapay.php | 4 ++-- readme.txt | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61ab08d4..a46d0bc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All notable changes to this project will be documented in this file. +## [3.8.8] +- Extended Apple Pay support to include the MarketPay acquirer. + ## [3.8.7] - Add support for MarketPay payment methods. - Fix: Renewal/Recurring order status automatically changed to Processing. diff --git a/altapay.php b/altapay.php index 5852b9af..5eeb973a 100755 --- a/altapay.php +++ b/altapay.php @@ -7,7 +7,7 @@ * Author URI: https://altapay.com * Text Domain: altapay * Domain Path: /languages - * Version: 3.8.7 + * Version: 3.8.8 * Name: SDM_Altapay * WC requires at least: 3.9.0 * WC tested up to: 10.9.4 @@ -41,7 +41,7 @@ } if ( ! defined( 'ALTAPAY_PLUGIN_VERSION' ) ) { - define( 'ALTAPAY_PLUGIN_VERSION', '3.8.7' ); + define( 'ALTAPAY_PLUGIN_VERSION', '3.8.8' ); } // Include the autoloader, so we can dynamically include the rest of the classes. diff --git a/readme.txt b/readme.txt index a8ca9c10..a666e716 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: AltaPay, Gateway, Payments, WooCommerce, Payment Card Industry Requires PHP: 7.4 Requires at least: 5.0 Tested up to: 7.0.2 -Stable tag: 3.8.7 +Stable tag: 3.8.8 License: MIT WC requires at least: 3.9.0 WC tested up to: 10.9.4 @@ -39,6 +39,9 @@ AltaPay's Payment Gateway for WooCommerce provides merchants with access to a fu == Changelog == += 3.8.8 = +* Extended Apple Pay support to include the MarketPay acquirer. + = 3.8.7 = * Add support for MarketPay payment methods. * Fix: Renewal/Recurring order status automatically changed to Processing. From c543feae6660ef224829ec65c1c8a58b59eb4940 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Wed, 12 Aug 2026 12:01:34 +0500 Subject: [PATCH 7/9] Remove redundant parameters and improve error handling for missing orders --- assets/js/applepay.js | 4 +--- classes/core/ApplePay.php | 12 +++++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/assets/js/applepay.js b/assets/js/applepay.js index bb37cd24..b3316d82 100644 --- a/assets/js/applepay.js +++ b/assets/js/applepay.js @@ -140,9 +140,7 @@ function onApplePayButtonClicked(applepay_obj, createSession, wc_checkout_form, validation_url: event.validationURL, terminal: applepay_obj.terminal, applepay_payment_method: applepay_obj.applepay_payment_method, - order_id: order_id, - amount: applepay_obj.subtotal, - currency: applepay_obj.currency + order_id: order_id }, function (res) { if (res.success === true) { diff --git a/classes/core/ApplePay.php b/classes/core/ApplePay.php index e8e1fce6..30c5ee1f 100644 --- a/classes/core/ApplePay.php +++ b/classes/core/ApplePay.php @@ -131,9 +131,15 @@ public function applepay_validate_merchant() { ->setDomain( $_SERVER['HTTP_HOST'] ); if ( ! $this->isLegacyApplePayFlow( $applepay_payment_method ) ) { - $request->setShopOrderId( $_POST['order_id'] ) - ->setAmount( (float) $_POST['amount'] ) - ->setCurrency( $_POST['currency'] ) + + if ( ! $order ) { + wc_add_notice( __( 'Payment failed. Please try again.', 'altapay' ), 'error' ); + wp_send_json_error( array( 'redirect' => wc_get_cart_url() ) ); + } + + $request->setShopOrderId( $order_id ) + ->setAmount( (float) $order->get_total() ) + ->setCurrency( $order->get_currency() ) ->setApplePayRequestData( [ 'validationUrl' => $validation_url, 'domain' => $_SERVER['HTTP_HOST'] From cb5088c994fece26c07cf19ccbf33440715ee260 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Wed, 12 Aug 2026 12:15:51 +0500 Subject: [PATCH 8/9] Create sendPaymentFailedResponse to send ajax response --- classes/core/ApplePay.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/classes/core/ApplePay.php b/classes/core/ApplePay.php index 30c5ee1f..a9ade99a 100644 --- a/classes/core/ApplePay.php +++ b/classes/core/ApplePay.php @@ -115,8 +115,7 @@ private function isLegacyApplePayFlow( $payment_method ) { public function applepay_validate_merchant() { if ( ! wp_verify_nonce( wp_unslash( $_POST['ajax_nonce'] ), 'apple-pay' ) ) { - wc_add_notice( __( 'Payment failed. Please try again.', 'altapay' ), 'error' ); - wp_send_json_error( array( 'redirect' => wc_get_cart_url() ) ); + $this->sendPaymentFailedResponse(); } $terminal = isset( $_POST['terminal'] ) ? sanitize_text_field( wp_unslash( $_POST['terminal'] ) ) : ''; @@ -133,8 +132,7 @@ public function applepay_validate_merchant() { if ( ! $this->isLegacyApplePayFlow( $applepay_payment_method ) ) { if ( ! $order ) { - wc_add_notice( __( 'Payment failed. Please try again.', 'altapay' ), 'error' ); - wp_send_json_error( array( 'redirect' => wc_get_cart_url() ) ); + $this->sendPaymentFailedResponse(); } $request->setShopOrderId( $order_id ) @@ -155,6 +153,16 @@ public function applepay_validate_merchant() { } } + /** + * Add a generic payment-failed notice and redirect to the cart page. + * + * @return void + */ + private function sendPaymentFailedResponse() { + wc_add_notice( __( 'Payment failed. Please try again.', 'altapay' ), 'error' ); + wp_send_json_error( array( 'redirect' => wc_get_cart_url() ) ); + } + /** * Send the AJAX response for a CardWalletSession result. * @@ -195,8 +203,7 @@ private function sendValidateMerchantResponse( $response, $order ) { public function applepay_card_wallet_authorize() { if ( ! wp_verify_nonce( wp_unslash( $_POST['ajax_nonce'] ), 'apple-pay' ) ) { - wc_add_notice( __( 'Payment failed. Please try again.', 'altapay' ), 'error' ); - wp_send_json_error( array( 'redirect' => wc_get_cart_url() ) ); + $this->sendPaymentFailedResponse(); } $provider_data = isset( $_POST['provider_data'] ) ? sanitize_text_field( wp_unslash( $_POST['provider_data'] ) ) : ''; From 2062d4f3a3f58c16aed66afc61708407cce3b42b Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Wed, 12 Aug 2026 13:13:02 +0500 Subject: [PATCH 9/9] Update documentation for new Apple Pay flow --- CHANGELOG.md | 2 +- readme.txt | 2 +- wiki.md | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a46d0bc6..ef6d0e67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. ## [3.8.8] -- Extended Apple Pay support to include the MarketPay acquirer. +- Extended Apple Pay support to include the MarketPay acquirer. For the updated payment methods settings please see [Configure the terminals for the checkout page](https://github.com/AltaPay/plugin-wordpress/wiki#configure-the-terminals-for-the-checkout-page) ## [3.8.7] - Add support for MarketPay payment methods. diff --git a/readme.txt b/readme.txt index a666e716..a3f0074c 100644 --- a/readme.txt +++ b/readme.txt @@ -40,7 +40,7 @@ AltaPay's Payment Gateway for WooCommerce provides merchants with access to a fu == Changelog == = 3.8.8 = -* Extended Apple Pay support to include the MarketPay acquirer. +* Extended Apple Pay support to include the MarketPay acquirer. For the updated payment methods settings please see [Configure the terminals for the checkout page](https://github.com/AltaPay/plugin-wordpress/wiki#configure-the-terminals-for-the-checkout-page) = 3.8.7 = * Add support for MarketPay payment methods. diff --git a/wiki.md b/wiki.md index 08c623ac..01f3d1fd 100644 --- a/wiki.md +++ b/wiki.md @@ -190,6 +190,7 @@ For the AltaPay payment method to appear in the checkout page: | Icon | Select image icon to display on checkout page. | | Secret | Add the payment method secret as defined in the AltaPay payment gateway to enable checksum validation. To disable checksum validation leave it empty. | | Is Apple Pay? | Check if the terminal is for Apple Pay payments. | + | Legacy Apple Pay flow | Supports the legacy Apple Pay flow. If your AltaPay gateway is on [version 20260113](https://documentation.altapay.com/Content/Ecom/Ecom%20Release%20Notes.htm) or later, uncheck this to use the new integration. If your gateway is on an older version, leave it checked (the default). | | Apple Pay form label | This controls the label shown on Apple Pay popup window. | | Apple Pay Supported Networks | The payment networks the merchant supports. | | Enable Surcharge? | Check this option to enable surcharge for this payment method. |