PluginProbe
Pay with Vipps and MobilePay for WooCommerce / 6.2.5
Pay with Vipps and MobilePay for WooCommerce v6.2.5
6.2.5 6.2.4 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 All 187 releases
woo-vipps / recurring / includes / models / WC_Vipps_Agreement_Pricing.php

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

82 lines 1.9 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_Pricing extends WC_Vipps_Model {
6 public const TYPE_LEGACY = "LEGACY";
7 public const TYPE_VARIABLE = "VARIABLE";
8
9 protected array $valid_types = [
10 self::TYPE_LEGACY,
11 self::TYPE_VARIABLE
12 ];
13
14 protected array $required_fields = [
15 "VARIABLE" => [ "type", "currency", "suggested_max_amount" ],
16 "LEGACY" => [ "type", "currency", "amount" ],
17 ];
18
19 public ?string $type = null;
20 public ?string $currency = null;
21 public ?int $amount = null;
22 public ?int $suggested_max_amount = null;
23 public ?int $max_amount = null;
24
25 /**
26 * @throws WC_Vipps_Recurring_Invalid_Value_Exception
27 */
28 public function set_type( string $type ): self {
29 if ( ! in_array( $type, $this->valid_types, true ) ) {
30 $class = get_class( $this );
31 throw new WC_Vipps_Recurring_Invalid_Value_Exception( "$type is not a valid value for `type` in $class." );
32 }
33
34 $this->type = $type;
35
36 return $this;
37 }
38
39 public function set_currency( string $currency ): self {
40 $this->currency = $currency;
41
42 return $this;
43 }
44
45 public function set_amount( int $amount ): self {
46 $this->amount = $amount;
47
48 return $this;
49 }
50
51 public function set_suggested_max_amount( int $suggested_max_amount ): self {
52 $this->suggested_max_amount = $suggested_max_amount;
53
54 return $this;
55 }
56
57 public function set_max_amount( int $max_amount ): self {
58 $this->max_amount = $max_amount;
59
60 return $this;
61 }
62
63 /**
64 * @throws WC_Vipps_Recurring_Missing_Value_Exception
65 */
66 public function to_array( bool $check_required = false ): array {
67 if ( $check_required ) {
68 $this->check_required( $this->type );
69 }
70
71 return array_merge(
72 [
73 "type" => $this->type,
74 "currency" => $this->currency,
75 ],
76 $this->conditional( "amount", $this->amount ),
77 $this->conditional( "suggestedMaxAmount", $this->suggested_max_amount ),
78 $this->conditional( "maxAmount", $this->max_amount )
79 );
80 }
81 }
82