PHPackages                             moyasar/moyasar - 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. moyasar/moyasar

AbandonedArchivedLibrary[Payment Processing](/categories/payments)

moyasar/moyasar
===============

PHP/Laravel wrapper library for Moyasar payment services

v1.1.1(4y ago)3070.7k↓24.7%14[3 issues](https://github.com/moyasar/moyasar-php/issues)1MITPHPPHP ^7.2|^8.0

Since Jul 19Pushed 10mo ago8 watchersCompare

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

READMEChangelog (9)Dependencies (4)Versions (11)Used By (1)

This project has been archived and is no longer maintained.
===========================================================

[](#this-project-has-been-archived-and-is-no-longer-maintained)

moyasar-php
===========

[](#moyasar-php)

[![PHP version](https://camo.githubusercontent.com/e53781a227b14832d27f88b9f37c28b8c8f2ff7198773e03d873602cb9c8991c/68747470733a2f2f62616467652e667572792e696f2f70682f6d6f79617361722532466d6f79617361722e737667)](https://badge.fury.io/ph/moyasar%2Fmoyasar)

Moyasar PHP wrapper library

Documentation
-------------

[](#documentation)

See the [PHP API docs](https://moyasar.com/docs/api/?php)

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

[](#requirements)

- PHP 5.6.0
- guzzlehttp/guzzle: ^6.3.0
- laravel/framework (Optional)

#### Notes

[](#notes)

- Please note that starting from version `1.0.0` the library was rewritten with breaking changes, so please do not update unless you need the new version. If you are new, it is recommended to use the new version.
- To use the PHP stream handler, allow\_url\_fopen must be enabled in your system's php.ini.
- To use the cURL handler, you must have a recent version of cURL &gt;= 7.19.4 compiled with OpenSSL and zlib.
- Please note that in version `0.5.0` the library name has been changed from `moyasar-php` to `moyasar`

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

[](#installation)

You can install it via [composer](https://getcomposer.org/)

```
$ composer require moyasar/moyasar

```

Usage
-----

[](#usage)

#### In a Standard Project

[](#in-a-standard-project)

After installing the library using composer and including `autoload.php`, the API key need to be set in order to use the services.

```
include_once 'vendor/autoload.php';

\Moyasar\Moyasar::setApiKey('api-key');
```

Setup is complete, create an instance of the service you need and start using it.

#### Payment

[](#payment)

Note: Moyasar does not allow creating payments using the API (with some exceptions), instead you can use the [payment form](https://moyasar.com/docs/payments/create-payment/mpf/). That is why, wrapper libraries does not support it.

---

To fetch a payment, just simply do the following:

```
$paymentService = new \Moyasar\Providers\PaymentService();

$payment = $paymentService->fetch('ae5e8c6a-1622-45a5-b7ca-9ead69be722e');
```

An instance of `Payment` will be returned, that has the data in addition to being able to perform operations like `update`, `refund`, `capture`, `void` on that payment instance, which we will get back to later.

---

To list payments associated with your account, simply do the following:

```
$paymentService = new \Moyasar\Providers\PaymentService();

$paginationResult = $paymentService->all();

$payments = $paginationResult->result;
```

The `all` method will return an instance of `PaginationResult` this contains meta data about our result, like `currentPage`, `totalPages` etc...

To get the payments from this object, we just read the `result` property of that object.

---

The `all` method accepts an instance of `Search` or an array, this allows us to filter results and move along pages. It is quite simple to use:

```
$search = \Moyasar\Search::query()->status('paid')->page(2);

$paginationResult = $paymentService->all($search);
```

The following methods are supported:

- `id($id)`
- `status($status)`
- `source($source)`
- `page($page)`
- `createdAfter($date)`
- `createdBefore($date)`

---

Once we fetch the desired payment, we can either `update` the description, `refund` it, `capture` it, or `void` it.

```
$payment->update('new description here');

// OR

$payment->refund(1000); // 10.00 SAR

// OR

$payment->capture(1000);

// OR

$payment->void();
```

#### Invoice

[](#invoice)

For invoices, fetching and listing them is the same as payments, instead we use `InvoiceService`.

Although, we can use the API to create a new invoice, by doing the following:

```
$invoiceService = new \Moyasar\Providers\InvoiceService();

$invoiceService->create([
    'amount' => 1000000, // 10000.00 SAR
    'currency' => 'SAR',
    'description' => 'iPhone XII Purchase',
    'callback_url' => 'http://www.example.com/invoice-status-changed', // Optional
    'expired_at' => '2020-01-20' // Optional
]);
```

---

With an instance of `Invoice`, we can either `update`, or `cancel` a given instance.

```
$invoice->update([
    'amount' => 900000, // 9000.00 SAR
    'currency' => 'SAR',
    'description' => 'iPhone XII Purchase (Updated)',
    'callback_url' => 'http://www.example.com/invoice-status-changed', // Optional
    'expired_at' => '2020-01-25' // Optional
]);

// OR

$invoice->cancel();
```

#### Laravel

[](#laravel)

First thing we need to add `moyasar/moyasar` to our Laravel project, to do it we need:

```
$ composer require moyasar/moyasar

```

After that, moyasar services need to be configured, so let us publish the configuration file:

```
$ php artisan vendor:publish --provider="Moyasar\Providers\LaravelServiceProvider"

```

Now edit `config/moyasar.php` and add your API key, by default the API key is read from an environment variable called `MOYASAR_API_KEY`, thus `.env` can be used to add the key.

```
MOYASAR_API_KEY=
```

If everything goes to plan, you should be able to get `PaymentService` and `InvoiceService`from laravel service container by simply called `app` helper function

```
app(PaymentService::class)
```

```
app(InvoiceService::class)
```

Or inside your controller, you can simply type-hint one of the services in the constructor:

```
public function __construct(PaymentService $paymentService)
{
    $this->paymentService = $paymentService;
}
```

---

Or if you want a quick way to use these services, you can use the `Payment` and `Invoice` facades:

- `Moyasar\Facades\Payment`
- `Moyasar\Facades\Invoice`

For example:

```
$payment = \Moyasar\Facades\Payment::fetch('id');
```

Contributing
------------

[](#contributing)

Bug reports and pull requests are welcome on GitHub at [https://github.com/\[USERNAME\]/moyasar-php](https://github.com/%5BUSERNAME%5D/moyasar-php). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.

License
-------

[](#license)

The package is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~231 days

Recently: every ~180 days

Total

10

Last Release

1510d ago

Major Versions

0.5.0 → v1.0.02020-04-06

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13823335?v=4)[Moyasar](/maintainers/moyasar)[@moyasar](https://github.com/moyasar)

---

Top Contributors

[![Sohib](https://avatars.githubusercontent.com/u/5610514?v=4)](https://github.com/Sohib "Sohib (14 commits)")[![ahoshaiyan](https://avatars.githubusercontent.com/u/17358604?v=4)](https://github.com/ahoshaiyan "ahoshaiyan (11 commits)")[![ecleel](https://avatars.githubusercontent.com/u/25447?v=4)](https://github.com/ecleel "ecleel (9 commits)")[![nuhamozaini](https://avatars.githubusercontent.com/u/7025901?v=4)](https://github.com/nuhamozaini "nuhamozaini (4 commits)")[![AbdullahDahmash](https://avatars.githubusercontent.com/u/9831367?v=4)](https://github.com/AbdullahDahmash "AbdullahDahmash (2 commits)")[![MarkRady](https://avatars.githubusercontent.com/u/17724927?v=4)](https://github.com/MarkRady "MarkRady (2 commits)")[![Fghurayri](https://avatars.githubusercontent.com/u/27068874?v=4)](https://github.com/Fghurayri "Fghurayri (1 commits)")

---

Tags

credit-cardgatewayinvoicemadamoyasarmoyasar-phppaymentphpsadadwrapperlaravelpaymentinvoicepaycardapplecapturerefundvisacreditvoidsadadmasterMoyasarmada

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/moyasar-moyasar/health.svg)

```
[![Health](https://phpackages.com/badges/moyasar-moyasar/health.svg)](https://phpackages.com/packages/moyasar-moyasar)
```

###  Alternatives

[larabook/gateway

A Laravel package for connecting to all Iraninan payment gateways

24553.7k](/packages/larabook-gateway)[php-junior/laravel-2c2p

2C2P Payment Gateway Api &amp; 123 API

456.7k](/packages/php-junior-laravel-2c2p)[dena-a/iran-payment

a Laravel package to handle Internet Payment Gateways for Iran Banking System

312.4k1](/packages/dena-a-iran-payment)[parsisolution/gateway

A Laravel package for connecting to all Iraninan payment gateways

231.7k](/packages/parsisolution-gateway)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
