Exemplo n.º 1
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);
 }
 /**
  * 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>';
 }
/**
 * 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.º 4
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;
 }