/**
 * Runs the process_recurring() method on a currently active gateway
 * @param  string $gateway_id Identifier of currently active gateway
 * @param  APP_Order $order   Order to be processed
 * @return boolean            False on error
 */
function appthemes_process_recurring_gateway($gateway_id, $order)
{
    $receipt_order = APP_Order_Receipt::retrieve($order->get_id());
    $options = APP_Gateway_Registry::get_gateway_options($gateway_id);
    $gateway = APP_Gateway_Registry::get_gateway($gateway_id);
    if (APP_Gateway_Registry::is_gateway_enabled($gateway_id) || current_user_can('manage_options')) {
        if (!$gateway->is_recurring()) {
            return false;
        }
        $gateway->process_recurring($receipt_order, $options);
        return true;
    } else {
        return false;
    }
}
Exemplo n.º 2
0
 /**
  * Displays the form for user redirection
  * @param  APP_Order $order   Order to process
  * @param  array $options     User inputted options
  * @return void
  */
 public static function create_form($order, $options, $return_url, $cancel_url)
 {
     $options = wp_parse_args($options, array('email_address' => ''));
     $fields = array(self::SELLER_EMAIL => $options['email_address'], self::ITEM_NAME => $order->get_description(), self::ITEM_NUMBER => $order->get_id(), self::CURRENCY_CODE => $order->get_currency(), self::RETURN_TEXT => sprintf(__('Continue to %s', APP_TD), get_bloginfo('name')), self::RETURN_URL => $return_url, self::CANCEL_URL => $cancel_url, self::NO_SHIPPING => 1, self::NO_NOTE => 1, self::RETURN_METHOD => self::RETURN_BY_GET, self::CHARSET => 'utf-8');
     if ($order->is_recurring()) {
         if (get_post_meta($order->get_id(), 'paypal_subscription_id', true)) {
             self::print_processing_script($order);
             return array();
         }
         $fields[self::TYPE] = self::SUBSCRIBE;
         $fields[self::RECURR_BILLING] = 1;
         $subscription_id = $order->get_id() . mt_rand(0, 1000);
         $fields[self::INVOICE] = $subscription_id;
         update_post_meta($order->get_id(), 'paypal_subscription_id', $subscription_id);
         $fields[self::RECURRING_AMOUNT] = $order->get_total();
         $recurring_period_info = self::get_recurring_period_info($order->get_recurring_period(), $order->get_recurring_period_type());
         $fields[self::RECURRING_PERIOD] = $recurring_period_info['recurring_period'];
         $fields[self::RECURRING_PERIOD_TYPE] = $recurring_period_info['recurring_period_type'];
     } else {
         $fields[self::TYPE] = self::BUY_NOW;
         $fields[self::AMOUNT] = $order->get_total();
     }
     if (!empty($options['ipn_enabled'])) {
         $fields[self::NOTIFY_URL] = APP_PayPal_IPN_Listener::get_listener_url();
     }
     $form = array('action' => APP_PayPal::get_request_url(), 'name' => 'paypal_payform', 'id' => 'create_listing');
     return array($form, $fields);
 }
Exemplo n.º 3
0
 /**
  * Processes a Bank Transfer Order to display
  * instructions to the user
  * @param  APP_Order $order   Order to display information for
  * @param  array $options     User entered options
  * @return void
  */
 public function process($order, $options)
 {
     $sent = get_post_meta($order->get_ID(), 'bt-sentemail', true);
     if (empty($sent)) {
         appthemes_bank_transfer_pending_email(get_post($order->get_ID()));
         update_post_meta($order->get_ID(), 'bt-sentemail', true);
     }
     $templates = appthemes_payments_get_args('templates');
     $template_name = $templates['bank-transfer'];
     $located = appthemes_locate_template($template_name);
     if ($located) {
         // load theme template
         $order = appthemes_get_order($order->get_ID());
         appthemes_load_template($template_name, array('order' => $order));
     } else {
         // load bundled template
         require_once dirname(__FILE__) . '/template/' . $template_name;
     }
 }
Exemplo n.º 4
0
/**
 * Completes the escrow order by moving the funds held in escrow to the secondary receiver(s).
 *
 * @uses do_action() Calls 'appthemes_escrow_completed'
 * @uses do_action() Calls 'appthemes_escrow_complete_failed'
 *
 * @param APP_Order $order The original Order object
 *
 * @return bool True on success, False on failure
 */
