Skip to content

The Intouch Payment Library is a PHP library that provides a simple interface for making payments with mobile money service providers that are supported by the Intouch platform. This library handles the complexities of interacting with the Intouch API, allowing you to focus on building your application.

License

Notifications You must be signed in to change notification settings

AlexNguetcha/intouch-api-wrapper

Repository files navigation

Intouch Payment Library

The Intouch Payment Library is a PHP library that provides a simple interface for making payments with mobile money service providers that are supported by the Intouch platform. This library handles the complexities of interacting with the Intouch API, allowing you to focus on building your application.

Installation

To install the Intouch Payment Library, you can use Composer, a package manager for PHP. Run the following command in your project directory:

composer require alex-nguetcha/intouch

Complete example

Here is an complete example of a use case

$intouch = Intouch::credentials(
    username: 'username',
    password: 'password',
    loginAgent: 'loginAgent',
    passwordAgent: 'passwordAgent',
    intouchId: 'passwordAgent'
)->callback('https://app.test/confirm-payment')
    ->amount(100)
    ->phone(6xxxxxx)
    ->operator('ORANGE')
    ->makeMerchantPayment(
        [
            "recipientEmail" => "john@example.com",
            "recipientFirstName" => "John",
            "recipientLastName" => "Doe",
        ]
    );


if ($intouch->isInitiated()) {
    // Your transaction has been initiated by intouch API
    // echo (string)($intouch->getResult()->getBody());
} else {
    // something went wrong
    // echo $intouch->getError()['request'];
    // echo $intouch->getError()['response'];
}

Usage

To use the Intouch Payment Library, you must first obtain credentials from the Intouch platform. These credentials include a username, password, login agent, password agent, and Intouch ID. You can then create an instance of the Intouch class, passing in your credentials:

use AlexNguetcha\Intouch\Intouch;

$intouch = Intouch::credentials(
    username: 'your-username',
    password: 'your-password',
    loginAgent: 'your-login-agent',
    passwordAgent: 'your-password-agent',
    intouchId: 'your-intouch-id'
);

Initiating a Payment

Once you have created an instance of the Intouch class, you can initiate a payment using the makeMerchantPayment method. This method takes an array of payment information, including the amount to be paid, the mobile money account to be debited, and the recipient information:

Before initiating a payment, you need to set the payment details using the following methods:

$intouch->amount(100); // Set the amount to be paid
$intouch->phone('1234567890'); // Set the mobile money account to be debited
$intouch->operator('MTN'); // Set the mobile money operator for the transaction
$intouch->callback('https://example.com/payment/callback');

Callbacks

Intouch sends a notification to your application when a payment is completed. You can set a callback URL using the callback method. This URL will be called by Intouch with a payload containing information about the completed payment:

$intouch->makeMerchantPayment([
    "recipientEmail" => "john@example.com",
    "recipientFirstName" => "John",
    "recipientLastName" => "Doe",
    "phone" => "1234567890",
    "amount" => 100,
    "operator" => "MTN",
    "reason" => "Payment for goods and services",
]);
$intouch->callback('https://your-app.com/intouch-callback');

Handling the Response

You can check if a payment was successfully initiated using the isInitiated method. If the payment was initiated, you can access the response using the getResult method. If something went wrong, you can access error information using the getError method:

if ($intouch->isInitiated()) {
    // Your transaction has been initiated by intouch API
    echo (string)($intouch->getResult()->getBody());
} else {
    // something went wrong
    // echo $intouch->getError()['request'];
    echo $intouch->getError()['response'];
}

Conclusion

The Intouch Payment Library provides a simple and convenient way to interact with the Intouch API and make mobile money payments. By following the steps outlined in this documentation, you can easily integrate mobile money payments into your PHP application.

About

The Intouch Payment Library is a PHP library that provides a simple interface for making payments with mobile money service providers that are supported by the Intouch platform. This library handles the complexities of interacting with the Intouch API, allowing you to focus on building your application.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages