Download the PHP package shwary/php-sdk without Composer

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

Shwary PHP SDK

PHP Version PHPStan

Official PHP SDK for the Shwary API - Mobile Money Payments for DRC, Kenya, and Uganda.


πŸ“‹ Table of Contents


🎯 Introduction

What is Shwary?

Shwary is a Mobile Money payment platform that enables merchants to accept payments from:

What does this SDK do?

This SDK allows you to easily integrate Shwary into your PHP application to:

How does a Mobile Money payment work?


πŸ“¦ Requirements

Before you begin, make sure you have:

Technical Requirements

Check your PHP version

Shwary Account

πŸ’‘ Where to find your credentials?
Log in to your Shwary Dashboard β†’ Settings β†’ API


πŸ”§ Installation

Step 1: Install the SDK via Composer

Open your terminal in your project folder and run:

Step 2: Verify the installation

Create a test file test-shwary.php:

Run it:


βš™οΈ Configuration

There are 3 ways to configure the SDK. Choose the one that suits your needs.

Method 1: Environment Variables (Recommended ⭐)

Why is this recommended? Your credentials are not in the code, which is more secure.

Step A: Create a .env file at the root of your project

Step B: Load the variables (if you're not using a framework)

Step C: Initialize the SDK


Method 2: Array Configuration

Useful if you store your configurations in a PHP file or database.


Method 3: Manual Configuration (Full Control)

For advanced developers who want full control.


πŸš€ Quick Start Guide

Your first payment in 5 minutes

Here's a complete, working example:

Expected output:


πŸ“š Detailed Usage

Payments by Country

πŸ‡¨πŸ‡© Payment in DRC (Democratic Republic of Congo)

⚠️ Important for DRC:

  • Minimum amount is 2901 CDF
  • Phone number must start with +243

πŸ‡°πŸ‡ͺ Payment in Kenya


πŸ‡ΊπŸ‡¬ Payment in Uganda


Generic Method with Country

If you want to handle multiple countries dynamically:


Using PaymentRequest (Advanced Control)

For full control over the payment request:


πŸ”” Handling Webhooks

What is a webhook?

A webhook is an automatic notification sent by Shwary to your server when a payment status changes (confirmed, failed, etc.).

Webhook Configuration

Step 1: Create an endpoint on your server

Step 2: Register the webhook URL

Configure the URL https://your-site.com/webhook.php in your Shwary Dashboard.


Parse a webhook manually

If you retrieve the payload differently (e.g., framework):


πŸ§ͺ Sandbox Mode (Testing)

Sandbox mode allows you to test without making real payments.

Enable sandbox mode

Make a sandbox payment

Sandbox vs Production differences

Aspect Sandbox Production
Real payment ❌ No βœ… Yes
Status Immediately completed pending then completed/failed
Webhooks Simulated Real
Money charged ❌ No βœ… Yes

⚠️ Error Handling

Exception Types

The SDK defines several error types to help you handle them:

Complete Error Handling Example

Common Error Codes

Code Meaning Recommended Action
400 Invalid request Check parameters
401 Unauthenticated Verify merchant_id and merchant_key
404 Resource not found The number is not registered
422 Validation failed Correct the sent data
500 Server error Retry or contact support
502 Gateway error Temporary issue, retry

🎨 Laravel Integration

Installation

Configuration

1. Create the configuration file

2. Add environment variables

3. Create a Service Provider

4. Register the provider

Using in a Controller

Webhook Controller

Routes


πŸ“– Complete Reference

Supported Countries

Constant Country Currency Dial Code Minimum Amount
Country::DRC DR Congo CDF +243 > 2900 CDF
Country::KENYA Kenya KES +254 > 0 KES
Country::UGANDA Uganda UGX +256 > 0 UGX

Transaction Statuses

Constant Value Description
TransactionStatus::PENDING pending Waiting for confirmation
TransactionStatus::COMPLETED completed Payment successful
TransactionStatus::FAILED failed Payment failed

Transaction Properties

Transaction Methods

Shwary Facade Methods


❓ FAQ & Troubleshooting

Frequently Asked Questions

Q: How can I test without making real payments?

A: Use sandbox mode by setting sandbox: true in your configuration.

Q: Why does my payment stay in "pending"?

A: The pending status means the customer hasn't confirmed on their phone yet. Wait for the confirmation webhook.

Q: How do I know if a payment was successful?

A: Check with $transaction->isCompleted() or wait for the webhook.

Q: What's the difference between pay() and payDRC()?

A: payDRC() is a shortcut for pay(..., Country::DRC). They do the same thing.

Common Errors

"Merchant ID is required"

"Amount must be greater than 2900 CDF for DRC"

"Phone number must start with +243 for DRC"

"Callback URL must use HTTPS"


πŸ§ͺ Tests

Run tests

Statistics


🀝 Contributing

Contributions are welcome! Here's how to proceed:

  1. Fork the repository
  2. Create a branch for your feature (git checkout -b feature/my-feature)
  3. Commit your changes (git commit -m 'Add my feature')
  4. Push to the branch (git push origin feature/my-feature)
  5. Open a Pull Request

Code Standards


πŸ“„ License

This project is licensed under the MIT License. See the LICENSE file for details.


πŸ“ž Support


Made with ❀️ by the Shwary Team


All versions of php-sdk with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
guzzlehttp/guzzle Version ^7.0
psr/log Version ^3.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 shwary/php-sdk contains the following files

Loading the files please wait ...