1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| <?php
include "header.php";
$id = $_GET['id'];
?>
<h2><center>Voici les information que Paypal retourne concernant la commande n°<?php echo $id ?></center></h2>
<?php
$bdd=bdd();
$transaction=$bdd->prepare("SELECT transaction_idP,prix_achats FROM achats WHERE id_achats=?");
$transaction->bindParam(1, $id, PDO::PARAM_INT);
$transaction -> execute();
$donnees = $transaction -> fetch();
$idtransaction=$donnees['transaction_idP'];
$prix1=$donnees['prix_achats'];
$prix=number_format( special_round($prix1*96/100,0.050) , $decimals =2);
//echo $prix;
//echo $id;
function get_transaction_details( $transaction_id,$id,$prix) {
$date = date("d-m-Y");
$bdd=bdd();
$req = $bdd->prepare("UPDATE achats SET status_achats = 'Remboursement' WHERE id_achats=? ");
$req->bindParam(1, $id, PDO::PARAM_INT);
$req -> execute();
$req = $bdd->prepare("UPDATE achats SET date_remboursement = ? WHERE id_achats=? ");
$req->bindParam(1, $date, PDO::PARAM_STR);
$req->bindParam(2, $id, PDO::PARAM_INT);
$req -> execute();
$req = $bdd->prepare("UPDATE ventes SET status_ventes = 'Remboursement' WHERE id_ventes=? ");
$req->bindParam(1, $id, PDO::PARAM_INT);
$req -> execute();
$req = $bdd->prepare("UPDATE achats SET remboursé = 1 WHERE id_achats=? ");
$req->bindParam(1, $id, PDO::PARAM_INT);
$req -> execute();
$api_request = 'USER=sb-ph43mb1573904_api1.business.example.com'
. '&PWD=2H8CW3P9C5FTKZYU'
. '&SIGNATURE=Ahiik-MviymUik2ju1GqUXqTniYDAMmKwo1TUWZUOP99G4ZagtecMWEY'
. '&VERSION=204.0'
. '&METHOD=RefundTransaction'
. '&rm=2'
. '&REFUNDTYPE=Partial'//Full'Partial
. '&AMT='.$prix
. '&TransactionID='.$transaction_id;
//. '&AMT='. $prix;
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp' ); // For live transactions, change to 'https://api-3t.paypal.com/nvp'
curl_setopt( $ch, CURLOPT_VERBOSE, 1 );
// Uncomment these to turn off server and peer verification
// curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
// curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_POST, 1 );
// Set the API parameters for this transaction
curl_setopt( $ch, CURLOPT_POSTFIELDS, $api_request );
// Request response from PayPal
$response = curl_exec( $ch );
// print_r($response);
// If no response was received from PayPal there is no point parsing the response
if( ! $response )
die( 'Calling PayPal to change_subscription_status failed: ' . curl_error( $ch ) . '(' . curl_errno( $ch ) . ')' );
curl_close( $ch );
// An associative array is more usable than a parameter string
parse_str( $response, $parsed_response );
return $parsed_response;
}
$response = get_transaction_details($idtransaction,$id,$prix);
echo "<pre>"; print_r($response); echo "</pre>";
$result = var_export($response, true);
$REFUNDTRANSACTIONID = $result['REFUNDTRANSACTIONID'];
echo $REFUNDTRANSACTIONID;
echo 'ok';
include "footer.php";
?> |