Download the PHP package ttpryg/payment-engine without Composer

On this page you can find all versions of the php package ttpryg/payment-engine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package payment-engine

PaymentEngine Library (ttpryg/payment-engine)

ttpryg/payment-engine is a production-ready, framework-agnostic standalone PHP 8.1+ Payment Engine designed to manage payment lifecycles, polymorphic payable/payer references, gateway abstraction, idempotent webhook processing, partial/full refunds, and append-only audit histories without coupling to any specific framework or external domain.


🌟 1. Introduction

In modern microservices and modular monolithic architectures, handling payments requires strict separation of domain boundaries. A Payment Engine must be responsible for orchestrating payment attempts, validating state transitions, guaranteeing idempotency during webhook retries, and recording immutable audit logsβ€”without possessing hardcoded dependencies on orders, shopping carts, product catalogs, or specific third-party payment gateway SDKs.

ttpryg/payment-engine decouples payment processing via a clean driver/adapter pattern (PaymentGatewayInterface) and generic references (PayableReference and PayerReference).


πŸš€ 2. Features


πŸ“¦ 3. Installation

Install via Composer:


🧬 4. Domain Model

Value Objects

Entities

  1. Payment: Core aggregate root representing the payment record, containing monetary balances (amount, fee, totalAmount, paidAmount, refundedAmount), status, and metadata.
  2. PaymentAttempt: Log of each payment attempt made against a gateway (gateway_provider, transaction_reference, status, raw request/response payloads).
  3. PaymentRefund: Detailed record of full or partial refunds issued against a completed payment.
  4. PaymentHistory: Immutable append-only audit trail capturing every status transition or webhook occurrence.
  5. WebhookEvent: Audit and deduplication log capturing inbound webhook deliveries with SHA-256 fingerprinting.

πŸ”„ 5. Payment Lifecycle & State Machine


πŸ”Œ 6. Gateway Driver Architecture

To add a new payment gateway (such as Midtrans, Xendit, Stripe, or DOKU), implement PaymentGatewayInterface:

Register drivers using GatewayManager:


πŸ›‘οΈ 7. Idempotent Webhook Processing

Webhooks sent by gateways are often redelivered multiple times. WebhookProcessorService prevents duplicate balance updates and duplicate domain events using:

  1. Gateway Event ID: Tracks unique delivery IDs supplied by the gateway.
  2. Payload Fingerprint: Computes SHA-256 hashes of the payload:

If a webhook with the same event_id or payload_fingerprint has already been processed, it returns immediately without firing duplicate events or inserting duplicate history entries.


πŸ’° 8. Partial & Full Refunds

Refunds are processed through PaymentRefundService:

If a refund request exceeds the remaining refundable amount, a RefundAmountExceededException is thrown.


πŸ—„οΈ 9. Database Schema

Run the SQL script from database/schema.sql:


πŸš€ 10. Quick Usage Example


πŸ§ͺ 11. Testing

Run tests with PHPUnit:

Or using Docker Compose:


πŸ“„ 12. License

MIT License.


All versions of payment-engine with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ttpryg/event-dispatcher Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ttpryg/payment-engine contains the following files

Loading the files please wait ...