Esempio n. 1
0
 /**
  * Displays notices if the user does have a premier/business account.
  */
 function invalid_account_type_warning()
 {
     $options = APP_Gateway_Registry::get_options();
     if (APP_Gateway_Registry::is_gateway_enabled('paypal', 'escrow') && empty($options->gateways['paypal']['business_account'])) {
         $this->admin_msg(__('<strong>Important:</strong> You need a Premier or Verified Business PayPal account to be able to use the PayPal Adaptive service.', APP_TD));
     }
 }
Esempio n. 2
0
 public function before_rendering_field($field)
 {
     if ('currency_identifier' == $field['name'] || 'currency_position' == $field['name']) {
         $currency = APP_Currencies::get_currency(APP_Gateway_Registry::get_options()->currency_code);
         foreach ($field['values'] as $key => $value) {
             $field['values'][$key] = str_replace(array('{symbol}', '{code}'), array($currency['symbol'], $currency['code']), $value);
         }
     }
     return $field;
 }
 public static function build_new()
 {
     $order_data = array("post_title" => "Transaction", "post_content" => "Transaction Data", "post_type" => APPTHEMES_ORDER_PTYPE);
     $order_id = wp_insert_post($order_data);
     $meta = array("addons" => array(), "gateway" => "", "ip_address" => $_SERVER['REMOTE_ADDR'], "currency" => APP_Gateway_Registry::get_options()->currency_code);
     foreach ($meta as $meta_key => $meta_value) {
         add_post_meta($order_id, $meta_key, $meta_value, true);
     }
     return self::retrieve($order_id);
 }
Esempio n. 4
0
 public static function get_price($number, $currency = '')
 {
     if (empty($currency)) {
         $currency = APP_Gateway_Registry::get_options()->currency_code;
     }
     $string = self::get_display($currency);
     $search = array('{symbol}', '{price}');
     $replace = array(self::get_symbol($currency), $number);
     return str_replace($search, $replace, $string);
 }
 /**
  * @depends test_register
  */
 public function test_gateway_defaults($gateway)
 {
     $options = APP_Gateway_Registry::get_gateway_options($gateway->identifier());
     $this->assertNotEmpty($options);
     $this->assertEquals($options['test_field'], 'test_value');
     $real_options = APP_Gateway_Registry::get_options();
     $real_options->gateways = array('enabled' => array(), $gateway->identifier() => array('test_field' => 'other_test_value'));
     $new_options = APP_Gateway_Registry::get_gateway_options($gateway->identifier());
     $this->assertNotEmpty($new_options);
     $this->assertEquals('other_test_value', $new_options['test_field']);
 }
Esempio n. 6
0
 /**
  * @depends test_gateway_creation
  * @depends test_anonymous_process_fail
  */
 public function test_anonymous_process_success($gateway)
 {
     $order = appthemes_new_order();
     $order->add_item('mock-process-test-item', 5, $order->get_id());
     $old_options = APP_Gateway_Registry::get_options();
     // Create new options object with gateway enabled
     $options = new stdClass();
     $options->gateways = array('enabled' => array('mock-gateway' => true));
     APP_Gateway_Registry::register_options($options);
     // Gateway should be enabled
     $this->assertTrue(APP_Gateway_Registry::is_gateway_enabled('mock-gateway'));
     // After enabled, it should pass
     $status = appthemes_process_gateway('mock-gateway', $order);
     $this->assertTrue($status);
     // Processing should call the gateway
     $this->assertTrue($gateway->process_called());
     APP_Gateway_Registry::register_options($old_options);
 }
Esempio n. 7
0
 /**
  * Displays the Form for Customer Submission
  */
 public function display_form($order, $options)
 {
     $defaults = array('email_address' => '', 'currency_code' => 'USD', 'sandbox_enabled' => false);
     $options = wp_parse_args($options, $defaults);
     $fields = array('noshipping' => 1, 'no_note' => 1, 'rm' => 0, 'cmd' => '_xclick', 'charset' => 'utf-8');
     // Item Information
     $first_item = $order->get_item();
     $fields['item_name'] = $first_item['post']->post_title;
     $fields['item_number'] = $order->get_id();
     // Seller Options
     $fields['business'] = $options['email_address'];
     $fields['currency_code'] = APP_Gateway_Registry::get_options()->currency_code;
     // Paypal Options
     $fields['cbt'] = sprintf(__('Continue to %s', APP_TD), get_bloginfo('name'));
     $site = !empty($options['sandbox_enabled']) ? 'sandbox' : 'live';
     $post_url = $this->post_urls[$site];
     $fields['amount'] = $order->get_total();
     $fields['return'] = wp_nonce_url($order->get_return_url(), 'paypal');
     $fields['cancel_return'] = $order->get_cancel_url();
     echo $this->create_form($fields, $post_url);
     echo html('script', array(), 'setTimeout( \'document.paypal_payform.submit();\' );');
 }
/**
 * Adds tax to an order based on settings
 */
function appthemes_payments_add_tax($order)
{
    $order->remove_item('_regional-tax');
    $options = APP_Gateway_Registry::get_options();
    $tax_rate = $options->tax_charge;
    $total = $order->get_total();
    $charged_tax = $total * ($tax_rate / 100);
    if ($charged_tax == 0) {
        return;
    }
    $order->add_item('_regional-tax', number_format($charged_tax, 2, '.', ''), $order->get_id());
}
Esempio n. 9
0
/**
 * Registers the payment settings page
 * @return void
 */
function appthemes_register_payments_settings()
{
    new APP_Payments_Settings_Admin(APP_Gateway_Registry::get_options());
}
Esempio n. 10
0
/**
 * The amount to be sent to the secondary receiver on an escrow Order.
 *
 * @param float $amount_no_fees The amount base to calculate fees.
 * @return float The final amount after fees
 */
function appthemes_escrow_receiver_amount($amount_no_fees)
{
    $payment_options = APP_Gateway_Registry::get_options();
    switch ($payment_options->escrow['retain_type']) {
        case 'percent':
            $multiplier = (int) $payment_options->escrow['retain_amount'] / 100;
            $sec_amount = $amount_no_fees * $multiplier;
            break;
        default:
            $sec_amount = (double) $payment_options->escrow['retain_amount'];
            break;
    }
    return number_format($amount_no_fees - $sec_amount, 2, '.', '');
}
Esempio n. 11
0
 protected function set_options($options)
 {
     $payment_options = APP_Gateway_Registry::get_options();
     $gateway_mode = !empty($options['sandbox_enabled']) ? 'sandbox' : 'live';
     $options_mode = sprintf('pp_adaptive_%s_', $gateway_mode);
     $all_options = array('appID' => empty($options['sandbox_enabled']) ? $options[$options_mode . 'appid'] : self::SANDBOX_APPID, 'fees_payer' => $options['pp_adaptive_fees_payer'], 'paypal_email' => $options['email_address'], 'username' => $options[$options_mode . 'username'], 'password' => $options[$options_mode . 'password'], 'signature' => $options[$options_mode . 'signature'], 'endpoint' => self::$endpoint_url[$gateway_mode]);
     $this->options = $all_options;
 }