| 1 |
<?php |
| 2 |
|
| 3 |
defined( 'ABSPATH' ) || exit; |
| 4 |
|
| 5 |
class WC_Vipps_Checkout_Session_Subscription extends WC_Vipps_Model { |
| 6 |
protected array $required_fields = [ |
| 7 |
"reference", |
| 8 |
"product_name", |
| 9 |
"pricing", |
| 10 |
"interval", |
| 11 |
"merchant_agreement_url" |
| 12 |
]; |
| 13 |
|
| 14 |
public ?string $product_name = null; |
| 15 |
public ?string $product_description = null; |
| 16 |
public ?WC_Vipps_Checkout_Session_Amount $amount = null; |
| 17 |
public ?WC_Vipps_Agreement_Interval $interval = null; |
| 18 |
public ?string $merchant_agreement_url = null; |
| 19 |
public ?WC_Vipps_Agreement_Initial_Charge $initial_charge = null; |
| 20 |
public ?WC_Vipps_Agreement_Campaign $campaign = null; |
| 21 |
|
| 22 |
public function set_product_name( string $product_name ): self { |
| 23 |
$this->product_name = $product_name; |
| 24 |
|
| 25 |
return $this; |
| 26 |
} |
| 27 |
|
| 28 |
public function set_product_description( string $product_description ): self { |
| 29 |
$this->product_description = $product_description; |
| 30 |
|
| 31 |
return $this; |
| 32 |
} |
| 33 |
|
| 34 |
public function set_amount( $amount ): self { |
| 35 |
return $this->_set_value( 'amount', $amount, WC_Vipps_Checkout_Session_Amount::class ); |
| 36 |
} |
| 37 |
|
| 38 |
public function set_interval( $interval ): self { |
| 39 |
return $this->_set_value( 'interval', $interval, WC_Vipps_Agreement_Interval::class ); |
| 40 |
} |
| 41 |
|
| 42 |
public function set_merchant_agreement_url( string $merchant_agreement_url ): self { |
| 43 |
$this->merchant_agreement_url = $merchant_agreement_url; |
| 44 |
|
| 45 |
return $this; |
| 46 |
} |
| 47 |
|
| 48 |
public function set_campaign( $campaign ): self { |
| 49 |
return $this->_set_value( 'campaign', $campaign, WC_Vipps_Agreement_Campaign::class ); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* @throws WC_Vipps_Recurring_Missing_Value_Exception |
| 54 |
*/ |
| 55 |
public function to_array( bool $check_required = false ): array { |
| 56 |
if ( $check_required ) { |
| 57 |
$this->check_required(); |
| 58 |
} |
| 59 |
|
| 60 |
return array_merge( |
| 61 |
[ |
| 62 |
"productName" => $this->product_name, |
| 63 |
"amount" => $this->amount, |
| 64 |
"interval" => $this->interval, |
| 65 |
"merchantAgreementUrl" => $this->merchant_agreement_url, |
| 66 |
], |
| 67 |
$this->conditional( "productDescription", $this->product_description ), |
| 68 |
$this->conditional( "campaign", $this->campaign ), |
| 69 |
); |
| 70 |
} |
| 71 |
} |
| 72 |
|