定制 moyasar/moyasar-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

moyasar/moyasar-php

最新稳定版本:v1.1.1

Composer 安装命令:

composer require moyasar/moyasar-php

包简介

PHP/Laravel wrapper library for Moyasar payment services

README 文档

README

moyasar-php

PHP version

Moyasar PHP wrapper library

Documentation

See the PHP API docs

Requirements

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

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 >= 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

You can install it via composer

$ composer require moyasar/moyasar 

Usage

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

Note: Moyasar does not allow creating payments using the API (with some exceptions), instead you can use the payment form. 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

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

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=<Your_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

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

License

The package is available as open source under the terms of the MIT License.

moyasar/moyasar-php 适用场景与选型建议

moyasar/moyasar-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.09k 次下载、GitHub Stars 达 28, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「payment」 「pay」 「apple」 「invoice」 「laravel」 「card」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 moyasar/moyasar-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 moyasar/moyasar-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 moyasar/moyasar-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8.09k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 28
  • 点击次数: 37
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 28
  • Watchers: 9
  • Forks: 14
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04