thulani/airtel-money-php-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thulani/airtel-money-php-sdk

Composer 安装命令:

composer require thulani/airtel-money-php-sdk

包简介

Airtel Money SDK for collection, disbursement and remmittance.

README 文档

README

AirtelMoneyPhpSdk

This is a PHP library for integrating with the Airtel Money Africa API.

Requirements

PHP 7.4 or higher
GuzzleHttp PHP library
PHP dotenv library

Installation

You can install the package via composer:

composer require thulani/airtel-money-php-sdk

Usage

Authorisation

Before you can make any API calls, you need to authorize your app:

$airtelMoney->authorize();

By default, this method will use the client ID and client secret provided when creating the AirtelMoney instance to obtain an access token using the client credentials grant. If you already have an access token, you can pass it as an argument:

$airtelMoney->authorize('your-access-token');

You can also provide a callback function that will be called after the access token is obtained:

$airtelMoney->authorize(null, function ($token) { // Do something with the token });

AirtelCollection Class

The AirtelCollection class provides methods for initiating a push request, requesting a refund, querying transaction status and processing reconciliations.

Initialize the class

use Thulani\AirtelMoneyPhpSdk\AirtelCollection;

$config = [ 'client_id' => 'your-client-id', 'client_secret' => 'your-client-secret', 'public_key' => 'your-public-key', 'currency' => 'your-currency-code', 'country' => 'your-country-code', 'env' => 'staging' // or 'production' ];

$airtel = new AirtelCollection($config);

Initiate USSD Push

initiateUssdPush($amount, $phoneNumber, $transactionId = null, $transactionRef = null, $currency = null, $country = null, $callback = null)

This method initiates an USSD push request.

$amount = 50; $phoneNumber = '712345678'; $transactionRef = 'trx-ref-1234'; // optional $transactionId = 'trx-id-1234'; // optional $currency = 'ZMW'; // optional $country = 'ZM'; // optional

$result = $airtel->initiateUssdPush($amount, $phoneNumber, $transactionId, $transactionRef, $currency, $country);

// If you want to pass in a callback function $airtel->initiateUssdPush($amount, $phoneNumber, $transactionId, $transactionRef, $currency, $country, function($result) { // Handle response });

Request Refund

try { $response = $airtelCollection->requestRefund( $transactionId, $country, $currency, function ($result) { // Do something with the result } ); } catch (\Exception $e) { // Handle error }

Query transaction Status

try { $response = $airtelCollection->queryTransactionStatus( $transactionId, $country, $currency, function ($result) { // Do something with the result } ); } catch (\Exception $e) { // Handle error }

Process Reconcilliation

$payload = '{"transaction": {"status": "SUCCESS", "transaction_reference": "abc123", "transaction_id": "12345", "msisdn": "26077XXXXXXX", "amount": "5000", "currency": "ZMW", "channel": "AIRTELMM", "narrative": "Payment for goods"}}';

$result = $airtelCollection->processReconciliation($payload, function ($transaction) { // Do something with the transaction });

Airtel Disbursement

use Thulani\AirtelMoneyPhpSdk\AirtelDisbursement;

// Your Airtel API credentials and other configuration options $config = [ 'client_id' => 'your_client_id', 'client_secret' => 'your_client_secret', 'public_key' => 'your_public_key', 'currency' => 'ZMW', 'country' => 'ZM', 'env' => 'production', ];

// Initialize the AirtelDisbursement object with the config options $airtelDisbursement = new AirtelDisbursement($config);

// Authorize using the authorize() method inherited from the AirtelService class $airtelDisbursement->authorize();

// Call the initiateDisbursement() method $phoneNumber = '2547xxxxxxxx'; $amount = 100; $transactionRef = 'ABC123'; $result = $airtelDisbursement->initiateDisbursement($phoneNumber, $amount, $transactionRef);

// Use the $result as needed

CallBacks

You can pass a callback function to any method to handle the response data.

function handleResponse($result) { // handle result data }

$result = $collection->initiateUssdPush($amount, $phoneNumber, $transactionId, $transactionRef, $currency, $country, 'handleResponse');

Licence

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 137
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-17