<?php

namespace FKWCSQ\Includes\Conversions;

class WCSquare extends Conversion {

	protected $meta_customer_key = '_wc_square_credit_card_customer_id';
	protected $meta_token_key = '_wc_square_credit_card_payment_token';
	protected $meta_location_key = '_wc_square_credit_card_square_location_id';

	public function get_location_id( $renewal_order, $subscription ) {
		$options = get_option( 'wc_square_settings', array() );
		if ( isset( $options['enable_sandbox'] ) && 'yes' === $options['enable_sandbox'] ) {
			// If sandbox is enabled, return the sandbox location ID
			return isset( $options['sandbox_location_id'] ) ? $options['sandbox_location_id'] : parent::get_location_id( $renewal_order, $subscription );

		}
		if ( isset( $options['production_location_id'] ) && ! empty( $options['production_location_id'] ) ) {
			// If sandbox is enabled, return the sandbox location ID
			return isset( $options['production_location_id'] ) ? $options['production_location_id'] : parent::get_location_id( $renewal_order, $subscription );
		}

		return $this->get_subscription_meta_value( $renewal_order, $subscription, $this->meta_location_key );
	}
}
