hamedov/omnipay-moyasar
Composer 安装命令:
composer require hamedov/omnipay-moyasar
包简介
Omnipay moyasar payment gateway
README 文档
README
This package makes it easy to process payments using moyasar gateway for credit card, sadad, apple pay and mada payments. For more information about different payment methods refer to Moyasar documentation. https://moyasar.com/docs/api
Installation
composer require hamedov/omnipay-moyasar
Usage
Initialize the gateway with api key
You can use test or live api key here.
use Omnipay\Omnipay;
$moyasar = Omnipay::create('Moyasar');
$moyasar->setApiKey('You test or live api key');
Initiate new payment
$request = $moyasar->purchase([
'amount' => 50,
'currency' => 'SAR',
'description' => 'Payment description',
'callbackUrl' => 'http://example.com/payments',
'source' => [
'type' => 'creditcard',
'name' => 'Mohamed Hamed',
'number' => '4111111111111111',
'cvc' => 785,
'month' => 11,
'year' => 2021,
'3ds' => true,
],
]);
$payment = $request->send();
Initiate new manual payment
To only authorize the payment and let it be captured manually by the merchant, use the authorize method. If the payment is not captured within 7 days, the authorization is canceled and funds released.
$request = $moyasar->authorize([
'amount' => 50,
'currency' => 'SAR',
'description' => 'Payment description',
'callbackUrl' => 'http://example.com/payments',
'source' => [
'type' => 'creditcard',
'name' => 'Mohamed Hamed',
'number' => '4111111111111111',
'cvc' => 785,
'month' => 11,
'year' => 2021,
'3ds' => true,
],
]);
$payment = $request->send();
Handle payment response
You will need to check the payment status to decide whether there will be a redirect to complete payment or not. You will also need to save reference to the payment for future reference such as refunding and voiding payments.
if ($payment->isSuccessful())
{
// Payment is successful no redirect requird
$transactionId = $payment->getTransactionReference();
}
elseif ($payment->isAuthorized())
{
// Payment is authorized and waiting to be capture by the merchant
$transactionId = $payment->getTransactionReference();
}
elseif ($payment->isFailed())
{
// Payment failed
$error = $payment->getMessage();
}
For Redirect response You can call the redirect() method to redirect the user automatically to complete payment, or you can get the
transaction url using $payment->getRedirectUrl() and handle the redirect yourself or return it in a json api response.
if ($payment->isRedirect())
{
$payment->redirect();
}
After the user is redirected back to your website you can fetch the payment using the id provided in the url to check payment status and process it as required. You will get the same response format as returned in the payment request.
$moyasar = Omnipay::create('Moyasar');
$moyasar->setApiKey('You test or live api key');
$payment = $moyasar->fetch($_GET['id'])->send();
if ($payment->isSuccessful())
{
// Payment successful
$transactionId = $payment->getTransactionReference();
}
elseif ($payment->isFailed())
{
// Payment failed
$error = $payment->getMessage();
}
Capture a previously authorized payment
You can provide the amount to be captured, it can be less than or equal to original amount provided during payment creation.
The remaining amount will be automatically released. The request will fail if the payment has any status other than authorized
$moyasar = Omnipay::create('Moyasar');
$moyasar->setApiKey('You test or live api key');
$payment = $moyasar->capture([
'id' => $transactionId,
'amount' => $amount, // Optional, defaults to total amount
])->send();
if ($payment->isCaptured())
{
// Success
}
elseif ($payment->hasError())
{
$error = $payment->getMessage();
}
Void a payment
- You can cancel/void an authorized payment which has not been captured yet.
- You can cancel/void captured or successful payments which have not yet settled in the customers bank account. Or you will need to send a refund request.
$moyasar = Omnipay::create('Moyasar');
$moyasar->setApiKey('You test or live api key');
$payment = $moyasar->void([
'id' => $transactionId,
])->send();
if ($payment->isVoided())
{
// Success
}
elseif ($payment->hasError())
{
$error = $payment->getMessage();
// You can fallback to the refund request here
}
Refund a payment
$moyasar = Omnipay::create('Moyasar');
$moyasar->setApiKey('You test or live api key');
$payment = $moyasar->refund([
'id' => $transactionId,
'amount' => $amount, // Optional
])->send();
if ($payment->isRefunded())
{
// Success
}
elseif ($payment->hasError())
{
// Payment cannot be refunded
$error = $payment->getMessage();
}
TODO
- Add update payment request.
- Add list payments request.
License
Released under the Mit license, see LICENSE
hamedov/omnipay-moyasar 适用场景与选型建议
hamedov/omnipay-moyasar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 450 次下载、GitHub Stars 达 5, 最近一次更新时间为 2020 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payment」 「pay」 「gateway」 「omnipay」 「Moyasar」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hamedov/omnipay-moyasar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hamedov/omnipay-moyasar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hamedov/omnipay-moyasar 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Payyo Gateway for the Omnipay payment processing library
Библиотека для приема платежей через Альфабанк.
Some pre-defined rules for validation in Omnipay payment processing library.
BluePay gateway for the Omnipay payment processing library
支付宝接口扩展包
统计信息
- 总下载量: 450
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-23