1
I have this code that makes a transparent purchase of 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 catch dynamically the cart items and place inside the array $params[]? 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)));
?>
would be so what? I answered you what’s in the question take a look?
– novic
I did what you asked that is to pick up the cart items!
– novic
How could I send the cart items to Pagseguro? $header = array('Content-Type' => 'application/json; charset=UTF-8;'); $Response = curlExec($PAGSEGURO_API_URL."/transactions", $params, $header); $json_decode(json_encode(simplexml_load_string($Response)));
– Wagner Martins Bodyboard
And then the solution worked out.?
– novic
it did work :)
– Wagner Martins Bodyboard
Because you do not score the questions and accept as an answer, your user has many questions open! because?
– novic
I don’t know how I do it, can you tell me?
– Wagner Martins Bodyboard
Let’s go continue this discussion in chat.
– novic