mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
Allow PaymentToken types to be filtered
This commit is contained in:
parent
0192141805
commit
d5ddbdf927
1 changed files with 17 additions and 5 deletions
|
@ -16,11 +16,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||||
*/
|
*/
|
||||||
class PaymentToken {
|
class PaymentToken {
|
||||||
|
|
||||||
|
|
||||||
const TYPE_PAYMENT_METHOD_TOKEN = 'PAYMENT_METHOD_TOKEN';
|
const TYPE_PAYMENT_METHOD_TOKEN = 'PAYMENT_METHOD_TOKEN';
|
||||||
const VALID_TYPES = array(
|
|
||||||
self::TYPE_PAYMENT_METHOD_TOKEN,
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Id.
|
* The Id.
|
||||||
|
@ -52,7 +48,7 @@ class PaymentToken {
|
||||||
* @throws RuntimeException When the type is not valid.
|
* @throws RuntimeException When the type is not valid.
|
||||||
*/
|
*/
|
||||||
public function __construct( string $id, string $type = self::TYPE_PAYMENT_METHOD_TOKEN, \stdClass $source ) {
|
public function __construct( string $id, string $type = self::TYPE_PAYMENT_METHOD_TOKEN, \stdClass $source ) {
|
||||||
if ( ! in_array( $type, self::VALID_TYPES, true ) ) {
|
if ( ! in_array( $type, self::get_valid_types(), true ) ) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
__( 'Not a valid payment source type.', 'woocommerce-paypal-payments' )
|
__( 'Not a valid payment source type.', 'woocommerce-paypal-payments' )
|
||||||
);
|
);
|
||||||
|
@ -101,4 +97,20 @@ class PaymentToken {
|
||||||
'source' => $this->source(),
|
'source' => $this->source(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of valid token types.
|
||||||
|
* Can be modified through the `woocommerce_paypal_payments_valid_payment_token_types` filter.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function get_valid_types() {
|
||||||
|
return apply_filters(
|
||||||
|
'woocommerce_paypal_payments_valid_payment_token_types',
|
||||||
|
array(
|
||||||
|
self::TYPE_PAYMENT_METHOD_TOKEN,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue