示例#1
0
 /**
  * Records the current IP Address of the user
  */
 public function __construct()
 {
     $args = appthemes_price_format_get_args();
     // Set defaults
     if (isset($_SERVER['REMOTE_ADDR'])) {
         $this->creator['ip_address'] = $_SERVER['REMOTE_ADDR'];
     }
     $this->description = __('Transaction', APP_TD);
     $this->payment['currency'] = $args['currency_default'];
 }
示例#2
0
/**
 * Returns the price given the arguments in add_theme_support for 'app-price-format'
 * Note: if hide_decimals is turned on, the amount will be rounded.
 * 
 * @param  int $price                The numerical value to format
 * @param  string $override_currency The currency the value is in (defaults to 'currency_default')
 * @param  string $override_format   The format the value is in (defaults to 'currency_identifier')
 * @return string                    The formatted price
 */
function appthemes_get_price($price, $override_currency = '', $override_identifier = '')
{
    $format_args = appthemes_price_format_get_args();
    $decimals = $format_args['hide_decimals'] ? 0 : 2;
    $base_price = number_format($price, $decimals, $format_args['decimal_separator'], $format_args['thousands_separator']);
    $currency_code = empty($override_currency) ? $format_args['currency_default'] : $override_currency;
    $currency_identifier = empty($override_identifier) ? $format_args['currency_identifier'] : $override_identifier;
    $position = $format_args['currency_position'];
    $identifier = APP_Currencies::get_currency($currency_code, $currency_identifier);
    return _appthemes_format_display_price($base_price, $identifier, $position);
}
 public function test_args()
 {
     $this->assertArrayHasPairs(array('hide_decimals' => false, 'currency_default' => 'USD', 'currency_identifier' => 'symbol', 'currency_position' => 'left', 'thousands_separator' => ',', 'decimal_separator' => '.'), appthemes_price_format_get_args());
     add_theme_support('app-price-format', array('currency_identifier' => 'code'));
     $args = appthemes_price_format_get_args();
     $this->assertEquals('code', $args['currency_identifier']);
     add_theme_support('app-price-format', array('currency_identifier' => 'not-supported'));
     $args = appthemes_price_format_get_args();
     $this->assertEquals('symbol', $args['currency_identifier']);
     add_theme_support('app-price-format', array('currency_default' => 'GBP'));
     $this->assertArrayHasPairs(array('currency_default' => 'GBP'), appthemes_price_format_get_args());
 }
 /**
  * Prepares and returns a new Order
  * @return APP_Order New Order object
  */
 protected static function make($description = '')
 {
     if (empty($description)) {
         $description = __('Transaction', APP_TD);
     }
     $id = wp_insert_post(array('post_title' => $description, 'post_content' => __('Transaction Data', APP_TD), 'post_type' => APPTHEMES_ORDER_PTYPE, 'post_status' => APPTHEMES_ORDER_PENDING));
     add_post_meta($id, 'currency', appthemes_price_format_get_args('currency_default'), true);
     if (isset($_SERVER['REMOTE_ADDR'])) {
         add_post_meta($id, 'ip_address', $_SERVER['REMOTE_ADDR'], true);
     }
     wp_update_post(array('ID' => $id, 'post_name' => $id));
     $order = self::retrieve($id);
     $order->log('Order Created', 'major');
     return $order;
 }
示例#5
0
 /**
  * Formats a price according to the formatting string given to a currency
  * See add_currency()
  * @param  string $number        Amount of currency to be displayed
  * @param  string $currency_code Currency code used to identify currency
  * @return string                Formatted price
  */
 public static function get_price($number, $currency_code = '', $identifier = '')
 {
     $args = appthemes_price_format_get_args();
     if (empty($currency_code)) {
         $currency_code = $args['currency_default'];
     }
     if (empty($identifier)) {
         $identifier = $args['currency_identifier'];
     }
     extract(self::get_currency($currency_code));
     if ($identifier == 'symbol') {
         return $symbol . $number;
     } else {
         return $number . ' ' . $code;
     }
 }
示例#6
0
function appthemes_payments_get_args($option = '')
{
    if (!current_theme_supports('app-payments')) {
        return array();
    }
    list($args) = get_theme_support('app-payments');
    $format = appthemes_price_format_get_args('', true);
    $defaults = array('items' => array(), 'items_post_types' => array('post'), 'options' => false, 'images_url' => get_template_directory_uri() . '/includes/payments/images/', 'templates' => array('bank-transfer' => 'order-bank-transfer.php'));
    $final = wp_parse_args($args, $defaults);
    if (empty($option)) {
        return $final;
    } else {
        return $final[$option];
    }
}