| 1 |
<?php |
| 2 |
/** |
| 3 |
* Payment Method Data DTO |
| 4 |
* |
| 5 |
* @package SeQura/WC |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace SeQura\WC\Dto; |
| 9 |
|
| 10 |
/** |
| 11 |
* Payment Method Data DTO. |
| 12 |
*/ |
| 13 |
class Payment_Method_Data extends Dto { |
| 14 |
|
| 15 |
/** |
| 16 |
* SeQura product |
| 17 |
* |
| 18 |
* @var string |
| 19 |
*/ |
| 20 |
public $product; |
| 21 |
|
| 22 |
/** |
| 23 |
* Campaign |
| 24 |
* |
| 25 |
* @var string |
| 26 |
*/ |
| 27 |
public $campaign; |
| 28 |
|
| 29 |
/** |
| 30 |
* SeQura product title |
| 31 |
* |
| 32 |
* @var string |
| 33 |
*/ |
| 34 |
public $title; |
| 35 |
|
| 36 |
/** |
| 37 |
* Encode the DTO instance into a raw string. Returns a base64 encoded JSON string. |
| 38 |
*/ |
| 39 |
public function encode(): string { |
| 40 |
$encoded = parent::encode(); |
| 41 |
$encoded = base64_encode( $encoded ); |
| 42 |
return $encoded ? $encoded : ''; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Decode a raw string into a DTO instance. Assumes that the raw string is a base64 encoded JSON string. |
| 47 |
* |
| 48 |
* @return static|null |
| 49 |
*/ |
| 50 |
public static function decode( string $raw ): mixed { |
| 51 |
$decoded = base64_decode( $raw ); |
| 52 |
if ( ! $decoded ) { |
| 53 |
return null; |
| 54 |
} |
| 55 |
return parent::decode( $decoded ); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Check if the instance contains valid data. |
| 60 |
*/ |
| 61 |
public function is_valid(): bool { |
| 62 |
return ! empty( $this->product ); |
| 63 |
} |
| 64 |
} |
| 65 |
|