/** * 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)); } }
/** * Displays a dropdown form with currently active gateways * @param string $input_name Name of the input field * @return void */ function appthemes_list_gateway_dropdown($input_name = 'payment_gateway', $recurring = false, $args = array()) { if (is_array($input_name)) { $args = $input_name; $input_name = 'payment_gateway'; } $args = wp_parse_args($args, array('input_name' => $input_name, 'recurring' => $recurring, 'service' => 'instant', 'empty_text' => __('No payment gateways are available.', APP_TD), 'disabled_text' => __(' (disabled)', APP_TD), 'admin_text' => __('Note: Disabled gateways are only available to administrators.', APP_TD))); $gateways = array(); foreach (APP_Gateway_Registry::get_gateways($args['service']) as $gateway) { if ($args['recurring'] && !$gateway->is_recurring()) { continue; } $text = $gateway->display_name('dropdown'); if (!APP_Gateway_registry::is_gateway_enabled($gateway->identifier(), $args['service'])) { if (current_user_can('manage_options')) { $text .= $args['disabled_text']; } else { continue; } } $gateways[$gateway->identifier()] = $text; } if (empty($gateways)) { $gateways[''] = $args['empty_text']; } echo scbForms::input(array('type' => 'select', 'name' => $input_name, 'values' => $gateways, 'extra' => array('class' => 'required'))); if (current_user_can('manage_options')) { echo html('p', array(), $args['admin_text']); } }
public function getResponse($order = '') { if (empty($order)) { $order = $this->getOrder(); } $options = APP_Gateway_Registry::get_gateway_options('paypal'); return array('item_number' => $order->get_id(), 'mc_currency' => $order->get_currency(), 'mc_gross' => $order->get_total(), 'business' => $options['email_address']); }
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); }
function template_vars() { $order = get_order(); if (!$order->get_gateway()) { return; } $gateway = APP_Gateway_Registry::get_gateway($order->get_gateway()); $template_vars = array('gateway' => $gateway->display_name('dropdown')); return $template_vars; }
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']); }
/** * See APP_Order::set_gateway() for more information * @param string $gateway_id The Gateway Identifier. See APP_gateway */ public function set_gateway($gateway_id) { if (!is_string($gateway_id)) { trigger_error('Gateway ID must be a string', E_USER_WARNING); } if ($gateway = APP_Gateway_Registry::get_gateway($gateway_id)) { $this->payment['gateway'] = $gateway->identifier(); $this->modified = true; return true; } return false; }
function appthemes_list_gateway_dropdown($input_name = 'payment_gateway') { $gateways = array(); foreach (APP_Gateway_Registry::get_gateways() as $gateway) { // Skip disabled gateways if (!APP_Gateway_registry::is_gateway_enabled($gateway->identifier())) { continue; } $gateways[$gateway->identifier()] = $gateway->display_name('dropdown'); } echo scbForms::input(array('type' => 'select', 'name' => $input_name, 'values' => $gateways, 'extra' => array('class' => 'required'))); }
static function get_fields($gateway_id = '') { $gateways = APP_Gateway_Registry::get_active_gateways('escrow'); $fields = array(); foreach ($gateways as $gateway) { if ($gateway_id && $gateway_id != $gateway->identifier()) { continue; } $section = $gateway->user_form(); $fields = array_merge($fields, $section['fields']); } return $fields; }
function appthemes_load_options() { extract(appthemes_payments_get_args(), EXTR_SKIP); if (is_admin()) { APP_Connected_Post_Orders::add_post_type($items_post_types); } if ($options) { APP_Gateway_Registry::register_options($options); } else { $defaults = array('currency_code' => 'USD', 'currency_identifier' => 'symbol', 'currency_position' => 'left', 'thousands_separator' => ',', 'decimal_separator' => '.', 'tax_charge' => 0, 'gateways' => array('enabled' => array())); $options = new scbOptions('app_payments', false, $defaults); APP_Gateway_Registry::register_options($options); } }
function pagseguro_create_payment_listener() { $code = isset($_POST['notificationCode']) && trim($_POST['notificationCode']) !== "" ? trim($_POST['notificationCode']) : null; $type = isset($_POST['notificationType']) && trim($_POST['notificationType']) !== "" ? trim($_POST['notificationType']) : null; if ($code && $type) { pagseguro_log('::::: Notificação PagSeguro recebida :::::'); $options = APP_Gateway_Registry::get_gateway_options('pagseguro'); $email = $options['user_email']; $token = $options['use_sandbox'] ? $options['user_token_sandbox'] : $options['user_token']; $url = $options['use_sandbox'] ? 'https://ws.sandbox.pagseguro.uol.com.br/v2/transactions/notifications/' : 'https://ws.pagseguro.uol.com.br/v2/transactions/notifications/'; $url = $url . $code . '?email=' . $email . '&token=' . $token; $ch = curl_init($url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $transaction = curl_exec($ch); if ($transaction == 'Unauthorized') { pagseguro_log('Transação não autorizada. Token: ' . $token); exit; } curl_close($ch); $transaction = simplexml_load_string($transaction); $status = $transaction->status; $order = APP_Order_Factory::retrieve(intval($transaction->reference)); if (false === $order) { pagseguro_log('ERRO: Não foi encontrado pedido com ID_TRANSACAO == ' . $transaction->reference); return; } switch ($status) { case 3: if ($order->get_status() == 'tr_activated') { pagseguro_log('Notificação repetida para ' . $transaction->reference . '. Ignorando...'); return; } $order->activate(); pagseguro_log('Pedido ' . $transaction->reference . ' foi ativado'); break; case 7: if ($order->get_status() == 'tr_failed') { pagseguro_log('Notificação repetida para ' . $transaction->reference . '. Ignorando...'); } $order->failed(); pagseguro_log('Pedido ' . $transaction->reference . ' foi cancelado'); } } }
/** * 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();\' );'); }
public function process_item($item) { $order = appthemes_get_order($item->ID, true); if (!$order) { return; } if ($order->get_status() == APPTHEMES_ORDER_PENDING) { $gateway = $order->get_gateway(); if (empty($gateway)) { return; } $gateway_object = APP_Gateway_Registry::get_gateway($gateway); if (!$gateway_object || !$gateway_object->is_recurring()) { return; } appthemes_process_recurring_gateway($gateway, $order); } $order = appthemes_get_order($item->ID, true); if ($order->get_status() == APPTHEMES_ORDER_COMPLETED) { $order->log('Processing Queue: Order is completed. Activating'); $order->activate(); } }
/** * Registers an instance of scbOptions as the options handler * Warning: Only use if you know what you're doing * * @param scbOptions $options Instance of scbOptions * @return void */ public static function register_options($options) { self::$options = $options; }
/** * Verify that the defaults are returned for gateway * @depends test_gateway_creation */ public function test_form_return($gateway) { $form = $gateway->form(); $values = APP_Gateway_Registry::get_gateway_options($gateway->identifier()); $this->assertNotEmpty($values); foreach ($form['fields'] as $field) { $this->assertEquals($values[$field['name']], $field['default']); } }
/** * Outputs column data for orders * @param string $column_index Name of the column being processed * @param int $post_id ID of order being dispalyed * @return void */ function appthemes_order_add_column_data($column_index, $post_id) { $order = appthemes_get_order($post_id); switch ($column_index) { case 'order': echo '<a href="' . get_edit_post_link($post_id) . '">' . $order->get_ID() . '</a>'; break; case 'order_author': $user = get_userdata($order->get_author()); echo $user->display_name; echo '<br>'; echo $order->get_ip_address(); break; case 'item': $count = count($order->get_items()); $string = _n('Purchased %s item', 'Purchased %s items', $count, APP_TD); printf($string, $count); break; case 'price': $currency = $order->get_currency(); if (!empty($currency)) { echo appthemes_get_price($order->get_total(), $order->get_currency()); } else { echo appthemes_get_price($order->get_total()); } break; case 'payment': $gateway_id = $order->get_gateway(); if (!empty($gateway_id)) { $gateway = APP_Gateway_Registry::get_gateway($gateway_id); if ($gateway) { echo $gateway->display_name('admin'); } else { _e('Unknown', APP_TD); } } else { _e('Undecided', APP_TD); } echo '</br>'; $status = $order->get_display_status(); if ($order->get_status() == APPTHEMES_ORDER_PENDING) { echo '<strong>' . ucfirst($status) . '</strong>'; } else { echo ucfirst($status); } break; case 'status': echo ucfirst($order->get_status()); break; case 'order_date': $order_post = get_post($order->get_ID()); if ('0000-00-00 00:00:00' == $order_post->post_date) { $t_time = $h_time = __('Unpublished', APP_TD); $time_diff = 0; } else { $t_time = get_the_time(_x('Y/m/d g:i:s A', 'Order Date Format', APP_TD)); $m_time = $order_post->post_date; $time = get_post_time('G', true, $order_post); $time_diff = time() - $time; if ($time_diff > 0 && $time_diff < 24 * 60 * 60) { $h_time = sprintf(__('%s ago', APP_TD), human_time_diff($time)); } else { $h_time = mysql2date(_x('Y/m/d', 'Order Date Format', APP_TD), $m_time); } } echo '<abbr title="' . $t_time . '">' . $h_time . '</abbr>'; break; } }
/** * Displays the order status summary * @param object $post Wordpress Post object * @return void */ function display($post) { $order = appthemes_get_order($post->ID); ?> <style type="text/css"> #admin-order-status th{ padding-right: 10px; text-align: right; width: 40%; } </style> <table id="admin-order-status"> <tbody> <tr> <th><?php _e('ID', APP_TD); ?> : </th> <td><?php echo $order->get_ID(); ?> </td> </tr> <tr> <th><?php _e('Status', APP_TD); ?> : </th> <td><?php echo $order->get_display_status(); ?> </td> </tr> <tr> <th><?php _e('Gateway', APP_TD); ?> : </th> <td> <?php $gateway_id = $order->get_gateway(); if (!empty($gateway_id)) { $gateway = APP_Gateway_Registry::get_gateway($gateway_id); if ($gateway) { echo $gateway->display_name('admin'); } else { _e('Unknown', APP_TD); } } else { _e('Undecided', APP_TD); } ?> </td> </tr> <tr> <th><?php _e('Currency', APP_TD); ?> : </th> <td><?php echo APP_Currencies::get_currency_string($order->get_currency()); ?> </td> </tr> <?php if ($order->is_recurring()) { $period = $order->get_recurring_period(); ?> <tr> <th><?php _e('Recurs:', APP_TD); ?> </th> <td><?php printf(_n('Every day', 'Every %d days', $period, APP_TD), $period); ?> </td> </tr> <tr> <th><?php _e('Payment Date:', APP_TD); ?> </th> <td><?php echo appthemes_display_date(get_post($order->get_id())->post_date, 'date'); ?> </td> </tr> <?php } ?> <?php if ($order->get_parent() != 0) { ?> <tr> <th><?php _e('Previously', APP_TD); ?> </th> <td><a href="<?php echo get_edit_post_link($order->get_parent()); ?> ">#<?php echo $order->get_parent(); ?> </a></td> </tr> <?php } ?> </tbody> </table> <?php }
function is_recurring() { $options = APP_Gateway_Registry::get_gateway_options('paypal'); return !empty($options['business_account']); }
/** * Checks that the order being given by PayPal matches the one on file * @return WP_Error Object containing errors, if any were found */ private function validate_order($order, $response, $errors = null) { $options = APP_Gateway_Registry::get_gateway_options('paypal'); if (!$errors) { $errors = new WP_Error(); } if (!isset($response['business']) || strtolower($options['email_address']) != strtolower($response['business'])) { $business = isset($response['business']) ? $response['business'] : 'no email given'; $errors->add('bad_email', 'Given email address did not match settings.' . $business . '/' . $options['email_address']); } if (!isset($response['mc_currency']) || $order->get_currency() != strtoupper($response['mc_currency'])) { $errors->add('bad_currency', 'Given currency code did not match order.'); } if ($order->get_gateway() != 'paypal') { $errors->add('bad_gateway', 'Order was not using PayPal as a gateway.'); } return $errors; }
/** * Registers the payment settings page * @return void */ function appthemes_register_payments_settings() { new APP_Payments_Settings_Admin(APP_Gateway_Registry::get_options()); }
/** * Retrieves the payment information for a given order. * * @since 3.5 * * @param $object $order The Order object. * * @return string The Order information. */ function the_orders_history_payment($order) { $gateway_id = $order->get_gateway(); if (!empty($gateway_id)) { $gateway = APP_Gateway_Registry::get_gateway($gateway_id); if ($gateway) { $gateway = $gateway->display_name('admin'); } else { $gateway = __('Unknown', APP_TD); } } else { $gateway = __('Undecided', APP_TD); } $gateway = html('div', array('class' => 'order-history-gateway'), $gateway); $status = html('div', array('class' => 'order-history-status'), $order->get_display_status()); echo $gateway . $status; }
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; }
/** * 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()); }
/** * 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, '.', ''); }