woocommerce-paypal-payments/modules/ppcp-api-client/src/Entity/class-paymenttoken.php

103 lines
1.7 KiB
PHP
Raw Normal View History

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;
/**
* @var \stdClass
*/
private $source;
/**
2020-09-01 09:00:45 +03:00
* 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, \stdClass $source ) {
2020-09-01 09:00:45 +03:00
if ( ! in_array( $type, self::VALID_TYPES, true ) ) {
throw new RuntimeException(
__( 'Not a valid payment source type.', 'woocommerce-paypal-payments' )
2020-09-01 09:00:45 +03:00
);
}
$this->id = $id;
$this->type = $type;
$this->source = $source;
}
2020-09-01 09:00:45 +03:00
/**
* 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 source.
*
* @return \stdClass
*/
public function source(): \stdClass
{
return $this->source;
}
2020-09-01 09:00:45 +03:00
/**
* Returns the object as array.
*
* @return array
*/
public function to_array(): array {
return array(
'id' => $this->id(),
'type' => $this->type(),
'source' => $this->source(),
2020-09-01 09:00:45 +03:00
);
}
}