Skip to content

Commit

Permalink
Add PHP composer installation guide to library
Browse files Browse the repository at this point in the history
  • Loading branch information
blessedjasonmwanza committed Oct 21, 2024
1 parent 7836074 commit be7a30e
Showing 1 changed file with 111 additions and 0 deletions.
111 changes: 111 additions & 0 deletions php_usage_documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# MoneyUnify Library PHP Documentation

## Introduction

The **MoneyUnify** library provides an easy interface for integrating with the Money Unify API to process payments. This documentation will guide you through the installation process and demonstrate how to use the library effectively.

## Installation

1. **Install Composer** (if you haven’t already). Follow the [Composer installation guide](https://getcomposer.org/download/).
2. **Install the MoneyUnify Library** by adding it to your `composer.json`:

```bash
composer require blessedjasonmwanza/moneyunify
```

## Usage

### Basic Usage

To use the MoneyUnify library, follow these steps:

1. **Include the Autoload File**: This file is generated by Composer and will allow you to use the classes in your project.

2. **Create an Instance of the `MoneyUnify` Class**: You will need a unique identifier (MUID) for your Money Unify account.

3. **Call the `requestPayment` Method**: This method takes the payer's phone number and the amount to pay as parameters.

### Example Code

Here’s an example demonstrating how to use the MoneyUnify library:

```php
<?php

require 'vendor/autoload.php'; // Include Composer autoload

use Blessedjasonmwanza\MoneyUnify\MoneyUnify;

// Step 1: Create an instance of MoneyUnify with your MUID
$muid = 'your_unique_muid'; // Replace with your actual MUID (MoneyUnify ID / token)
$moneyUnify = new MoneyUnify($muid);

// Step 2: Call the requestPayment method
$payerPhoneNumber = '0xxxxxxxx'; // Replace with the payer's (or buyer of your product) phone number (10 digits phone number)
$amountToPay = '10'; // The amount to be paid

$response = $moneyUnify->requestPayment($payerPhoneNumber, $amountToPay);

// Step 3: Check the response
if ($response->isError) {
// Handle the error
echo "Error: " . $response->message . "\n";
echo "Console: " . ($response->console ?? 'No console message to debug') . "\n";
} else {
// Payment request was successful
echo "Success: " . $response->message . "\n";
echo "Data: " . json_encode($response->data) . "\n";
}
```

### Explanation of the Code

- **Line 1**: Loads Composer's autoload file, allowing you to use the MoneyUnify library.
- **Line 5**: Imports the `MoneyUnify` class from the `Blessedjasonmwanza\MoneyUnify` namespace.
- **Line 8**: Creates a new instance of the `MoneyUnify` class, passing in your unique MUID.
- **Line 12**: Calls the `requestPayment` method with the payer's phone number and the payment amount.
- **Lines 15-23**: Checks if there was an error in the response and handles it accordingly, or displays the success message.


### Example Successful Response

Here’s an example of a successful transaction response from the Money Unify API:

```json
{
"message": "Transaction successful",
"data": {
"amount": "5.00",
"customer_name": "Blessed Mwanza",
"customerMobileWallet": "0769641179",
"reference": "0762611179_1713450343",
"status": "successful"
},
"isError": false
}
```
## Conclusion

The MoneyUnify library simplifies the process of integrating with the Money Unify API. By following the steps outlined in this documentation, you can easily set up and make payment requests. For further assistance, feel free to reach out or check the official documentation for more advanced features.


# Author

👤 **Blessed Jason Mwanza** - [Buy him a Coffee](https://www.buymeacoffee.com/mwanzabj)

- LinkedIn: [Connect with Blessed on LinkedIn](https://www.linkedin.com/in/blessedjasonmwanza)

- Github : [@blessedjasonmwanza](https://github.com/blessedjasonmwanza)

- Twitter : [Follow Blessed Jason @mwanzabj](https://twitter.com/mwanzabj)

- Youtube : [Youtube](https://www.youtube.com/@blessedjasonmwanza)

# 🤝 Contributing

Contributions, issues, and feature requests are welcome!

Feel free to check the [issues page](https://github.com/blessedjasonmwanza/MoneyUnify/issues).
# Show your support

Give a ⭐️ if you like this project! or [Donate](https://www.buymeacoffee.com/mwanzabj)

0 comments on commit be7a30e

Please sign in to comment.