Plugin Directory

Changeset 3114383


Ignore:
Timestamp:
07/08/2024 02:27:45 PM (21 months ago)
Author:
multisafepayplugin
Message:

Update to version 6.6.0 from GitHub

Location:
multisafepay
Files:
6 added
50 edited
1 copied

Legend:

Unmodified
Added
Removed
  • multisafepay/tags/6.6.0/multisafepay.php

    r3099249 r3114383  
    55 * Plugin URI:              https://docs.multisafepay.com/docs/woocommerce
    66 * Description:             MultiSafepay Payment Plugin
    7  * Version:                 6.5.1
     7 * Version:                 6.6.0
    88 * Author:                  MultiSafepay
    99 * Author URI:              https://www.multisafepay.com
     
    1212 * License URI:             http://www.gnu.org/licenses/gpl-3.0.html
    1313 * Requires at least:       6.0
    14  * Tested up to:            6.5.4
     14 * Tested up to:            6.5.5
    1515 * WC requires at least:    6.0.0
    16  * WC tested up to:         8.8.3
     16 * WC tested up to:         9.0.2
    1717 * Requires PHP:            7.3
    1818 * Text Domain:             multisafepay
     
    2727 * Plugin version
    2828 */
    29 define( 'MULTISAFEPAY_PLUGIN_VERSION', '6.5.1' );
     29define( 'MULTISAFEPAY_PLUGIN_VERSION', '6.6.0' );
    3030
    3131/**
  • multisafepay/tags/6.6.0/readme.txt

    r3099249 r3114383  
    33Tags: multisafepay, payment gateway, credit cards, ideal, bnpl
    44Requires at least: 6.0
    5 Tested up to: 6.5.4
     5Tested up to: 6.5.5
    66Requires PHP: 7.3
    7 Stable tag: 6.5.1
     7Stable tag: 6.6.0
    88License: MIT
    99
     
    128128== Upgrade Notice ==
    129129
    130 = 6.5.1 =
     130= 6.6.0 =
    1311316.x.x is a major upgrade in which the MultiSafepay payment methods are registered dynamically via an API request to MultiSafepay. If you are upgrading from 5.X.X version, after the upgrade, please navigate to the MultiSafepay settings page, and to each one of the payment methods enabled in your account, and confirm the settings in each section are set up according to your preferences.
    132132
     
    144144
    145145== Changelog ==
     146= Release Notes - WooCommerce 6.6.0 (Jul 8th, 2024) =
     147
     148### Added
     149+ PLGWOOS-946: Add support for branded credit and debit cards
     150
     151### Changed
     152+ PLGWOOS-943: Refactor PaymentMethodCallback class (#574)
     153+ PLGWOOS-948: General improvements to increase unit test coverage
     154
    146155= Release Notes - WooCommerce 6.5.1 (Jun 7th, 2024) =
    147156
  • multisafepay/tags/6.6.0/src/Client/MultiSafepayClient.php

    r3090804 r3114383  
    1414 */
    1515class MultiSafepayClient implements ClientInterface {
     16
     17    /**
     18     * @var Logger
     19     */
     20    private $logger;
     21
     22    /**
     23     * @param Logger|null $logger
     24     */
     25    public function __construct( ?Logger $logger = null ) {
     26        $this->logger = $logger ?? new Logger();
     27    }
    1628
    1729    /**
     
    3345            }
    3446        } catch ( Exception $exception ) {
    35             Logger::log_error( 'Error when process request via MultiSafepayClient: ' . $exception->getMessage() );
     47            $this->logger->log_error( 'Error when process request via MultiSafepayClient: ' . $exception->getMessage() );
    3648            throw new Exception( $exception->getMessage() );
    3749        }
  • multisafepay/tags/6.6.0/src/PaymentMethods/Base/BasePaymentMethod.php

    r3099249 r3114383  
    109109
    110110    /**
    111      * Defines if the payment method is tokenizable
     111     * @var Logger
     112     */
     113    private $logger;
     114
     115    /**
     116     * BasePaymentMethod constructor.
    112117     *
    113118     * @param PaymentMethod $payment_method
    114      */
    115     public function __construct( PaymentMethod $payment_method ) {
     119     * @param Logger|null   $logger
     120     */
     121    public function __construct( PaymentMethod $payment_method, ?Logger $logger = null ) {
     122        $this->logger         = $logger ?? new Logger();
    116123        $this->payment_method = $payment_method;
    117124        $this->supports       = array( 'products', 'refunds' );
     
    636643            $transaction = $transaction_manager->create( $order_request );
    637644        } catch ( ApiException | ClientExceptionInterface $exception ) {
    638             Logger::log_error( $exception->getMessage() );
     645            $this->logger->log_error( $exception->getMessage() );
    639646            wc_add_notice( __( 'There was a problem processing your payment. Please try again later or contact with us.', 'multisafepay' ), 'error' );
    640647            return;
     
    642649
    643650        if ( get_option( 'multisafepay_debugmode', false ) ) {
    644             Logger::log_info( 'Start MultiSafepay transaction for the order ID ' . $order_id . ' on ' . date( 'd/m/Y H:i:s' ) . ' with payment URL ' . $transaction->getPaymentUrl() );
     651            $this->logger->log_info( 'Start MultiSafepay transaction for the order ID ' . $order_id . ' on ' . date( 'd/m/Y H:i:s' ) . ' with payment URL ' . $transaction->getPaymentUrl() );
    645652        }
    646653
  • multisafepay/tags/6.6.0/src/PaymentMethods/Base/BasePaymentMethodBlocks.php

    r3090804 r3114383  
    4242            $multisafepay_payment_methods = $payment_method_service->get_multisafepay_payment_methods_from_api();
    4343            foreach ( $multisafepay_payment_methods as $multisafepay_payment_method ) {
    44                 $woocommerce_payment_gateway = null;
     44                $woocommerce_payment_gateways = array();
     45
    4546                if ( isset( $multisafepay_payment_method['type'] ) && ( 'coupon' === $multisafepay_payment_method['type'] ) ) {
    46                     $woocommerce_payment_gateway = new BaseGiftCardPaymentMethod( new PaymentMethod( $multisafepay_payment_method ) );
    47                 }
    48                 if ( isset( $multisafepay_payment_method['type'] ) && ( 'payment-method' === $multisafepay_payment_method['type'] ) ) {
    49                     $woocommerce_payment_gateway = new BasePaymentMethod( new PaymentMethod( $multisafepay_payment_method ) );
     47                    $woocommerce_payment_gateways[] = new BaseGiftCardPaymentMethod( new PaymentMethod( $multisafepay_payment_method ) );
    5048                }
    5149
    52                 // Include direct payment methods without components just in the checkout page of the frontend context
    53                 if (
    54                     $woocommerce_payment_gateway->check_direct_payment_methods_without_components() &&
    55                     ! $woocommerce_payment_gateway->admin_editing_checkout_page()
    56                 ) {
    57                     $this->gateways[] = $woocommerce_payment_gateway;
     50                if ( isset( $multisafepay_payment_method['type'] ) && ( 'payment-method' === $multisafepay_payment_method['type'] ) ) {
     51                    $woocommerce_payment_gateways[] = new BasePaymentMethod( new PaymentMethod( $multisafepay_payment_method ) );
     52                    foreach ( $multisafepay_payment_method['brands'] as $brand ) {
     53                        if ( ! empty( $brand['allowed_countries'] ) ) {
     54                            $woocommerce_payment_gateways[] = new BaseBrandedPaymentMethod( new PaymentMethod( $multisafepay_payment_method ), $brand );
     55                        }
     56                    }
    5857                }
    5958
    60                 if ( ( 'redirect' === $woocommerce_payment_gateway->get_payment_method_type() ) && $woocommerce_payment_gateway->is_available() ) {
    61                     $this->gateways[] = $woocommerce_payment_gateway;
     59                foreach ( $woocommerce_payment_gateways as $woocommerce_payment_gateway ) {
     60                    // Include direct payment methods without components just in the checkout page of the frontend context
     61                    if (
     62                        $woocommerce_payment_gateway->check_direct_payment_methods_without_components() &&
     63                        ! $woocommerce_payment_gateway->admin_editing_checkout_page()
     64                    ) {
     65                        $this->gateways[] = $woocommerce_payment_gateway;
     66                    }
     67
     68                    if ( ( 'redirect' === $woocommerce_payment_gateway->get_payment_method_type() ) && $woocommerce_payment_gateway->is_available() ) {
     69                        $this->gateways[] = $woocommerce_payment_gateway;
     70                    }
    6271                }
    6372            }
  • multisafepay/tags/6.6.0/src/PaymentMethods/Base/BaseRefunds.php

    r3048898 r3114383  
    1010use MultiSafepay\ValueObject\CartItem;
    1111use MultiSafepay\WooCommerce\Services\SdkService;
    12 use MultiSafepay\WooCommerce\Utils\Logger;
    1312use MultiSafepay\WooCommerce\Utils\MoneyUtil;
    1413use Psr\Http\Client\ClientExceptionInterface;
     
    7675        } catch ( Exception | ClientExceptionInterface | ApiException $exception ) {
    7776            $error = __( 'Error:', 'multisafepay' ) . htmlspecialchars( $exception->getMessage() );
    78             Logger::log_error( $error );
     77            $this->logger->log_error( $error );
    7978            wc_add_notice( $error, 'error' );
    8079        }
     
    8382            /* translators: %1$: The currency code. %2$ The transaction amount */
    8483            $note = sprintf( __( 'Refund of %1$s%2$s has been processed successfully.', 'multisafepay' ), get_woocommerce_currency_symbol( $order->get_currency() ), $amount );
    85             Logger::log_info( $note );
     84            $this->logger->log_info( $note );
    8685            $order->add_order_note( $note );
    8786            return true;
     
    9190            /* translators: %1$: The order ID. %2$ The PSP transaction ID */
    9291            $message = sprintf( __( 'Refund for Order ID: %1$s with transactionId: %2$s gives message: %3$s.', 'multisafepay' ), $order_id, $multisafepay_transaction->getTransactionId(), $error );
    93             Logger::log_warning( $message );
     92            $this->logger->log_warning( $message );
    9493        }
    9594
  • multisafepay/tags/6.6.0/src/PaymentMethods/PaymentMethodCallback.php

    r3048898 r3114383  
    1010use MultiSafepay\WooCommerce\Settings\SettingsFields;
    1111use MultiSafepay\WooCommerce\Utils\Logger;
     12use MultiSafepay\WooCommerce\Utils\Order as OrderUtil;
    1213use Psr\Http\Client\ClientExceptionInterface;
    1314use WC_Data_Exception;
     
    5758
    5859    /**
    59      * PaymentMethodCallback constructor
    60      *
    61      * @param  string               $multisafepay_order_id
    62      * @param  ?TransactionResponse $multisafepay_transaction
    63      */
    64     public function __construct( string $multisafepay_order_id, $multisafepay_transaction = null ) {
    65         $this->multisafepay_order_id = $multisafepay_order_id;
    66 
    67         if ( ! isset( $multisafepay_transaction ) ) {
    68             $multisafepay_transaction = $this->get_transaction();
    69         }
    70 
    71         $this->multisafepay_transaction = $multisafepay_transaction;
    72 
    73         // For most transactions, var2 contains the order id since the order request is being register using order number
    74         if ( ! empty( $this->multisafepay_transaction->getVar2() ) ) {
    75             $this->woocommerce_order_id = (int) $this->multisafepay_transaction->getVar2();
    76         }
    77 
    78         // In case we need it, a filter to set the right order id, based on order number
    79         if ( empty( $this->multisafepay_transaction->getVar2() ) ) {
    80             $this->woocommerce_order_id = apply_filters( 'multisafepay_transaction_order_id', $this->multisafepay_order_id );
    81         }
    82 
    83         $this->time_stamp = date( 'd/m/Y H:i:s' );
    84         $this->order      = wc_get_order( $this->woocommerce_order_id );
     60     * @var Logger
     61     */
     62    private $logger;
     63
     64    /**
     65     * @param string                   $multisafepay_order_id
     66     * @param TransactionResponse|null $multisafepay_transaction
     67     * @param Logger|null              $logger
     68     */
     69    public function __construct( string $multisafepay_order_id, ?TransactionResponse $multisafepay_transaction = null, ?Logger $logger = null ) {
     70        $this->logger                   = $logger ?? new Logger();
     71        $this->multisafepay_order_id    = $multisafepay_order_id;
     72        $this->multisafepay_transaction = $multisafepay_transaction ?? $this->get_transaction();
     73        $this->woocommerce_order_id     = $this->get_woocommerce_order_id();
     74        $this->time_stamp               = date( 'd/m/Y H:i:s' );
     75        $this->order                    = wc_get_order( $this->woocommerce_order_id );
    8576    }
    8677
     
    9586            $transaction = $transaction_manager->get( $this->multisafepay_order_id );
    9687        } catch ( ClientExceptionInterface $client_exception ) {
    97             Logger::log_error( $client_exception->getMessage() );
     88            $this->logger->log_error( $client_exception->getMessage() );
    9889            wp_die( esc_html__( 'Invalid request', 'multisafepay' ), esc_html__( 'Invalid request', 'multisafepay' ), 400 );
    9990        } catch ( ApiException $api_exception ) {
    100             Logger::log_error( $api_exception->getMessage() );
     91            $this->logger->log_error( $api_exception->getMessage() );
    10192            wp_die( esc_html__( 'Invalid request', 'multisafepay' ), esc_html__( 'Invalid request', 'multisafepay' ), 400 );
    10293        }
     
    10596
    10697    /**
     98     * Return the WooCommerce order id
     99     *
     100     * @return int
     101     */
     102    private function get_woocommerce_order_id(): int {
     103        // For most transactions, var2 contains the order id since the order request is being registered using order number
     104        if ( ! empty( $this->multisafepay_transaction->getVar2() ) ) {
     105            return (int) $this->multisafepay_transaction->getVar2();
     106        }
     107        return apply_filters( 'multisafepay_transaction_order_id', $this->multisafepay_order_id );
     108    }
     109
     110    /**
    107111     * Return the WooCommerce order status
    108112     *
    109113     * @return string
    110114     */
    111     private function get_wc_order_status(): string {
     115    private function get_woocommerce_order_status(): string {
    112116        return $this->order->get_status();
    113117    }
     
    164168
    165169    /**
     170     * Return the initial order status configured in the payment method settings
     171     *
     172     * @return string|null
     173     */
     174    private function get_initial_order_status(): ?string {
     175        $registered_payment_method = ( new PaymentMethodService() )->get_woocommerce_payment_gateway_by_id( $this->order->get_payment_method() );
     176        return $registered_payment_method ? $registered_payment_method->initial_order_status : null;
     177    }
     178
     179    /**
    166180     * Check if the order status should be updated or not
    167181     *
     
    170184    private function should_status_be_updated(): bool {
    171185        // Check if the WooCommerce completed order status is considered as the final one
    172         if ( $this->is_completed_the_final_status( $this->get_wc_order_status() ) ) {
     186        if ( $this->is_completed_the_final_status( $this->get_woocommerce_order_status() ) ) {
    173187            // phpcs:ignore WordPress.Security.NonceVerification.Recommended
    174188            $message = 'It seems a notification is trying to process an order which already has defined completed as the final order status. For this reason notification is being ignored. Transaction ID received is ' . sanitize_text_field( (string) wp_unslash( $this->get_multisafepay_transaction_id() ) ) . ' with status ' . $this->get_multisafepay_transaction_status();
    175             Logger::log_warning( $message );
     189            $this->logger->log_warning( $message );
    176190            $this->order->add_order_note( $message );
    177191            return false;
     
    191205        // On pre-transactions notification, and using sequential order numbers plugins, var 2 is not received in the notification, then order doesn't exist
    192206        if ( ! $this->order ) {
    193             if ( get_option( 'multisafepay_debugmode', false ) ) {
    194                 Logger::log_info( 'Notification has been received for the transaction ID ' . $this->multisafepay_order_id . ' but WooCommerce order object has not been found' );
    195             }
     207            $this->logger->log_info( 'Notification has been received for the transaction ID ' . $this->multisafepay_order_id . ' but WooCommerce order object has not been found' );
    196208            header( 'Content-type: text/plain' );
    197209            die( 'OK' );
     
    199211
    200212        // If payment method of the order does not belong to MultiSafepay
    201         if ( strpos( $this->order->get_payment_method(), 'multisafepay_' ) === false ) {
    202             if ( get_option( 'multisafepay_debugmode', false ) ) {
    203                 $message = 'It seems a notification is trying to process an order processed by another payment method. Transaction ID received is ' . $this->order->get_id();
    204                 Logger::log_info( $message );
    205             }
    206             header( 'Content-type: text/plain' );
    207             die( 'OK' );
    208         }
    209 
    210         if ( $this->get_wc_order_status() === 'trash' ) {
    211             if ( get_option( 'multisafepay_debugmode', false ) ) {
    212                 $message = 'It seems a notification is trying to change the order status, but the order has been moved to the trash. Transaction ID received is ' . $this->order->get_id() . ' and transaction status is ' . $this->get_multisafepay_transaction_status();
    213                 Logger::log_info( $message );
    214                 $this->order->add_order_note( $message );
    215             }
     213        if ( ! OrderUtil::is_multisafepay_order( $this->order ) ) {
     214            $message = 'It seems a notification is trying to process an order processed by another payment method. Transaction ID received is ' . $this->order->get_id();
     215            $this->logger->log_info( $message );
     216            header( 'Content-type: text/plain' );
     217            die( 'OK' );
     218        }
     219
     220        if ( $this->get_woocommerce_order_status() === 'trash' ) {
     221            $message = 'It seems a notification is trying to change the order status, but the order has been moved to the trash. Transaction ID received is ' . $this->order->get_id() . ' and transaction status is ' . $this->get_multisafepay_transaction_status();
     222            $this->logger->log_info( $message );
     223            OrderUtil::add_order_note( $this->order, $message, true );
    216224            header( 'Content-type: text/plain' );
    217225            die( 'OK' );
     
    221229        if ( $this->get_multisafepay_transaction_status() === Transaction::PARTIAL_REFUNDED ) {
    222230            $message = 'A partial refund has been registered within MultiSafepay Control for Order ID: ' . $this->woocommerce_order_id . ' and Order Number: ' . $this->multisafepay_order_id;
    223             $this->order->add_order_note( $message );
     231            OrderUtil::add_order_note( $this->order, $message );
    224232            header( 'Content-type: text/plain' );
    225233            die( 'OK' );
     
    231239        $payment_method_id_registered_by_wc               = $this->order->get_payment_method();
    232240        $payment_method_title_registered_by_wc            = $this->order->get_payment_method_title();
    233         $registered_by_woocommerce_payment_method_object  = ( new PaymentMethodService() )->get_woocommerce_payment_gateway_by_id( $payment_method_id_registered_by_wc );
    234         $initial_order_status                             = $registered_by_woocommerce_payment_method_object ? $registered_by_woocommerce_payment_method_object->initial_order_status : false;
     241        $initial_order_status                             = $this->get_initial_order_status();
    235242        $default_order_status                             = SettingsFields::get_multisafepay_order_statuses();
    236243
     
    238245        // Or if the custom initial order status of the gateway is different than the general one, and the MultiSafepay transaction status is initialized, and custom initial order status is different than the current WooCommerce order status
    239246        if (
    240             $this->get_wc_order_status() !== str_replace( 'wc-', '', get_option( 'multisafepay_' . $this->get_multisafepay_transaction_status() . '_status', $default_order_status[ $this->get_multisafepay_transaction_status() . '_status' ]['default'] ) ) ||
    241             get_option( 'multisafepay_' . $this->get_multisafepay_transaction_status() . '_status', $default_order_status[ $this->get_multisafepay_transaction_status() . '_status' ]['default'] ) !== $initial_order_status && $this->get_multisafepay_transaction_status() === Transaction::INITIALIZED && $this->get_wc_order_status() !== $initial_order_status
     247            $this->get_woocommerce_order_status() !== str_replace( 'wc-', '', get_option( 'multisafepay_' . $this->get_multisafepay_transaction_status() . '_status', $default_order_status[ $this->get_multisafepay_transaction_status() . '_status' ]['default'] ) ) ||
     248            get_option( 'multisafepay_' . $this->get_multisafepay_transaction_status() . '_status', $default_order_status[ $this->get_multisafepay_transaction_status() . '_status' ]['default'] ) !== $initial_order_status && $this->get_multisafepay_transaction_status() === Transaction::INITIALIZED && $this->get_woocommerce_order_status() !== $initial_order_status
    242249        ) {
    243 
    244250            // If MultiSafepay transaction status is initialized, check if there is a custom initial order status for this payment method.
    245251            if ( $this->get_multisafepay_transaction_status() === Transaction::INITIALIZED ) {
    246                 if ( $initial_order_status && 'wc-default' !== $initial_order_status && $this->get_wc_order_status() !== $initial_order_status ) {
     252                if ( $initial_order_status && 'wc-default' !== $initial_order_status && $this->get_woocommerce_order_status() !== $initial_order_status ) {
    247253                    $this->order->update_status( str_replace( 'wc-', '', $initial_order_status ), __( 'Transaction has been initialized.', 'multisafepay' ) );
    248254                }
     
    266272            }
    267273
    268             if ( get_option( 'multisafepay_debugmode', false ) ) {
    269                 $message = 'Callback received for Order ID: ' . $this->woocommerce_order_id . ' and Order Number: ' . $this->multisafepay_order_id . ' on ' . $this->time_stamp . ' with status: ' . $this->get_multisafepay_transaction_status() . ' and PSP ID: ' . $this->get_multisafepay_transaction_id() . '.';
    270                 Logger::log_info( $message );
    271                 $this->order->add_order_note( $message );
    272             }
     274            $message = 'Callback received for Order ID: ' . $this->woocommerce_order_id . ' and Order Number: ' . $this->multisafepay_order_id . ' on ' . $this->time_stamp . ' with status: ' . $this->get_multisafepay_transaction_status() . ' and PSP ID: ' . $this->get_multisafepay_transaction_id() . '.';
     275            $this->logger->log_info( $message );
     276            OrderUtil::add_order_note( $this->order, $message, true );
    273277        }
    274278
    275279        // If the payment method changed in MultiSafepay payment page, after leave WooCommerce checkout page
    276280        if ( $payment_method_id_registered_by_multisafepay && $payment_method_id_registered_by_wc !== $payment_method_id_registered_by_multisafepay ) {
    277             if ( get_option( 'multisafepay_debugmode', false ) ) {
    278                 $message = 'Callback received with a different payment method for Order ID: ' . $this->woocommerce_order_id . ' and Order Number: ' . $this->multisafepay_order_id . ' on ' . $this->time_stamp . '. Payment method changed from ' . $payment_method_title_registered_by_wc . ' to ' . $payment_method_title_registered_by_multisafepay . '.';
    279                 Logger::log_info( $message );
    280                 $this->order->add_order_note( $message );
    281             }
    282 
     281            $message = 'Callback received with a different payment method for Order ID: ' . $this->woocommerce_order_id . ' and Order Number: ' . $this->multisafepay_order_id . ' on ' . $this->time_stamp . '. Payment method changed from ' . $payment_method_title_registered_by_wc . ' to ' . $payment_method_title_registered_by_multisafepay . '.';
     282            $this->logger->log_info( $message );
     283            OrderUtil::add_order_note( $this->order, $message, true );
    283284            $this->order = wc_get_order( $this->woocommerce_order_id );
    284285            $this->order->set_payment_method( $registered_by_multisafepay_payment_method_object );
  • multisafepay/tags/6.6.0/src/PaymentMethods/PaymentMethodsController.php

    r3050467 r3114383  
    66use MultiSafepay\Api\Transactions\TransactionResponse;
    77use MultiSafepay\Api\Transactions\UpdateRequest;
     8use MultiSafepay\Api\Wallets\ApplePay\MerchantSessionRequest;
    89use MultiSafepay\Exception\ApiException;
    9 use MultiSafepay\Api\Wallets\ApplePay\MerchantSessionRequest;
    1010use MultiSafepay\Util\Notification;
    1111use MultiSafepay\WooCommerce\Services\OrderService;
     
    1414use MultiSafepay\WooCommerce\Utils\Hpos;
    1515use MultiSafepay\WooCommerce\Utils\Logger;
     16use MultiSafepay\WooCommerce\Utils\Order as OrderUtil;
    1617use Psr\Http\Client\ClientExceptionInterface;
    1718use WC_Data_Exception;
     
    2627    public const VALIDATION_URL_KEY = 'validation_url';
    2728    public const ORIGIN_DOMAIN_KEY  = 'origin_domain';
     29
     30    /**
     31     * @var Logger
     32     */
     33    private $logger;
     34
     35    /**
     36     * @param Logger|null $logger
     37     */
     38    public function __construct( ?Logger $logger = null ) {
     39        $this->logger = $logger ?? new Logger();
     40    }
    2841
    2942    /**
     
    104117    public function set_multisafepay_transaction_as_shipped( int $order_id ): void {
    105118        $order = wc_get_order( $order_id );
    106         if ( strpos( $order->get_payment_method(), 'multisafepay_' ) !== false ) {
     119        if ( OrderUtil::is_multisafepay_order( $order ) ) {
    107120            $sdk                 = new SdkService();
    108121            $transaction_manager = $sdk->get_transaction_manager();
     
    112125                $transaction_manager->update( (string) $order->get_order_number(), $update_order );
    113126            } catch ( ApiException $api_exception ) {
    114                 Logger::log_error( $api_exception->getMessage() );
     127                $this->logger->log_error( $api_exception->getMessage() );
    115128                return;
    116129            }
     
    128141    public function set_multisafepay_transaction_as_invoiced( int $order_id ): void {
    129142        $order = wc_get_order( $order_id );
    130         if ( strpos( $order->get_payment_method(), 'multisafepay_' ) !== false ) {
     143        if ( OrderUtil::is_multisafepay_order( $order ) ) {
    131144            $sdk                 = new SdkService();
    132145            $transaction_manager = $sdk->get_transaction_manager();
     
    136149                $transaction_manager->update( (string) $order->get_order_number(), $update_order );
    137150            } catch ( ApiException $api_exception ) {
    138                 Logger::log_error( $api_exception->getMessage() );
     151                $this->logger->log_error( $api_exception->getMessage() );
    139152                return;
    140153            }
     
    178191
    179192        if ( ! $request->sanitize_params() ) {
    180             Logger::log_info( 'Notification for transactionid . ' . $transactionid . ' has been received but could not be sanitized' );
     193            $this->logger->log_info( 'Notification for transactionid . ' . $transactionid . ' has been received but could not be sanitized' );
    181194            header( 'Content-type: text/plain' );
    182195            die( 'OK' );
     
    185198        $payload_type = $request->get_param( 'payload_type' ) ?? '';
    186199        if ( 'pretransaction' === $payload_type ) {
    187             Logger::log_info( 'Notification for transactionid . ' . $transactionid . ' has been received but is going to be ignored, because is pretransaction type' );
     200            $this->logger->log_info( 'Notification for transactionid . ' . $transactionid . ' has been received but is going to be ignored, because is pretransaction type' );
    188201            header( 'Content-type: text/plain' );
    189202            die( 'OK' );
     
    196209
    197210        if ( ! $verify_notification ) {
    198             Logger::log_info( 'Notification for transactionid . ' . $transactionid . ' has been received but is not validated' );
     211            $this->logger->log_info( 'Notification for transactionid . ' . $transactionid . ' has been received but is not validated' );
    199212            header( 'Content-type: text/plain' );
    200213            die( 'OK' );
     
    202215
    203216        if ( get_option( 'multisafepay_debugmode', false ) ) {
    204             Logger::log_info( 'Notification has been received and validated for transaction id ' . $transactionid );
     217            $this->logger->log_info( 'Notification has been received and validated for transaction id ' . $transactionid );
    205218
    206219            if ( ! empty( $body ) ) {
    207                 Logger::log_info( 'Body of the POST notification: ' . wc_print_r( $body, true ) );
     220                $this->logger->log_info( 'Body of the POST notification: ' . wc_print_r( $body, true ) );
    208221            }
    209222        }
     
    250263
    251264        // Check if the payment method belongs to MultiSafepay
    252         if ( strpos( $order->get_payment_method(), 'multisafepay_' ) === false ) {
     265        if ( ! OrderUtil::is_multisafepay_order( $order ) ) {
    253266            return;
    254267        }
     
    260273        $gateway_object      = ( new PaymentMethodService() )->get_woocommerce_payment_gateway_by_id( $order->get_payment_method() );
    261274        if ( ! $gateway_object ) {
    262             Logger::log_error( ' Gateway object is null ' );
     275            $this->logger->log_error( ' Gateway object is null ' );
    263276            return;
    264277        }
     
    275288                if ( get_option( 'multisafepay_debugmode', false ) ) {
    276289                    $message = 'Order details has been registered in MultiSafepay and a payment link has been generated: ' . esc_url( $transaction->getPaymentUrl() );
    277                     Logger::log_info( $message );
     290                    $this->logger->log_info( $message );
    278291                    $order->add_order_note( $message );
    279292                }
    280293            }
    281294        } catch ( Exception | ApiException | ClientExceptionInterface $exception ) {
    282             Logger::log_error( $exception->getMessage() );
     295            $this->logger->log_error( $exception->getMessage() );
    283296        }
    284297    }
     
    326339     */
    327340    public function allow_cancel_multisafepay_orders_with_on_hold_status( array $order_status, WC_Order $order ): array {
    328         if ( strpos( $order->get_payment_method(), 'multisafepay_' ) !== false ) {
     341        if ( OrderUtil::is_multisafepay_order( $order ) ) {
    329342            $gateway = ( new PaymentMethodService() )->get_woocommerce_payment_gateway_by_id( $order->get_payment_method() );
    330343            if ( ! $gateway ) {
    331                 Logger::log_error( ' Gateway object is null ' );
     344                $this->logger->log_error( ' Gateway object is null ' );
    332345                return $order_status;
    333346            }
     
    363376        } catch ( ApiException | Exception | ClientExceptionInterface $exception ) {
    364377            $error_message = 'Error when trying to get the ApplePay session via MultiSafepay SDK';
    365             Logger::log_error( $error_message . ': ' . $exception->getMessage() );
     378            $this->logger->log_error( $error_message . ': ' . $exception->getMessage() );
    366379            wp_send_json( array( 'message' => $error_message ) );
    367380        }
     
    397410
    398411        if ( empty( $validation_url ) ) {
    399             Logger::log_error( 'Error when trying to get the ApplePay session. Validation URL empty' );
     412            $this->logger->log_error( 'Error when trying to get the ApplePay session. Validation URL empty' );
    400413            exit;
    401414        }
    402415
    403416        if ( empty( $origin_domain ) ) {
    404             Logger::log_error( 'Error when trying to get the ApplePay session. Origin domain empty' );
     417            $this->logger->log_error( 'Error when trying to get the ApplePay session. Origin domain empty' );
    405418            exit;
    406419        }
  • multisafepay/tags/6.6.0/src/Services/ApiTokenService.php

    r2974626 r3114383  
    2626
    2727    /**
     28     * @var Logger
     29     */
     30    private $logger;
     31
     32    /**
    2833     * ApiTokenService constructor.
     34     *
     35     * @param Logger|null $logger
    2936     */
    30     public function __construct() {
     37    public function __construct( ?Logger $logger = null ) {
     38        $this->logger            = $logger ?? new Logger();
    3139        $this->api_token_manager = ( new SdkService() )->get_api_token_manager();
    3240    }
     
    5058            $api_token = $this->api_token_manager->get()->getApiToken();
    5159        } catch ( ApiException | ClientExceptionInterface $exception ) {
    52             Logger::log_error( $exception->getMessage() );
     60            $this->logger->log_error( $exception->getMessage() );
    5361            return '';
    5462        }
  • multisafepay/tags/6.6.0/src/Services/OrderService.php

    r3048898 r3114383  
    7474        }
    7575
    76         if ( ! empty( $_POST[ ( $this->payment_method_service->get_woocommerce_payment_gateway_by_multisafepay_gateway_code( $gateway_code ) )->get_payment_method_id() . '_payment_component_payload' ] ) ) {
    77             $payment_method_id             = ( new PaymentMethodService() )->get_woocommerce_payment_gateway_by_multisafepay_gateway_code( $gateway_code )->get_payment_method_id();
     76        if ( ! empty( $_POST[ $order->get_payment_method() . '_payment_component_payload' ] ) ) {
     77            $payment_method_id             = $order->get_payment_method();
    7878            $payment_component_payload_key = $payment_method_id . '_payment_component_payload';
    7979            $payment_component_payload     = sanitize_text_field( wp_unslash( $_POST[ $payment_component_payload_key ] ?? '' ) );
  • multisafepay/tags/6.6.0/src/Services/PaymentMethodService.php

    r3088253 r3114383  
    1010use MultiSafepay\WooCommerce\PaymentMethods\Base\BaseGiftCardPaymentMethod;
    1111use MultiSafepay\WooCommerce\PaymentMethods\Base\BasePaymentMethod;
     12use MultiSafepay\WooCommerce\PaymentMethods\Base\BaseBrandedPaymentMethod;
    1213use MultiSafepay\WooCommerce\Utils\Logger;
    1314use Psr\Http\Client\ClientExceptionInterface;
     
    3132
    3233    /**
    33      * PaymentMethodsService constructor.
    34      *
    35      * @return void
    36      */
    37     public function __construct() {
     34     * @var Logger
     35     */
     36    private $logger;
     37
     38    /**
     39     * @param Logger|null $logger
     40     */
     41    public function __construct( ?Logger $logger = null ) {
     42        $this->logger = $logger ?? new Logger();
    3843        try {
    3944            $this->payment_method_manager = ( new SdkService() )->get_payment_method_manager();
    4045        } catch ( ApiException $api_exception ) {
    41             Logger::log_error( $api_exception->getMessage() );
     46            $this->logger->log_error( $api_exception->getMessage() );
    4247        }
    4348    }
     
    7580
    7681        if ( null === $this->payment_method_manager ) {
    77             Logger::log_error( 'SDK is not initialized' );
     82            $this->logger->log_error( 'SDK is not initialized' );
    7883            return array();
    7984        }
     
    9095            );
    9196        } catch ( Exception | ApiException | InvalidDataInitializationException | ClientExceptionInterface $exception ) {
    92             Logger::log_error( $exception->getMessage() );
     97            $this->logger->log_error( $exception->getMessage() );
    9398            return array();
    9499        }
     
    108113        $multisafepay_payment_methods = $this->get_multisafepay_payment_methods_from_api();
    109114        foreach ( $multisafepay_payment_methods as $multisafepay_payment_method ) {
    110             if ( isset( $multisafepay_payment_method['type'] ) && 'coupon' === $multisafepay_payment_method['type'] ) {
    111                 $woocommerce_payment_gateways[ self::get_legacy_woocommerce_payment_gateway_ids( $multisafepay_payment_method['id'] ) ] = new BaseGiftCardPaymentMethod( new PaymentMethod( $multisafepay_payment_method ) );
    112             }
    113             if ( isset( $multisafepay_payment_method['type'] ) && 'payment-method' === $multisafepay_payment_method['type'] ) {
    114                 $woocommerce_payment_gateways[ self::get_legacy_woocommerce_payment_gateway_ids( $multisafepay_payment_method['id'] ) ] = new BasePaymentMethod( new PaymentMethod( $multisafepay_payment_method ) );
    115             }
    116         }
     115            if ( isset( $multisafepay_payment_method['type'] ) ) {
     116                $woocommerce_payment_gateways = $this->create_woocommerce_payment_gateways( $multisafepay_payment_method, $woocommerce_payment_gateways );
     117            }
     118        }
     119
     120        return $woocommerce_payment_gateways;
     121    }
     122
     123    /**
     124     * @param array $multisafepay_payment_method
     125     * @param array $woocommerce_payment_gateways
     126     * @return array
     127     */
     128    public function create_woocommerce_payment_gateways( array $multisafepay_payment_method, array $woocommerce_payment_gateways ) : array {
     129        $payment_method_id = self::get_legacy_woocommerce_payment_gateway_ids( $multisafepay_payment_method['id'] );
     130
     131        try {
     132            $payment_method = new PaymentMethod( $multisafepay_payment_method );
     133        } catch ( InvalidDataInitializationException $exception ) {
     134            $this->logger->log_error( $exception->getMessage() );
     135            return $woocommerce_payment_gateways;
     136        }
     137
     138        if ( 'payment-method' === $multisafepay_payment_method['type'] ) {
     139            $woocommerce_payment_gateways[ $payment_method_id ] = new BasePaymentMethod( $payment_method );
     140            $woocommerce_payment_gateways                       = $this->create_branded_woocommerce_payment_gateways( $multisafepay_payment_method, $woocommerce_payment_gateways, $payment_method );
     141        }
     142
     143        if ( 'coupon' === $multisafepay_payment_method['type'] ) {
     144            $woocommerce_payment_gateways[ $payment_method_id ] = new BaseGiftCardPaymentMethod( $payment_method );
     145        }
     146
     147        return $woocommerce_payment_gateways;
     148    }
     149
     150    /**
     151     * @param array         $multisafepay_payment_method
     152     * @param array         $woocommerce_payment_gateways
     153     * @param PaymentMethod $payment_method
     154     * @return array
     155     */
     156    public function create_branded_woocommerce_payment_gateways( array $multisafepay_payment_method, array $woocommerce_payment_gateways, PaymentMethod $payment_method ) : array {
     157        foreach ( $multisafepay_payment_method['brands'] as $brand ) {
     158            if ( ! empty( $brand['allowed_countries'] ) ) {
     159                $payment_method_id                                  = self::get_legacy_woocommerce_payment_gateway_ids( $brand['id'] );
     160                $woocommerce_payment_gateways[ $payment_method_id ] = new BaseBrandedPaymentMethod( $payment_method, $brand );
     161            }
     162        }
     163
    117164        return $woocommerce_payment_gateways;
    118165    }
     
    174221            if ( $payment_method_object->supportsPaymentComponent() ) {
    175222                $payment_methods_with_payment_component[] = self::get_legacy_woocommerce_payment_gateway_ids( $payment_method_object->getId() );
     223                foreach ( $payment_method['brands'] as $brand ) {
     224                    if ( ! empty( $brand['allowed_countries'] ) ) {
     225                        $payment_methods_with_payment_component[] = self::get_legacy_woocommerce_payment_gateway_ids( $brand['id'] );
     226                    }
     227                }
    176228            }
    177229        }
     
    188240     */
    189241    public static function get_legacy_woocommerce_payment_gateway_ids( string $code ): string {
    190 
    191242        $woocommerce_payment_gateway_id = 'multisafepay_' . str_replace( '-', '_', sanitize_title( strtolower( $code ) ) );
    192243
  • multisafepay/tags/6.6.0/src/Services/SdkService.php

    r3048898 r3114383  
    1414use MultiSafepay\Sdk;
    1515use MultiSafepay\WooCommerce\Client\MultiSafepayClient;
    16 use MultiSafepay\WooCommerce\Services\PaymentMethodService;
    1716use MultiSafepay\WooCommerce\Utils\Logger;
    1817use Nyholm\Psr7\Factory\Psr17Factory;
     
    4443    private $sdk = null;
    4544
     45    /**
     46     * @var Logger
     47     */
     48    private $logger;
    4649
    4750    /**
    4851     * SdkService constructor.
    4952     *
    50      * @param  string  $api_key
    51      * @param  boolean $test_mode
    52      */
    53     public function __construct( string $api_key = null, bool $test_mode = null ) {
     53     * @param  string      $api_key
     54     * @param  boolean     $test_mode
     55     * @param Logger|null $logger
     56     */
     57    public function __construct( string $api_key = null, bool $test_mode = null, ?Logger $logger = null ) {
    5458        $this->api_key   = $api_key ?? $this->get_api_key();
    5559        $this->test_mode = $test_mode ?? $this->get_test_mode();
     60        $this->logger    = $logger ?? new Logger();
    5661        $psr_factory     = new Psr17Factory();
    5762        $client          = new MultiSafepayClient();
     
    6065        } catch ( InvalidApiKeyException $invalid_api_key_exception ) {
    6166            set_transient( 'multisafepay_payment_methods', array() );
    62             Logger::log_error( $invalid_api_key_exception->getMessage() );
     67            $this->logger->log_error( $invalid_api_key_exception->getMessage() );
    6368        }
    6469    }
     
    96101            return $this->sdk->getGatewayManager();
    97102        } catch ( ApiException $api_exception ) {
    98             Logger::log_error( $api_exception->getMessage() );
     103            $this->logger->log_error( $api_exception->getMessage() );
    99104            return new WP_Error( 'multisafepay-warning', $api_exception->getMessage() );
    100105        }
     
    111116            return $this->get_gateway_manager()->getGateways( true );
    112117        } catch ( ApiException $api_exception ) {
    113             Logger::log_error( $api_exception->getMessage() );
     118            $this->logger->log_error( $api_exception->getMessage() );
    114119            return new WP_Error( 'multisafepay-warning', $api_exception->getMessage() );
    115120        }
     
    149154    public function get_api_token_manager(): ?ApiTokenManager {
    150155        if ( null === $this->sdk ) {
    151             Logger::log_error( 'SDK is not initialized' );
     156            $this->logger->log_error( 'SDK is not initialized' );
    152157            return null;
    153158        }
     
    162167    public function get_payment_method_manager(): ?PaymentMethodManager {
    163168        if ( null === $this->sdk ) {
    164             Logger::log_error( 'SDK is not initialized' );
     169            $this->logger->log_error( 'SDK is not initialized' );
    165170            return null;
    166171        }
     
    168173            return $this->sdk->getPaymentMethodManager();
    169174        } catch ( ApiException $api_exception ) {
    170             Logger::log_error( $api_exception->getMessage() );
     175            $this->logger->log_error( $api_exception->getMessage() );
    171176            return null;
    172177        }
     
    184189            $tokens = $this->sdk->getTokenManager()->getListByGatewayCodeAsArray( $customer_reference, $gateway_code );
    185190        } catch ( ApiException $api_exception ) {
    186             Logger::log_error( $api_exception->getMessage() );
     191            $this->logger->log_error( $api_exception->getMessage() );
    187192            return array();
    188193        } catch ( ClientExceptionInterface $client_exception ) {
    189             Logger::log_error( $client_exception->getMessage() );
     194            $this->logger->log_error( $client_exception->getMessage() );
    190195            return array();
    191196        } catch ( Exception $exception ) {
    192             Logger::log_error( $exception->getMessage() );
     197            $this->logger->log_error( $exception->getMessage() );
    193198            return array();
    194199        }
     
    207212            $gateway_merchant_id = $account_manager->get()->getAccountId();
    208213        } catch ( ApiException | ClientExceptionInterface | Exception $exception ) {
    209             Logger::log_error( 'Error when try to set the merchant credentials: ' . $exception->getMessage() );
     214            $this->logger->log_error( 'Error when try to set the merchant credentials: ' . $exception->getMessage() );
    210215        }
    211216
  • multisafepay/tags/6.6.0/src/Services/ShoppingCartService.php

    r2995309 r3114383  
    2525
    2626    /**
     27     * @var Logger
     28     */
     29    private $logger;
     30
     31    /**
     32     * @param Logger|null $logger
     33     */
     34    public function __construct( ?Logger $logger = null ) {
     35        $this->logger = $logger ?? new Logger();
     36    }
     37
     38    /**
    2739     * @param WC_Order $order
    2840     * @param string   $currency
     
    3951
    4052        if ( get_option( 'multisafepay_debugmode', false ) ) {
    41             Logger::log_info( wc_print_r( $order->get_items(), true ) );
     53            $this->logger->log_info( wc_print_r( $order->get_items(), true ) );
    4254        }
    4355
     
    7284
    7385        if ( get_option( 'multisafepay_debugmode', false ) ) {
    74             Logger::log_info( wp_json_encode( $shopping_cart->getData() ) );
     86            $this->logger->log_info( wp_json_encode( $shopping_cart->getData() ) );
    7587        }
    7688
  • multisafepay/tags/6.6.0/src/Utils/Logger.php

    r2974626 r3114383  
    44
    55use WC_Log_Handler_File;
     6use WC_Logger_Interface;
    67
    78/**
     
    910 */
    1011class Logger {
     12
     13    /**
     14     * @var WC_Logger_Interface
     15     */
     16    private $logger;
     17
     18    /**
     19     * @param WC_Logger_Interface|null $logger
     20     */
     21    public function __construct( ?WC_Logger_Interface $logger = null ) {
     22        $this->logger = $logger ?? wc_get_logger();
     23    }
    1124
    1225    /**
     
    1730     * @param string $message
    1831     */
    19     public static function log_emergency( string $message ) {
    20         $logger = wc_get_logger();
    21         $logger->log( 'emergency', $message, array( 'source' => 'multisafepay' ) );
     32    public function log_emergency( string $message ) {
     33        $this->logger->log( 'emergency', $message, array( 'source' => 'multisafepay' ) );
    2234    }
    2335
     
    2941     * @param string $message
    3042     */
    31     public static function log_alert( string $message ) {
    32         $logger = wc_get_logger();
    33         $logger->log( 'alert', $message, array( 'source' => 'multisafepay' ) );
     43    public function log_alert( string $message ) {
     44        $this->logger->log( 'alert', $message, array( 'source' => 'multisafepay' ) );
    3445    }
    3546
     
    4152     * @param string $message
    4253     */
    43     public static function log_critical( string $message ) {
    44         $logger = wc_get_logger();
    45         $logger->log( 'critical', $message, array( 'source' => 'multisafepay' ) );
     54    public function log_critical( string $message ) {
     55        $this->logger->log( 'critical', $message, array( 'source' => 'multisafepay' ) );
    4656    }
    4757
     
    5363     * @param string $message
    5464     */
    55     public static function log_error( string $message ) {
    56         $logger = wc_get_logger();
    57         $logger->log( 'error', $message, array( 'source' => 'multisafepay' ) );
     65    public function log_error( string $message ) {
     66        $this->logger->log( 'error', $message, array( 'source' => 'multisafepay' ) );
    5867    }
    5968
     
    6574     * @param string $message
    6675     */
    67     public static function log_warning( string $message ) {
    68         $logger = wc_get_logger();
    69         $logger->log( 'warning', $message, array( 'source' => 'multisafepay' ) );
     76    public function log_warning( string $message ) {
     77        $this->logger->log( 'warning', $message, array( 'source' => 'multisafepay' ) );
    7078    }
    7179
     
    7785     * @param string $message
    7886     */
    79     public static function log_notice( string $message ) {
    80         $logger = wc_get_logger();
    81         $logger->log( 'notice', $message, array( 'source' => 'multisafepay' ) );
     87    public function log_notice( string $message ) {
     88        $this->logger->log( 'notice', $message, array( 'source' => 'multisafepay' ) );
    8289    }
    8390
     
    8996     * @param string $message
    9097     */
    91     public static function log_info( string $message ) {
     98    public function log_info( string $message ) {
    9299        if ( get_option( 'multisafepay_debugmode', false ) ) {
    93             $logger = wc_get_logger();
    94             $logger->log( 'info', $message, array( 'source' => 'multisafepay' ) );
     100            $this->logger->log( 'info', $message, array( 'source' => 'multisafepay' ) );
    95101        }
    96102    }
     
    103109     * @param string $message
    104110     */
    105     public static function log_debug( string $message ) {
     111    public function log_debug( string $message ) {
    106112        if ( get_option( 'multisafepay_debugmode', false ) ) {
    107             $logger = wc_get_logger();
    108             $logger->log( 'debug', $message, array( 'source' => 'multisafepay' ) );
     113            $this->logger->log( 'debug', $message, array( 'source' => 'multisafepay' ) );
    109114        }
    110115    }
     
    116121     */
    117122    private function get_logs(): array {
    118         $logs = WC_Log_Handler_File::get_log_files();
    119         return $logs;
     123        return WC_Log_Handler_File::get_log_files();
    120124    }
    121125
  • multisafepay/tags/6.6.0/vendor/autoload.php

    r3048898 r3114383  
    2323require_once __DIR__ . '/composer/autoload_real.php';
    2424
    25 return ComposerAutoloaderInit8122490751e95ad36d38dc1115ae59ff::getLoader();
     25return ComposerAutoloaderInitdbc0eb47ba0f8cbc67eba2344d97c2f8::getLoader();
  • multisafepay/tags/6.6.0/vendor/composer/autoload_real.php

    r3048898 r3114383  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInit8122490751e95ad36d38dc1115ae59ff
     5class ComposerAutoloaderInitdbc0eb47ba0f8cbc67eba2344d97c2f8
    66{
    77    private static $loader;
     
    2525        require __DIR__ . '/platform_check.php';
    2626
    27         spl_autoload_register(array('ComposerAutoloaderInit8122490751e95ad36d38dc1115ae59ff', 'loadClassLoader'), true, true);
     27        spl_autoload_register(array('ComposerAutoloaderInitdbc0eb47ba0f8cbc67eba2344d97c2f8', 'loadClassLoader'), true, true);
    2828        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
    29         spl_autoload_unregister(array('ComposerAutoloaderInit8122490751e95ad36d38dc1115ae59ff', 'loadClassLoader'));
     29        spl_autoload_unregister(array('ComposerAutoloaderInitdbc0eb47ba0f8cbc67eba2344d97c2f8', 'loadClassLoader'));
    3030
    3131        require __DIR__ . '/autoload_static.php';
    32         call_user_func(\Composer\Autoload\ComposerStaticInit8122490751e95ad36d38dc1115ae59ff::getInitializer($loader));
     32        call_user_func(\Composer\Autoload\ComposerStaticInitdbc0eb47ba0f8cbc67eba2344d97c2f8::getInitializer($loader));
    3333
    3434        $loader->register(true);
  • multisafepay/tags/6.6.0/vendor/composer/autoload_static.php

    r3048898 r3114383  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInit8122490751e95ad36d38dc1115ae59ff
     7class ComposerStaticInitdbc0eb47ba0f8cbc67eba2344d97c2f8
    88{
    99    public static $prefixLengthsPsr4 = array (
     
    6363    {
    6464        return \Closure::bind(function () use ($loader) {
    65             $loader->prefixLengthsPsr4 = ComposerStaticInit8122490751e95ad36d38dc1115ae59ff::$prefixLengthsPsr4;
    66             $loader->prefixDirsPsr4 = ComposerStaticInit8122490751e95ad36d38dc1115ae59ff::$prefixDirsPsr4;
    67             $loader->classMap = ComposerStaticInit8122490751e95ad36d38dc1115ae59ff::$classMap;
     65            $loader->prefixLengthsPsr4 = ComposerStaticInitdbc0eb47ba0f8cbc67eba2344d97c2f8::$prefixLengthsPsr4;
     66            $loader->prefixDirsPsr4 = ComposerStaticInitdbc0eb47ba0f8cbc67eba2344d97c2f8::$prefixDirsPsr4;
     67            $loader->classMap = ComposerStaticInitdbc0eb47ba0f8cbc67eba2344d97c2f8::$classMap;
    6868
    6969        }, null, ClassLoader::class);
  • multisafepay/tags/6.6.0/vendor/composer/installed.json

    r3088253 r3114383  
    33        {
    44            "name": "multisafepay/php-sdk",
    5             "version": "5.13.0",
    6             "version_normalized": "5.13.0.0",
     5            "version": "5.14.0",
     6            "version_normalized": "5.14.0.0",
    77            "source": {
    88                "type": "git",
    99                "url": "https://github.com/MultiSafepay/php-sdk.git",
    10                 "reference": "b88fa079981d590a70275d528cf52d8fd07affab"
    11             },
    12             "dist": {
    13                 "type": "zip",
    14                 "url": "https://api.github.com/repos/MultiSafepay/php-sdk/zipball/b88fa079981d590a70275d528cf52d8fd07affab",
    15                 "reference": "b88fa079981d590a70275d528cf52d8fd07affab",
     10                "reference": "408f102e3228f072f2c1bcc76ac29a8031415480"
     11            },
     12            "dist": {
     13                "type": "zip",
     14                "url": "https://api.github.com/repos/MultiSafepay/php-sdk/zipball/408f102e3228f072f2c1bcc76ac29a8031415480",
     15                "reference": "408f102e3228f072f2c1bcc76ac29a8031415480",
    1616                "shasum": ""
    1717            },
     
    3838                "jschaedl/iban-validation": "Adds additional IBAN validation for \\MultiSafepay\\ValueObject\\IbanNumber"
    3939            },
    40             "time": "2024-04-16T11:41:31+00:00",
     40            "time": "2024-07-08T12:43:31+00:00",
    4141            "type": "library",
    4242            "installation-source": "dist",
     
    5353            "support": {
    5454                "issues": "https://github.com/MultiSafepay/php-sdk/issues",
    55                 "source": "https://github.com/MultiSafepay/php-sdk/tree/5.13.0"
     55                "source": "https://github.com/MultiSafepay/php-sdk/tree/5.14.0"
    5656            },
    5757            "install-path": "../multisafepay/php-sdk"
  • multisafepay/tags/6.6.0/vendor/composer/installed.php

    r3099249 r3114383  
    22    'root' => array(
    33        'name' => 'multisafepay/woocommerce',
    4         'pretty_version' => '6.5.1',
    5         'version' => '6.5.1.0',
    6         'reference' => 'a57a06a32837f1542476a9726a1e3749e08ba92d',
     4        'pretty_version' => '6.6.0',
     5        'version' => '6.6.0.0',
     6        'reference' => null,
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1212    'versions' => array(
    1313        'multisafepay/php-sdk' => array(
    14             'pretty_version' => '5.13.0',
    15             'version' => '5.13.0.0',
    16             'reference' => 'b88fa079981d590a70275d528cf52d8fd07affab',
     14            'pretty_version' => '5.14.0',
     15            'version' => '5.14.0.0',
     16            'reference' => '408f102e3228f072f2c1bcc76ac29a8031415480',
    1717            'type' => 'library',
    1818            'install_path' => __DIR__ . '/../multisafepay/php-sdk',
     
    2121        ),
    2222        'multisafepay/woocommerce' => array(
    23             'pretty_version' => '6.5.1',
    24             'version' => '6.5.1.0',
    25             'reference' => 'a57a06a32837f1542476a9726a1e3749e08ba92d',
     23            'pretty_version' => '6.6.0',
     24            'version' => '6.6.0.0',
     25            'reference' => null,
    2626            'type' => 'wordpress-plugin',
    2727            'install_path' => __DIR__ . '/../../',
  • multisafepay/tags/6.6.0/vendor/multisafepay/php-sdk/CHANGELOG.md

    r3072171 r3114383  
    77## [Unreleased]
    88
     9## [5.14.0] - 2024-07-08
     10### Added
     11- PHPSDK-155: Throw ApiUnavailableException when API returns 501/503 HTTP codes
     12- PHPSDK-156: Add getGatewayId in TransactionResponse class
     13
    914## [5.13.0] - 2024-04-16
    1015### Added
    11 + PHPSDK-151: Update Gateways::SHOPPING_CART_REQUIRED_GATEWAYS adding 'BNPL_INST', 'IN3B2B', 'SANTANDER', 'ZINIA', 'ZINIA_IN3', 'BNPL_OB', 'BNPL_MF' gateways codes
     16- PHPSDK-151: Update Gateways::SHOPPING_CART_REQUIRED_GATEWAYS adding 'BNPL_INST', 'IN3B2B', 'SANTANDER', 'ZINIA', 'ZINIA_IN3', 'BNPL_OB', 'BNPL_MF' gateways codes
    1217
    1318## [5.12.1] - 2024-03-11
    1419### Fixed
    15 + PHPSDK-146: Fix ApiException not being hinted as a thrown exception, even though it is, by fixing the PHP DocBlocks @throws tags
     20- PHPSDK-146: Fix ApiException not being hinted as a thrown exception, even though it is, by fixing the PHP DocBlocks @throws tags
    1621
    1722## [5.12.0] - 2023-12-01
    1823### Added
    19 + PHPSDK-139: Add support to set var1, var2 and var3, within the OrderRequest object
    20 + PHPSDK-140: Add support to set custom_info, within the OrderRequest object, thanks to @DaanDeSmedt
     24- PHPSDK-139: Add support to set var1, var2 and var3, within the OrderRequest object
     25- PHPSDK-140: Add support to set custom_info, within the OrderRequest object, thanks to @DaanDeSmedt
    2126
    2227## [5.11.2] - 2023-10-13
    2328### Fixed
    24 + PHPSDK-134: Fix errors when only reference is set, within the CustomerDetails object
    25 
    26 ### Changed
    27 + PHPSDK-136: Remove PluginDetails as mandatory from the Order Request
     29- PHPSDK-134: Fix errors when only reference is set, within the CustomerDetails object
     30
     31### Changed
     32- PHPSDK-136: Remove PluginDetails as mandatory from the Order Request
    2833
    2934## [5.11.1] - 2023-07-31
     
    8994## [5.5.0] - 2022-05-11
    9095### Added
    91 + PHPSDK-90: Add MAESTRO tokens within the results of the CREDITCARD tokens request
    92 
    93 ### Changed
    94 + PHPSDK-91: Add trim on API key when initializing the SDK
     96- PHPSDK-90: Add MAESTRO tokens within the results of the CREDITCARD tokens request
     97
     98### Changed
     99- PHPSDK-91: Add trim on API key when initializing the SDK
    95100
    96101## [5.4.0] - 2021-11-30
  • multisafepay/tags/6.6.0/vendor/multisafepay/php-sdk/composer.json

    r3072171 r3114383  
    44  "type": "library",
    55  "license": "MIT",
    6   "version": "5.13.0",
     6  "version": "5.14.0",
    77  "require": {
    88    "php": "^7.2|^8.0",
  • multisafepay/tags/6.6.0/vendor/multisafepay/php-sdk/src/Api/Base/Response.php

    r3050467 r3114383  
    99use MultiSafepay\Api\Pager\Pager;
    1010use MultiSafepay\Exception\ApiException;
     11use MultiSafepay\Exception\ApiUnavailableException;
    1112
    1213/**
     
    3839     * @param array $context
    3940     * @return Response
    40      * @throws ApiException
     41     * @throws ApiException|ApiUnavailableException
    4142     */
    4243    public static function withJson(string $json, array $context = []): Response
     
    5556     * @param array $context
    5657     * @param string $raw
    57      * @throws ApiException
     58     * @throws ApiException|ApiUnavailableException
    5859     */
    5960    public function __construct(array $data, array $context = [], string $raw = '')
     
    8384     * @return void
    8485     * @throws ApiException
     86     * @throws ApiUnavailableException
    8587     */
    8688    private function validate(array $data, array $context = []): void
     
    9597        if (!empty($data['data']) && !is_array($data['data'])) {
    9698            [$errorCode, $errorInfo] = self::ERROR_INVALID_DATA_TYPE;
     99        }
     100
     101        if (in_array($context['http_response_code'], [501, 503])) {
     102            throw (new ApiUnavailableException(
     103                'The MultiSafepay API could not be reached',
     104                $context['http_response_code']
     105            ));
    97106        }
    98107
  • multisafepay/tags/6.6.0/vendor/multisafepay/php-sdk/src/Api/Transactions/TransactionResponse.php

    r3050467 r3114383  
    3131class TransactionResponse extends ResponseBody
    3232{
    33 
    3433    /**
    3534     * @var string
     
    383382        return in_array($this->getPaymentDetails()->getType(), Gateways::SHOPPING_CART_REQUIRED_GATEWAYS, true);
    384383    }
     384
     385    /**
     386     * Retrieve the gateway ID from the transaction
     387     * Will return multiple gateway IDs as a string of comma separated values if multiple payment methods are used
     388     *
     389     * @return string
     390     */
     391    public function getGatewayId(): string
     392    {
     393        $paymentMethods = [];
     394
     395        foreach ($this->getPaymentMethods() as $paymentMethod) {
     396            if ($paymentMethod->getType() === 'COUPON') {
     397                $paymentMethods[] = $paymentMethod->getData()['coupon_brand'] ?? 'unknown';
     398                continue;
     399            }
     400
     401            $paymentMethods[] = $paymentMethod->getType();
     402        }
     403
     404        return implode(', ', $paymentMethods);
     405    }
    385406}
  • multisafepay/tags/6.6.0/vendor/multisafepay/php-sdk/src/Client/Client.php

    r3050467 r3114383  
    1212use MultiSafepay\Api\Base\Response as ApiResponse;
    1313use MultiSafepay\Exception\ApiException;
     14use MultiSafepay\Exception\ApiUnavailableException;
    1415use MultiSafepay\Exception\InvalidApiKeyException;
    15 use MultiSafepay\Exception\StrictModeException;
    1616use Psr\Http\Client\ClientExceptionInterface;
    1717use Psr\Http\Client\ClientInterface;
     
    105105     * @param array $context
    106106     * @return ApiResponse
    107      * @throws ClientExceptionInterface
    108      * @throws ApiException
     107     * @throws ClientExceptionInterface|ApiException|ApiUnavailableException
    109108     */
    110109    public function createPostRequest(
     
    116115            ->withBody($this->createBody($this->getRequestBody($requestBody)))
    117116            ->withHeader('Content-Length', strlen($this->getRequestBody($requestBody)));
     117        $httpResponse = $this->httpClient->sendRequest($request);
    118118
    119119        $context['headers'] = $request->getHeaders();
    120120        $context['request_body'] = $this->getRequestBody($requestBody);
    121         $httpResponse = $this->httpClient->sendRequest($request);
     121        $context['http_response_code'] = $httpResponse->getStatusCode() ?? 0;
     122
    122123        return ApiResponse::withJson($httpResponse->getBody()->getContents(), $context);
    123124    }
     
    129130     * @param array $context
    130131     * @return ApiResponse
    131      * @throws ClientExceptionInterface|ApiException
     132     * @throws ClientExceptionInterface|ApiException|ApiUnavailableException
    132133     */
    133134    public function createPatchRequest(
     
    139140            ->withBody($this->createBody($this->getRequestBody($requestBody)))
    140141            ->withHeader('Content-Length', strlen($this->getRequestBody($requestBody)));
     142        $httpResponse = $this->httpClient->sendRequest($request);
    141143
    142144        $context['headers'] = $request->getHeaders();
    143145        $context['request_body'] = $this->getRequestBody($requestBody);
    144         $httpResponse = $this->httpClient->sendRequest($request);
    145         return ApiResponse::withJson($httpResponse->getBody()->getContents(), $context);
    146     }
    147 
    148     /**
    149      * @param string $endpoint
    150      * @param array $parameters
    151      * @param array $context
    152      * @return ApiResponse
    153      * @throws ClientExceptionInterface|ApiException
     146        $context['http_response_code'] = $httpResponse->getStatusCode() ?? 0;
     147
     148        return ApiResponse::withJson($httpResponse->getBody()->getContents(), $context);
     149    }
     150
     151    /**
     152     * @param string $endpoint
     153     * @param array $parameters
     154     * @param array $context
     155     * @return ApiResponse
     156     * @throws ClientExceptionInterface|ApiException|ApiUnavailableException
    154157     */
    155158    public function createGetRequest(string $endpoint, array $parameters = [], array $context = []): ApiResponse
     
    157160        $request = $this->createRequest($endpoint, self::METHOD_GET, $parameters);
    158161        $httpResponse = $this->httpClient->sendRequest($request);
     162
    159163        $context['headers'] = $request->getHeaders();
    160164        $context['request_params'] = $parameters;
    161         return ApiResponse::withJson($httpResponse->getBody()->getContents(), $context);
    162     }
    163 
    164     /**
    165      * @param string $endpoint
    166      * @param array $parameters
    167      * @param array $context
    168      * @return ApiResponse
    169      * @throws ClientExceptionInterface|ApiException
     165        $context['http_response_code'] = $httpResponse->getStatusCode() ?? 0;
     166
     167        return ApiResponse::withJson($httpResponse->getBody()->getContents(), $context);
     168    }
     169
     170    /**
     171     * @param string $endpoint
     172     * @param array $parameters
     173     * @param array $context
     174     * @return ApiResponse
     175     * @throws ClientExceptionInterface|ApiException|ApiUnavailableException
    170176     */
    171177    public function createDeleteRequest(string $endpoint, array $parameters = [], array $context = []): ApiResponse
     
    173179        $request = $this->createRequest($endpoint, self::METHOD_DELETE, $parameters);
    174180        $httpResponse = $this->httpClient->sendRequest($request);
     181
    175182        $context['headers'] = $request->getHeaders();
    176183        $context['request_params'] = $parameters;
     184        $context['http_response_code'] = $httpResponse->getStatusCode() ?? 0;
     185
    177186        return ApiResponse::withJson($httpResponse->getBody()->getContents(), $context);
    178187    }
     
    203212        }
    204213        $endpoint .= '?' . http_build_query($parameters);
     214
    205215        return $this->url . $endpoint;
    206216    }
     
    236246    {
    237247        $this->strictMode = $strictMode;
     248
    238249        return $this;
    239250    }
     
    249260        $url = $this->getRequestUrl($endpoint, $parameters);
    250261        $requestFactory = $this->getRequestFactory();
     262
    251263        return $requestFactory->createRequest($method, $url)
    252264            ->withHeader('api_key', $this->apiKey->get())
     
    262274    {
    263275        $requestBody->useStrictMode($this->strictMode);
     276
    264277        return json_encode($requestBody->getData(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
    265278    }
  • multisafepay/tags/6.6.0/vendor/multisafepay/php-sdk/src/Util/Version.php

    r3072171 r3114383  
    1818class Version
    1919{
    20     public const SDK_VERSION = '5.13.0';
     20    public const SDK_VERSION = '5.14.0';
    2121
    2222    /**
  • multisafepay/trunk/multisafepay.php

    r3099249 r3114383  
    55 * Plugin URI:              https://docs.multisafepay.com/docs/woocommerce
    66 * Description:             MultiSafepay Payment Plugin
    7  * Version:                 6.5.1
     7 * Version:                 6.6.0
    88 * Author:                  MultiSafepay
    99 * Author URI:              https://www.multisafepay.com
     
    1212 * License URI:             http://www.gnu.org/licenses/gpl-3.0.html
    1313 * Requires at least:       6.0
    14  * Tested up to:            6.5.4
     14 * Tested up to:            6.5.5
    1515 * WC requires at least:    6.0.0
    16  * WC tested up to:         8.8.3
     16 * WC tested up to:         9.0.2
    1717 * Requires PHP:            7.3
    1818 * Text Domain:             multisafepay
     
    2727 * Plugin version
    2828 */
    29 define( 'MULTISAFEPAY_PLUGIN_VERSION', '6.5.1' );
     29define( 'MULTISAFEPAY_PLUGIN_VERSION', '6.6.0' );
    3030
    3131/**
  • multisafepay/trunk/readme.txt

    r3099249 r3114383  
    33Tags: multisafepay, payment gateway, credit cards, ideal, bnpl
    44Requires at least: 6.0
    5 Tested up to: 6.5.4
     5Tested up to: 6.5.5
    66Requires PHP: 7.3
    7 Stable tag: 6.5.1
     7Stable tag: 6.6.0
    88License: MIT
    99
     
    128128== Upgrade Notice ==
    129129
    130 = 6.5.1 =
     130= 6.6.0 =
    1311316.x.x is a major upgrade in which the MultiSafepay payment methods are registered dynamically via an API request to MultiSafepay. If you are upgrading from 5.X.X version, after the upgrade, please navigate to the MultiSafepay settings page, and to each one of the payment methods enabled in your account, and confirm the settings in each section are set up according to your preferences.
    132132
     
    144144
    145145== Changelog ==
     146= Release Notes - WooCommerce 6.6.0 (Jul 8th, 2024) =
     147
     148### Added
     149+ PLGWOOS-946: Add support for branded credit and debit cards
     150
     151### Changed
     152+ PLGWOOS-943: Refactor PaymentMethodCallback class (#574)
     153+ PLGWOOS-948: General improvements to increase unit test coverage
     154
    146155= Release Notes - WooCommerce 6.5.1 (Jun 7th, 2024) =
    147156
  • multisafepay/trunk/src/Client/MultiSafepayClient.php

    r3090804 r3114383  
    1414 */
    1515class MultiSafepayClient implements ClientInterface {
     16
     17    /**
     18     * @var Logger
     19     */
     20    private $logger;
     21
     22    /**
     23     * @param Logger|null $logger
     24     */
     25    public function __construct( ?Logger $logger = null ) {
     26        $this->logger = $logger ?? new Logger();
     27    }
    1628
    1729    /**
     
    3345            }
    3446        } catch ( Exception $exception ) {
    35             Logger::log_error( 'Error when process request via MultiSafepayClient: ' . $exception->getMessage() );
     47            $this->logger->log_error( 'Error when process request via MultiSafepayClient: ' . $exception->getMessage() );
    3648            throw new Exception( $exception->getMessage() );
    3749        }
  • multisafepay/trunk/src/PaymentMethods/Base/BasePaymentMethod.php

    r3099249 r3114383  
    109109
    110110    /**
    111      * Defines if the payment method is tokenizable
     111     * @var Logger
     112     */
     113    private $logger;
     114
     115    /**
     116     * BasePaymentMethod constructor.
    112117     *
    113118     * @param PaymentMethod $payment_method
    114      */
    115     public function __construct( PaymentMethod $payment_method ) {
     119     * @param Logger|null   $logger
     120     */
     121    public function __construct( PaymentMethod $payment_method, ?Logger $logger = null ) {
     122        $this->logger         = $logger ?? new Logger();
    116123        $this->payment_method = $payment_method;
    117124        $this->supports       = array( 'products', 'refunds' );
     
    636643            $transaction = $transaction_manager->create( $order_request );
    637644        } catch ( ApiException | ClientExceptionInterface $exception ) {
    638             Logger::log_error( $exception->getMessage() );
     645            $this->logger->log_error( $exception->getMessage() );
    639646            wc_add_notice( __( 'There was a problem processing your payment. Please try again later or contact with us.', 'multisafepay' ), 'error' );
    640647            return;
     
    642649
    643650        if ( get_option( 'multisafepay_debugmode', false ) ) {
    644             Logger::log_info( 'Start MultiSafepay transaction for the order ID ' . $order_id . ' on ' . date( 'd/m/Y H:i:s' ) . ' with payment URL ' . $transaction->getPaymentUrl() );
     651            $this->logger->log_info( 'Start MultiSafepay transaction for the order ID ' . $order_id . ' on ' . date( 'd/m/Y H:i:s' ) . ' with payment URL ' . $transaction->getPaymentUrl() );
    645652        }
    646653
  • multisafepay/trunk/src/PaymentMethods/Base/BasePaymentMethodBlocks.php

    r3090804 r3114383  
    4242            $multisafepay_payment_methods = $payment_method_service->get_multisafepay_payment_methods_from_api();
    4343            foreach ( $multisafepay_payment_methods as $multisafepay_payment_method ) {
    44                 $woocommerce_payment_gateway = null;
     44                $woocommerce_payment_gateways = array();
     45
    4546                if ( isset( $multisafepay_payment_method['type'] ) && ( 'coupon' === $multisafepay_payment_method['type'] ) ) {
    46                     $woocommerce_payment_gateway = new BaseGiftCardPaymentMethod( new PaymentMethod( $multisafepay_payment_method ) );
    47                 }
    48                 if ( isset( $multisafepay_payment_method['type'] ) && ( 'payment-method' === $multisafepay_payment_method['type'] ) ) {
    49                     $woocommerce_payment_gateway = new BasePaymentMethod( new PaymentMethod( $multisafepay_payment_method ) );
     47                    $woocommerce_payment_gateways[] = new BaseGiftCardPaymentMethod( new PaymentMethod( $multisafepay_payment_method ) );
    5048                }
    5149
    52                 // Include direct payment methods without components just in the checkout page of the frontend context
    53                 if (
    54                     $woocommerce_payment_gateway->check_direct_payment_methods_without_components() &&
    55                     ! $woocommerce_payment_gateway->admin_editing_checkout_page()
    56                 ) {
    57                     $this->gateways[] = $woocommerce_payment_gateway;
     50                if ( isset( $multisafepay_payment_method['type'] ) && ( 'payment-method' === $multisafepay_payment_method['type'] ) ) {
     51                    $woocommerce_payment_gateways[] = new BasePaymentMethod( new PaymentMethod( $multisafepay_payment_method ) );
     52                    foreach ( $multisafepay_payment_method['brands'] as $brand ) {
     53                        if ( ! empty( $brand['allowed_countries'] ) ) {
     54                            $woocommerce_payment_gateways[] = new BaseBrandedPaymentMethod( new PaymentMethod( $multisafepay_payment_method ), $brand );
     55                        }
     56                    }
    5857                }
    5958
    60                 if ( ( 'redirect' === $woocommerce_payment_gateway->get_payment_method_type() ) && $woocommerce_payment_gateway->is_available() ) {
    61                     $this->gateways[] = $woocommerce_payment_gateway;
     59                foreach ( $woocommerce_payment_gateways as $woocommerce_payment_gateway ) {
     60                    // Include direct payment methods without components just in the checkout page of the frontend context
     61                    if (
     62                        $woocommerce_payment_gateway->check_direct_payment_methods_without_components() &&
     63                        ! $woocommerce_payment_gateway->admin_editing_checkout_page()
     64                    ) {
     65                        $this->gateways[] = $woocommerce_payment_gateway;
     66                    }
     67
     68                    if ( ( 'redirect' === $woocommerce_payment_gateway->get_payment_method_type() ) && $woocommerce_payment_gateway->is_available() ) {
     69                        $this->gateways[] = $woocommerce_payment_gateway;
     70                    }
    6271                }
    6372            }
  • multisafepay/trunk/src/PaymentMethods/Base/BaseRefunds.php

    r3048898 r3114383  
    1010use MultiSafepay\ValueObject\CartItem;
    1111use MultiSafepay\WooCommerce\Services\SdkService;
    12 use MultiSafepay\WooCommerce\Utils\Logger;
    1312use MultiSafepay\WooCommerce\Utils\MoneyUtil;
    1413use Psr\Http\Client\ClientExceptionInterface;
     
    7675        } catch ( Exception | ClientExceptionInterface | ApiException $exception ) {
    7776            $error = __( 'Error:', 'multisafepay' ) . htmlspecialchars( $exception->getMessage() );
    78             Logger::log_error( $error );
     77            $this->logger->log_error( $error );
    7978            wc_add_notice( $error, 'error' );
    8079        }
     
    8382            /* translators: %1$: The currency code. %2$ The transaction amount */
    8483            $note = sprintf( __( 'Refund of %1$s%2$s has been processed successfully.', 'multisafepay' ), get_woocommerce_currency_symbol( $order->get_currency() ), $amount );
    85             Logger::log_info( $note );
     84            $this->logger->log_info( $note );
    8685            $order->add_order_note( $note );
    8786            return true;
     
    9190            /* translators: %1$: The order ID. %2$ The PSP transaction ID */
    9291            $message = sprintf( __( 'Refund for Order ID: %1$s with transactionId: %2$s gives message: %3$s.', 'multisafepay' ), $order_id, $multisafepay_transaction->getTransactionId(), $error );
    93             Logger::log_warning( $message );
     92            $this->logger->log_warning( $message );
    9493        }
    9594
  • multisafepay/trunk/src/PaymentMethods/PaymentMethodCallback.php

    r3048898 r3114383  
    1010use MultiSafepay\WooCommerce\Settings\SettingsFields;
    1111use MultiSafepay\WooCommerce\Utils\Logger;
     12use MultiSafepay\WooCommerce\Utils\Order as OrderUtil;
    1213use Psr\Http\Client\ClientExceptionInterface;
    1314use WC_Data_Exception;
     
    5758
    5859    /**
    59      * PaymentMethodCallback constructor
    60      *
    61      * @param  string               $multisafepay_order_id
    62      * @param  ?TransactionResponse $multisafepay_transaction
    63      */
    64     public function __construct( string $multisafepay_order_id, $multisafepay_transaction = null ) {
    65         $this->multisafepay_order_id = $multisafepay_order_id;
    66 
    67         if ( ! isset( $multisafepay_transaction ) ) {
    68             $multisafepay_transaction = $this->get_transaction();
    69         }
    70 
    71         $this->multisafepay_transaction = $multisafepay_transaction;
    72 
    73         // For most transactions, var2 contains the order id since the order request is being register using order number
    74         if ( ! empty( $this->multisafepay_transaction->getVar2() ) ) {
    75             $this->woocommerce_order_id = (int) $this->multisafepay_transaction->getVar2();
    76         }
    77 
    78         // In case we need it, a filter to set the right order id, based on order number
    79         if ( empty( $this->multisafepay_transaction->getVar2() ) ) {
    80             $this->woocommerce_order_id = apply_filters( 'multisafepay_transaction_order_id', $this->multisafepay_order_id );
    81         }
    82 
    83         $this->time_stamp = date( 'd/m/Y H:i:s' );
    84         $this->order      = wc_get_order( $this->woocommerce_order_id );
     60     * @var Logger
     61     */
     62    private $logger;
     63
     64    /**
     65     * @param string                   $multisafepay_order_id
     66     * @param TransactionResponse|null $multisafepay_transaction
     67     * @param Logger|null              $logger
     68     */
     69    public function __construct( string $multisafepay_order_id, ?TransactionResponse $multisafepay_transaction = null, ?Logger $logger = null ) {
     70        $this->logger                   = $logger ?? new Logger();
     71        $this->multisafepay_order_id    = $multisafepay_order_id;
     72        $this->multisafepay_transaction = $multisafepay_transaction ?? $this->get_transaction();
     73        $this->woocommerce_order_id     = $this->get_woocommerce_order_id();
     74        $this->time_stamp               = date( 'd/m/Y H:i:s' );
     75        $this->order                    = wc_get_order( $this->woocommerce_order_id );
    8576    }
    8677
     
    9586            $transaction = $transaction_manager->get( $this->multisafepay_order_id );
    9687        } catch ( ClientExceptionInterface $client_exception ) {
    97             Logger::log_error( $client_exception->getMessage() );
     88            $this->logger->log_error( $client_exception->getMessage() );
    9889            wp_die( esc_html__( 'Invalid request', 'multisafepay' ), esc_html__( 'Invalid request', 'multisafepay' ), 400 );
    9990        } catch ( ApiException $api_exception ) {
    100             Logger::log_error( $api_exception->getMessage() );
     91            $this->logger->log_error( $api_exception->getMessage() );
    10192            wp_die( esc_html__( 'Invalid request', 'multisafepay' ), esc_html__( 'Invalid request', 'multisafepay' ), 400 );
    10293        }
     
    10596
    10697    /**
     98     * Return the WooCommerce order id
     99     *
     100     * @return int
     101     */
     102    private function get_woocommerce_order_id(): int {
     103        // For most transactions, var2 contains the order id since the order request is being registered using order number
     104        if ( ! empty( $this->multisafepay_transaction->getVar2() ) ) {
     105            return (int) $this->multisafepay_transaction->getVar2();
     106        }
     107        return apply_filters( 'multisafepay_transaction_order_id', $this->multisafepay_order_id );
     108    }
     109
     110    /**
    107111     * Return the WooCommerce order status
    108112     *
    109113     * @return string
    110114     */
    111     private function get_wc_order_status(): string {
     115    private function get_woocommerce_order_status(): string {
    112116        return $this->order->get_status();
    113117    }
     
    164168
    165169    /**
     170     * Return the initial order status configured in the payment method settings
     171     *
     172     * @return string|null
     173     */
     174    private function get_initial_order_status(): ?string {
     175        $registered_payment_method = ( new PaymentMethodService() )->get_woocommerce_payment_gateway_by_id( $this->order->get_payment_method() );
     176        return $registered_payment_method ? $registered_payment_method->initial_order_status : null;
     177    }
     178
     179    /**
    166180     * Check if the order status should be updated or not
    167181     *
     
    170184    private function should_status_be_updated(): bool {
    171185        // Check if the WooCommerce completed order status is considered as the final one
    172         if ( $this->is_completed_the_final_status( $this->get_wc_order_status() ) ) {
     186        if ( $this->is_completed_the_final_status( $this->get_woocommerce_order_status() ) ) {
    173187            // phpcs:ignore WordPress.Security.NonceVerification.Recommended
    174188            $message = 'It seems a notification is trying to process an order which already has defined completed as the final order status. For this reason notification is being ignored. Transaction ID received is ' . sanitize_text_field( (string) wp_unslash( $this->get_multisafepay_transaction_id() ) ) . ' with status ' . $this->get_multisafepay_transaction_status();
    175             Logger::log_warning( $message );
     189            $this->logger->log_warning( $message );
    176190            $this->order->add_order_note( $message );
    177191            return false;
     
    191205        // On pre-transactions notification, and using sequential order numbers plugins, var 2 is not received in the notification, then order doesn't exist
    192206        if ( ! $this->order ) {
    193             if ( get_option( 'multisafepay_debugmode', false ) ) {
    194                 Logger::log_info( 'Notification has been received for the transaction ID ' . $this->multisafepay_order_id . ' but WooCommerce order object has not been found' );
    195             }
     207            $this->logger->log_info( 'Notification has been received for the transaction ID ' . $this->multisafepay_order_id . ' but WooCommerce order object has not been found' );
    196208            header( 'Content-type: text/plain' );
    197209            die( 'OK' );
     
    199211
    200212        // If payment method of the order does not belong to MultiSafepay
    201         if ( strpos( $this->order->get_payment_method(), 'multisafepay_' ) === false ) {
    202             if ( get_option( 'multisafepay_debugmode', false ) ) {
    203                 $message = 'It seems a notification is trying to process an order processed by another payment method. Transaction ID received is ' . $this->order->get_id();
    204                 Logger::log_info( $message );
    205             }
    206             header( 'Content-type: text/plain' );
    207             die( 'OK' );
    208         }
    209 
    210         if ( $this->get_wc_order_status() === 'trash' ) {
    211             if ( get_option( 'multisafepay_debugmode', false ) ) {
    212                 $message = 'It seems a notification is trying to change the order status, but the order has been moved to the trash. Transaction ID received is ' . $this->order->get_id() . ' and transaction status is ' . $this->get_multisafepay_transaction_status();
    213                 Logger::log_info( $message );
    214                 $this->order->add_order_note( $message );
    215             }
     213        if ( ! OrderUtil::is_multisafepay_order( $this->order ) ) {
     214            $message = 'It seems a notification is trying to process an order processed by another payment method. Transaction ID received is ' . $this->order->get_id();
     215            $this->logger->log_info( $message );
     216            header( 'Content-type: text/plain' );
     217            die( 'OK' );
     218        }
     219
     220        if ( $this->get_woocommerce_order_status() === 'trash' ) {
     221            $message = 'It seems a notification is trying to change the order status, but the order has been moved to the trash. Transaction ID received is ' . $this->order->get_id() . ' and transaction status is ' . $this->get_multisafepay_transaction_status();
     222            $this->logger->log_info( $message );
     223            OrderUtil::add_order_note( $this->order, $message, true );
    216224            header( 'Content-type: text/plain' );
    217225            die( 'OK' );
     
    221229        if ( $this->get_multisafepay_transaction_status() === Transaction::PARTIAL_REFUNDED ) {
    222230            $message = 'A partial refund has been registered within MultiSafepay Control for Order ID: ' . $this->woocommerce_order_id . ' and Order Number: ' . $this->multisafepay_order_id;
    223             $this->order->add_order_note( $message );
     231            OrderUtil::add_order_note( $this->order, $message );
    224232            header( 'Content-type: text/plain' );
    225233            die( 'OK' );
     
    231239        $payment_method_id_registered_by_wc               = $this->order->get_payment_method();
    232240        $payment_method_title_registered_by_wc            = $this->order->get_payment_method_title();
    233         $registered_by_woocommerce_payment_method_object  = ( new PaymentMethodService() )->get_woocommerce_payment_gateway_by_id( $payment_method_id_registered_by_wc );
    234         $initial_order_status                             = $registered_by_woocommerce_payment_method_object ? $registered_by_woocommerce_payment_method_object->initial_order_status : false;
     241        $initial_order_status                             = $this->get_initial_order_status();
    235242        $default_order_status                             = SettingsFields::get_multisafepay_order_statuses();
    236243
     
    238245        // Or if the custom initial order status of the gateway is different than the general one, and the MultiSafepay transaction status is initialized, and custom initial order status is different than the current WooCommerce order status
    239246        if (
    240             $this->get_wc_order_status() !== str_replace( 'wc-', '', get_option( 'multisafepay_' . $this->get_multisafepay_transaction_status() . '_status', $default_order_status[ $this->get_multisafepay_transaction_status() . '_status' ]['default'] ) ) ||
    241             get_option( 'multisafepay_' . $this->get_multisafepay_transaction_status() . '_status', $default_order_status[ $this->get_multisafepay_transaction_status() . '_status' ]['default'] ) !== $initial_order_status && $this->get_multisafepay_transaction_status() === Transaction::INITIALIZED && $this->get_wc_order_status() !== $initial_order_status
     247            $this->get_woocommerce_order_status() !== str_replace( 'wc-', '', get_option( 'multisafepay_' . $this->get_multisafepay_transaction_status() . '_status', $default_order_status[ $this->get_multisafepay_transaction_status() . '_status' ]['default'] ) ) ||
     248            get_option( 'multisafepay_' . $this->get_multisafepay_transaction_status() . '_status', $default_order_status[ $this->get_multisafepay_transaction_status() . '_status' ]['default'] ) !== $initial_order_status && $this->get_multisafepay_transaction_status() === Transaction::INITIALIZED && $this->get_woocommerce_order_status() !== $initial_order_status
    242249        ) {
    243 
    244250            // If MultiSafepay transaction status is initialized, check if there is a custom initial order status for this payment method.
    245251            if ( $this->get_multisafepay_transaction_status() === Transaction::INITIALIZED ) {
    246                 if ( $initial_order_status && 'wc-default' !== $initial_order_status && $this->get_wc_order_status() !== $initial_order_status ) {
     252                if ( $initial_order_status && 'wc-default' !== $initial_order_status && $this->get_woocommerce_order_status() !== $initial_order_status ) {
    247253                    $this->order->update_status( str_replace( 'wc-', '', $initial_order_status ), __( 'Transaction has been initialized.', 'multisafepay' ) );
    248254                }
     
    266272            }
    267273
    268             if ( get_option( 'multisafepay_debugmode', false ) ) {
    269                 $message = 'Callback received for Order ID: ' . $this->woocommerce_order_id . ' and Order Number: ' . $this->multisafepay_order_id . ' on ' . $this->time_stamp . ' with status: ' . $this->get_multisafepay_transaction_status() . ' and PSP ID: ' . $this->get_multisafepay_transaction_id() . '.';
    270                 Logger::log_info( $message );
    271                 $this->order->add_order_note( $message );
    272             }
     274            $message = 'Callback received for Order ID: ' . $this->woocommerce_order_id . ' and Order Number: ' . $this->multisafepay_order_id . ' on ' . $this->time_stamp . ' with status: ' . $this->get_multisafepay_transaction_status() . ' and PSP ID: ' . $this->get_multisafepay_transaction_id() . '.';
     275            $this->logger->log_info( $message );
     276            OrderUtil::add_order_note( $this->order, $message, true );
    273277        }
    274278
    275279        // If the payment method changed in MultiSafepay payment page, after leave WooCommerce checkout page
    276280        if ( $payment_method_id_registered_by_multisafepay && $payment_method_id_registered_by_wc !== $payment_method_id_registered_by_multisafepay ) {
    277             if ( get_option( 'multisafepay_debugmode', false ) ) {
    278                 $message = 'Callback received with a different payment method for Order ID: ' . $this->woocommerce_order_id . ' and Order Number: ' . $this->multisafepay_order_id . ' on ' . $this->time_stamp . '. Payment method changed from ' . $payment_method_title_registered_by_wc . ' to ' . $payment_method_title_registered_by_multisafepay . '.';
    279                 Logger::log_info( $message );
    280                 $this->order->add_order_note( $message );
    281             }
    282 
     281            $message = 'Callback received with a different payment method for Order ID: ' . $this->woocommerce_order_id . ' and Order Number: ' . $this->multisafepay_order_id . ' on ' . $this->time_stamp . '. Payment method changed from ' . $payment_method_title_registered_by_wc . ' to ' . $payment_method_title_registered_by_multisafepay . '.';
     282            $this->logger->log_info( $message );
     283            OrderUtil::add_order_note( $this->order, $message, true );
    283284            $this->order = wc_get_order( $this->woocommerce_order_id );
    284285            $this->order->set_payment_method( $registered_by_multisafepay_payment_method_object );
  • multisafepay/trunk/src/PaymentMethods/PaymentMethodsController.php

    r3050467 r3114383  
    66use MultiSafepay\Api\Transactions\TransactionResponse;
    77use MultiSafepay\Api\Transactions\UpdateRequest;
     8use MultiSafepay\Api\Wallets\ApplePay\MerchantSessionRequest;
    89use MultiSafepay\Exception\ApiException;
    9 use MultiSafepay\Api\Wallets\ApplePay\MerchantSessionRequest;
    1010use MultiSafepay\Util\Notification;
    1111use MultiSafepay\WooCommerce\Services\OrderService;
     
    1414use MultiSafepay\WooCommerce\Utils\Hpos;
    1515use MultiSafepay\WooCommerce\Utils\Logger;
     16use MultiSafepay\WooCommerce\Utils\Order as OrderUtil;
    1617use Psr\Http\Client\ClientExceptionInterface;
    1718use WC_Data_Exception;
     
    2627    public const VALIDATION_URL_KEY = 'validation_url';
    2728    public const ORIGIN_DOMAIN_KEY  = 'origin_domain';
     29
     30    /**
     31     * @var Logger
     32     */
     33    private $logger;
     34
     35    /**
     36     * @param Logger|null $logger
     37     */
     38    public function __construct( ?Logger $logger = null ) {
     39        $this->logger = $logger ?? new Logger();
     40    }
    2841
    2942    /**
     
    104117    public function set_multisafepay_transaction_as_shipped( int $order_id ): void {
    105118        $order = wc_get_order( $order_id );
    106         if ( strpos( $order->get_payment_method(), 'multisafepay_' ) !== false ) {
     119        if ( OrderUtil::is_multisafepay_order( $order ) ) {
    107120            $sdk                 = new SdkService();
    108121            $transaction_manager = $sdk->get_transaction_manager();
     
    112125                $transaction_manager->update( (string) $order->get_order_number(), $update_order );
    113126            } catch ( ApiException $api_exception ) {
    114                 Logger::log_error( $api_exception->getMessage() );
     127                $this->logger->log_error( $api_exception->getMessage() );
    115128                return;
    116129            }
     
    128141    public function set_multisafepay_transaction_as_invoiced( int $order_id ): void {
    129142        $order = wc_get_order( $order_id );
    130         if ( strpos( $order->get_payment_method(), 'multisafepay_' ) !== false ) {
     143        if ( OrderUtil::is_multisafepay_order( $order ) ) {
    131144            $sdk                 = new SdkService();
    132145            $transaction_manager = $sdk->get_transaction_manager();
     
    136149                $transaction_manager->update( (string) $order->get_order_number(), $update_order );
    137150            } catch ( ApiException $api_exception ) {
    138                 Logger::log_error( $api_exception->getMessage() );
     151                $this->logger->log_error( $api_exception->getMessage() );
    139152                return;
    140153            }
     
    178191
    179192        if ( ! $request->sanitize_params() ) {
    180             Logger::log_info( 'Notification for transactionid . ' . $transactionid . ' has been received but could not be sanitized' );
     193            $this->logger->log_info( 'Notification for transactionid . ' . $transactionid . ' has been received but could not be sanitized' );
    181194            header( 'Content-type: text/plain' );
    182195            die( 'OK' );
     
    185198        $payload_type = $request->get_param( 'payload_type' ) ?? '';
    186199        if ( 'pretransaction' === $payload_type ) {
    187             Logger::log_info( 'Notification for transactionid . ' . $transactionid . ' has been received but is going to be ignored, because is pretransaction type' );
     200            $this->logger->log_info( 'Notification for transactionid . ' . $transactionid . ' has been received but is going to be ignored, because is pretransaction type' );
    188201            header( 'Content-type: text/plain' );
    189202            die( 'OK' );
     
    196209
    197210        if ( ! $verify_notification ) {
    198             Logger::log_info( 'Notification for transactionid . ' . $transactionid . ' has been received but is not validated' );
     211            $this->logger->log_info( 'Notification for transactionid . ' . $transactionid . ' has been received but is not validated' );
    199212            header( 'Content-type: text/plain' );
    200213            die( 'OK' );
     
    202215
    203216        if ( get_option( 'multisafepay_debugmode', false ) ) {
    204             Logger::log_info( 'Notification has been received and validated for transaction id ' . $transactionid );
     217            $this->logger->log_info( 'Notification has been received and validated for transaction id ' . $transactionid );
    205218
    206219            if ( ! empty( $body ) ) {
    207                 Logger::log_info( 'Body of the POST notification: ' . wc_print_r( $body, true ) );
     220                $this->logger->log_info( 'Body of the POST notification: ' . wc_print_r( $body, true ) );
    208221            }
    209222        }
     
    250263
    251264        // Check if the payment method belongs to MultiSafepay
    252         if ( strpos( $order->get_payment_method(), 'multisafepay_' ) === false ) {
     265        if ( ! OrderUtil::is_multisafepay_order( $order ) ) {
    253266            return;
    254267        }
     
    260273        $gateway_object      = ( new PaymentMethodService() )->get_woocommerce_payment_gateway_by_id( $order->get_payment_method() );
    261274        if ( ! $gateway_object ) {
    262             Logger::log_error( ' Gateway object is null ' );
     275            $this->logger->log_error( ' Gateway object is null ' );
    263276            return;
    264277        }
     
    275288                if ( get_option( 'multisafepay_debugmode', false ) ) {
    276289                    $message = 'Order details has been registered in MultiSafepay and a payment link has been generated: ' . esc_url( $transaction->getPaymentUrl() );
    277                     Logger::log_info( $message );
     290                    $this->logger->log_info( $message );
    278291                    $order->add_order_note( $message );
    279292                }
    280293            }
    281294        } catch ( Exception | ApiException | ClientExceptionInterface $exception ) {
    282             Logger::log_error( $exception->getMessage() );
     295            $this->logger->log_error( $exception->getMessage() );
    283296        }
    284297    }
     
    326339     */
    327340    public function allow_cancel_multisafepay_orders_with_on_hold_status( array $order_status, WC_Order $order ): array {
    328         if ( strpos( $order->get_payment_method(), 'multisafepay_' ) !== false ) {
     341        if ( OrderUtil::is_multisafepay_order( $order ) ) {
    329342            $gateway = ( new PaymentMethodService() )->get_woocommerce_payment_gateway_by_id( $order->get_payment_method() );
    330343            if ( ! $gateway ) {
    331                 Logger::log_error( ' Gateway object is null ' );
     344                $this->logger->log_error( ' Gateway object is null ' );
    332345                return $order_status;
    333346            }
     
    363376        } catch ( ApiException | Exception | ClientExceptionInterface $exception ) {
    364377            $error_message = 'Error when trying to get the ApplePay session via MultiSafepay SDK';
    365             Logger::log_error( $error_message . ': ' . $exception->getMessage() );
     378            $this->logger->log_error( $error_message . ': ' . $exception->getMessage() );
    366379            wp_send_json( array( 'message' => $error_message ) );
    367380        }
     
    397410
    398411        if ( empty( $validation_url ) ) {
    399             Logger::log_error( 'Error when trying to get the ApplePay session. Validation URL empty' );
     412            $this->logger->log_error( 'Error when trying to get the ApplePay session. Validation URL empty' );
    400413            exit;
    401414        }
    402415
    403416        if ( empty( $origin_domain ) ) {
    404             Logger::log_error( 'Error when trying to get the ApplePay session. Origin domain empty' );
     417            $this->logger->log_error( 'Error when trying to get the ApplePay session. Origin domain empty' );
    405418            exit;
    406419        }
  • multisafepay/trunk/src/Services/ApiTokenService.php

    r2974626 r3114383  
    2626
    2727    /**
     28     * @var Logger
     29     */
     30    private $logger;
     31
     32    /**
    2833     * ApiTokenService constructor.
     34     *
     35     * @param Logger|null $logger
    2936     */
    30     public function __construct() {
     37    public function __construct( ?Logger $logger = null ) {
     38        $this->logger            = $logger ?? new Logger();
    3139        $this->api_token_manager = ( new SdkService() )->get_api_token_manager();
    3240    }
     
    5058            $api_token = $this->api_token_manager->get()->getApiToken();
    5159        } catch ( ApiException | ClientExceptionInterface $exception ) {
    52             Logger::log_error( $exception->getMessage() );
     60            $this->logger->log_error( $exception->getMessage() );
    5361            return '';
    5462        }
  • multisafepay/trunk/src/Services/OrderService.php

    r3048898 r3114383  
    7474        }
    7575
    76         if ( ! empty( $_POST[ ( $this->payment_method_service->get_woocommerce_payment_gateway_by_multisafepay_gateway_code( $gateway_code ) )->get_payment_method_id() . '_payment_component_payload' ] ) ) {
    77             $payment_method_id             = ( new PaymentMethodService() )->get_woocommerce_payment_gateway_by_multisafepay_gateway_code( $gateway_code )->get_payment_method_id();
     76        if ( ! empty( $_POST[ $order->get_payment_method() . '_payment_component_payload' ] ) ) {
     77            $payment_method_id             = $order->get_payment_method();
    7878            $payment_component_payload_key = $payment_method_id . '_payment_component_payload';
    7979            $payment_component_payload     = sanitize_text_field( wp_unslash( $_POST[ $payment_component_payload_key ] ?? '' ) );
  • multisafepay/trunk/src/Services/PaymentMethodService.php

    r3088253 r3114383  
    1010use MultiSafepay\WooCommerce\PaymentMethods\Base\BaseGiftCardPaymentMethod;
    1111use MultiSafepay\WooCommerce\PaymentMethods\Base\BasePaymentMethod;
     12use MultiSafepay\WooCommerce\PaymentMethods\Base\BaseBrandedPaymentMethod;
    1213use MultiSafepay\WooCommerce\Utils\Logger;
    1314use Psr\Http\Client\ClientExceptionInterface;
     
    3132
    3233    /**
    33      * PaymentMethodsService constructor.
    34      *
    35      * @return void
    36      */
    37     public function __construct() {
     34     * @var Logger
     35     */
     36    private $logger;
     37
     38    /**
     39     * @param Logger|null $logger
     40     */
     41    public function __construct( ?Logger $logger = null ) {
     42        $this->logger = $logger ?? new Logger();
    3843        try {
    3944            $this->payment_method_manager = ( new SdkService() )->get_payment_method_manager();
    4045        } catch ( ApiException $api_exception ) {
    41             Logger::log_error( $api_exception->getMessage() );
     46            $this->logger->log_error( $api_exception->getMessage() );
    4247        }
    4348    }
     
    7580
    7681        if ( null === $this->payment_method_manager ) {
    77             Logger::log_error( 'SDK is not initialized' );
     82            $this->logger->log_error( 'SDK is not initialized' );
    7883            return array();
    7984        }
     
    9095            );
    9196        } catch ( Exception | ApiException | InvalidDataInitializationException | ClientExceptionInterface $exception ) {
    92             Logger::log_error( $exception->getMessage() );
     97            $this->logger->log_error( $exception->getMessage() );
    9398            return array();
    9499        }
     
    108113        $multisafepay_payment_methods = $this->get_multisafepay_payment_methods_from_api();
    109114        foreach ( $multisafepay_payment_methods as $multisafepay_payment_method ) {
    110             if ( isset( $multisafepay_payment_method['type'] ) && 'coupon' === $multisafepay_payment_method['type'] ) {
    111                 $woocommerce_payment_gateways[ self::get_legacy_woocommerce_payment_gateway_ids( $multisafepay_payment_method['id'] ) ] = new BaseGiftCardPaymentMethod( new PaymentMethod( $multisafepay_payment_method ) );
    112             }
    113             if ( isset( $multisafepay_payment_method['type'] ) && 'payment-method' === $multisafepay_payment_method['type'] ) {
    114                 $woocommerce_payment_gateways[ self::get_legacy_woocommerce_payment_gateway_ids( $multisafepay_payment_method['id'] ) ] = new BasePaymentMethod( new PaymentMethod( $multisafepay_payment_method ) );
    115             }
    116         }
     115            if ( isset( $multisafepay_payment_method['type'] ) ) {
     116                $woocommerce_payment_gateways = $this->create_woocommerce_payment_gateways( $multisafepay_payment_method, $woocommerce_payment_gateways );
     117            }
     118        }
     119
     120        return $woocommerce_payment_gateways;
     121    }
     122
     123    /**
     124     * @param array $multisafepay_payment_method
     125     * @param array $woocommerce_payment_gateways
     126     * @return array
     127     */
     128    public function create_woocommerce_payment_gateways( array $multisafepay_payment_method, array $woocommerce_payment_gateways ) : array {
     129        $payment_method_id = self::get_legacy_woocommerce_payment_gateway_ids( $multisafepay_payment_method['id'] );
     130
     131        try {
     132            $payment_method = new PaymentMethod( $multisafepay_payment_method );
     133        } catch ( InvalidDataInitializationException $exception ) {
     134            $this->logger->log_error( $exception->getMessage() );
     135            return $woocommerce_payment_gateways;
     136        }
     137
     138        if ( 'payment-method' === $multisafepay_payment_method['type'] ) {
     139            $woocommerce_payment_gateways[ $payment_method_id ] = new BasePaymentMethod( $payment_method );
     140            $woocommerce_payment_gateways                       = $this->create_branded_woocommerce_payment_gateways( $multisafepay_payment_method, $woocommerce_payment_gateways, $payment_method );
     141        }
     142
     143        if ( 'coupon' === $multisafepay_payment_method['type'] ) {
     144            $woocommerce_payment_gateways[ $payment_method_id ] = new BaseGiftCardPaymentMethod( $payment_method );
     145        }
     146
     147        return $woocommerce_payment_gateways;
     148    }
     149
     150    /**
     151     * @param array         $multisafepay_payment_method
     152     * @param array         $woocommerce_payment_gateways
     153     * @param PaymentMethod $payment_method
     154     * @return array
     155     */
     156    public function create_branded_woocommerce_payment_gateways( array $multisafepay_payment_method, array $woocommerce_payment_gateways, PaymentMethod $payment_method ) : array {
     157        foreach ( $multisafepay_payment_method['brands'] as $brand ) {
     158            if ( ! empty( $brand['allowed_countries'] ) ) {
     159                $payment_method_id                                  = self::get_legacy_woocommerce_payment_gateway_ids( $brand['id'] );
     160                $woocommerce_payment_gateways[ $payment_method_id ] = new BaseBrandedPaymentMethod( $payment_method, $brand );
     161            }
     162        }
     163
    117164        return $woocommerce_payment_gateways;
    118165    }
     
    174221            if ( $payment_method_object->supportsPaymentComponent() ) {
    175222                $payment_methods_with_payment_component[] = self::get_legacy_woocommerce_payment_gateway_ids( $payment_method_object->getId() );
     223                foreach ( $payment_method['brands'] as $brand ) {
     224                    if ( ! empty( $brand['allowed_countries'] ) ) {
     225                        $payment_methods_with_payment_component[] = self::get_legacy_woocommerce_payment_gateway_ids( $brand['id'] );
     226                    }
     227                }
    176228            }
    177229        }
     
    188240     */
    189241    public static function get_legacy_woocommerce_payment_gateway_ids( string $code ): string {
    190 
    191242        $woocommerce_payment_gateway_id = 'multisafepay_' . str_replace( '-', '_', sanitize_title( strtolower( $code ) ) );
    192243
  • multisafepay/trunk/src/Services/SdkService.php

    r3048898 r3114383  
    1414use MultiSafepay\Sdk;
    1515use MultiSafepay\WooCommerce\Client\MultiSafepayClient;
    16 use MultiSafepay\WooCommerce\Services\PaymentMethodService;
    1716use MultiSafepay\WooCommerce\Utils\Logger;
    1817use Nyholm\Psr7\Factory\Psr17Factory;
     
    4443    private $sdk = null;
    4544
     45    /**
     46     * @var Logger
     47     */
     48    private $logger;
    4649
    4750    /**
    4851     * SdkService constructor.
    4952     *
    50      * @param  string  $api_key
    51      * @param  boolean $test_mode
    52      */
    53     public function __construct( string $api_key = null, bool $test_mode = null ) {
     53     * @param  string      $api_key
     54     * @param  boolean     $test_mode
     55     * @param Logger|null $logger
     56     */
     57    public function __construct( string $api_key = null, bool $test_mode = null, ?Logger $logger = null ) {
    5458        $this->api_key   = $api_key ?? $this->get_api_key();
    5559        $this->test_mode = $test_mode ?? $this->get_test_mode();
     60        $this->logger    = $logger ?? new Logger();
    5661        $psr_factory     = new Psr17Factory();
    5762        $client          = new MultiSafepayClient();
     
    6065        } catch ( InvalidApiKeyException $invalid_api_key_exception ) {
    6166            set_transient( 'multisafepay_payment_methods', array() );
    62             Logger::log_error( $invalid_api_key_exception->getMessage() );
     67            $this->logger->log_error( $invalid_api_key_exception->getMessage() );
    6368        }
    6469    }
     
    96101            return $this->sdk->getGatewayManager();
    97102        } catch ( ApiException $api_exception ) {
    98             Logger::log_error( $api_exception->getMessage() );
     103            $this->logger->log_error( $api_exception->getMessage() );
    99104            return new WP_Error( 'multisafepay-warning', $api_exception->getMessage() );
    100105        }
     
    111116            return $this->get_gateway_manager()->getGateways( true );
    112117        } catch ( ApiException $api_exception ) {
    113             Logger::log_error( $api_exception->getMessage() );
     118            $this->logger->log_error( $api_exception->getMessage() );
    114119            return new WP_Error( 'multisafepay-warning', $api_exception->getMessage() );
    115120        }
     
    149154    public function get_api_token_manager(): ?ApiTokenManager {
    150155        if ( null === $this->sdk ) {
    151             Logger::log_error( 'SDK is not initialized' );
     156            $this->logger->log_error( 'SDK is not initialized' );
    152157            return null;
    153158        }
     
    162167    public function get_payment_method_manager(): ?PaymentMethodManager {
    163168        if ( null === $this->sdk ) {
    164             Logger::log_error( 'SDK is not initialized' );
     169            $this->logger->log_error( 'SDK is not initialized' );
    165170            return null;
    166171        }
     
    168173            return $this->sdk->getPaymentMethodManager();
    169174        } catch ( ApiException $api_exception ) {
    170             Logger::log_error( $api_exception->getMessage() );
     175            $this->logger->log_error( $api_exception->getMessage() );
    171176            return null;
    172177        }
     
    184189            $tokens = $this->sdk->getTokenManager()->getListByGatewayCodeAsArray( $customer_reference, $gateway_code );
    185190        } catch ( ApiException $api_exception ) {
    186             Logger::log_error( $api_exception->getMessage() );
     191            $this->logger->log_error( $api_exception->getMessage() );
    187192            return array();
    188193        } catch ( ClientExceptionInterface $client_exception ) {
    189             Logger::log_error( $client_exception->getMessage() );
     194            $this->logger->log_error( $client_exception->getMessage() );
    190195            return array();
    191196        } catch ( Exception $exception ) {
    192             Logger::log_error( $exception->getMessage() );
     197            $this->logger->log_error( $exception->getMessage() );
    193198            return array();
    194199        }
     
    207212            $gateway_merchant_id = $account_manager->get()->getAccountId();
    208213        } catch ( ApiException | ClientExceptionInterface | Exception $exception ) {
    209             Logger::log_error( 'Error when try to set the merchant credentials: ' . $exception->getMessage() );
     214            $this->logger->log_error( 'Error when try to set the merchant credentials: ' . $exception->getMessage() );
    210215        }
    211216
  • multisafepay/trunk/src/Services/ShoppingCartService.php

    r2995309 r3114383  
    2525
    2626    /**
     27     * @var Logger
     28     */
     29    private $logger;
     30
     31    /**
     32     * @param Logger|null $logger
     33     */
     34    public function __construct( ?Logger $logger = null ) {
     35        $this->logger = $logger ?? new Logger();
     36    }
     37
     38    /**
    2739     * @param WC_Order $order
    2840     * @param string   $currency
     
    3951
    4052        if ( get_option( 'multisafepay_debugmode', false ) ) {
    41             Logger::log_info( wc_print_r( $order->get_items(), true ) );
     53            $this->logger->log_info( wc_print_r( $order->get_items(), true ) );
    4254        }
    4355
     
    7284
    7385        if ( get_option( 'multisafepay_debugmode', false ) ) {
    74             Logger::log_info( wp_json_encode( $shopping_cart->getData() ) );
     86            $this->logger->log_info( wp_json_encode( $shopping_cart->getData() ) );
    7587        }
    7688
  • multisafepay/trunk/src/Utils/Logger.php

    r2974626 r3114383  
    44
    55use WC_Log_Handler_File;
     6use WC_Logger_Interface;
    67
    78/**
     
    910 */
    1011class Logger {
     12
     13    /**
     14     * @var WC_Logger_Interface
     15     */
     16    private $logger;
     17
     18    /**
     19     * @param WC_Logger_Interface|null $logger
     20     */
     21    public function __construct( ?WC_Logger_Interface $logger = null ) {
     22        $this->logger = $logger ?? wc_get_logger();
     23    }
    1124
    1225    /**
     
    1730     * @param string $message
    1831     */
    19     public static function log_emergency( string $message ) {
    20         $logger = wc_get_logger();
    21         $logger->log( 'emergency', $message, array( 'source' => 'multisafepay' ) );
     32    public function log_emergency( string $message ) {
     33        $this->logger->log( 'emergency', $message, array( 'source' => 'multisafepay' ) );
    2234    }
    2335
     
    2941     * @param string $message
    3042     */
    31     public static function log_alert( string $message ) {
    32         $logger = wc_get_logger();
    33         $logger->log( 'alert', $message, array( 'source' => 'multisafepay' ) );
     43    public function log_alert( string $message ) {
     44        $this->logger->log( 'alert', $message, array( 'source' => 'multisafepay' ) );
    3445    }
    3546
     
    4152     * @param string $message
    4253     */
    43     public static function log_critical( string $message ) {
    44         $logger = wc_get_logger();
    45         $logger->log( 'critical', $message, array( 'source' => 'multisafepay' ) );
     54    public function log_critical( string $message ) {
     55        $this->logger->log( 'critical', $message, array( 'source' => 'multisafepay' ) );
    4656    }
    4757
     
    5363     * @param string $message
    5464     */
    55     public static function log_error( string $message ) {
    56         $logger = wc_get_logger();
    57         $logger->log( 'error', $message, array( 'source' => 'multisafepay' ) );
     65    public function log_error( string $message ) {
     66        $this->logger->log( 'error', $message, array( 'source' => 'multisafepay' ) );
    5867    }
    5968
     
    6574     * @param string $message
    6675     */
    67     public static function log_warning( string $message ) {
    68         $logger = wc_get_logger();
    69         $logger->log( 'warning', $message, array( 'source' => 'multisafepay' ) );
     76    public function log_warning( string $message ) {
     77        $this->logger->log( 'warning', $message, array( 'source' => 'multisafepay' ) );
    7078    }
    7179
     
    7785     * @param string $message
    7886     */
    79     public static function log_notice( string $message ) {
    80         $logger = wc_get_logger();
    81         $logger->log( 'notice', $message, array( 'source' => 'multisafepay' ) );
     87    public function log_notice( string $message ) {
     88        $this->logger->log( 'notice', $message, array( 'source' => 'multisafepay' ) );
    8289    }
    8390
     
    8996     * @param string $message
    9097     */
    91     public static function log_info( string $message ) {
     98    public function log_info( string $message ) {
    9299        if ( get_option( 'multisafepay_debugmode', false ) ) {
    93             $logger = wc_get_logger();
    94             $logger->log( 'info', $message, array( 'source' => 'multisafepay' ) );
     100            $this->logger->log( 'info', $message, array( 'source' => 'multisafepay' ) );
    95101        }
    96102    }
     
    103109     * @param string $message
    104110     */
    105     public static function log_debug( string $message ) {
     111    public function log_debug( string $message ) {
    106112        if ( get_option( 'multisafepay_debugmode', false ) ) {
    107             $logger = wc_get_logger();
    108             $logger->log( 'debug', $message, array( 'source' => 'multisafepay' ) );
     113            $this->logger->log( 'debug', $message, array( 'source' => 'multisafepay' ) );
    109114        }
    110115    }
     
    116121     */
    117122    private function get_logs(): array {
    118         $logs = WC_Log_Handler_File::get_log_files();
    119         return $logs;
     123        return WC_Log_Handler_File::get_log_files();
    120124    }
    121125
  • multisafepay/trunk/vendor/autoload.php

    r3048898 r3114383  
    2323require_once __DIR__ . '/composer/autoload_real.php';
    2424
    25 return ComposerAutoloaderInit8122490751e95ad36d38dc1115ae59ff::getLoader();
     25return ComposerAutoloaderInitdbc0eb47ba0f8cbc67eba2344d97c2f8::getLoader();
  • multisafepay/trunk/vendor/composer/autoload_real.php

    r3048898 r3114383  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInit8122490751e95ad36d38dc1115ae59ff
     5class ComposerAutoloaderInitdbc0eb47ba0f8cbc67eba2344d97c2f8
    66{
    77    private static $loader;
     
    2525        require __DIR__ . '/platform_check.php';
    2626
    27         spl_autoload_register(array('ComposerAutoloaderInit8122490751e95ad36d38dc1115ae59ff', 'loadClassLoader'), true, true);
     27        spl_autoload_register(array('ComposerAutoloaderInitdbc0eb47ba0f8cbc67eba2344d97c2f8', 'loadClassLoader'), true, true);
    2828        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
    29         spl_autoload_unregister(array('ComposerAutoloaderInit8122490751e95ad36d38dc1115ae59ff', 'loadClassLoader'));
     29        spl_autoload_unregister(array('ComposerAutoloaderInitdbc0eb47ba0f8cbc67eba2344d97c2f8', 'loadClassLoader'));
    3030
    3131        require __DIR__ . '/autoload_static.php';
    32         call_user_func(\Composer\Autoload\ComposerStaticInit8122490751e95ad36d38dc1115ae59ff::getInitializer($loader));
     32        call_user_func(\Composer\Autoload\ComposerStaticInitdbc0eb47ba0f8cbc67eba2344d97c2f8::getInitializer($loader));
    3333
    3434        $loader->register(true);
  • multisafepay/trunk/vendor/composer/autoload_static.php

    r3048898 r3114383  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInit8122490751e95ad36d38dc1115ae59ff
     7class ComposerStaticInitdbc0eb47ba0f8cbc67eba2344d97c2f8
    88{
    99    public static $prefixLengthsPsr4 = array (
     
    6363    {
    6464        return \Closure::bind(function () use ($loader) {
    65             $loader->prefixLengthsPsr4 = ComposerStaticInit8122490751e95ad36d38dc1115ae59ff::$prefixLengthsPsr4;
    66             $loader->prefixDirsPsr4 = ComposerStaticInit8122490751e95ad36d38dc1115ae59ff::$prefixDirsPsr4;
    67             $loader->classMap = ComposerStaticInit8122490751e95ad36d38dc1115ae59ff::$classMap;
     65            $loader->prefixLengthsPsr4 = ComposerStaticInitdbc0eb47ba0f8cbc67eba2344d97c2f8::$prefixLengthsPsr4;
     66            $loader->prefixDirsPsr4 = ComposerStaticInitdbc0eb47ba0f8cbc67eba2344d97c2f8::$prefixDirsPsr4;
     67            $loader->classMap = ComposerStaticInitdbc0eb47ba0f8cbc67eba2344d97c2f8::$classMap;
    6868
    6969        }, null, ClassLoader::class);
  • multisafepay/trunk/vendor/composer/installed.json

    r3088253 r3114383  
    33        {
    44            "name": "multisafepay/php-sdk",
    5             "version": "5.13.0",
    6             "version_normalized": "5.13.0.0",
     5            "version": "5.14.0",
     6            "version_normalized": "5.14.0.0",
    77            "source": {
    88                "type": "git",
    99                "url": "https://github.com/MultiSafepay/php-sdk.git",
    10                 "reference": "b88fa079981d590a70275d528cf52d8fd07affab"
    11             },
    12             "dist": {
    13                 "type": "zip",
    14                 "url": "https://api.github.com/repos/MultiSafepay/php-sdk/zipball/b88fa079981d590a70275d528cf52d8fd07affab",
    15                 "reference": "b88fa079981d590a70275d528cf52d8fd07affab",
     10                "reference": "408f102e3228f072f2c1bcc76ac29a8031415480"
     11            },
     12            "dist": {
     13                "type": "zip",
     14                "url": "https://api.github.com/repos/MultiSafepay/php-sdk/zipball/408f102e3228f072f2c1bcc76ac29a8031415480",
     15                "reference": "408f102e3228f072f2c1bcc76ac29a8031415480",
    1616                "shasum": ""
    1717            },
     
    3838                "jschaedl/iban-validation": "Adds additional IBAN validation for \\MultiSafepay\\ValueObject\\IbanNumber"
    3939            },
    40             "time": "2024-04-16T11:41:31+00:00",
     40            "time": "2024-07-08T12:43:31+00:00",
    4141            "type": "library",
    4242            "installation-source": "dist",
     
    5353            "support": {
    5454                "issues": "https://github.com/MultiSafepay/php-sdk/issues",
    55                 "source": "https://github.com/MultiSafepay/php-sdk/tree/5.13.0"
     55                "source": "https://github.com/MultiSafepay/php-sdk/tree/5.14.0"
    5656            },
    5757            "install-path": "../multisafepay/php-sdk"
  • multisafepay/trunk/vendor/composer/installed.php

    r3099249 r3114383  
    22    'root' => array(
    33        'name' => 'multisafepay/woocommerce',
    4         'pretty_version' => '6.5.1',
    5         'version' => '6.5.1.0',
    6         'reference' => 'a57a06a32837f1542476a9726a1e3749e08ba92d',
     4        'pretty_version' => '6.6.0',
     5        'version' => '6.6.0.0',
     6        'reference' => null,
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1212    'versions' => array(
    1313        'multisafepay/php-sdk' => array(
    14             'pretty_version' => '5.13.0',
    15             'version' => '5.13.0.0',
    16             'reference' => 'b88fa079981d590a70275d528cf52d8fd07affab',
     14            'pretty_version' => '5.14.0',
     15            'version' => '5.14.0.0',
     16            'reference' => '408f102e3228f072f2c1bcc76ac29a8031415480',
    1717            'type' => 'library',
    1818            'install_path' => __DIR__ . '/../multisafepay/php-sdk',
     
    2121        ),
    2222        'multisafepay/woocommerce' => array(
    23             'pretty_version' => '6.5.1',
    24             'version' => '6.5.1.0',
    25             'reference' => 'a57a06a32837f1542476a9726a1e3749e08ba92d',
     23            'pretty_version' => '6.6.0',
     24            'version' => '6.6.0.0',
     25            'reference' => null,
    2626            'type' => 'wordpress-plugin',
    2727            'install_path' => __DIR__ . '/../../',
  • multisafepay/trunk/vendor/multisafepay/php-sdk/CHANGELOG.md

    r3072171 r3114383  
    77## [Unreleased]
    88
     9## [5.14.0] - 2024-07-08
     10### Added
     11- PHPSDK-155: Throw ApiUnavailableException when API returns 501/503 HTTP codes
     12- PHPSDK-156: Add getGatewayId in TransactionResponse class
     13
    914## [5.13.0] - 2024-04-16
    1015### Added
    11 + PHPSDK-151: Update Gateways::SHOPPING_CART_REQUIRED_GATEWAYS adding 'BNPL_INST', 'IN3B2B', 'SANTANDER', 'ZINIA', 'ZINIA_IN3', 'BNPL_OB', 'BNPL_MF' gateways codes
     16- PHPSDK-151: Update Gateways::SHOPPING_CART_REQUIRED_GATEWAYS adding 'BNPL_INST', 'IN3B2B', 'SANTANDER', 'ZINIA', 'ZINIA_IN3', 'BNPL_OB', 'BNPL_MF' gateways codes
    1217
    1318## [5.12.1] - 2024-03-11
    1419### Fixed
    15 + PHPSDK-146: Fix ApiException not being hinted as a thrown exception, even though it is, by fixing the PHP DocBlocks @throws tags
     20- PHPSDK-146: Fix ApiException not being hinted as a thrown exception, even though it is, by fixing the PHP DocBlocks @throws tags
    1621
    1722## [5.12.0] - 2023-12-01
    1823### Added
    19 + PHPSDK-139: Add support to set var1, var2 and var3, within the OrderRequest object
    20 + PHPSDK-140: Add support to set custom_info, within the OrderRequest object, thanks to @DaanDeSmedt
     24- PHPSDK-139: Add support to set var1, var2 and var3, within the OrderRequest object
     25- PHPSDK-140: Add support to set custom_info, within the OrderRequest object, thanks to @DaanDeSmedt
    2126
    2227## [5.11.2] - 2023-10-13
    2328### Fixed
    24 + PHPSDK-134: Fix errors when only reference is set, within the CustomerDetails object
    25 
    26 ### Changed
    27 + PHPSDK-136: Remove PluginDetails as mandatory from the Order Request
     29- PHPSDK-134: Fix errors when only reference is set, within the CustomerDetails object
     30
     31### Changed
     32- PHPSDK-136: Remove PluginDetails as mandatory from the Order Request
    2833
    2934## [5.11.1] - 2023-07-31
     
    8994## [5.5.0] - 2022-05-11
    9095### Added
    91 + PHPSDK-90: Add MAESTRO tokens within the results of the CREDITCARD tokens request
    92 
    93 ### Changed
    94 + PHPSDK-91: Add trim on API key when initializing the SDK
     96- PHPSDK-90: Add MAESTRO tokens within the results of the CREDITCARD tokens request
     97
     98### Changed
     99- PHPSDK-91: Add trim on API key when initializing the SDK
    95100
    96101## [5.4.0] - 2021-11-30
  • multisafepay/trunk/vendor/multisafepay/php-sdk/composer.json

    r3072171 r3114383  
    44  "type": "library",
    55  "license": "MIT",
    6   "version": "5.13.0",
     6  "version": "5.14.0",
    77  "require": {
    88    "php": "^7.2|^8.0",
  • multisafepay/trunk/vendor/multisafepay/php-sdk/src/Api/Base/Response.php

    r3050467 r3114383  
    99use MultiSafepay\Api\Pager\Pager;
    1010use MultiSafepay\Exception\ApiException;
     11use MultiSafepay\Exception\ApiUnavailableException;
    1112
    1213/**
     
    3839     * @param array $context
    3940     * @return Response
    40      * @throws ApiException
     41     * @throws ApiException|ApiUnavailableException
    4142     */
    4243    public static function withJson(string $json, array $context = []): Response
     
    5556     * @param array $context
    5657     * @param string $raw
    57      * @throws ApiException
     58     * @throws ApiException|ApiUnavailableException
    5859     */
    5960    public function __construct(array $data, array $context = [], string $raw = '')
     
    8384     * @return void
    8485     * @throws ApiException
     86     * @throws ApiUnavailableException
    8587     */
    8688    private function validate(array $data, array $context = []): void
     
    9597        if (!empty($data['data']) && !is_array($data['data'])) {
    9698            [$errorCode, $errorInfo] = self::ERROR_INVALID_DATA_TYPE;
     99        }
     100
     101        if (in_array($context['http_response_code'], [501, 503])) {
     102            throw (new ApiUnavailableException(
     103                'The MultiSafepay API could not be reached',
     104                $context['http_response_code']
     105            ));
    97106        }
    98107
  • multisafepay/trunk/vendor/multisafepay/php-sdk/src/Api/Transactions/TransactionResponse.php

    r3050467 r3114383  
    3131class TransactionResponse extends ResponseBody
    3232{
    33 
    3433    /**
    3534     * @var string
     
    383382        return in_array($this->getPaymentDetails()->getType(), Gateways::SHOPPING_CART_REQUIRED_GATEWAYS, true);
    384383    }
     384
     385    /**
     386     * Retrieve the gateway ID from the transaction
     387     * Will return multiple gateway IDs as a string of comma separated values if multiple payment methods are used
     388     *
     389     * @return string
     390     */
     391    public function getGatewayId(): string
     392    {
     393        $paymentMethods = [];
     394
     395        foreach ($this->getPaymentMethods() as $paymentMethod) {
     396            if ($paymentMethod->getType() === 'COUPON') {
     397                $paymentMethods[] = $paymentMethod->getData()['coupon_brand'] ?? 'unknown';
     398                continue;
     399            }
     400
     401            $paymentMethods[] = $paymentMethod->getType();
     402        }
     403
     404        return implode(', ', $paymentMethods);
     405    }
    385406}
  • multisafepay/trunk/vendor/multisafepay/php-sdk/src/Client/Client.php

    r3050467 r3114383  
    1212use MultiSafepay\Api\Base\Response as ApiResponse;
    1313use MultiSafepay\Exception\ApiException;
     14use MultiSafepay\Exception\ApiUnavailableException;
    1415use MultiSafepay\Exception\InvalidApiKeyException;
    15 use MultiSafepay\Exception\StrictModeException;
    1616use Psr\Http\Client\ClientExceptionInterface;
    1717use Psr\Http\Client\ClientInterface;
     
    105105     * @param array $context
    106106     * @return ApiResponse
    107      * @throws ClientExceptionInterface
    108      * @throws ApiException
     107     * @throws ClientExceptionInterface|ApiException|ApiUnavailableException
    109108     */
    110109    public function createPostRequest(
     
    116115            ->withBody($this->createBody($this->getRequestBody($requestBody)))
    117116            ->withHeader('Content-Length', strlen($this->getRequestBody($requestBody)));
     117        $httpResponse = $this->httpClient->sendRequest($request);
    118118
    119119        $context['headers'] = $request->getHeaders();
    120120        $context['request_body'] = $this->getRequestBody($requestBody);
    121         $httpResponse = $this->httpClient->sendRequest($request);
     121        $context['http_response_code'] = $httpResponse->getStatusCode() ?? 0;
     122
    122123        return ApiResponse::withJson($httpResponse->getBody()->getContents(), $context);
    123124    }
     
    129130     * @param array $context
    130131     * @return ApiResponse
    131      * @throws ClientExceptionInterface|ApiException
     132     * @throws ClientExceptionInterface|ApiException|ApiUnavailableException
    132133     */
    133134    public function createPatchRequest(
     
    139140            ->withBody($this->createBody($this->getRequestBody($requestBody)))
    140141            ->withHeader('Content-Length', strlen($this->getRequestBody($requestBody)));
     142        $httpResponse = $this->httpClient->sendRequest($request);
    141143
    142144        $context['headers'] = $request->getHeaders();
    143145        $context['request_body'] = $this->getRequestBody($requestBody);
    144         $httpResponse = $this->httpClient->sendRequest($request);
    145         return ApiResponse::withJson($httpResponse->getBody()->getContents(), $context);
    146     }
    147 
    148     /**
    149      * @param string $endpoint
    150      * @param array $parameters
    151      * @param array $context
    152      * @return ApiResponse
    153      * @throws ClientExceptionInterface|ApiException
     146        $context['http_response_code'] = $httpResponse->getStatusCode() ?? 0;
     147
     148        return ApiResponse::withJson($httpResponse->getBody()->getContents(), $context);
     149    }
     150
     151    /**
     152     * @param string $endpoint
     153     * @param array $parameters
     154     * @param array $context
     155     * @return ApiResponse
     156     * @throws ClientExceptionInterface|ApiException|ApiUnavailableException
    154157     */
    155158    public function createGetRequest(string $endpoint, array $parameters = [], array $context = []): ApiResponse
     
    157160        $request = $this->createRequest($endpoint, self::METHOD_GET, $parameters);
    158161        $httpResponse = $this->httpClient->sendRequest($request);
     162
    159163        $context['headers'] = $request->getHeaders();
    160164        $context['request_params'] = $parameters;
    161         return ApiResponse::withJson($httpResponse->getBody()->getContents(), $context);
    162     }
    163 
    164     /**
    165      * @param string $endpoint
    166      * @param array $parameters
    167      * @param array $context
    168      * @return ApiResponse
    169      * @throws ClientExceptionInterface|ApiException
     165        $context['http_response_code'] = $httpResponse->getStatusCode() ?? 0;
     166
     167        return ApiResponse::withJson($httpResponse->getBody()->getContents(), $context);
     168    }
     169
     170    /**
     171     * @param string $endpoint
     172     * @param array $parameters
     173     * @param array $context
     174     * @return ApiResponse
     175     * @throws ClientExceptionInterface|ApiException|ApiUnavailableException
    170176     */
    171177    public function createDeleteRequest(string $endpoint, array $parameters = [], array $context = []): ApiResponse
     
    173179        $request = $this->createRequest($endpoint, self::METHOD_DELETE, $parameters);
    174180        $httpResponse = $this->httpClient->sendRequest($request);
     181
    175182        $context['headers'] = $request->getHeaders();
    176183        $context['request_params'] = $parameters;
     184        $context['http_response_code'] = $httpResponse->getStatusCode() ?? 0;
     185
    177186        return ApiResponse::withJson($httpResponse->getBody()->getContents(), $context);
    178187    }
     
    203212        }
    204213        $endpoint .= '?' . http_build_query($parameters);
     214
    205215        return $this->url . $endpoint;
    206216    }
     
    236246    {
    237247        $this->strictMode = $strictMode;
     248
    238249        return $this;
    239250    }
     
    249260        $url = $this->getRequestUrl($endpoint, $parameters);
    250261        $requestFactory = $this->getRequestFactory();
     262
    251263        return $requestFactory->createRequest($method, $url)
    252264            ->withHeader('api_key', $this->apiKey->get())
     
    262274    {
    263275        $requestBody->useStrictMode($this->strictMode);
     276
    264277        return json_encode($requestBody->getData(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
    265278    }
  • multisafepay/trunk/vendor/multisafepay/php-sdk/src/Util/Version.php

    r3072171 r3114383  
    1818class Version
    1919{
    20     public const SDK_VERSION = '5.13.0';
     20    public const SDK_VERSION = '5.14.0';
    2121
    2222    /**
Note: See TracChangeset for help on using the changeset viewer.