定制 academe/elavon-epg-psr7 二次开发

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

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

academe/elavon-epg-psr7

Composer 安装命令:

composer require academe/elavon-epg-psr7

包简介

PSR-7 messages and DTO classes for the Elavon Payment Gateway (EPG) API

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Elavon EPG PSR-7

PSR-7 HTTP messages and Data Transfer Object (DTO) classes for the Elavon Payment Gateway (EPG) API.

The API is described here and the OpenAPI description is here

Table of Contents

Overview

This package provides strongly-typed PHP classes for interacting with the Elavon Payment Gateway API. It includes:

  • PSR-7 compliant HTTP message implementations
  • DTO classes for request and response data structures
  • Type-safe value objects for payment data
  • Support for all EPG API resources and operations

This package handles message construction and serialization. A separate HTTP client package will handle the actual sending of requests.

Get an Elavon Merchant Account

Tip

Don't have an Elavon merchant account yet? Sign up here to get started. Elavon's team will contact you within 24-48 hours to discuss your payment processing needs.

Requirements

  • PHP 8.1 or higher
  • An Elavon merchant account with API credentials
  • PSR-7 HTTP Message implementation (or use built-in message factory)
  • PSR-17 HTTP Factory implementation (or user built-in factory)

Installation

composer require academe/elavon-epg-psr7

Quick Start

Here's a complete example creating a credit card payment using Guzzle:

<?php

use Academe\Elavon\Epg\Psr7\Messages\Request\Transaction\CreateTransactionRequest;
use Academe\Elavon\Epg\Psr7\Messages\Response\Transaction\TransactionResponse;
use Academe\Elavon\Epg\Psr7\Support\ElavonApiFactory;
use GuzzleHttp\Client;

// 1. Configure the API factory (reusable for multiple requests)
$factory = ElavonApiFactory::configure()
    ->withRegion('eu')                                    // 'eu' or 'us'
    ->withEnvironment('sandbox')                          // 'sandbox' or 'live'
    ->withAuthentication($merchantAlias, $apiSecret);     // Your credentials

// 2. Create the transaction request
$request = CreateTransactionRequest::fromData([
    'transaction' => [
        'total' => [
            'amount' => '99.99',
            'currencyCode' => 'USD',
        ],
        'card' => [
            'number' => '4111111111111111',
            'securityCode' => '123',
            'expirationMonth' => 12,
            'expirationYear' => 2025,
            'holderName' => 'John Doe',
        ],
        'description' => 'Order #12345',
    ],
]);

// 3. Build and apply API configuration
$psr7Request = $factory->apply($request->build());

// 4. Send with Guzzle (or any PSR-18 client)
$client = new Client();
$psr7Response = $client->sendRequest($psr7Request);

// 5. Parse the response
$response = TransactionResponse::fromPsr7Response($psr7Response);

if ($response->isSuccessful()) {
    echo "Transaction ID: {$response->transaction->id}\n";
    echo "State: {$response->transaction->state->value}\n";
} else {
    echo "Error: {$response->error->getMessage()}\n";
}

Using DTOs (fromData)

You can create DTOs explicitly from array data using fromData():

use Academe\Elavon\Epg\Psr7\Dtos\Transaction;

$transaction = Transaction::fromData([
    // Note: major units, but can also supply ['amountMinor' => 9999, ...]
    'total' => ['amount' => '99.99', 'currencyCode' => 'USD'],
    'card' => [
        'number' => '4111111111111111',
        'securityCode' => '123',
        'expirationMonth' => 12,
        'expirationYear' => 2025,
        'holderName' => 'John Doe',
    ],
    'description' => 'Order #12345',
]);

$request = new CreateTransactionRequest($transaction);

Using Value Objects (Type-Safe)

For full type safety, construct DTOs with typed value objects:

use Academe\Elavon\Epg\Psr7\Dtos\Transaction;
use Academe\Elavon\Epg\Psr7\Dtos\Card;
use Academe\Elavon\Epg\Psr7\Enums\Currency;
use Money\Money;

$transaction = new Transaction(
    total: new Money('9999', Currency::USD), // Note: minor units
    card: new Card(
        number: '4111111111111111',
        securityCode: '123',
        expirationMonth: 12,
        expirationYear: 2025,
        holderName: 'John Doe',
    ),
    description: 'Order #12345',
);

$request = new CreateTransactionRequest($transaction);

Paginated Lists with QueryParams

Many API endpoints return paginated lists of resources. The QueryParams class provides a fluent interface for pagination and filtering:

use Academe\Elavon\Epg\Psr7\Dtos\QueryParams;
use Academe\Elavon\Epg\Psr7\Messages\Request\Order\RetrieveOrderListRequest;
use Academe\Elavon\Epg\Psr7\Messages\Response\Order\OrderListResponse;

// First page with pagination
$queryParams = QueryParams::create()->withLimit(25);
$request = (new RetrieveOrderListRequest($queryParams))->build();
$request = $factory->apply($request);

$response = OrderListResponse::fromPsr7Response($client->sendRequest($request));

