1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
<?php
defined( 'ABSPATH' ) || exit();
if ( ! class_exists( 'WC_Product_Simple' ) ) {
return;
}
class WC_Product_Braintree_Subscription extends WC_Product_Simple {
public function __construct( $product ) {
$this->extra_data['subscription_price'] = 0;
$this->extra_data['subscription_length'] = 0;
$this->extra_data['sandbox_subscription_period_interval'] = 1;
$this->extra_data['production_subscription_period_interval'] = 1;
$this->extra_data['subscription_period'] = 'month';
$this->extra_data['subscription_sign_up_fee'] = 0;
$this->extra_data['subscription_trial_length'] = 0;
$this->extra_data['subscription_trial_period'] = '';
$this->extra_data['subscription_one_time_shipping'] = '';
$this->extra_data['braintree_sandbox_plans'] = array();
$this->extra_data['braintree_production_plans'] = array();
parent::__construct( $product );
$this->subscription_period = 'month';
$this->product_type = 'braintree-subscription';
}
public function __get( $key ) {
return $this->get_prop( $key );
}
public function __set( $key, $value ) {
$this->set_prop( $key, $value );
}
public function get_price( $context = 'view' ) {
return $this->get_subscription_price();
}
public function get_price_html( $deprecated = '' ) {
return wcs_braintree_get_product_price_html( $this, parent::get_price_html( $deprecated ) );
}
public function get_plans() {
$plans = $this->get_prop( 'braintree_' . wc_braintree_environment() . '_plans' );
return $plans ? $plans : array();
}
public function get_signup_fee() {
return $this->subscription_sign_up_fee ? $this->subscription_sign_up_fee : 0;
}
public function is_one_time_shipping() {
return $this->subscription_one_time_shipping === 'yes';
}
public function get_type() {
return 'braintree-subscription';
}
public function get_subscription_length() {
return $this->subscription_length;
}
public function get_subscription_price() {
return $this->get_prop( 'subscription_price' );
}
public function get_subscription_period_interval() {
$value = $this->get_prop( wc_braintree_environment() . '_subscription_period_interval' );
$plans = wcs_braintree_get_plans( wc_braintree_environment() );
if ( ( $id = wcs_braintree_get_plan_from_product( $this ) ) ) {
$value = $plans[ $id ]['billingFrequency'];
}
return $value;
}
public function get_subscription_period() {
return $this->subscription_period;
}
public function get_subscription_sign_up_fee() {
return $this->subscription_sign_up_fee;
}
public function get_subscription_trial_length() {
$trial_length = $this->subscription_trial_length;
return empty( $trial_length ) ? 0 : $trial_length;
}
public function get_subscription_trial_period() {
return $this->subscription_trial_period;
}
public function get_subscription_one_time_shipping() {
return $this->subscription_one_time_shipping;
}
public function get_braintree_sandbox_plans() {
return $this->braintree_sandbox_plans;
}
public function get_braintree_production_plans() {
return $this->braintree_production_plans;
}
public function get_braintree_plans( $env = '' ) {
$env = empty( $env ) ? wc_braintree_environment() : $env;
return $this->get_prop( 'braintree_' . $env . '_plans' );
}
public function get_sandbox_subscription_period_interval() {
return $this->get_prop( 'sandbox_subscription_period_interval' );
}
public function get_production_subscription_period_interval() {
return $this->get_prop( 'production_subscription_period_interval' );
}
public function set_subscription_price( $price ) {
$this->subscription_price = $price;
}
public function set_subscription_length( $length ) {
$this->subscription_length = $length;
}
public function set_subscription_period_interval( $interval ) {
$this->subscription_period_interval = $interval;
}
public function set_subscription_period( $period ) {
$this->subscription_period = $period;
}
public function set_subscription_sign_up_fee( $fee ) {
$this->subscription_sign_up_fee = $fee;
}
public function set_subscription_trial_length( $trial_length ) {
$this->subscription_trial_length = $trial_length;
}
public function set_subscription_trial_period( $trial_period ) {
$this->subscription_trial_period = $trial_period;
}
public function set_subscription_one_time_shipping( $one_time_shipping ) {
$this->subscription_one_time_shipping = $one_time_shipping;
}
public function set_braintree_sandbox_plans( $plans ) {
$this->braintree_sandbox_plans = $plans;
}
public function set_braintree_production_plans( $plans ) {
$this->braintree_production_plans = $plans;
}
public function has_trial() {
return $this->get_subscription_trial_length() != 0;
}
public function set_sandbox_subscription_period_interval( $value ) {
$this->set_prop( 'sandbox_subscription_period_interval', $value );
}
public function set_production_subscription_period_interval( $value ) {
$this->set_prop( 'production_subscription_period_interval', $value );
}
}