geekabel/mobile-money-payment 问题修复 & 功能扩展

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

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

geekabel/mobile-money-payment

Composer 安装命令:

composer require geekabel/mobile-money-payment

包简介

A flexible and extensible PHP package for integrating mobile money payment services, supporting Tmoney and Flooz payment providers.

README 文档

README

Overview

The Mobile Money Payment package provides a flexible and extensible solution for integrating mobile money payment services into PHP applications. It currently supports Tmoney and Flooz payment services, with an architecture that allows easy addition of new payment providers.

Features

  • Support for multiple payment services (currently Tmoney and Flooz)
  • Extensible architecture using the Strategy pattern
  • Standardized payment responses across different services
  • Flexible Flooz counter management system
  • Easy integration with various PHP applications, including Symfony

Requirements

  • PHP 8.2 or higher
  • Symfony HTTP Client

Installation

Install the package via Composer:

composer geekabel/mobile-money-payment

Basic Usage

Setting up the Payment Manager

use MobileMoneyPayment\PaymentManager;
use MobileMoneyPayment\Service\TmoneyService;
use MobileMoneyPayment\Service\FloozService;
use MobileMoneyPayment\Service\DefaultFloozCounterManager;

// Create service instances
$tmoneyService = new TmoneyService(
    $httpClient,
    $logger,
    'tmoney_username',
    'tmoney_password',
    'tmoney_alias',
    'https://tmoney-api-url.com'
);

$floozService = new FloozService(
    $httpClient,
    $logger,
    new DefaultFloozCounterManager(),
    'flooz_username',
    'flooz_password',
    'flooz_key',
    'flooz_merchant_name',
    'flooz_partner_msisdn',
    'https://flooz-api-url.com'
);

// Create and set up the Payment Manager
$paymentManager = new PaymentManager();
$paymentManager->addService('tmoney', $tmoneyService);
$paymentManager->addService('flooz', $floozService);

Making a Payment

$response = $paymentManager->pay('tmoney', '1234567890', 100.00, 'REF123', 'Payment for order #123');

if ($response->success) {
    echo "Payment successful! Transaction ID: " . $response->transactionId;
} else {
    echo "Payment failed: " . $response->message;
}

Checking Payment Status

$status = $paymentManager->checkStatus('flooz', 'REF123');

echo "Payment status: " . $status->status;

Extending the Package

Adding a New Payment Service

  1. Create a new class that implements PaymentServiceInterface:
use MobileMoneyPayment\Interface\PaymentServiceInterface;
use MobileMoneyPayment\Model\PaymentResponse;

class NewPaymentService implements PaymentServiceInterface
{
    public function pay(string $phone, float $amount, string $reference, string $description = ''): PaymentResponse
    {
        // Implement payment logic
    }

    public function checkStatus(string $reference): PaymentResponse
    {
        // Implement status check logic
    }
}
  1. Add the new service to the Payment Manager:
$newService = new NewPaymentService(/* ... */);
$paymentManager->addService('new_service', $newService);

Custom Flooz Counter Manager

  1. Create a class that implements FloozCounterManagerInterface:
use MobileMoneyPayment\Interface\FloozCounterManagerInterface;

class CustomFloozCounterManager implements FloozCounterManagerInterface
{
    public function getAndIncrementCounter(): int
    {
        // Implement custom counter logic
    }
}
  1. Use the custom manager when creating the Flooz service:
$customCounterManager = new CustomFloozCounterManager();
$floozService = new FloozService(
    $httpClient,
    $logger,
    $customCounterManager,
    // ... other parameters
);

Advanced Usage

Error Handling

The package uses PaymentException for specific payment-related errors. It's recommended to catch these exceptions:

use MobileMoneyPayment\Exception\PaymentException;

try {
    $response = $paymentManager->pay('tmoney', '1234567890', 100.00, 'REF123');
} catch (PaymentException $e) {
    echo "Payment error: " . $e->getMessage();
} catch (\Exception $e) {
    echo "Unexpected error: " . $e->getMessage();
}

Logging

The package accepts a PSR-3 compatible logger. You can provide your own logger implementation for custom logging behavior:

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('payment');
$logger->pushHandler(new StreamHandler('path/to/your.log', Logger::DEBUG));

$tmoneyService = new TmoneyService(
    $httpClient,
    $logger,
    // ... other parameters
);

Symfony Integration

For detailed instructions on how to integrate this package with Symfony 6.4, 7.0, 7.1, and superior versions, please refer to our Symfony Integration Guide.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This package is open-sourced software licensed under the MIT license.

geekabel/mobile-money-payment 适用场景与选型建议

geekabel/mobile-money-payment 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 geekabel/mobile-money-payment 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-20