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
<?php
defined( 'ABSPATH' ) || exit();
class WC_Stripe_Product_Gateway_Option {
private $id;
private $settings = array();
private $product;
private $payment_method;
public function __construct( $product, $payment_method ) {
if ( ! is_object( $product ) ) {
$this->product = wc_get_product( $product );
} else {
$this->product = $product;
}
$this->payment_method = $payment_method;
$this->init_settings();
}
public function get_id() {
return '_' . $this->payment_method->id . '_options';
}
public function save() {
$this->product->update_meta_data( $this->get_id(), $this->settings );
$this->product->save();
}
public function init_settings() {
if ( ! $this->settings ) {
$this->settings = $this->product->get_meta( $this->get_id() );
$this->settings = is_array( $this->settings ) ? $this->settings : array();
$this->settings = wp_parse_args( $this->settings, $this->get_default_values() );
}
}
public function get_default_values() {
return array(
'enabled' => $this->payment_method->product_checkout_enabled(),
'charge_type' => $this->payment_method->get_option( 'charge_type' ),
);
}
public function get_option( $key, $default = null ) {
if ( ! isset( $this->settings[ $key ] ) && null != $default ) {
$this->settings[ $key ] = $default;
}
return $this->settings[ $key ];
}
public function set_option( $key, $value ) {
$this->settings[ $key ] = $value;
}
public function enabled() {
return $this->get_option( 'enabled', false );
}
}