PHPackages                             soap/laravel-omise - 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. soap/laravel-omise

ActiveLibrary[Payment Processing](/categories/payments)

soap/laravel-omise
==================

Make Omise payment gateway integration easier with Laravel

v1.2.5(6mo ago)11.3k↓50%1MITPHPPHP &gt;=8.1CI passing

Since Dec 12Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/soap/laravel-omise)[ Packagist](https://packagist.org/packages/soap/laravel-omise)[ Docs](https://github.com/soap/laravel-omise)[ GitHub Sponsors]()[ RSS](/packages/soap-laravel-omise/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (17)Versions (34)Used By (1)

Laravel Omise Integration with Ease
===================================

[](#laravel-omise-integration-with-ease)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f5bcc749beade9670f50008ffc812910de0298102f457595e65445976d036f4f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736f61702f6c61726176656c2d6f6d6973652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/soap/laravel-omise)[![GitHub Tests Action Status](https://camo.githubusercontent.com/18148f8f90b9c4b1f5c895b67f2bb13efa0c0f39e9c4410234fb4d4d6c749414/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736f61702f6c61726176656c2d6f6d6973652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/soap/laravel-omise/actions?query=workflow%3Arun-tests+branch%3Amain)[![PHPStan](https://github.com/soap/laravel-omise/actions/workflows/phpstan.yml/badge.svg)](https://github.com/soap/laravel-omise/actions/workflows/phpstan.yml)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/1b5a9f09e4eb442e5548837b1a89d99803674e3c5c59405ad9df82e2cf5d0d71/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736f61702f6c61726176656c2d6f6d6973652f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/soap/laravel-omise/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/d093cfcfed7803dade1cee1010baf18748b4c56532025c759c68e5da231dbfbc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736f61702f6c61726176656c2d6f6d6973652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/soap/laravel-omise)

Make Omise payment gateway integration easier with Laravel.

Features
--------

[](#features)

- 🚀 **Easy Integration** - Simple Laravel service provider setup
- 🔐 **Secure Configuration** - Environment-based API key management
- 💳 **Multiple Payment Methods** - Credit cards, PromptPay, Internet Banking, Installments
- 🧪 **Comprehensive Testing** - Full test suite with real API integration tests
- 🎛️ **Artisan Commands** - Built-in commands for account verification and management
- 📱 **Token Management** - Secure card tokenization support
- �💰 **Refund Support** - Full and partial refund capabilities
- 🔄 **Error Handling** - Robust error handling with detailed error objects

Table of Contents
-----------------

[](#table-of-contents)

- [Laravel Omise Integration with Ease](#laravel-omise-integration-with-ease)
    - [Features](#features)
    - [Table of Contents](#table-of-contents)
    - [Support us](#support-us)
    - [Installation](#installation)
    - [Configuration](#configuration)
    - [Usage](#usage)
        - [Quick Start](#quick-start)
        - [Basic Usage](#basic-usage)
        - [Advanced Usage](#advanced-usage)
    - [API Objects](#api-objects)
        - [Create Omise API Objects](#create-omise-api-objects)
    - [Artisan Commands](#artisan-commands)
        - [Verify Configuration](#verify-configuration)
        - [Account Information](#account-information)
        - [Account Balance](#account-balance)
        - [Capabilities](#capabilities)
- [Verification](#verification)
- [Account Management](#account-management)
- [Token Management](#token-management)
- [Source Management (Offline Payments)](#source-management-offline-payments)
- [Charge](#charge)
    - [Find a charge object created](#find-a-charge-object-created)
    - [Charge customer for some amount](#charge-customer-for-some-amount)
    - [Examples](#examples)
        - [Complete Payment Flow Examples](#complete-payment-flow-examples)
            - [Credit Card Payment Processor](#credit-card-payment-processor)
            - [PromptPay Payment Processor](#promptpay-payment-processor)
            - [Controller Implementation Example](#controller-implementation-example)
- [Refund Management](#refund-management)
    - [Testing](#testing)
        - [Integration Tests](#integration-tests)
    - [Development](#development)
        - [Code Quality Tools](#code-quality-tools)
            - [PHPStan Static Analysis](#phpstan-static-analysis)
            - [Running Tests](#running-tests)
            - [GitHub Actions](#github-actions)
        - [Contributing](#contributing)
    - [Error Handling](#error-handling)
    - [Troubleshooting](#troubleshooting)
        - [Common Issues](#common-issues)
    - [Changelog](#changelog)
    - [Contributing](#contributing-1)
    - [Security Vulnerabilities](#security-vulnerabilities)
    - [Credits](#credits)
    - [License](#license)

Support us
----------

[](#support-us)

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

[](#installation)

You can install the package via composer:

```
composer require soap/laravel-omise
```

You can publish the config file with:

```
php artisan vendor:publish --tag="omise-config"
```

Configuration
-------------

[](#configuration)

After publishing the config file, update your `.env` file with your Omise API keys:

```
# Omise API Configuration
OMISE_TEST_PUBLIC_KEY=pkey_test_xxxxxxxxxxxxxxxxxxxxx
OMISE_TEST_SECRET_KEY=skey_test_xxxxxxxxxxxxxxxxxxxxx
OMISE_LIVE_PUBLIC_KEY=pkey_live_xxxxxxxxxxxxxxxxxxxxx
OMISE_LIVE_SECRET_KEY=skey_live_xxxxxxxxxxxxxxxxxxxxx

# Environment Settings
OMISE_SANDBOX_MODE=true  # Set to false for production
OMISE_API_VERSION=2019-05-29

# Optional HTTP Settings
OMISE_HTTP_TIMEOUT=30
OMISE_HTTP_CONNECT_TIMEOUT=10
OMISE_VERIFY_SSL=true
```

The published config file (`config/omise.php`) contains:

```
return [
    'api' => [
        'url' => env('OMISE_API_URL', 'https://api.omise.co'),
        'version' => env('OMISE_API_VERSION', '2019-05-29'),
    ],

    'keys' => [
        'live' => [
            'public' => env('OMISE_LIVE_PUBLIC_KEY', ''),
            'secret' => env('OMISE_LIVE_SECRET_KEY', ''),
        ],
        'test' => [
            'public' => env('OMISE_TEST_PUBLIC_KEY', ''),
            'secret' => env('OMISE_TEST_SECRET_KEY', ''),
        ],
    ],

    'sandbox' => env('OMISE_SANDBOX_MODE', true),

    'http' => [
        'timeout' => env('OMISE_HTTP_TIMEOUT', 30),
        'connect_timeout' => env('OMISE_HTTP_CONNECT_TIMEOUT', 10),
        'verify_ssl' => env('OMISE_VERIFY_SSL', true),
        'user_agent' => env('OMISE_USER_AGENT', 'Laravel-Omise-Package/2.0'),
    ],
];
```

Usage
-----

[](#usage)

### Quick Start

[](#quick-start)

First, register with Omise and add your API keys to your `.env` file. Test your configuration:

```
php artisan omise:verify
```

### Basic Usage

[](#basic-usage)

```
// Get Omise instance
$omise = app('omise');

// Check configuration
if (!$omise->validConfig()) {
    throw new Exception('Omise not configured properly');
}

// Create a token for credit card payment
$token = $omise->token()->create([
    'card' => [
        'name' => 'John Doe',
        'number' => '4242424242424242',
        'expiration_month' => 12,
        'expiration_year' => 2025,
        'security_code' => '123',
    ],
]);

// Create a charge
$charge = $omise->charge()->create([
    'amount' => 100000, // 1000.00 THB in satang
    'currency' => 'thb',
    'description' => 'Product purchase',
    'card' => $token->id,
]);

if ($charge->isSuccessful()) {
    echo "Payment successful!";
}
```

### Advanced Usage

[](#advanced-usage)

You have to register with Omise, then fill in the keys as in the configuration file. Note: you just add your keys in the .env file, and then test if it is valid using artisan command.

```
php artisan omise:verify
```

API Objects
-----------

[](#api-objects)

### Create Omise API Objects

[](#create-omise-api-objects)

To create Omise API objects like Charge, Source, Customer you can use Laravel dependency injection or the app helper:

```
// Using dependency injection
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Soap\LaravelOmise\Omise;
use Soap\LaravelOmise\Omise\Error;

class PaymentController extends Controller
{
    public function __construct(protected Omise $omise) {}

    public function create()
    {
        $publicKey = $this->omise->getPublicKey();
        return view('payments.form', compact('publicKey'));
    }
}

// Using app helper
$omise = app('omise');
$account = $omise->account()->retrieve();

// Access properties in different ways
$account->livemode;           // Property access
$account->livemode();         // Method access
$account->api_version;        // Snake case (as returned from Omise)
$account->apiVersion();       // CamelCase method access

// Get API keys
$omise->getPublicKey();       // Gets live or test key based on sandbox_mode
$omise->getSecretKey();       // Gets corresponding secret key
```

Artisan Commands
----------------

[](#artisan-commands)

The package provides several helpful Artisan commands:

### Verify Configuration

[](#verify-configuration)

```
php artisan omise:verify
```

Validates your Omise configuration and tests API connectivity.

### Account Information

[](#account-information)

```
php artisan omise:account
```

Display detailed account information including live mode status, supported currencies, and API version.

### Account Balance

[](#account-balance)

```
php artisan omise:balance
```

Show current account balance with optional JSON output (`--json` flag).

### Capabilities

[](#capabilities)

```
php artisan omise:capabilities
```

List supported payment methods and features for your account.

Verification
============

[](#verification)

Account Management
==================

[](#account-management)

Retrieve and configure account information:

```
// Get account information
$account = app('omise')->account()->retrieve();

if ($account instanceof \Soap\LaravelOmise\Omise\Error) {
    echo "Error: " . $account->getMessage();
} else {
    echo "Account ID: " . $account->id;
    echo "Email: " . $account->email;
    echo "Live Mode: " . ($account->livemode ? 'Yes' : 'No');
    echo "Currency: " . $account->currency;
}

// Update webhook URI
$account->updateWebhookUri('https://mydomain.com/api/omise/webhooks');
```

Token Management
================

[](#token-management)

Securely handle credit card information using tokens:

```
// Create token from card data
$token = app('omise')->token()->create([
    'card' => [
        'name' => 'John Doe',
        'number' => '4242424242424242',
        'expiration_month' => 12,
        'expiration_year' => 2025,
        'security_code' => '123',
    ],
]);

if ($token instanceof \Soap\LaravelOmise\Omise\Error) {
    echo "Token creation failed: " . $token->getMessage();
} else {
    echo "Token created: " . $token->id;

    // Check token status
    echo "Used: " . ($token->isUsed() ? 'Yes' : 'No');
    echo "Valid: " . ($token->isUnused() ? 'Yes' : 'No');

    // Get card information
    $cardBrand = $token->getCardBrand();
    $lastDigits = $token->getMaskedCardNumber();
    $isExpired = $token->isCardExpired();
}

// Retrieve existing token
$token = app('omise')->token()->find('tokn_xxxxxxxxxxxxx');

// Use token for payment
$charge = app('omise')->charge()->create([
    'amount' => 100000,
    'currency' => 'thb',
    'card' => $token->id,
]);
```

Source Management (Offline Payments)
====================================

[](#source-management-offline-payments)

Handle offline payment methods like PromptPay, Internet Banking:

```
// Create PromptPay source
$source = app('omise')->source()->create([
    'type' => 'promptpay',
    'amount' => 100000, // 1000.00 THB
    'currency' => 'thb',
]);

if ($source instanceof \Soap\LaravelOmise\Omise\Error) {
    echo "Source creation failed: " . $source->getMessage();
} else {
    // Create charge with source
    $charge = app('omise')->charge()->create([
        'amount' => 100000,
        'currency' => 'thb',
        'source' => $source->id,
        'return_uri' => 'https://yoursite.com/payment/complete',
    ]);

    // Get QR code for PromptPay
    if ($charge->source['type'] === 'promptpay') {
        $qrCodeUrl = $charge->source['scannable_code']['image']['download_uri'];
        echo "QR Code: " . $qrCodeUrl;
    }

    // For Internet Banking
    if ($charge->source['type'] === 'internet_banking_scb') {
        $bankUrl = $charge->authorize_uri;
        echo "Redirect to bank: " . $bankUrl;
    }
}

// Supported source types
$sources = [
    'promptpay',
    'internet_banking_scb',  // Siam Commercial Bank
    'internet_banking_bbl',  // Bangkok Bank
    'internet_banking_ktb',  // Krung Thai Bank
    'internet_banking_kbank', // Kasikorn Bank
    'internet_banking_bay',  // Bank of Ayudhya
];
```

Create and manage customers for recurring payments:

```
$customer = app('omise')->customer()->create([
    'email' => 'customer@example.com',
    'description' => 'John Doe',
    'card' => $token->id, // Token from frontend
]);

// Retrieve customer
$customer = app('omise')->customer()->find('cust_xxxxxxxxxxxxx');

// Update customer
$customer->update([
    'description' => 'John Doe - Premium Customer',
]);

// List all customers
$customers = app('omise')->customer()->all();

// Charge existing customer
$charge = app('omise')->charge()->create([
    'amount' => 100000,
    'currency' => 'thb',
    'customer' => $customer->id,
]);
```

Charge
======

[](#charge)

Find a charge object created
----------------------------

[](#find-a-charge-object-created)

To find charge transaaction using id (string provided by Omise), using find() method of charge object. You can using an id provided by a webhook called from Omise to confirm for a payment. If you want to use webhook, please visit my package; [soap/laravel-omise-webhooks](https://github.com/soap/laravel-omise-webhooks)

```
$charge = app('omise')->charge()->find($id);
$charge->isPaid(); // is it paid?
$charge->isAwaitCapture(); // is it waiting for capture
$charge->isFailed(); // status == failed
$charge->getAmount(); // get unit amount in the based currency e.g. 100 THB
$charge->getRawAmount(); // get minor amount in based currency e.g. 10000 Satang (THB)
$charge->getMetadata('booking_id'); // get metadata you provide when create a charge
```

Charge customer for some amount
-------------------------------

[](#charge-customer-for-some-amount)

To use a charge object to make a payment, you have to consult Omise workflow for each supported type of payment. To create a credit card payment, on frontend use Javascript to get charge token first. Then you can call charge-&gt;create() to make a corresponding payment.

Examples
--------

[](#examples)

### Complete Payment Flow Examples

[](#complete-payment-flow-examples)

The following examples show real-world payment processing scenarios:

#### Credit Card Payment Processor

[](#credit-card-payment-processor)

```
namespace App\Services;

use App\Contracts\PaymentProcessorInterface;
use Soap\LaravelOmise\Omise\Error;

class CreditCardPaymentProcessor implements PaymentProcessorInterface
{
    /**
     * Use token to authorize payment
     */
    public function createPayment(float $amounnt, string $currency = 'THB', array $paymentDetails = []): array
    {
        $charge = app('omise')->charge()->create([
            'amount' => $amounnt * 100,
            'currency' => $currency,
            'card' => $paymentDetails['token'],
            'capture' => $paymentDetails['capture'] ?? true,
            'webhook_endpoints' => $paymentDetails['webhook_endpoints'] ?? null,
            'metadata' => $paymentDetails['metadata'] ?? [],
        ]);

        if ($charge instanceof Error) {
            return [
                'code' => $charge->getCode(),
                'error' => $charge->getMessage(),
            ];
        }

        return [
            'charge_id' => $charge->id,
            'amount' => $charge->amount / 100,
            'currency' => $charge->currency,
            'status' => $charge->status,
            'paid' => $charge->paid,
            'paid_at' => $charge->paid_at,
            'charge' => $charge,
        ];
    }

    /**
     * Process payment using charge id
     */
    public function processPayment(array $paymentData): array
    {
        return [];
    }

    /**
     * Refund payment using charge id
     */
    public function refundPayment(string $chargeId, float $amount): bool
    {
        return true;
    }

    public function hasRefundSupport(): bool
    {
        return true;
    }

    public function isOffline(): bool
    {
        return false;
    }
}
```

#### PromptPay Payment Processor

[](#promptpay-payment-processor)

The PromptPay processor handles offline payments by generating QR codes:

```
