Download the PHP package xfix/xfix-pay without Composer

On this page you can find all versions of the php package xfix/xfix-pay. 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 xfix-pay

XfixPay PHP SDK

A unified PHP SDK for integrating with multiple payment gateways through a consistent, extensible API.

XfixPay currently supports M-Pesa in Kenya, with additional payment providers planned, including PayPal, Stripe, bank transfers, and other payment services.

Features


Requirements


Installation

Install XfixPay using Composer:

Composer will automatically install the required dependencies.


Configuration

XfixPay uses a shared client configuration while allowing each gateway to define its own credentials and settings.

Global Configuration

The global configuration can be shared across gateways.

M-Pesa Configuration

Where:

Configuration Description
consumer_key Safaricom Daraja consumer key
consumer_secret Safaricom Daraja consumer secret
passkey Lipa Na M-Pesa Online passkey
shortcode PayBill or Till number
initiator Initiator name for B2C, Balance, and Reversal
initiator_password Initiator password
environment sandbox or live
cert_path Path to the Safaricom.cer certificate

The cert_path is required only for:

The certificate can also be configured after creating the gateway:


M-Pesa Usage

1. STK Push

Initiate a Lipa Na M-Pesa Online payment request.

The response contains the M-Pesa checkout request identifier.

Store the CheckoutRequestID if you need to query the transaction status later.

Important Parameters


2. Query STK Push Status

Check the status of an STK Push transaction using its CheckoutRequestID.

The returned response should be evaluated according to the M-Pesa API response codes.


3. Register C2B URLs

Register the validation and confirmation URLs used for Customer-to-Business payments.

Supported response types include:

or:

The validation endpoint can be used to validate incoming transactions before confirmation.


4. B2C Payment

Send money from a business M-Pesa account to a customer's M-Pesa account.

Supported commands include:

The occasion parameter is optional.


5. Account Balance Inquiry

Retrieve the balance of an M-Pesa shortcode.

When partyA is null, the configured shortcode is used.

Supported identifier types include:

Type Description
1 MSISDN
2 Till Number
4 PayBill

6. Transaction Reversal

Reverse a completed M-Pesa transaction using its M-Pesa receipt number.

Use transaction reversals carefully and only when the transaction meets Safaricom's reversal requirements.


Security Certificate

Safaricom requires the initiator password used by the B2C, Balance Inquiry, and Reversal APIs to be encrypted using Safaricom's public certificate.

The certificate is normally provided as a .cer file.

Example:

XfixPay handles the following automatically:

  1. Loads the Safaricom certificate.
  2. Encrypts the initiator password.
  3. Reuses the encrypted credential for subsequent requests within the gateway instance.

The SDK does not bundle Safaricom certificates.

If the certificate path is missing, invalid, or unreadable, XfixPay throws an MpesaException with a descriptive error message.


Error Handling

M-Pesa operations may throw MpesaException for errors such as:

Handle exceptions using try/catch:

Applications should log relevant error information without exposing credentials or other sensitive data.


Testing

Run the PHPUnit test suite with:

The SDK is designed to support HTTP client mocking, allowing unit tests to run without making real requests to payment providers.

Integration tests can be used separately for environments where real API credentials are available.


Gateway Architecture

XfixPay is designed around an extensible gateway architecture.

Each payment provider is implemented as an independent gateway while sharing common infrastructure through the main client.

Example:

Future gateways will follow the same pattern:

This allows applications to integrate multiple payment providers without having to learn a completely different SDK structure for each provider.


Planned Gateways

The following gateways are planned for future releases:

Gateway availability depends on implementation status and the relevant provider's API requirements.


Project Structure


Key Components

Component Purpose
src/XfixPayClient.php Main SDK entry point and gateway factory
src/GatewayInterface.php Common contract for payment gateways
src/AbstractGateway.php Shared gateway functionality
src/Mpesa/MpesaGateway.php M-Pesa API implementation
src/Mpesa/MpesaAuth.php M-Pesa OAuth authentication and token caching
src/Mpesa/MpesaConfig.php M-Pesa configuration container
src/Exception/MpesaException.php M-Pesa-specific exception
src/Mpesa/certs/ Optional certificate directory for local development
examples/ Common integration examples
tests/ Unit and integration tests
docs/ Extended technical documentation

Gateway Isolation

Each payment provider is kept within its own namespace and directory.

For example:

This keeps provider-specific authentication, configuration, exceptions, and API implementations isolated from one another.


Certificate Handling

The SDK does not include payment-provider certificates.

For local development, users may optionally place their own certificates under:

However, production applications should preferably store certificates outside the source repository and reference them through configuration or environment variables.

For example:

Never commit private credentials, certificates, API secrets, or production configuration to source control.


Contributing

Contributions are welcome.

Before submitting a pull request:

  1. Follow PSR-12 coding standards.
  2. Add or update tests for changed functionality.
  3. Ensure the PHPUnit test suite passes.
  4. Keep gateway-specific logic isolated within its gateway namespace.
  5. Do not commit credentials, certificates, tokens, or other secrets.

Please open an issue before making substantial architectural changes.


License

XfixPay is released under the MIT License.

See the LICENSE file for the full license text.


All versions of xfix-pay with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
guzzlehttp/guzzle Version ^7.0
ext-json Version *
ext-openssl Version *
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 xfix/xfix-pay contains the following files

Loading the files please wait ...