PluginProbe
Pay with Vipps and MobilePay for WooCommerce / 6.0.2
Pay with Vipps and MobilePay for WooCommerce v6.0.2
6.2.3 6.2.2 6.2.1 6.2.0 6.1.10 6.1.9 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1.0 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 6.0.0 5.4.3 5.4.2 5.4.1 5.4.0 All 185 releases
woo-vipps / recurring / includes / models / WC_Vipps_Agreement_Interval.php

WC_Vipps_Agreement_Interval.php in Pay with Vipps and MobilePay for WooCommerce 6.0.2, at recurring/includes/models/WC_Vipps_Agreement_Interval.php

57 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined( 'ABSPATH' ) || exit;
4
5 class WC_Vipps_Agreement_Interval extends WC_Vipps_Model {
6 public const UNIT_YEAR = "YEAR";
7 public const UNIT_MONTH = "MONTH";
8 public const UNIT_WEEK = "WEEK";
9 public const UNIT_DAY = "DAY";
10
11 protected array $valid_units = [
12 self::UNIT_YEAR,
13 self::UNIT_MONTH,
14 self::UNIT_WEEK,
15 self::UNIT_DAY
16 ];
17
18 protected array $required_fields = [ "unit", "count" ];
19
20 public ?string $unit = null;
21 public ?int $count = null;
22
23 /**
24 * @throws WC_Vipps_Recurring_Invalid_Value_Exception
25 */
26 public function set_unit( string $unit ): self {
27 if ( ! in_array( $unit, $this->valid_units ) ) {
28 $class = get_class( $this );
29 throw new WC_Vipps_Recurring_Invalid_Value_Exception( "$unit is not a valid value for `unit` in $class." );
30 }
31
32 $this->unit = $unit;
33
34 return $this;
35 }
36
37 public function set_count( int $count ): self {
38 $this->count = $count;
39
40 return $this;
41 }
42
43 /**
44 * @throws WC_Vipps_Recurring_Missing_Value_Exception
45 */
46 public function to_array( bool $check_required = false ): array {
47 if ( $check_required ) {
48 $this->check_required();
49 }
50
51 return [
52 "unit" => $this->unit,
53 "count" => $this->count
54 ];
55 }
56 }
57