Bonjour, Voila je rencontre un petit problème hier j'ai integrer le système de paiement paypal à mon site alors tout fonctionne correctement mais je ne c'est pas comment envoyer a la basse de donnée les détails du paiement tels que l'id et le statut par exemple 😕 j'utilise la librairie php https://packagist.org/packages/paypal/rest-api-sdk-php page payment.php Voici le code de ma page payment.php <?php
// Charger l'api de PayPal
require 'vendor/autoload.php';
// En se connecte à la basse de donnée
$db = db::getdatabase();
// Charger la class detailsPrice.php
require 'detailsPrice.php';
$detail = new detailsPrice($db);
// Sous-total des produis
$Price = $detail->Price(auth::client($db)->id);
// Prix total de livraison
$Delivery = $detail->Delivery(auth::client($db)->id);
// Prix total des produis
$Total = $detail->Total(auth::client($db)->id);
// Afficher la table cart
$cart = $db->query("SELECT * FROM cart WHERE client = ?", [users::clients($db)->id])->fetchALL();
$ids = require('paypal.php');
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
$ids['id'],
$ids['secret']
)
);
$list = new \PayPal\Api\ItemList();
foreach ($cart as $products) {
$product = $db->query("SELECT * FROM products WHERE token = ?", [$products->token])->fetch();
$item = (new \PayPal\Api\Item())
->setName($product->name)
->setPrice($product->price)
->setCurrency('EUR')
->setQuantity($products->amount);
$list->addItem($item);
}
$details = (new \PayPal\Api\Details())
->setSubtotal($Price)
->setShipping($Delivery);
$amount = (new \PayPal\Api\Amount())
->setTotal($Total)
->setCurrency('EUR')
->setDetails($details);
$transaction = (new \PayPal\Api\Transaction())
->setItemList($list)
->setDescription('description')
->setAmount($amount)
->setCustom('demo-1');
$payment = new \PayPal\Api\Payment();
$payment->setTransactions([$transaction]);
$payment->setIntent('sale');
$redirectUrls = (new \PayPal\Api\RedirectUrls())
->setReturnUrl('http://localhost/pay.php')
->setCancelUrl('http://localhost/error.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()));
} La page pour recupéré le payment <?php
// Charger l'api de PayPal
require 'vendor/autoload.php';
// ---
$ids = require 'paypal.php';
$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()
]);
} catch (\PayPal\Exception\PayPalConnectionException $e) {
header('HTTP 500 Internal server error', true, 500);
var_dump(json_decode($e->getDate()));
}
... View more