| 1 |
<?php |
| 2 |
/** |
| 3 |
* Payment Methods: Collection |
| 4 |
* |
| 5 |
* @package SimplePay\Core\PaymentMethods |
| 6 |
* @copyright Copyright (c) 2022, Sandhills Development, LLC |
| 7 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 8 |
* @since 3.8.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace SimplePay\Core\PaymentMethods; |
| 12 |
|
| 13 |
use SimplePay\Core\Utils; |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Collection class |
| 21 |
* |
| 22 |
* @since 3.8.0 |
| 23 |
*/ |
| 24 |
class Collection extends Utils\Collection { |
| 25 |
|
| 26 |
/** |
| 27 |
* Adds a Payment Method to the registry. |
| 28 |
* |
| 29 |
* @since 3.8.0 |
| 30 |
* |
| 31 |
* @param string $payment_method_id Payment Method ID. |
| 32 |
* @param \SimplePay\Core\PaymentMethods\PaymentMethod $payment_method Payment Method. |
| 33 |
* @return \WP_Error|true True on successful addition, otherwise a \WP_Error object. |
| 34 |
*/ |
| 35 |
public function add( $payment_method_id, $payment_method ) { |
| 36 |
if ( empty( $payment_method_id ) ) { |
| 37 |
return new \WP_Error( |
| 38 |
'invalid_payment_method_id', |
| 39 |
sprintf( |
| 40 |
/* translators: %s Collection ID that could not be registered. */ |
| 41 |
__( 'The %s Payment Method already exists and cannot be added.', 'stripe' ), |
| 42 |
$payment_method_id |
| 43 |
) |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
if ( ! is_a( $payment_method, 'SimplePay\Core\PaymentMethods\PaymentMethod' ) ) { |
| 48 |
return new \WP_Error( |
| 49 |
'invalid_payment_method', |
| 50 |
sprintf( |
| 51 |
/* translators: %s Collection ID that could not be registered. */ |
| 52 |
__( 'The Payment Method is invalid.', 'stripe' ), |
| 53 |
$payment_method |
| 54 |
) |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
return $this->add_item( $payment_method_id, $payment_method ); |
| 59 |
} |
| 60 |
} |
| 61 |
|