camoo/payment-api 问题修复 & 功能扩展

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

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

camoo/payment-api

Composer 安装命令:

composer require camoo/payment-api

包简介

CAMOO Payment API

README 文档

README

Below is an example README.md you could include in your project. It provides an overview, installation instructions, usage examples, endpoint references, and credits. Feel free to customize this to your specific needs (e.g., project naming, author info, licensing).

Camoo Payment API – PHP Library

A simple, PSR-4 compliant PHP library for accessing the Camoo Payment API. This library provides convenient classes for working with Account and Payment endpoints, while allowing you to inject your own HTTP client if desired.

Table of Contents

Requirements

Developer Notes (Self-Implementation)

  • OpenAPI Documentation
  • 📦 Postman Collection

Payment Notifications (Signed Callbacks)

Camoo sends payment status notifications via HTTP GET requests to the merchant’s notification_url.

Each notification is cryptographically signed and includes a sig query parameter.

Signature details

  • Algorithm: HMAC-SHA256
  • Secret: API Secret (X-Api-Secret)
  • Payload: Canonical query string built from request parameters
  • Encoding: RFC3986 (URL-encoded)

Signature base string format:

payment_id={value}&status={value}&status_time={value}[&trx={value}]

Notes:

  • The sig parameter is excluded from the base string
  • The merchant endpoint MUST be idempotent
  • Camoo may retry notifications until HTTP 200 is returned

Merchants MUST verify the signature before trusting or processing the callback.

Example notification request

GET /callback?
payment_id=934ca3f6
&status=CONFIRMED
&status_time=2026-01-18T11:42:03+00:00
&trx=my-site-ref
&sig=7f9c8b8d1c0e9c...

Installation

Install the package via Composer:

composer require camoo/payment-api

If you are installing from a local copy or private repository, ensure your composer.json and repositories settings are correctly configured, then run composer install.

Getting Started

Configuration & Client

  1. Instantiate the main HTTP Client, providing your API key and API secret.
  2. Optionally set debug to true if you want to see more verbose debugging info.
  3. The API version defaults to v1.
<?php

require __DIR__ . '/vendor/autoload.php';

use Camoo\Payment\Http\Client as PaymentClient;

// Your credentials
$apiKey = 'YOUR_API_KEY';
$apiSecret = 'YOUR_API_SECRET';

$client = new PaymentClient(
    apiKey: $apiKey,
    apiSecret: $apiSecret,
    httpClient: null,  // optionally pass a custom ClientInterface
    debug: false,      // set to true for verbose logging
    apiVersion: 'v1'
);

Working with Account API

Use the Camoo\Payment\Api\Account class to fetch account info (e.g. balance, etc.):

use Camoo\Payment\Api\AccountApi;

$accountApi = new AccountApi($client);

try {
    $accountInfo = $accountApi->get();
    // $accountInfo is an instance of \Camoo\Payment\Models\Account

    echo "Balance: " . $accountInfo->balance->amount . " " . $accountInfo->balance->currency->value . PHP_EOL;
    echo "Viewed At: " . $accountInfo->viewedAt->format('Y-m-d H:i:s') . PHP_EOL;
} catch (\Camoo\Payment\Exception\ApiException $e) {
    // Handle error
    echo "Error fetching account: " . $e->getMessage();
}

Working with Payment API

Use the Camoo\Payment\Api\Payment class to cash out or verify a payment.

use Camoo\Payment\Api\PaymentApi;

$paymentApi = new PaymentApi($client);

// 1) Cash Out (example usage)
try {
    $response = $paymentApi->cashout([
        'phone_number' => '+237612345678',
        'amount'      => 5000,
        'notification_url'    => 'https://example.com/notify-me',
    ]);

    // $response is an instance of \Camoo\Payment\Models\Payment
    echo "Cashout ID: " . $response->id . PHP_EOL;
    echo "Status: " . $response->status . PHP_EOL;
} catch (\Camoo\Payment\Exception\ApiException $e) {
    // Handle error
    echo "Cashout error: " . $e->getMessage();
}

// 2) Verify a payment (example usage)
try {
    $paymentId = '12345';
    $verifiedPayment = $paymentApi->verify($paymentId);

    echo "Payment " . $verifiedPayment->id . " status: " . $verifiedPayment->status . PHP_EOL;
} catch (\Camoo\Payment\Exception\ApiException $e) {
    // Handle error
    echo "Verification error: " . $e->getMessage();
}

Models

This library returns response data as Model classes. Notable models include:

  • Camoo\Payment\Models\Account

    • Properties: balance (a Money object) and viewedAt (DateTimeInterface).
    • Use Account::fromArray($data) to create from raw response data.
    • Use toArray() or JSON-encode it for debugging or storage.
  • Camoo\Payment\Models\Payment

    • Holds payment data (id, amount, network, status, timestamps, etc.).
    • Use Payment::fromArray($data) to create from raw response data.
    • Use toArray() to convert back to a standard PHP array.

Money Class

  • Found in Camoo\Payment\ValueObject\Money, which pairs an amount (float) with a currency (an enum from Camoo\Payment\Enum\Currency).

Error Handling

Most client or API errors throw a Camoo\Payment\Exception\ApiException. This exception will include the HTTP status code (if available) and a message from the API response (or a fallback).

Example:

try {
    // Some Payment API call
} catch (\Camoo\Payment\Exception\ApiException $e) {
    echo 'API Error (code ' . $e->getCode() . '): ' . $e->getMessage();
}

Development & Contributing

  1. Clone the repository.
  2. Install dependencies:
    composer install
  3. Run tests (if available):
    composer test
  4. Pull Requests: Please submit PRs that follow PSR-12 coding style and include tests.

We welcome issues and pull requests to make this library more robust, add additional endpoints, or improve performance.

License

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

Enjoy building with Camoo Payment API! If you have any feedback or questions, feel free to open an issue or reach out to us.

camoo/payment-api 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-18