Bonjour,
j'ai suivis le tutoriel Express Checkout ce trouvant sur grafitkart mais je rencontre un problème j'aimerais update une de mes tables et insérer les informations de payement dans une autres tables, mais mes reqûetes ne marche pas et aucune erreur le payement est bien effectué et l'utilisateur et bien débiter sur son compte, voici mon code:
index.php:
<div id="paypal-button"></div>
<script>
var paymentlien = 'paypal2/payment.php';
var paylien = 'paypal2/pay.php';
var test = '<?= $pubinfos['pub_prix']; ?>';
var useridpub = '<?= $_SESSION['id']; ?>';
var pubidpub = '<?= $pubinfos['pub_id']; ?>';
var tempspub = '<?= $pubinfos['pub_times']; ?>';
paypal.Button.render({
env: 'sandbox', // Or 'sandbox',
commit: true, // Show a 'Pay Now' button
style: {
color: 'blue',
size: 'small'
},
payment: function() {
return paypal.request.post(paymentlien, {
foo: test,
}).then(function(data) {
return data.id;
})
},
onAuthorize: function(data, actions) {
return paypal.request.post(paylien, {
paymentID: data.paymentID,
payerID: data.payerID,
userID: useridpub,
pubID: pubidpub,
tempsPUB: tempspub
}).then(function() {
console.log(data)
$('#resultpaypal').html("Annonce déposée !");
}).catch(function (err) {
console.log('erreur', err)
});
},
}, '#paypal-button');
</script>
Ensuite mon code payment.php:
<?php
require '../vendor/autoload.php';
$ids = require('paypal.php');
$bdd = new PDO('mysql:host=****;dbname=******;charset=utf8', '*******', '*******');
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
$ids['id'],
$ids['secret']
)
);
$list = new \PayPal\Api\ItemList();
$item = (new \PayPal\Api\Item())
->setName('Publicity')
->setPrice($_POST['foo'])
->setCurrency('EUR')
->setQuantity(1);
$list->addItem($item);
$details = (new \PayPal\Api\Details())
->setSubtotal($_POST['foo']);
$amount = (new \PayPal\Api\Amount())
->setTotal($_POST['foo'])
->setCurrency('EUR')
->setDetails($details);
$transaction = (new \PayPal\Api\Transaction())
->setItemList($list)
->setDescription('Achat sur monsite.com')
->setAmount($amount)
->setCustom('achat test');
$payment = new \PayPal\Api\Payment();
$payment->setTransactions([$transaction]);
$payment->setIntent('sale');
$redirectUrls = (new \PayPal\Api\RedirectUrls())
->setReturnUrl('paypal2/pay.php')
->setCancelUrl('paypal2/index.php');
$payment->setRedirectUrls($redirectUrls);
$payment->setPayer((new \PayPal\Api\Payer())->setPaymentMethod('paypal'));
try {
$payment->create($apiContext);
echo json_encode([
'id' => $payment->getId()
]);
} catch (\PayPal\Exception\PayPalConnectionException $e) {
var_dump(json_decode($e->getData()));
}
Et enfin mon code pay.php ou j'aimerais insérer les données et faire l'update:
<?php
require '../vendor/autoload.php';
$ids = require 'paypal.php';
$bdd = new PDO('mysql:host=*******;dbname=******;charset=utf8', '*****', '********');
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
$ids['id'],
$ids['secret']
)
);
$payment = \PayPal\Api\Payment::get($_POST['paymentID'], $apiContext);
$execution = (new \PayPal\Api\PaymentExecution())
->setPayerId($_POST['payerID'])
->setTransactions($payment->getTransactions());
try {
$payment->execute($execution, $apiContext);
echo json_encode([
'id' => $payment->getId()
]);
$datepub = date_create();
$timestamppub = date_timestamp_get($datepub) + $_POST['tempsPUB'] * 60;
$pubverif = 4;
$useridpub2 = $_POST['userID'];
$pubid2 = $_POST['pubID'];
$updatetest = $bdd->prepare("UPDATE buston_pubs
SET pub_verif = ?
WHERE pub_id = ?");
$updatetest->execute(array($pubverif, $pubid2));
$updatetest->closeCursor();
} catch (\PayPal\Exception\PayPalConnectionException $e) {
header('HTTP 500 Internal Server Error', true, 500);
var_dump(json_decode($e->getData()));
}
Voilà mon code qui marche très bien sauf la requête sql :D
PS: J'ai pas mis la requete d'insertion parceque je l'avais supprimer juste avant pour faire des test x)
Cordialement