Пример #1
0
 public static function createByType($type)
 {
     $ShippingType = new PagSeguroShippingType();
     $ShippingType->setByType($type);
     return $ShippingType;
 }
Пример #2
0
 /**
  * Generate PagSeguro Shipping Type
  * @return \PagSeguroShippingTyp
  */
 private function _generatePagSeguroShippingTypeObject()
 {
     $shippingType = new PagSeguroShippingType();
     $shippingType->setByType('NOT_SPECIFIED');
     return $shippingType;
 }
/**
 * Processa o formulário, 
 */
function process_form()
{
    //var_dump($_POST);
    //die();
    require_once "PagSeguroLibrary/PagSeguroLibrary.php";
    $id = $_POST['item_id'];
    $descricao = $_POST['item_descricao'];
    $qtd = $_POST['item_qtd'];
    $valor = $_POST['item_valor'];
    $peso = $_POST['item_peso'];
    $frete = $_POST['frete'];
    $valor = str_replace(",", ".", $valor);
    //Instancia uma requisicao de pagamento
    $paymentRequest = new PagSeguroPaymentRequest();
    //Seta a moeda
    $paymentRequest->setCurrency("BRL");
    //Adiciona os itens para gerar a url
    $paymentRequest->addItem($id, $descricao, $qtd, $valor, $peso);
    //Seta o ambiente de producao, se é Sandbox, ou production
    $is_sandbox = get_option('ps_config_enable_sandbox');
    if (strlen($is_sandbox) > 0) {
        PagSeguroConfig::setEnvironment('sandbox');
        $PagSeguroConfig['log']['active'] = TRUE;
    } else {
        PagSeguroConfig::setEnvironment('production');
    }
    /* Infos seguintes apenas para referencia*/
    // Add another item for this payment request
    //$paymentRequest->addItem('0002', 'Notebook rosa', 2, 1.00);
    // Sets a reference code for this payment request, it is useful to identify this payment in future notifications.
    //$paymentRequest->setReference($dadosComprador["codReference"]);
    // Sets shipping information for this payment request
    //$CODIGO_SEDEX = PagSeguroShippingType::getCodeByType('SEDEX');
    //$paymentRequest->setShippingType($CODIGO_SEDEX);
    //$paymentRequest->setShippingAddress('30315230', 'Rua Zito Soares', '179', '', 'Mangabeiras', 'Belo Horizonte', 'MG', 'BRA');
    /* Criando o tipo de frete */
    $shippingType = new PagSeguroShippingType();
    /* Definindo tipo de frete 'PAC' */
    $shippingType->setByType('PAC');
    $shipping = new PagSeguroShipping();
    $shipping->setType($shippingType);
    $data = array('postalCode' => '01452002', 'street' => 'Av. Brig. Faria Lima', 'number' => '1384', 'complement' => 'apto. 114', 'district' => 'Jardim Paulistano', 'city' => 'São Paulo', 'state' => 'SP', 'country' => 'BRA');
    $address = new PagSeguroAddress($data);
    // objeto PagSeguroAddress
    $shipping->setAddress($address);
    $type = $shipping->getType();
    // Objeto PagSeguroShippingType
    $address = $shipping->getAddress();
    // objeto PagSeguroAddress
    $cost = $shipping->getCost();
    // Float
    $shipping->setCost($cost);
    /* $paymentRequest deve ser um objeto do tipo PagSeguroPaymentRequest */
    $paymentRequest->setShipping($shipping);
    var_dump($shipping->setCost);
    die;
    // Sets your customer information.
    //$paymentRequest->setSender($dadosComprador["nome"] . ' ' . $dadosComprador["sobrenome"], $dadosComprador["email"]);
    //Seta a URL de retorno
    $paymentRequest->setRedirectUrl(get_option('ps_config_return_url'));
    try {
        //Inicializa as credenciais
        $credentials = new PagSeguroAccountCredentials(get_option('ps_config_auth_email'), get_option('ps_config_auth_token'));
        //obtem-se a URL da compra
        $url = $paymentRequest->register($credentials);
        //faz o redirect para a url do pagseguro
        wp_redirect($url);
        exit;
    } catch (PagSeguroServiceException $e) {
        die($e->getMessage());
    }
    var_dump($dadosComprador);
    die;
}