PHP code example of richnessagency / rich-payments
1. Go to this page and download the library: Download richnessagency/rich-payments 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/ */
use Richness\RichPayments\Contracts\ManagesTransactions;
$driver = app(\Richness\RichPayments\Gateways\GatewayManager::class)->driver($gateway);
if ($driver instanceof ManagesTransactions) {
$result = $driver->refund($gateway, $transactionId, 50000);
}
declare(strict_types=1);
namespace App\Payments\Gateways\Stripe;
use Illuminate\Http\Request;
use Richness\RichPayments\Contracts\PaymentGatewayDriver;
use Richness\RichPayments\Contracts\SupportsConnectionTest;
use Richness\RichPayments\Data\ConnectionResult;
use Richness\RichPayments\Data\InquiryResult;
use Richness\RichPayments\Data\PaymentRequest;
use Richness\RichPayments\Data\PaymentSession;
use Richness\RichPayments\Data\WebhookResult;
use Richness\RichPayments\Enums\PaymentStatus;
use Richness\RichPayments\Models\PaymentGateway;
final class StripeGateway implements PaymentGatewayDriver, SupportsConnectionTest
{
public function createSession(PaymentGateway $gateway, PaymentRequest $request): PaymentSession
{
// Read encrypted credentials, call the gateway API, and return checkout data.
return new PaymentSession(
gatewayCode: $gateway->code,
status: PaymentStatus::Redirected->value,
externalReference: 'gateway-session-id',
checkoutUrl: 'https://checkout.example/session',
payload: [],
);
}
public function handleWebhook(PaymentGateway $gateway, Request $request): WebhookResult
{
// Verify signature, normalize status, and return a gateway-independent result.
return new WebhookResult(
verified: true,
success: true,
status: PaymentStatus::Paid->value,
merchantReference: 'order-123',
externalTransactionId: 'txn-123',
paidAmountMinor: 150000,
currency: 'EGP',
payload: $request->all(),
);
}
public function inquire(PaymentGateway $gateway, string $externalTransactionId): InquiryResult
{
// Return normalized inquiry status from the gateway.
}
public function checkoutUrl(PaymentGateway $gateway, string $clientSecret): string
{
return 'https://checkout.example/' . $clientSecret;
}
public function testConnection(PaymentGateway $gateway): ConnectionResult
{
// Call a lightweight authenticated gateway endpoint.
}
}