escolalms/payments 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

escolalms/payments

Composer 安装命令:

composer require escolalms/payments

包简介

Escola LMS Payments Package.

README 文档

README

swagger codecov phpunit downloads downloads downloads Maintainability Mutation testing badge

Purpose

This package lets you create Payments and process them using integrations with external payment providers (gateways).

Dependencies

  • Stripe integration is based on league/omnipay and omnipay/stripe packages.
  • Przelewy24 integration is based on mnastalski/przelewy24-php package.
  • Optional integration with escolalms/settings package enables changing payment gateway api keys & secrets using Settings API (and Admin Panel).

Installation

  • composer require escolalms/payments
  • php artisan migrate
  • php artisan db:seed --class="EscolaLms\Cart\Database\Seeders\CartPermissionSeeder"

Usage

Facades

Payments Facade

Use EscolaLms\Payments\Facades\Payments for starting payment processing. You can create PaymentProcessor` either from a model using Payable trait or from precreated Payment object.

use EscolaLms\Cart\Models\Cart;
use EscolaLms\Payments\Dtos\PaymentMethodDto;
use EscolaLms\Payments\Facades\Payments;

$payable = Cart::find($id); // Cart must implement Payable interface and use Payable trait
$paymentMethodDto = PaymentMethodDto::instantiateFromRequest($request);
$processor = Payments::processPayment($payable);
$processor->purchase($paymentMethodDto); // will emit PaymentPaid event on success
if($payment->status->is(PaymentStatus::PAID)){
    // ...
}

PaymentGateway Facade

With EscolaLms\Payments\Facades\PaymentGateway you can call payment provider gateways directly.

For existing payment you can for example do:

use EscolaLms\Payments\Dtos\PaymentMethodDto;
use EscolaLms\Payments\Facades\PaymentGateway;
use EscolaLms\Payments\Models\Payment;

$payment = Payment::find($id);
$paymentMethodDto = PaymentMethodDto::instantiateFromRequest($request);
$paymentDto = PaymentDto::instantiateFromPayment($payment); // or you can create it manually
PaymentGateway::purchase($paymentDto, $paymentMethodDto); // will use default payment driver

Important: This will not save Payment object.

To use specific driver, you can call

PaymentGateway::driver('stripe')->purchase($paymentDto, $paymentMethodDto);

Available payment drivers

  • stripe (using Stripe Payment Intent)
  • free
  • przelewy24
  • TODO: stripe-checkout

Payable Trait & Interface

Payable trait and interface are the core of this package, enabling simplified calling of PaymentsService and GatewayManager. When you include it in your model that represents a Payable (for example Cart or Order or Product) you can begin payment processing for that Payable by calling $payable->process() which calls Payments::processPayable($this) and automatically creates a Payment and returns a PaymentProcessor instance for that Payment.

EscolaLms\Cart package uses this trait and interface in EscolaLms\Cart\Models\Order.

Payment Processor

EscolaLms\Payments\Entities\PaymentProcessor is a special class which wraps around Payment and contains functionality related to processing that payment, for example generating links to payment gateways, automatically setting payment status after purchase, emiting events related to payment status, etc.

use EscolaLms\Payments\Dtos\PaymentMethodDto;
use EscolaLms\Payments\Entities\PaymentProcessor;
use EscolaLms\Payments\Models\Payment;

$payment = Payment::find($id);
$paymentMethodDto = PaymentMethodDto::instantiateFromRequest($request);
$processor = new PaymentProcessor($payment); // instead of using Payments facade
$processor->purchase($paymentMethodDto);

PaymentProcessor automatically selects free driver when payment amount equals 0.

Payment Model

This package defines a EscolaLms\Payments\Models\Payment which contains all data abount given payment required for payment gateways to work.

Endpoints

All the endpoints are defined in swagger.

Tests

Run ./vendor/bin/phpunit to run tests. See tests/Mocks/Payable as an example how a Payable is defined.

Test details: codecov phpunit

Events

  • EscolaLms\Payments\Events\PaymentCancelled - - emited after payment processing is cancelled (by user action or possibly by timeout sent from payment gateway)
  • EscolaLms\Payments\Events\PaymentFailed - emited after payment has failed (payment gateway returns error)
  • EscolaLms\Payments\Events\PaymentRegistered - emited when new Payment is created
  • EscolaLms\Payments\Events\PaymentSuccess - emited when payment gateway returns success

Listeners

No Listeners are defined in this package.

How to use this package on Frontend

Admin Panel

Left Menu

Admin panel menu

List of Payments

List of Payments

Permissions

Permissions are defined in Enum and seeded in Seeder.

Roadmap. Todo. Troubleshooting

  • ???

escolalms/payments 适用场景与选型建议

escolalms/payments 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 63.72k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 06 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 escolalms/payments 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-17