Skip to content

Instantly share code, notes, and snippets.

@it-cast
Created August 25, 2017 17:47
Show Gist options
  • Save it-cast/2df3dea64fa962b634975b976e665acb to your computer and use it in GitHub Desktop.
Save it-cast/2df3dea64fa962b634975b976e665acb to your computer and use it in GitHub Desktop.
pagseguro
<?php
public function getsession_(){
$json = file_get_contents('php://input');
$data = json_decode($json, true);
//set POST variables
$url = 'https://ws.pagseguro.uol.com.br/v2/sessions';
$fields = "email=".$data['email'].
"&token=ACA47C51E3434D699501197AF97C1487";
$result = $this->postPagSeguro($url, $fields);
$dados = simplexml_load_string($result);
if ($dados){
echo json_encode(array("1",$dados));
} else {
echo json_encode(array("0", $data));
}
}
public function transaction_(){
$json = file_get_contents('php://input');
$data = json_decode($json, true);
$url = 'https://ws.pagseguro.uol.com.br/v2/transactions';
$fields = "email=".$data['empresa']['pagseguro_email'].
"&token=ACA47C51E3434D699501197AF97C1487".
"&paymentMode=default".
"&paymentMethod=creditCard".
"&currency=BRL".
"&receiverEmail=".$data['empresa']['pagseguro_email'].
"&itemId1=1".
"&itemDescription1=Compra FooDica".
"&itemAmount1=".number_format($data['valor'],2).
"&itemQuantity1=1".
"&notificationURL=http://localhost/php/delivery/public/aplicativo/pagsegnotifica".
"&senderName=".$data['nome'].
"&senderCPF=".$data['cpf'].
"&senderAreaCode=".substr($data['user']['telefone'],0,2).
"&senderPhone=".substr($data['user']['telefone'],2,9).
"&[email protected]".
// "&senderEmail=".$data['user']['email'].
"&senderHash=".$data['hashVendedor'].
"&shippingAddressRequired=false".
"&installmentQuantity=1".
"&installmentValue=".number_format($data['valor'],2).
"&creditCardToken=".$data['hashCard'].
"&creditCardHolderName=".$data['nome'].
"&creditCardHolderCPF=".$data['cpf'].
"&creditCardHolderBirthDate=".$data['diaNascimento']."/".$data['mesNascimento']."/".$data['anoNascimento'].
"&creditCardHolderAreaCode=".substr($data['user']['telefone'],0,2).
"&creditCardHolderPhone=".substr($data['user']['telefone'],2,9).
"&billingAddressStreet=".$data['endereco']['endereco'].
"&billingAddressNumber=".$data['endereco']['numero'].
"&billingAddressComplement=".$data['endereco']['complemento'].
"&billingAddressDistrict=".$data['endereco']['bairro'].
"&billingAddressPostalCode=28470000".
// "&billingAddressPostalCode=".$data['endereco']['cep'].
"&billingAddressCity=".$data['endereco']['cidade'].
"&billingAddressState=RJ".
// "&billingAddressState=".$data['endereco']['cidade'].
"&billingAddressCountry=BRA";
$result = $this->postPagSeguro($url, $fields);
$dados = simplexml_load_string($result);
// echo $fields;
// $dados = $fields;
// print_r($dados);
if ($dados){
echo json_encode(array("1",$dados));
} else {
echo json_encode(array("0", $data));
}
}
public function postPagSeguro($url, $fields){
//open connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec ($ch);
curl_close ($ch);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment