1. Go to this page and download the library: Download mdiqbal/laravel-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 Mdiqbal\LaravelPayments\Facades\Payment;
use Mdiqbal\LaravelPayments\DTO\PaymentRequest;
// Create a payment request
$paymentRequest = new PaymentRequest(
amount: 100.00,
currency: 'USD',
description: 'Payment for Order #12345'
);
// Set optional parameters
$paymentRequest->setTransactionId('order_' . uniqid());
$paymentRequest->setReturnUrl(route('payment.success'));
$paymentRequest->setCancelUrl(route('payment.cancel'));
// Process payment with default gateway
$response = Payment::pay($paymentRequest);
// Or process with a specific gateway
$response = Payment::gateway('stripe')->pay($paymentRequest);
// Handle response
if ($response->isSuccess()) {
if ($response->isRedirect()) {
return redirect($response->getRedirectUrl());
}
$transactionId = $response->getTransactionId();
// Save transaction ID to database
} else {
$errorMessage = $response->getMessage();
// Handle error
}
use Mdiqbal\LaravelPayments\Facades\Payment;
$transactionId = 'txn_1234567890';
$response = Payment::gateway('stripe')->retrievePayment($transactionId);
if ($response->isSuccess()) {
$status = $response->getData()['status'];
$amount = $response->getData()['amount'];
// Update order status
}