1
Good morning to all,
I have a question and a problem to solve. I’m setting up a transparent checkout, and it works by the way. Currently I put products in the cart, we are the subtotals, to transform into total result and it is perfect, and when I assemble the array of the checkout of the pagseguro, I inform an id, description and standard quantity, with the calculated total, and the payment is accomplished. My doubt and problem eh: how can I put my products in the array of pagseguro, taking in example basket session loop, stating Description, id, quantity and value, follows the example:
"[email protected]\
&token=57BE455F4EC148E5A54D9BB91C5AC12C\
&paymentMode=default\
&paymentMethod=creditCard\
&[email protected]\
¤cy=BRL\
&extraAmount=1.00\
&itemId1=0001\ // essa linha precisa ser o loop
&itemDescription1=Produto PagSeguroI\ // essa linha precisa ser o loop
&itemAmount1=99999.99\ //essa linha precisa ser o loop
&itemQuantity1=1\ //essa linha precisa ser o loop
&itemId1=0002\
&itemDescription1=Produto PagSeguroII\
&itemAmount1=99999.98\
&itemQuantity1=2\
¬ificationURL=https://sualoja.com.br/notifica.html\
&reference=REF1234\
&senderName=Jose Comprador\
&senderCPF=11475714734\
&senderAreaCode=99\
&senderPhone=99999999\
&[email protected]\
&senderHash=52578d5d3336ec7a43ff1dae4794d0c5625feddcc8fbc0e80bcb0cb46c9947d4\
&shippingAddressStreet=Av. PagSeguro\
&shippingAddressNumber=9999\
&shippingAddressComplement=99o andar\
&shippingAddressDistrict=Jardim Internet\
&shippingAddressPostalCode=99999999\
&shippingAddressCity=Cidade Exemplo\
&shippingAddressState=SP\
&shippingAddressCountry=ATA\
&shippingType=1\
&shippingCost=21.50\
&creditCardToken=1e358d39e26448dc8a28d0f1815f08c5\
&installmentQuantity=1\
&installmentValue=300021.45\
&noInterestInstallmentQuantity=2\
&creditCardHolderName=Jose Comprador\
&creditCardHolderCPF=11475714734\
&creditCardHolderBirthDate=01/01/1900\
&creditCardHolderAreaCode=99\
&creditCardHolderPhone=99999999\
&billingAddressStreet=Av. PagSeguro\
&billingAddressNumber=9999\
&billingAddressComplement=99o andar\
&billingAddressDistrict=Jardim Internet\
&billingAddressPostalCode=99999999\
&billingAddressCity=Cidade Exemplo\
&billingAddressState=SP\
&billingAddressCountry=ATA".
Or I would have to put all this information inside the loop, and have to put the xml mount, I would have the status return, duplicated several times as many items?
Tenho esse código que faz uma compra transparente do Pagseguro.
$params = array(
'email => $PAGSEGURO_EMAIL,
'token => $PAGSEGURO_TOKEN,
'creditCardToken => $creditCardToken,
'senderHash' => $senderHash,
'receiverEmail => $PAGSEGURO_EMAIL,
'paymentMode => 'default',
'paymentMethod => 'creditcard',
'currency' => 'BRL',
// 'extraAmount' => '1.00',
'itemId1' => '0001',
'itemDescription1' => 'PHP Test',
'itemAmount1' => $numero,
'itemQuantity1' => 1,
'itemId2' => '0002',
'itemDescription2' => 'PHP Test2',
'itemAmount2' => $numero,
'itemQuantity2' => 1,
'reference' => 'REF1234',
'senderName' => $senderName,
'senderCPF' => $senderCPF,
'senderAreaCode' => 83,
'senderPhone' => $senderPhone,
'senderEmail' => $senderEmail,
'shippingAddressStreet' => $shippingAddressStreet,
'shippingAddressNumber' => $shippingAddressNumber,
'shippingAddressDistrict' => $shippingAddressDistrict,
'shippingAddressPostalCode' => $shippingAddressPostalCode,
'shippingAddressCity' => $shippingAddressCity,
'shippingAddressState' => $shippingAddressState,
'shippingAddressCountry' => 'BRA',
'shippingType' => 1,
'shippingCost' => $shippingCost,
'installmentQuantity' => 1,
'installmentValue' => $installmentValue,
'creditCardHolderName' => 'Chuck Norris',
'creditCardHolderCPF' => '54793120652',
'creditCardHolderBirthDate' => '01/01/1990',
'creditCardHolderAreaCode' => 83,
'creditCardHolderPhone' => '999999999',
'billingAddressStreet' => 'Address',
'billingAddressNumber' => '1234',
'billingAddressDistrict' => 'Bairro',
'billingAddressPostalCode' => '58075000',
'billingAddressCity' => 'João Pessoa',
'billingAddressState' => 'PB',
'billingAddressCountry' => 'BRA'
);
How do I get PHP to dynamically pick up cart items and place them inside the $params[] array? So that all products of the trolley can be sent?
This part takes the products to be generated within the array by PHP:
'itemId1' => '0001',
'itemDescription1' => 'PHP Test',
'itemAmount1' => $numero,
'itemQuantity1' => 1,
'itemId2' => '0002',
'itemDescription2' => 'PHP Test2',
'itemAmount2' => $numero,
'itemQuantity2' => 1,
Would look like this?
$params = array(
'email' => $PAGSEGURO_EMAIL,
'token' => $PAGSEGURO_TOKEN,
'creditCardToken' => $creditCardToken,
'senderHash' => $senderHash,
'receiverEmail' => $PAGSEGURO_EMAIL,
'paymentMode' => 'default',
'paymentMethod' => 'creditCard',
'currency' => 'BRL',
// 'extraAmount' => '1.00',
'reference' => 'REF1234',
'senderName' => $senderName,
'senderCPF' => $senderCPF,
'senderAreaCode' => 83,
'senderPhone' => $senderPhone,
'senderEmail' => $senderEmail,
'shippingAddressStreet' => $shippingAddressStreet,
'shippingAddressNumber' => $shippingAddressNumber,
'shippingAddressDistrict' => $shippingAddressDistrict,
'shippingAddressPostalCode' => $shippingAddressPostalCode,
'shippingAddressCity' => $shippingAddressCity,
'shippingAddressState' => $shippingAddressState,
'shippingAddressCountry' => 'BRA',
'shippingType' => 1,
'shippingCost' => '1.00',
'installmentQuantity' => 1,
'installmentValue' => '3.00',
'creditCardHolderName' => 'Chuck Norris',
'creditCardHolderCPF' => '54793120652',
'creditCardHolderBirthDate' => '01/01/1990',
'creditCardHolderAreaCode' => 83,
'creditCardHolderPhone' => '999999999',
'billingAddressStreet' => 'Address',
'billingAddressNumber' => '1234',
'billingAddressDistrict' => 'Bairro',
'billingAddressPostalCode' => '58075000',
'billingAddressCity' => 'João Pessoa',
'billingAddressState' => 'PB',
'billingAddressCountry' => 'BRA'
);
$filter = preg_grep('/ Itemid([0-9]{1,})/', array_keys( $params )); $result = array(); for($i = 0; $i < Count($filter); $i++) {
$result['itemId' . ($i + 1)] = $params['itemId' . ($i + 1)];
$result['itemDescription' . ($i + 1)] = $params['itemDescription' . ($i + 1)];
$result['itemAmount' . ($i + 1)] = $params['itemAmount' . ($i + 1)];
$result['itemQuantity' . ($i + 1)] = $params['itemQuantity' . ($i + 1)];
}
$header = array('Content-Type' => 'application/json; charset=UTF-8;');
$response = curlExec($PAGSEGURO_API_URL."/transactions", $params, $header);
$json = json_decode(json_encode(simplexml_load_string($response)));
?>