dp-soft-co / payments
Payment helper for Paypal, Paymob, Kashier, Hyperpay, Fawry and more - Forked from nafezly/payments with Kashier Payment Sessions API fix
Requires
- php: >=7.2
- ext-curl: *
- ext-json: *
- laravel/framework: >=6.0
- paypal/paypal-server-sdk: ^2.3
README
Payment Helper for Laravel — supports PayPal, Paymob, Kashier, Fawry, HyperPay, Thawani, Tap, Opay, Paytabs, Binance, PerfectMoney, NowPayments, Payeer, Telr, Clickpay, MyFatoorah, Stripe, and E-Wallets (Vodafone Cash, Orange Money, Meza Wallet, Etisalat Cash).
Forked from nafezly/payments with Kashier Payment Sessions API fix and improvements.
Supported gateways
- PayPal
- PayMob
- WeAccept
- Kashier
- Fawry
- HyperPay
- Thawani
- Tap
- Opay
- Paytabs
- Binance
- PerfectMoney
- NowPayments
- Payeer
- Telr
- Clickpay
- MyFatoorah
- Stripe
- E Wallets (Vodafone Cash - Orange Money - Meza Wallet - Etisalat Cash)
Installation
composer require dp-soft-co/payments
Publish Vendor Files
php artisan vendor:publish --tag="dpsoft-payments-config" php artisan vendor:publish --tag="dpsoft-payments-lang"
dpsoft-payments.php file
<?php return [ #PAYMOB 'PAYMOB_SECRET_KEY' => env('PAYMOB_SECRET_KEY'), 'PAYMOB_PUBLIC_KEY' => env('PAYMOB_PUBLIC_KEY'), 'PAYMOB_BASE_URL' => env('PAYMOB_BASE_URL', 'https://accept.paymob.com'), 'PAYMOB_INTEGRATION_ID' => env('PAYMOB_INTEGRATION_ID'), 'PAYMOB_HMAC' => env('PAYMOB_HMAC'), 'PAYMOB_CURRENCY'=> env('PAYMOB_CURRENCY',"EGP"), 'PAYMOB_NOTIFICATION_URL' => env('PAYMOB_NOTIFICATION_URL'), 'PAYMOB_REDIRECTION_URL' => env('PAYMOB_REDIRECTION_URL'), #HYPERPAY 'HYPERPAY_BASE_URL' => env('HYPERPAY_BASE_URL', "https://eu-test.oppwa.com"), 'HYPERPAY_URL' => env('HYPERPAY_URL', env('HYPERPAY_BASE_URL') . "/v1/checkouts"), 'HYPERPAY_TOKEN' => env('HYPERPAY_TOKEN'), 'HYPERPAY_CREDIT_ID' => env('HYPERPAY_CREDIT_ID'), 'HYPERPAY_MADA_ID' => env('HYPERPAY_MADA_ID'), 'HYPERPAY_APPLE_ID' => env('HYPERPAY_APPLE_ID'), 'HYPERPAY_CURRENCY' => env('HYPERPAY_CURRENCY', "SAR"), #KASHIER 'KASHIER_ACCOUNT_KEY' => env('KASHIER_ACCOUNT_KEY'), 'KASHIER_IFRAME_KEY' => env('KASHIER_IFRAME_KEY'), 'KASHIER_TOKEN' => env('KASHIER_TOKEN'), 'KASHIER_URL' => env('KASHIER_URL', "https://checkout.kashier.io"), 'KASHIER_MODE' => env('KASHIER_MODE', "test"), //live or test 'KASHIER_CURRENCY'=>env('KASHIER_CURRENCY',"EGP"), 'KASHIER_WEBHOOK_URL'=>env('KASHIER_WEBHOOK_URL'), #STRIPE 'STRIPE_SECRET_KEY' => env('STRIPE_SECRET_KEY'), 'STRIPE_PUBLISHABLE_KEY' => env('STRIPE_PUBLISHABLE_KEY'), 'STRIPE_CURRENCY' => env('STRIPE_CURRENCY', 'USD'), 'VERIFY_ROUTE_NAME' => "verify-payment", 'APP_NAME'=>env('APP_NAME'), //and more config for another payment gateways ];
How To Use
Standard Controller Example
The following Laravel controller pattern works with every gateway supported by the package. Store the gateway class name used to create the invoice so the callback can use the same gateway. Replace Invoice, the payment view, and success/failure routes with your application equivalents.
use App\Models\Invoice; use Dpsoft\Payments\Facades\DpsoftPaymentsFacade as DpsoftPayments; use Illuminate\Http\Request; public function pay(Request $request) { $data = $request->validate([ 'gateway' => ['required', 'string'], 'amount' => ['required', 'numeric', 'min:0.01'], ]); $user = $request->user(); $gateway = $data['gateway']; $source = match (strtolower($gateway)) { 'kashier' => 'card,bank_installments,wallet,fawry', 'hyperpay' => 'CREDIT', default => null, }; $response = DpsoftPayments::gateway($gateway) ->setPaymentData([ 'amount' => $data['amount'], 'user_id' => $user->id, 'user_first_name' => $user->firstname, 'user_last_name' => $user->lastname, 'user_email' => $user->email, 'user_phone' => $user->phone, 'source' => $source, ]) ->pay(); if (empty($response['payment_id'])) { abort(422, strip_tags($response['html'] ?? 'Payment creation failed.')); } Invoice::create([ 'user_id' => $user->id, 'amount' => $data['amount'], 'status' => 'pending', 'pid' => $response['payment_id'], 'gateway' => $gateway, ]); if (!empty($response['redirect_url'])) { return redirect()->away($response['redirect_url']); } if (!empty($response['html'])) { return view('payments.pay', ['link' => $response['html']]); } abort(422, 'Invalid gateway response.'); } public function verify(string $gateway, Request $request) { $result = DpsoftPayments::gateway($gateway)->verify($request); $invoice = Invoice::where('pid', $result['payment_id'] ?? null) ->where('gateway', $gateway) ->firstOrFail(); if ($result['success']) { $invoice->update(['status' => 'paid']); return redirect()->route('payments.success'); } return redirect()->route('payments.failed'); }
Render gateway HTML only when it comes directly from the package response:
{!! $link !!}
Register the verification route:
Route::match(['get', 'post'], '/payments/verify/{gateway}', [PaymentController::class, 'verify']) ->name('verify-payment');
CSRF Protection
Payment gateways send POST callbacks from an iframe or external page and will not include the Laravel CSRF token. You must exclude the verification route from CSRF validation:
-
Laravel 11 (
bootstrap/app.php):$middleware->validateCsrfTokens(except: [ '*payment/verify*', ]);
-
Laravel 10 (
app/Http/Middleware/VerifyCsrfToken.php):protected $except = [ '*payment/verify*', ];
Adjust the wildcard to match your actual route path and any language prefix (e.g. *payments/verify*).
Use the gateway class name when starting a payment, for example Paymob, PaymobWallet, Kashier, Fawry, or MyFatoorah.
Gateway-specific source values
The standard example assigns a fixed source value from the selected gateway. Change the values in the match expression to match the payment methods enabled in your merchant account.
| Gateway | source values |
|---|---|
Kashier |
Comma-separated allowed methods, such as card,wallet, card,bank_installments,wallet,fawry, or another supported Kashier method list. If omitted, the gateway defaults to card,wallet. |
HyperPay |
CREDIT, MADA, or APPLE. This is required to select the matching HyperPay entity ID and payment brand. |
Most other gateways do not use source; passing null is valid.
