Set Pagseguro API delivery address

Asked

Viewed 371 times

4

I have to pre-set the delivery address of the pagseguro in my code PHP. The problem is I’ve tried and I can’t, what I can do is just set the billing address. My code:

$paymentRequest = new PagSeguroPaymentRequest();

        $paymentRequest->setCurrency("BRL");

        $address = new PagSeguroAddress();

        /* Define o valor do frete */
        $shipping = new PagSeguroShipping();
        $type = new PagSeguroShippingType(3);
        $shipping->setType($type);
        $shipping->setCost($frete);


        $address->setStreet('Av. Brig. Faria Lima');

        /* Informando o número do logradouro */
        $address->setNumber('1384');

        /* Informando o complemento do logradouro */
        $address->setComplement('apto. 114');  //

        /* Informando o bairro do logradouro */
        $address->setDistrict('Jardim Paulistano');

        /* Informando o bairro a cidade */
        $address->setCity('São Paulo');

        /* Informando o bairro o estado */
        $address->setState('SP');

        /* Informando o bairro o país */
        $address->setCountry('BRA');

        $shipping->setAddress($address);

        $paymentRequest->setShipping($shipping);

This code is only setting the charge, but the delivery code it can for me to enter the CEP.

1 answer

5


Use the setShippingAddress

$shipping->setShippingAddress(  
  '01452002',  
  'Av. Brig. Faria Lima',  
  '1384',  
  'apto. 114',  
  'Jardim Paulistano',  
  'São Paulo',  
  'SP',  
  'BRA'  
); 

Complete code:

$paymentRequest = new PagSeguroPaymentRequest();

$paymentRequest->setCurrency("BRL");

$address = new PagSeguroAddress();

/* Define o valor do frete */
$shipping = new PagSeguroShipping();
$type = new PagSeguroShippingType(3);
$shipping->setType($type);
$shipping->setCost($frete);
$shipping->setShippingAddress(  
  '01452002',  
  'Av. Brig. Faria Lima',  
  '1384',  
  'apto. 114',  
  'Jardim Paulistano',  
  'São Paulo',  
  'SP',  
  'BRA'  
); 

$address->setStreet('Av. Brig. Faria Lima');

/* Informando o número do logradouro */
$address->setNumber('1384');

/* Informando o complemento do logradouro */
$address->setComplement('apto. 114');  //

/* Informando o bairro do logradouro */
$address->setDistrict('Jardim Paulistano');

/* Informando o bairro a cidade */
$address->setCity('São Paulo');

/* Informando o bairro o estado */
$address->setState('SP');

/* Informando o bairro o país */
$address->setCountry('BRA');

$shipping->setAddress($address);

$paymentRequest->setShipping($shipping);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.