Search by

astral-php / astral-paypal

astral-php

Paiement PayPal pour Astral — Orders API v2, capture, webhooks, remboursements

Package info

github.com/astral-php/astral-paypal

pkg:composer/astral-php/astral-paypal

Statistics

Installs: 3

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2026-10-23 15:37 UTC

This package is auto-updated.

Last update: 2026-10-23 15:52:19 UTC


README

Paiement PayPal pour Astral — Orders API v2 (create → approve → capture), webhooks, remboursements.

PHP License: MIT

Statut : 0.1.0 — MVP sandbox. Package dédié (option A), miroir conceptuel de astral-payment (Stripe).
UX MVP = redirect vers le lien approve (JS Buttons = backlog).

Installation

composer require astral-php/astral-paypal

1. ServiceProvider — config/dependencies.php

return [
    // …
    AstralPaypal\PaypalServiceProvider::class,
];

2. Variables d’environnement

Copier stubs/.env.paypal.example :

PAYPAL_MODE=sandbox
PAYPAL_CLIENT_ID=...
PAYPAL_CLIENT_SECRET=...
# PAYPAL_WEBHOOK_ID=...   # requis pour parseWebhook()

Clés : Developer Dashboard → Apps & Credentials → Sandbox.

3. Usage

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
}

4. Webhook

$event = $paypal->parseWebhook($rawBody, $requestHeaders);
// event_type : PAYMENT.CAPTURE.COMPLETED, …

Endpoint shop typique : POST /webhooks/paypal (sans CSRF).

5. Remboursement

$paypal->refundCapture($captureId, amountCents: null); // total

Événements

Classe Quand
AstralPaypal\Events\PaymentSucceeded Capture OK (shop peut dispatcher)
AstralPaypal\Events\PaymentFailed Échec / annulation
AstralPaypal\Events\PaymentRefunded Refund API OK

Le package ne branche pas automatiquement les mails / stock : l’app hôte écoute ou appelle ses services (comme pour Stripe côté shop).

Tests

composer install
composer test

Hors scope 0.1

  • PayPal JS Buttons / Pay Later / Venmo
  • Abonnements
  • Marketplace Platforms

Licence

MIT