PluginProbe
Pay with Vipps and MobilePay for WooCommerce / 6.2.4
Pay with Vipps and MobilePay for WooCommerce v6.2.4
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_Initial_Charge.php

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

83 lines 2.1 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_Initial_Charge extends WC_Vipps_Model {
6 public const TRANSACTION_TYPE_RESERVE_CAPTURE = "RESERVE_CAPTURE";
7 public const TRANSACTION_TYPE_DIRECT_CAPTURE = "DIRECT_CAPTURE";
8
9 protected array $valid_transaction_types = [
10 self::TRANSACTION_TYPE_RESERVE_CAPTURE,
11 self::TRANSACTION_TYPE_DIRECT_CAPTURE
12 ];
13
14 protected array $required_fields = [ "amount", "description", "transaction_type" ];
15
16 public ?int $amount = null;
17 public ?string $description = null;
18 public ?string $transaction_type = null;
19 public ?string $order_id = null;
20 public ?string $external_id = null;
21
22 public function set_amount( int $amount ): self {
23 $this->amount = $amount;
24
25 return $this;
26 }
27
28 public function set_description( string $description ): self {
29 if ( strlen( $description ) > 100 ) {
30 $description = mb_substr( $description, 0, 97 ) . '...';
31 }
32
33 $this->description = $description;
34
35 return $this;
36 }
37
38 /**
39 * @throws WC_Vipps_Recurring_Invalid_Value_Exception
40 */
41 public function set_transaction_type( string $transaction_type ): self {
42 if ( ! in_array( $transaction_type, $this->valid_transaction_types, true ) ) {
43 $class = get_class( $this );
44 throw new WC_Vipps_Recurring_Invalid_Value_Exception( "$transaction_type is not a valid value for `transaction_type` in $class." );
45 }
46
47 $this->transaction_type = $transaction_type;
48
49 return $this;
50 }
51
52 public function set_order_id( string $order_id ): self {
53 $this->order_id = $order_id;
54
55 return $this;
56 }
57
58 public function set_external_id( string $external_id ): self {
59 $this->external_id = $external_id;
60
61 return $this;
62 }
63
64 /**
65 * @throws WC_Vipps_Recurring_Missing_Value_Exception
66 */
67 public function to_array( bool $check_required = false ): array {
68 if ( $check_required ) {
69 $this->check_required();
70 }
71
72 return array_merge(
73 [
74 "amount" => $this->amount,
75 "description" => $this->description,
76 "transactionType" => $this->transaction_type,
77 ],
78 $this->conditional( "orderId", $this->order_id ),
79 $this->conditional( "externalId", $this->external_id )
80 );
81 }
82 }
83