function appthemes_escrow_complete($order)
{
    if (!$order->is_escrow()) {
        return false;
    }
    $gateway_id = $order->get_gateway();
    $gateway = APP_Gateway_Registry::get_gateway($gateway_id);
    if ($gateway && (APP_Gateway_Registry::is_gateway_enabled($gateway_id, 'escrow') || current_user_can('manage_options'))) {
        if (!$gateway instanceof APP_Escrow_Payment_Processor) {
            return false;
        }
        $options = APP_Gateway_Registry::get_gateway_options($gateway_id);
        $result = $gateway->complete_escrow($order, $options);
        if (!$result) {
            do_action('appthemes_escrow_complete_failed', $order);
        } else {
            do_action('appthemes_escrow_completed', $order);
        }
        return $result;
    } else {
        return false;
    }
}
 /**
  * Processes an order payment
  *
  * @param  APP_Order $order   The order to be processed
  * @param  array     $options An array of user-entered options
  *                            corresponding to the values provided in form()
  *
  * @return void
  */
 public function process($order, $options)
 {
     $url = $options['use_sandbox'] ? 'https://ws.sandbox.pagseguro.uol.com.br/v2/checkout' : 'https://ws.pagseguro.uol.com.br/v2/checkout';
     $description = 'Compra no site ' . get_bloginfo('url');
     $payment_request['email'] = $options['user_email'];
     $payment_request['token'] = $options['use_sandbox'] ? $options['user_token_sandbox'] : $options['user_token'];
     $payment_request['currency'] = 'BRL';
     $payment_request['itemId1'] = $order->get_id();
     $payment_request['itemDescription1'] = $description;
     $payment_request['itemAmount1'] = $order->get_total();
     $payment_request['itemQuantity1'] = 1;
     $payment_request['redirectURL'] = get_bloginfo('url');
     $payment_request['notificationURL'] = get_bloginfo('url');
     $payment_request['reference'] = $order->get_id();
     $buyer = get_userdata($order->get_author());
     $payment_request['senderEmail'] = $buyer->user_email;
     $payment_request = http_build_query($payment_request);
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $payment_request);
     $xml = curl_exec($ch);
     curl_close($ch);
     if ($xml == 'Unauthorized') {
         echo 'Houve um erro ao comunicar com o servidor do PagSeguro <br>';
         pagseguro_log('status => UNAUTHORIZED');
         exit;
     }
     $xml = simplexml_load_string($xml);
     if (count($xml->error) > 0) {
         echo 'Falha na requisição.<br>';
         foreach ($xml->error as $error) {
             echo $error . '<br>';
         }
         exit;
     }
     $payment_url = $options['use_sandbox'] ? 'https://sandbox.pagseguro.uol.com.br/v2/checkout/payment.html' : 'https://pagseguro.uol.com.br/v2/checkout/payment.html';
     echo '<p>Total do pedido: ' . $order->get_total() . '</p>';
     echo '<a class="obtn btn_orange" href=' . $payment_url . '?code=' . $xml->code . '>Concluir pagamento agora</a>';
 }
Exemplo n.º 6
0
 /**
  * Completes an order and redirects the user to the listing
  * @param  APP_Order $order Order to complete
  * @return void
  */
 protected function complete_order($order)
 {
     if (!$order instanceof APP_Order && !$order instanceof APP_Order_Receipt) {
         trigger_error('Order must be an instance of APP_Order or APP_Order_Receipt', E_USER_WARNING);
     }
     $order->complete();
 }
/**
 * Returns the URL for an order
 * @param int $order_id An order ID
 * @return string The URL for the order
 */
function appthemes_get_order_url($order_id)
{
    return APP_Order::get_url($order_id);
}
Exemplo n.º 8
0
 /**
  * Completes the given order. Simple, but useful for callbacks
  * @param  APP_Order $order The order to be completed
  * @return void
  */
 public function complete($order)
 {
     $order->complete();
 }
Exemplo n.º 9
0
 /**
  * Adds general order sections to the fields displayed
  * See view_transaction()
  * @param  array $sections 	Sections already being displayed
  * @param  APP_Order $order Order being processed
  * @return array           	$sections with added sections
  */
 public function display_order($sections, $order)
 {
     $sections['General Information'] = array('ID' => $order->get_id());
     $sections['Money &amp; Currency'] = array('Currency' => APP_Currencies::get_name($order->get_currency()) . ' (' . $order->get_currency() . ')', 'Total' => APP_Currencies::get_price($order->get_total(), $order->get_currency()));
     return $sections;
 }
Exemplo n.º 10
0
 /**
  * Sets up the order objects.
  *
  * @param object $post Post object returned from get_post()
  * See (http://codex.wordpress.org/Function_Reference/get_post)
  * @param array $items Array of items currently attached to the order
  */
 public function __construct($post, $items)
 {
     parent::__construct($post, $items);
     $this->receivers = get_post_meta($this->id, 'receivers', true);
 }