PHPackages                             aldiazhar/laravel-payment-gateways - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. aldiazhar/laravel-payment-gateways

ActiveLibrary[Payment Processing](/categories/payments)

aldiazhar/laravel-payment-gateways
==================================

Laravel package for multiple payment gateway integration (SenangPay, iPay88, PayPal, Billplz, Midtrans)

04PHP

Since Nov 21Pushed 5mo agoCompare

[ Source](https://github.com/aldiazhar/laravel-payment-gateways)[ Packagist](https://packagist.org/packages/aldiazhar/laravel-payment-gateways)[ RSS](/packages/aldiazhar-laravel-payment-gateways/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Payment Gateways by Aldi
================================

[](#laravel-payment-gateways-by-aldi)

A comprehensive Laravel package for integrating multiple payment gateways with unified API and multi-account support.

Supported Payment Gateways
--------------------------

[](#supported-payment-gateways)

GatewayStatusRegion**SenangPay**ReadyMalaysia**iPay88**Coming Soon**PayPal**Coming Soon**Billplz**Coming Soon**Midtrans**Coming SoonFeatures
--------

[](#features)

**Unified API** - Same interface for all payment gateways
**Exception-Based** - Clean error handling with specific exceptions
**Multi-Account** - Support multiple merchant accounts per gateway
**Type Safety** - Full PHP type hints and return types
**Laravel Integration** - Service provider, facades, and config publishing
**Sandbox Mode** - Easy testing with sandbox environments
**Logging** - Built-in logging for debugging and monitoring
**Extensible** - Easy to add new payment gateways

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Laravel 10.x or higher

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require aldiazhar/laravel-payment-gateways
```

Publish the configuration file:

```
php artisan vendor:publish --tag=payment-gateways-config
```

Add your payment gateway credentials to `.env`:

```
# SenangPay Configuration
SENANGPAY_MERCHANT_ID=your_merchant_id
SENANGPAY_SECRET_KEY=your_secret_key
SENANGPAY_SANDBOX=true

# Optional: Multiple SenangPay Accounts
SENANGPAY_SECONDARY_MERCHANT_ID=secondary_merchant_id
SENANGPAY_SECONDARY_SECRET_KEY=secondary_secret_key
SENANGPAY_SECONDARY_SANDBOX=true
```

Quick Start
-----------

[](#quick-start)

### 1. Basic Payment Flow

[](#1-basic-payment-flow)

```
use Aldiazhar\PaymentGateways\Facades\SenangPay;

// Prepare payment data
$payload = [
    'description' => 'Order #12345',
    'amount' => '50.00',
    'order_id' => 'INV-12345',
    'customer_name' => 'John Doe',
    'customer_email' => 'john@example.com',
    'customer_phone' => '60123456789',
];

// Get payment form inputs
$inputs = SenangPay::inputs($payload);

// Get payment gateway URL
$paymentUrl = SenangPay::url();

// Render payment form
return view('payment.form', compact('inputs', 'paymentUrl'));
```

### 2. Payment Form (Blade Template)

[](#2-payment-form-blade-template)

```

    Proceed to Payment

```

### 3. Handle Payment Return/Callback

[](#3-handle-payment-returncallback)

```
use Aldiazhar\PaymentGateways\Facades\SenangPay;
use Aldiazhar\PaymentGateways\Exceptions\InvalidHashException;
use Aldiazhar\PaymentGateways\Exceptions\PaymentFailedException;

public function return(Request $request)
{
    try {
        // Verify signature and ensure payment success in one call
        SenangPay::validatePayment($request->all());

        // Payment is verified and successful!
        $invoice = Invoice::where('invoice_no', $request->order_id)->first();
        $invoice->markAsPaid();

        return redirect()->route('payment.success');

    } catch (InvalidHashException $e) {
        // Invalid signature - possible tampering
        Log::warning('Invalid payment hash', ['error' => $e->getMessage()]);
        return redirect()->route('payment.failed')
            ->with('error', 'Payment verification failed');

    } catch (PaymentFailedException $e) {
        // Payment failed or cancelled
        Log::info('Payment failed', ['error' => $e->getMessage()]);
        return redirect()->route('payment.failed')
            ->with('error', $e->getMessage());
    }
}
```

Advanced Usage
--------------

[](#advanced-usage)

### Multiple Accounts

[](#multiple-accounts)

Switch between different merchant accounts:

```
// Use secondary account
$inputs = SenangPay::account('secondary')->inputs($payload);
$url = SenangPay::account('secondary')->url();

// Use tertiary account
$inputs = SenangPay::account('tertiary')->inputs($payload);

// Switch back to default account
$inputs = SenangPay::account()->inputs($payload);
```

### Separate Verification Steps

[](#separate-verification-steps)

```
// Option 1: Verify hash only (throws exception)
try {
    SenangPay::verifyOrFail($request->all());
    // Hash is valid
} catch (InvalidHashException $e) {
    // Invalid hash
}

// Option 2: Verify hash only (returns boolean)
if (SenangPay::verify($request->all())) {
    // Hash is valid
}

// Option 3: Ensure payment success (throws exception)
try {
    SenangPay::ensureSuccess($request->all());
    // Payment is successful
} catch (PaymentFailedException $e) {
    // Payment failed
}

// Option 4: Verify both hash and success (recommended)
SenangPay::validatePayment($request->all()); // Throws exceptions if fails
```

### Check Transaction Status

[](#check-transaction-status)

```
$result = SenangPay::check('INV-12345');

if ($result['status'] === 1) {
    // Payment successful
    $transactionDetails = $result['data'];
    echo "Transaction ID: " . $transactionDetails['payment_info']['transaction_id'];
} else {
    // Payment pending or failed
    echo $result['message'];
}
```

### Get Gateway Information

[](#get-gateway-information)

```
// Get gateway name
$name = SenangPay::getName(); // Returns: "SenangPay"

// Get current configuration
$config = SenangPay::getConfig();
// Returns: ['merchant_id' => '...', 'secret' => '...', 'sandbox' => true]

// Get current account name
$account = SenangPay::getCurrentAccount(); // Returns: "default" or "secondary"
```

Controller Example
------------------

[](#controller-example)

Complete controller implementation:

```
