PHPackages                             moolre/moolre-php - 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. moolre/moolre-php

ActiveLibrary[Payment Processing](/categories/payments)

moolre/moolre-php
=================

Framework-agnostic PHP SDK for initiating and verifying Moolre payments.

v1.0.1(4w ago)00GPL-2.0-or-laterPHPPHP ^7.4 || ^8.0

Since Jul 17Pushed 4w agoCompare

[ Source](https://github.com/moolrehq/moolre-php)[ Packagist](https://packagist.org/packages/moolre/moolre-php)[ Docs](https://github.com/moolrehq/moolre-php)[ RSS](/packages/moolre-moolre-php/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (6)Versions (3)Used By (0)

Moolre PHP SDK
==============

[](#moolre-php-sdk)

Framework-agnostic PHP package for initiating Moolre hosted payments and verifying transactions from any PHP application.

This package was extracted from the working Moolre WooCommerce gateway flow. It uses the same Moolre API endpoint:

- `state=starter` starts a payment and returns `data.authorization_url`
- `POST /open/transact/status` verifies a transaction by reference

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

[](#requirements)

- PHP 7.4 or newer
- JSON extension
- cURL extension recommended, with PHP streams used as a fallback
- HTTPS access to the Moolre API

For integration testing only, set `MOOLRE_FORCE_STREAMS=1` to exercise the PHP-stream transport even when cURL is installed.

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

[](#installation)

Install with Composer:

```
composer require moolre/moolre-php
```

Until the package is published to Packagist, install it into an app as a local path repository:

```
composer config repositories.moolre path /absolute/path/to/moolre-php
composer require moolre/moolre-php:@dev
```

For development inside this package:

```
cd moolre-php
composer install
```

Example Project
---------------

[](#example-project)

A complete raw PHP demo app is included at [`examples/raw-php-app`](examples/raw-php-app). It shows a cart checkout, payment initiation, webhook callback handling, customer redirect verification, and a small local JSON order store.

Run it from the SDK repository:

```
cd examples/raw-php-app
composer install
php -S localhost:8080 -t public
```

Set your credentials before starting the server:

```
cp .env.example .env
```

Then edit `.env` with your Moolre values. You can also set environment variables directly:

```
export MOOLRE_PRODUCTION="false"
export MOOLRE_ACCOUNT_NUMBER="your_account_number"
export MOOLRE_API_USER="your_moolre_account_username"
export MOOLRE_PUBLIC_KEY=""
export MOOLRE_EXPIRATION_TIME="10"
export APP_URL="http://localhost:8080"
```

On Windows PowerShell:

```
Copy-Item .env.example .env
```

Then edit `.env`, or set variables in the same terminal:

```
$env:MOOLRE_PRODUCTION="false"
$env:MOOLRE_ACCOUNT_NUMBER="your_account_number"
$env:MOOLRE_API_USER="your_moolre_account_username"
$env:MOOLRE_PUBLIC_KEY=""
$env:MOOLRE_EXPIRATION_TIME="10"
$env:APP_URL="http://localhost:8080"
```

Then open `http://localhost:8080`. If Moolre needs to call your local callback/webhook, expose the app through a tunnel and set `APP_URL` to the public tunnel URL.

Live and Sandbox Mode
---------------------

[](#live-and-sandbox-mode)

The raw PHP example uses `MOOLRE_PRODUCTION` as the environment switch:

- `MOOLRE_PRODUCTION=true`: live mode, using `https://api.moolre.com/embed/src/start`
- `MOOLRE_PRODUCTION=false` or unset: sandbox mode, using `https://sandbox.moolre.com/embed/src/start`

Live payment initiation requires `MOOLRE_PUBLIC_KEY` and `MOOLRE_ACCOUNT_NUMBER`; live verification also requires `MOOLRE_API_USER`.

Sandbox mode requires `MOOLRE_ACCOUNT_NUMBER` and `MOOLRE_API_USER`. The SDK sends `MOOLRE_API_USER` as the `X-API-USER` header. `MOOLRE_PUBLIC_KEY` is optional only in sandbox.

`MOOLRE_API_USER` is required for every `verifyPayment()` call, including live mode. Transaction-status requests also include `X-API-PUBKEY` when a public key is configured.

For a direct SDK integration, choose the endpoint with your own config:

```
use Moolre\Client;

$isProduction = false;

$client = new Client(
    $isProduction ? 'your_public_key' : '',
    'your_account_number',
    null,
    $isProduction ? Client::DEFAULT_BASE_URL : Client::SANDBOX_BASE_URL,
    60,
    false,
    'your_moolre_account_username',
    $isProduction ? Client::DEFAULT_VERIFICATION_URL : Client::SANDBOX_VERIFICATION_URL
);
```

`MOOLRE_BASE_URL` and `MOOLRE_VERIFICATION_URL` are supported in the raw PHP example as advanced overrides, but most apps should switch with `MOOLRE_PRODUCTION`.

Raw PHP
-------

[](#raw-php)

```
