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
<?php
defined( 'ABSPATH' ) || exit();
class WC_Stripe_Payment_Balance {
private $data = array();
private $order;
public function __construct( $order ) {
$this->order = $order;
$this->data = array(
'currency' => $order->get_meta( WC_Stripe_Constants::STRIPE_CURRENCY ),
'fee' => $order->get_meta( WC_Stripe_Constants::STRIPE_FEE ),
'net' => $order->get_meta( WC_Stripe_Constants::STRIPE_NET )
);
}
public function __isset( $name ) {
return isset( $this->data[ $name ] );
}
public function __set( $name, $value ) {
$this->set_prop( $name, $value );
}
public function __get( $name ) {
if ( method_exists( $this, 'get_' . $name ) ) {
return $this->{'get_' . $name}();
}
return $this->get_prop( $name );
}
private function set_prop( $name, $value ) {
$this->data[ $name ] = $value;
}
private function get_prop( $key, $default = '' ) {
if ( ! isset( $this->data[ $key ] ) ) {
$this->data[ $key ] = $default;
}
return $this->data[ $key ];
}
public function get_fee() {
return $this->get_prop( 'fee', 0 );
}
public function get_net() {
return $this->get_prop( 'net', 0 );
}
public function get_currency() {
return $this->get_prop( 'currency' );
}
public function to_array() {
return $this->data;
}
public function update_meta_data( $save = false ) {
if ( $this->order ) {
$this->order->update_meta_data( WC_Stripe_Constants::STRIPE_CURRENCY, $this->currency );
$this->order->update_meta_data( WC_Stripe_Constants::STRIPE_FEE, $this->fee );
$this->order->update_meta_data( WC_Stripe_Constants::STRIPE_NET, $this->net );
if ( $save ) {
$this->order->save();
}
}
}
}