/**
  * 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>';
 }
示例#2
0
文件: test.php 项目: kalushta/darom
 /**
  * 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;
 }