Example #1
0
 protected function ajaxCallbackForPay()
 {
     if (Login::checkLogin(false)) {
         $json['message']['type'] = "warning";
         $json['message']['text'] = Text::read('message.order.needLogin');
     } else {
         $this->myView->data = $this->myModel->selectForDetail($this->myView->data->id);
         if ($this->myView->data) {
             // Seleciona dados do produto e da conta que realizou a compra
             $account = $this->myModel->buyerModel->selectForDetail($this->myView->data->buyer);
             $product = $this->myModel->productModel->selectForDetail($this->myView->data->product);
             // Preenche dados para criação da transação
             CreatePaymentRequest::setOrderData($this->myView->data);
             CreatePaymentRequest::setAccountData($account);
             CreatePaymentRequest::setProductData($product);
             $json['redirect'] = CreatePaymentRequest::main();
         } else {
             $json['message']['type'] = "error";
             $json['message']['text'] = Text::read('message.order.orderError');
         }
     }
     return $json;
 }
 public static function setProductData($data)
 {
     self::$productData = $data;
 }
        $paymentRequest->addPaymentMethodConfig('BALANCE', 0.01, 'DISCOUNT_PERCENT');
        try {
            /*
                         * #### Credentials #####
                         * Replace the parameters below with your credentials
                         * You can also get your credentials from a config file. See an example:
                         * $credentials = PagSeguroConfig::getAccountCredentials();
                        //  */
            // seller authentication
            $credentials = new PagSeguroAccountCredentials("*****@*****.**", "E231B2C9BCC8474DA2E260B6C8CF60D3");
            // application authentication
            //$credentials = PagSeguroConfig::getApplicationCredentials();
            //$credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3");
            // Register this payment request in PagSeguro to obtain the payment URL to redirect your customer.
            $url = $paymentRequest->register($credentials);
            self::printPaymentUrl($url);
        } catch (PagSeguroServiceException $e) {
            die($e->getMessage());
        }
    }
    public static function printPaymentUrl($url)
    {
        if ($url) {
            echo "<h2>Criando requisi&ccedil;&atilde;o de pagamento</h2>";
            echo "<p>URL do pagamento: <strong>{$url}</strong></p>";
            echo "<p><a title=\"URL do pagamento\" href=\"{$url}\">Ir para URL do pagamento.</a></p>";
        }
    }
}
CreatePaymentRequest::main();