Initial commit.

This commit is contained in:
2025-11-24 21:33:55 +00:00
parent 14b7ade051
commit d6e9d316bc
8974 changed files with 1423277 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
<?php
/**
* Class Add_Payment_Method_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
defined( 'ABSPATH' ) || exit;
/**
* Exception for throwing an error when we have issues with creating
* payment methods, e.g. invalid requests or errors on the server side.
*/
class Add_Payment_Method_Exception extends Base_Exception {
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* Class Amount_Too_Large_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
defined( 'ABSPATH' ) || exit;
/**
* Class representing Amount_Too_Large_Exception
*/
class Amount_Too_Large_Exception extends API_Exception {
/**
* Constructor
*
* @param string $message The Exception message to throw.
* @param int $http_code HTTP response code.
*/
public function __construct( $message, $http_code ) {
parent::__construct( $message, 'amount_too_large', $http_code, null, null );
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* Class Amount_Too_Small_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
defined( 'ABSPATH' ) || exit;
/**
* Class representing Amount_Too_Small_Exception
*/
class Amount_Too_Small_Exception extends API_Exception {
/**
* Holds the minimum amount, returned from the API.
*
* @var int
*/
private $amount;
/**
* Holds the currency for this minimum amount.
*
* @var string
*/
private $currency;
/**
* Constructor
*
* @param string $message The Exception message to throw.
* @param int $minimum_amount The minimum amount, required to create an intent in the request currency.
* @param string $currency The currency for which this is the minimum amount.
* @param int $http_code HTTP response code.
* @param int $code The Exception code.
* @param \Throwable $previous The previous exception used for the exception chaining.
*/
public function __construct( $message, $minimum_amount, $currency, $http_code, $code = 0, $previous = null ) {
$this->amount = $minimum_amount;
$this->currency = $currency;
parent::__construct( $message, 'amount_too_small', $http_code, null, null, $code, $previous );
}
/**
* Returns the minimum required amount.
*
* @return int
*/
public function get_minimum_amount() {
return $this->amount;
}
/**
* Returns the currency of the minumum required amount.
*
* @return string
*/
public function get_currency() {
return $this->currency;
}
}

View File

@@ -0,0 +1,82 @@
<?php
/**
* Class API_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
defined( 'ABSPATH' ) || exit;
/**
* Class representing API_Exception
*/
class API_Exception extends Base_Exception {
/**
* HTTP error code, for example 404, 500 etc.
*
* @var int
*/
private $http_code = 0;
/**
* Error type attribute from the server.
*
* @var string
*/
private $error_type = null;
/**
* Decline code if it is a card error.
*
* @var string
*/
private $decline_code = null;
/**
* Constructor
*
* @param string $message The Exception message to throw.
* @param string $error_code Error code returned by the server, for example wcpay_account_not_found.
* @param int $http_code HTTP response code.
* @param string $error_type Error type attribute.
* @param string $decline_code The decline code if it is a card error.
* @param int $code The Exception code.
* @param \Throwable $previous The previous exception used for the exception chaining.
*/
public function __construct( $message, $error_code, $http_code, $error_type = null, $decline_code = null, $code = 0, $previous = null ) {
$this->http_code = $http_code;
$this->error_type = $error_type;
$this->decline_code = $decline_code;
parent::__construct( $message, $error_code, $code, $previous );
}
/**
* Returns the HTTP code.
*
* @return int HTTP code, for example 404.
*/
public function get_http_code() {
return $this->http_code;
}
/**
* Returns the error type attribute from the server.
*
* @return string|null Error type, for example 'api_error' or 'card_error'.
*/
public function get_error_type() {
return $this->error_type;
}
/**
* Returns the decline code attribute from the server.
*
* @return string|null Decline code, for example 'expired_card' or 'insufficient_funds'.
*/
public function get_decline_code() {
return $this->decline_code;
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* Class API_Merchant_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
defined( 'ABSPATH' ) || exit;
/**
* Class extending API_Exception to include the error message for merchants only.
*/
class API_Merchant_Exception extends API_Exception {
/**
* Merchant message. This message should not be shown to shoppers.
*
* @var string
*/
private $merchant_message;
/**
* Constructor
*
* @param string $message The Exception message to throw.
* @param string $error_code Error code returned by the server, for example wcpay_account_not_found.
* @param int $http_code HTTP response code.
* @param string $merchant_message The merchant message. This message should not be shown to shoppers.
* @param string|null $error_type Error type attribute.
* @param string|null $decline_code The decline code if it is a card error.
* @param int $code The Exception code.
* @param \Throwable|null $previous The previous exception used for the exception chaining.
*/
public function __construct( $message, $error_code, $http_code, $merchant_message, $error_type = null, $decline_code = null, $code = 0, $previous = null ) {
$this->merchant_message = $merchant_message;
parent::__construct( $message, $error_code, $http_code, $error_type, $decline_code, $code, $previous );
}
/**
* Returns the merchant message.
*
* @return string Merchant message.
*/
public function get_merchant_message(): string {
return $this->merchant_message;
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* Class Base_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
use Exception;
defined( 'ABSPATH' ) || exit;
/**
* Abstract class for payments extension exceptions, where we allow to inject
* human-friendly error codes, e.g. 'order_not_found'.
*/
abstract class Base_Exception extends Exception {
/**
* String error code, for example 'order_not_found'.
*
* @var string
*/
private $error_code;
/**
* Constructor, including the usual $message, $code, and $previous,
* and a new parameter $error_code.
*
* @param string $message The Exception message to throw.
* @param string $error_code String error code.
* @param int $code The Exception code.
* @param \Throwable $previous The previous exception used for the exception chaining.
*/
public function __construct( $message, $error_code, $code = 0, $previous = null ) {
$this->error_code = $error_code;
parent::__construct( $message, $code, $previous );
}
/**
* Returns the error code.
*
* @return string Error code, for example 'order_not_found'.
*/
public function get_error_code() {
return $this->error_code;
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* Class Cannot_Combine_Currencies_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
defined( 'ABSPATH' ) || exit;
/**
* Class representing Amount_Too_Small_Exception
*/
class Cannot_Combine_Currencies_Exception extends API_Exception {
/**
* Holds the attempted currency, extracted from the error message returned by the API.
*
* @var string
*/
private $currency;
/**
* Constructor
*
* @param string $message The Exception message to throw.
* @param string $currency The currency for which this is the minimum amount.
* @param int $http_code HTTP response code.
* @param int $code The Exception code.
* @param \Throwable $previous The previous exception used for the exception chaining.
*/
public function __construct( $message, $currency, $http_code, $code = 0, $previous = null ) {
$this->currency = $currency;
parent::__construct( $message, 'cannot_combine_currencies', $http_code, null, null, $code, $previous );
}
/**
* Returns the currency of the minumum required amount.
*
* @return string
*/
public function get_currency() {
return $this->currency;
}
}

View File

@@ -0,0 +1,16 @@
<?php
/**
* Class Connection_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
defined( 'ABSPATH' ) || exit;
/**
* Class representing Connection_Exception
*/
class Connection_Exception extends API_Exception {
}

View File

@@ -0,0 +1,16 @@
<?php
/**
* Class Fraud_Prevention_Enabled_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
defined( 'ABSPATH' ) || exit;
/**
* Exception for throwing an error when fraud prevension service is enabled.
*/
class Fraud_Prevention_Enabled_Exception extends Process_Payment_Exception {
}

View File

@@ -0,0 +1,17 @@
<?php
/**
* Class Fraud_Ruleset_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
use Exception;
defined( 'ABSPATH' ) || exit;
/**
* Exception for throwing errors in the fraud prevention and ruleset logic.
*/
class Fraud_Ruleset_Exception extends Exception {}

View File

@@ -0,0 +1,17 @@
<?php
/**
* Class Intent_Authentication_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
defined( 'ABSPATH' ) || exit;
/**
* Exception for throwing an error when there's a problem updating an order after a payment
* authentication attempt was made by the customer, e.g. for 3DS authentication.
*/
class Intent_Authentication_Exception extends Base_Exception {
}

View File

@@ -0,0 +1,17 @@
<?php
/**
* Class Invalid_Address_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
use Exception;
defined( 'ABSPATH' ) || exit;
/**
* Exception for throwing errors when address is invalid.
*/
class Invalid_Address_Exception extends Exception {}

View File

@@ -0,0 +1,16 @@
<?php
/**
* Class Invalid_Payment_Method_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
defined( 'ABSPATH' ) || exit;
/**
* Exception for throwing an error when payment method can not be identified or used.
*/
class Invalid_Payment_Method_Exception extends Base_Exception {
}

View File

@@ -0,0 +1,16 @@
<?php
/**
* Class Invalid_Phone_Number_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
defined( 'ABSPATH' ) || exit;
/**
* Exception for throwing an error when phone number is invalid.
*/
class Invalid_Phone_Number_Exception extends Process_Payment_Exception {
}

View File

@@ -0,0 +1,17 @@
<?php
/**
* Class Rest_Request_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
use Exception;
defined( 'ABSPATH' ) || exit;
/**
* Exception for throwing errors in REST API controllers (e.g. issues with missing parameters in requests).
*/
class Invalid_Price_Exception extends Exception {}

View File

@@ -0,0 +1,18 @@
<?php
/**
* Class Invalid_Webhook_Data_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
use Exception;
defined( 'ABSPATH' ) || exit;
/**
* Exception for throwing an error when webhook data is invalid.
*/
class Invalid_Webhook_Data_Exception extends Exception {
}

View File

@@ -0,0 +1,16 @@
<?php
/**
* Class Order_ID_Mismatch_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
defined( 'ABSPATH' ) || exit;
/**
* Exception for throwing an error when payment processing is not possible or fails.
*/
class Order_ID_Mismatch_Exception extends Base_Exception {
}

View File

@@ -0,0 +1,15 @@
<?php
/**
* Class Order_Not_Found_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
defined( 'ABSPATH' ) || exit;
/**
* Exception for throwing an error when we have issues when trying to find/use an order.
*/
class Order_Not_Found_Exception extends Base_Exception {}

View File

@@ -0,0 +1,16 @@
<?php
/**
* Class Process_Payment_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
defined( 'ABSPATH' ) || exit;
/**
* Exception for throwing an error when payment processing is not possible or fails.
*/
class Process_Payment_Exception extends Base_Exception {
}

View File

@@ -0,0 +1,16 @@
<?php
/**
* Class Rate_Limiter_Enabled_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
defined( 'ABSPATH' ) || exit;
/**
* Exception for throwing an error when rate limiter is enabled.
*/
class Rate_Limiter_Enabled_Exception extends Process_Payment_Exception {
}

View File

@@ -0,0 +1,17 @@
<?php
/**
* Class Rest_Request_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
use Exception;
defined( 'ABSPATH' ) || exit;
/**
* Exception for throwing errors in REST API controllers (e.g. issues with missing parameters in requests).
*/
class Rest_Request_Exception extends Exception {}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Class Subscription_Mode_Mismatch_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
use WCPay\Exceptions\Base_Exception;
defined( 'ABSPATH' ) || exit;
/**
* Subscription_Mode_Mismatch_Exception class.
*/
class Subscription_Mode_Mismatch_Exception extends Base_Exception {
/**
* Subscription_Mode_Mismatch_Exception constructor.
*
* @param string $message The exception message.
* @param int $code The exception code.
* @param \Throwable|null $previous The previous exception.
*/
public function __construct( $message = 'The subscription mode does not match the current WooPayments mode.', $code = 0, $previous = null ) {
parent::__construct( $message, 'subscription_mode_mismatch', $code, $previous );
}
}