Intégration formulaire payplug + recuperation POST
Boniour,
j'essaye d'intégrer un formulaire de paiement avec payplug.
Lors du retour du paiement valide sur mon site je n'arrive pas à récupérer les post input du mon formulaire.
j'ai lu tout leur docs :
formulaire html:
Code:
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
| <form action="paiement.php" method="post" id="contact_form">
<p><label for="tel">Votre nom :</label>
<input type="text" name="nom" id="nom" value="">
</p>
<p><label for="tel">Votre prenom :</label>
<input type="text" name="prenom" id="prenom" value="">
</p>
<p><label for="tel">Votre email :</label>
<input type="text" name="email" id="email" value="">
</p>
<p><label for="tel">Votre téléphone :</label>
<input type="text" name="tel" id="tel" value="">
</p>
<p><label for="tel">Votre titre de livre :</label>
<select id="livre" name="livre" onChange="affichageDiv()">
<option value="0" selected> Choisissez votre livre numérique : </option>
<option value="livre1" selected>livre1</option>
<option value="livre2">livre2</option>
<option value="livre3">livre3</option>
</select>
</p>
<p><label for="tel">Votre format désiré :</label>
<select id="format" name="format">
<option value="epub" selected>epub (IPad/IPhone)</option>
<option value="pdf">pdf (Version ordinateur)</option>
<option value="mobi">mobi (Tablette)</option>
</select>
</p>
Nous utilisons les services sécurisés de Payplug qui est une startup 100% Française.<br />
Vous pouvez régler votre acompte ou paiement à partir de votre tablette ou de votre ordinateur ainsi que par smarthphone en utilisant votre carte bancaire.<br />
Il n’est pas nécessaire de posséder un compte Payplug !<br /> <br />
<input type="submit" name="envoi" id="envoi" value="Payer maintenant" /><br /><br />
</form> |
page paiement.php
Code:
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
|
<?php
require_once('payplug_php/lib/init.php');
Payplug\Payplug::setSecretKey('sk_test_00000000000000');
$email = ''.$_POST['email'].'';
$amount = 9;
$titre_livre = ''.$_POST['titre'].'';
$format_livre = ''.$_POST['format'].'';
$nom = ''.$_POST['format'].'';
$prenom = ''.$_POST['format'].'';
$payment = Payplug\Payment::create(array(
'amount' => $amount * 100,
'currency' => 'EUR',
'customer' => array(
'email' => $email,
'first_name' => $prenom,
'last_name' => $nom
),
'hosted_payment' => array(
'return_url' => 'http://test1.com/paiement-valide.php',
'cancel_url' => 'http://test1.com/paiement-refuse.php?id='.$email
),
'notification_url' => 'http://test1.com/notifications.php',
'metadata' => array(
"product_id": $titre_livre,
"shipping": $format_livre
)
));
$payment_url = $payment->hosted_payment->payment_url;
$payment_id = $payment->id;
header('Location:' . $payment_url);
?> |
page notifications.php
Code:
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
|
<?php
require_once('payplug_php/lib/init.php');
Payplug\Payplug::setSecretKey('sk_test_00000000000000000);
$headers = getallheaders();
/* For more security, put the keys in uppercase and retrieve
* the signature using the key in uppercase
*/
$headers = array_change_key_case($headers, CASE_UPPER);
$signature = base64_decode($headers['PAYPLUG-SIGNATURE']);
/* The data is sent in the body of the POST request in JSON format
* (MIME type = application / json).
* Example : {"state": "paid", "customer", "2", "transaction_id": 4121, "custom_data": "29", "order": "42"}
*/
$body = file_get_contents('php://input');
$data = json_decode($body);
$pbkey = PayPlug public pk_test_00000000000000000000000000;
$publicKey = openssl_pkey_get_public($pbkey);
$isSignatureValid = (openssl_verify($body , $signature, $publicKey, OPENSSL_ALGO_SHA1) === 1);
/* Take into account the IPN and send an email with the confirmation*/
if($isSignatureValid){
/* $message = "IPN received for ".$data->first_name." ".$data->last_name." for an amount of ".$data->amount." EUR";
mail("merchant@example.org","IPN Received",$message);*/
$_POST['titre_livre']=$data->product_id;
$_POST['format_livre']=$data->shipping;
} else {
mail("test@gmail.com","IPN Failed","The signature was invalid");
}
?> |
Merci.