if ($response->isSuccessful()) {
    foreach ($response->orders as $order) {
        echo "Order: {$order->id} - {$order->description}\n";
    }

    // Fetch next page using the nextPageToken
    if ($response->nextPageToken) {
        $nextParams = QueryParams::create()
            ->withLimit(25)
            ->withPageToken($response->nextPageToken);
        $nextRequest = (new RetrieveOrderListRequest($nextParams))->build();
        // ...
    }
}

QueryParams Methods

Method Description
QueryParams::create() Create an empty QueryParams instance
withPageToken(?string $token) Set the pagination token for the next page
withLimit(?int $limit) Set page size (1-200, throws exception if out of range)
withFilter(string $field, QueryFilterOperator $operator, string $value) Add a filter condition
isEmpty() Check if any parameters are set
apply(UriInterface $uri) Apply parameters to a PSR-7 URI

Filtering

The Elavon API supports filtering on list endpoints. Use withFilter() with the QueryFilterOperator enum to add filter conditions:

use Academe\Elavon\Epg\Psr7\Enums\QueryFilterOperator;

$queryParams = QueryParams::create()
    ->withLimit(50)
    ->withFilter('createdAt', QueryFilterOperator::GT, '2024-01-01')
    ->withFilter('type', QueryFilterOperator::EQ, 'refund')
    ->withFilter('total.amount', QueryFilterOperator::GE, '100');

Available filter operators (QueryFilterOperator enum):

Enum Case Value Description
EQ eq Equals
NE ne Not equals
GT gt Greater than
GE ge Greater than or equal
LT lt Less than
LE le Less than or equal
LIKE like Like pattern
IN in In list
CONTAINS contains Contains
IS is Is (for null checks)
IS_NOT isnot Is not (for null checks)

Note: Available filters vary by endpoint. See the Elavon API documentation for endpoint-specific filters.

Response Pagination Properties

Property Description
$response->nextPageToken Token for the next page (use with withPageToken())
$response->nextPage Full URL for the next page
$response->firstPage Full URL to return to the first page
$response->hasMorePages() Returns true if more pages are available

List Requests Supporting QueryParams

The following request classes accept a QueryParams parameter:

Top-level resources:

  • RetrieveAccountListRequest → GET /accounts
  • RetrieveBatchListRequest → GET /batches
  • RetrieveHostedCardListRequest → GET /hosted-cards
  • RetrieveManualBatchListRequest → GET /manual-batches
  • RetrieveMerchantListRequest → GET /merchants
  • RetrieveNotificationListRequest → GET /notifications
  • RetrieveOrderListRequest → GET /orders
  • RetrievePaymentLinkEventListRequest → GET /payment-link-events
  • RetrievePaymentLinkListRequest → GET /payment-links
  • RetrievePaymentMethodLinkListRequest → GET /payment-method-links
  • RetrievePlanListListRequest → GET /plan-lists
  • RetrieveProcessorAccountListRequest → GET /processor-accounts
  • RetrieveShopperListRequest → GET /shoppers
  • RetrieveStoredAchPaymentListRequest → GET /stored-ach-payments
  • RetrieveStoredCardListRequest → GET /stored-cards
  • RetrieveTerminalListRequest → GET /terminals
  • RetrieveTransactionListRequest → GET /transactions

Nested resources (require parent ID + QueryParams):

  • RetrieveEmvKeyListRequest → GET /terminals/{id}/emv-keys
  • RetrievePaymentLinkEventListRequest → GET /payment-links/{id}/events
  • RetrieveProvisioningCodeListRequest → GET /terminals/{id}/provisioning-codes
  • RetrieveShopperStoredCardsRequest → GET /shoppers/{id}/stored-cards
  • RetrieveTotalAdjustmentListRequest → GET /transactions/{id}/total-adjustments

See docs/examples/ for more examples.

Features

Based on the Elavon Payment Gateway API version 2025-10-01, this package supports:

Resources

  • Merchants
  • Processor Accounts
  • Terminals
  • Accounts
  • Orders
  • Payment Links & Payment Link Events
  • Payment Sessions
  • Payment Method Links & Payment Method Sessions
  • Apple Pay Payment Sessions
  • Hosted Cards & Hosted ACH Payments
  • HSM Cards
  • Forex Advices
  • Transactions
  • Apple Pay, Google Pay, and Paze Payments
  • Surcharge & Refund Surcharge Advices
  • Batches & Manual Batches
  • Shoppers
  • Stored Cards & Stored ACH Payments
  • Plans & Subscriptions
  • Notifications
  • Total Adjustments

API Endpoints

The Elavon Payment Gateway API base URLs:

  • EU Sandbox: https://uat.api.converge.eu.elavonaws.com
  • EU Production: https://api.eu.convergepay.com
  • US Sandbox: https://uat.api.convergepay.com
  • US Production: https://api.convergepay.com

Development

Testing

composer test

Code Quality

composer phpstan
composer cs-check
composer cs-fix

License

MIT License. See LICENSE file for details.

Contributing

Contributions are welcome. Please ensure all tests pass and code follows PSR-12 coding standards.

Namespace

All classes are under the Academe\Elavon\Epg\Psr7\ namespace.

academe/elavon-epg-psr7 适用场景与选型建议

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

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

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

围绕 academe/elavon-epg-psr7 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-23