PHP code example of astral-php / astral-paypal
1. Go to this page and download the library: Download astral-php/astral-paypal library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
astral-php / astral-paypal example snippets
return [
// …
AstralPaypal\PaypalServiceProvider::class,
];
use AstralPaypal\PaypalService;
/** @var PaypalService $paypal */
$order = $paypal->createOrder(
amountCents: 2880,
currency: 'EUR',
shopOrderReference: (string) $shopOrderId,
context: [
'return_url' => 'https://shop.example/checkout/paypal/return',
'cancel_url' => 'https://shop.example/checkout/paypal/cancel',
'brand_name' => 'Ma boutique',
],
);
// Rediriger le client :
header('Location: ' . $order->approveUrl());
// Sur return_url ?token=PAYPAL_ORDER_ID :
$captured = $paypal->captureOrder($_GET['token']);
if ($captured->isCompleted()) {
// marquer la commande payée + $captured->captureId pour refunds
}
$event = $paypal->parseWebhook($rawBody, $requestHeaders);
// event_type : PAYMENT.CAPTURE.COMPLETED, …
$paypal->refundCapture($captureId, amountCents: null); // total
bash
composer