 wp-pay-gateways    /
                    adyen
                      wp-pay-gateways    /
                    adyen
                
                            | 1 | <?php | ||
| 2 | /** | ||
| 3 | * Amount | ||
| 4 | * | ||
| 5 | * @author Pronamic <[email protected]> | ||
| 6 | * @copyright 2005-2019 Pronamic | ||
| 7 | * @license GPL-3.0-or-later | ||
| 8 | * @package Pronamic\WordPress\Pay\Gateways\OmniKassa2 | ||
| 9 | */ | ||
| 10 | |||
| 11 | namespace Pronamic\WordPress\Pay\Gateways\Adyen; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * Amount | ||
| 15 | * | ||
| 16 | * @author Remco Tolsma | ||
| 17 | * @version 2.1.0 | ||
| 18 | * @since 2.0.2 | ||
| 19 | */ | ||
| 20 | class Amount { | ||
| 21 | /** | ||
| 22 | * Currency. | ||
| 23 | * | ||
| 24 | * @var string | ||
| 25 | */ | ||
| 26 | private $currency; | ||
| 27 | |||
| 28 | /** | ||
| 29 | * Value. | ||
| 30 | * | ||
| 31 | * @var int | ||
| 32 | */ | ||
| 33 | private $value; | ||
| 34 | |||
| 35 | /** | ||
| 36 | * Construct amount. | ||
| 37 | * | ||
| 38 | * @param string $currency Currency. | ||
| 39 | * @param int $value Value. | ||
| 40 | */ | ||
| 41 | 1 | 	public function __construct( $currency, $value ) { | |
| 42 | 1 | $this->currency = $currency; | |
| 43 | 1 | $this->value = $value; | |
| 44 | 1 | } | |
| 45 | |||
| 46 | /** | ||
| 47 | * Get currency. | ||
| 48 | * | ||
| 49 | * @return string | ||
| 50 | */ | ||
| 51 | 	public function get_currency() { | ||
| 52 | return $this->currency; | ||
| 53 | } | ||
| 54 | |||
| 55 | /** | ||
| 56 | * Get amount. | ||
| 57 | * | ||
| 58 | * @return int | ||
| 59 | */ | ||
| 60 | 	public function get_value() { | ||
| 61 | return $this->value; | ||
| 62 | } | ||
| 63 | |||
| 64 | /** | ||
| 65 | * Get JSON. | ||
| 66 | * | ||
| 67 | * @return object | ||
| 68 | */ | ||
| 69 | 	public function get_json() { | ||
| 70 | return (object) array( | ||
| 71 | 'currency' => $this->get_currency(), | ||
| 72 | 'value' => $this->get_value(), | ||
| 73 | ); | ||
| 74 | } | ||
| 75 | |||
| 76 | /** | ||
| 77 | * Create amount from object. | ||
| 78 | * | ||
| 79 | * @param object $object Object. | ||
| 80 | * @return Amount | ||
| 81 | * @throws InvalidArgumentException Throws invalid argument exception when object does not contains the required properties. | ||
| 82 | */ | ||
| 83 | 1 | 	public static function from_object( $object ) { | |
| 84 | 1 | 		if ( ! isset( $object->currency ) ) { | |
| 85 | throw new InvalidArgumentException( 'Object must contain `currency` property.' ); | ||
| 0 ignored issues–
                            show             Bug
    
    
    
        introduced 
                            by  
  Loading history... | |||
| 86 | } | ||
| 87 | |||
| 88 | 1 | 		if ( ! isset( $object->value ) ) { | |
| 89 | throw new InvalidArgumentException( 'Object must contain `value` property.' ); | ||
| 90 | } | ||
| 91 | |||
| 92 | 1 | return new self( | |
| 93 | 1 | $object->currency, | |
| 94 | 1 | $object->value | |
| 95 | ); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | 
