2020-09-01 09:00:45 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* The PaymentToken object.
|
|
|
|
*
|
2020-09-11 14:11:10 +03:00
|
|
|
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
2020-09-01 09:00:45 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-09-11 14:11:10 +03:00
|
|
|
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
2020-09-01 09:00:45 +03:00
|
|
|
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
2020-09-01 09:00:45 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class PaymentToken
|
|
|
|
*/
|
|
|
|
class PaymentToken {
|
|
|
|
|
|
|
|
|
2020-09-11 13:38:02 +03:00
|
|
|
const TYPE_PAYMENT_METHOD_TOKEN = 'PAYMENT_METHOD_TOKEN';
|
|
|
|
const VALID_TYPES = array(
|
2020-09-01 09:00:45 +03:00
|
|
|
self::TYPE_PAYMENT_METHOD_TOKEN,
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Id.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PaymentToken constructor.
|
|
|
|
*
|
|
|
|
* @param string $id The Id.
|
|
|
|
* @param string $type The type.
|
|
|
|
* @throws RuntimeException When the type is not valid.
|
|
|
|
*/
|
|
|
|
public function __construct( string $id, string $type = self::TYPE_PAYMENT_METHOD_TOKEN ) {
|
|
|
|
if ( ! in_array( $type, self::VALID_TYPES, true ) ) {
|
|
|
|
throw new RuntimeException(
|
2020-09-11 10:20:12 +03:00
|
|
|
__( 'Not a valid payment source type.', 'paypal-payments-for-woocommerce' )
|
2020-09-01 09:00:45 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
$this->id = $id;
|
|
|
|
$this->type = $type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the ID.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function id(): string {
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the type.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function type(): string {
|
|
|
|
return $this->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the object as array.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function to_array(): array {
|
|
|
|
return array(
|
|
|
|
'id' => $this->id(),
|
|
|
|
'type' => $this->type(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|