codelords/ssentezo-wallet

一个帮助将 ssentezo 钱包集成到您的 PHP 应用程序中的包

v2.0.02 2024-06-19 13:05 UTC

README

一个帮助将 ssentezo 钱包集成到您的 PHP 应用程序中的包

入门

  1. 创建 ssentezo 钱包账户

Ssentezo 钱包

安装

安装 ssentezo 钱包的推荐方式是通过 Composer

$ composer require codelords/ssentezo-wallet

ssentezo 钱包安装完成后,您可以将示例文件复制到项目根目录。

$ cp vendor/code-lords/ssentezo-wallet/resources/example.php .

进行交易

要进行交易,您只需创建一个 ssentezo 钱包实例即可

use Codelords\SsentezoWallet;

$username = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$password = "zzzzzzzzzzzzzzzzzzzzzzzzzzzz";
$wallet = new SentezoWallet($username, $password);

使用钱包对象,您可以轻松检查余额、进行存取款以及检查交易状态。

配置

在我们探讨如何进行交易之前,让我们先看看配置。

/**
 * Environment
 * You can choose which environment you are using your wallet.
 * There are two possibilites production and sandbox
 * For testing purposes always use sandbox to avoid making errors that may result int real
 * money losses.
 */
$wallet->setEnvironment("sandbox");


/**
 * Currency
 * You can also select a currency you want to use
 *
 */
$wallet->setCurrency("UGX");

以下是一个所有可能的配置及其各种操纵方法的列表。

存款

use Codelords\SsentezoWallet;

$wallet = new SsentezoWallet($username, $password);
$username =  "xxxxxxxxxxxxxxxxxxxxx";//Put here your API username
$password =  "xxxxxxxxxxxxxxxxxxxxx";//Put here your API password
$phone_number = "+256771234567";
$amount = 10000.00;
$transaction_ref = "xxx";//Some unique reference to the transaction
$narrative = "xxx"; //A description of the transaction
$successCallbackUrl = "https://example.com/success";//A call back once the transaction is successful
try {

    $ret = $wallet->deposit($phone_number,$amount,$transaction_ref,$narrative,$successCallbackUrl);
    //
}catch(\Exception $e){
    //Something wrong happened
    echo "Exception: ". $e->getMessage();
}

检查交易状态

$transaction_ref = "xxx";//The unique identifier of the transaction
$username =  "xxxxxxxxxxxxxxxxxxxxx";//Put here your API username
$password =  "xxxxxxxxxxxxxxxxxxxxx";//Put here your API password
$wallet = new SsentezoWallet($username, $password);

try {
    $response = $wallet->checkStatus($prn);//The response object has all the information about the transaction
    //You can then find the status
    switch ($response->status) {
        case "SUCCEEDED": // For success
            break;
        case "FAILED": //Failed the transaction 
            break;
        case "PENDING": //Still Pending
            break;
        case "INDETERMINATE": //As the name suggests 
            break;
        default:// WTF
    }
} catch (Exception $e) {
    //Something went wrong
    echo "Exception: ".$e->getMessage();
            
}

取款

use Codelords\SsentezoWallet;

$wallet = new SsentezoWallet($username, $password);
$username =  "xxxxxxxxxxxxxxxxxxxxx";//Put here your API username
$password =  "xxxxxxxxxxxxxxxxxxxxx";//Put here your API password
$phone_number = "+256771234567";
$amount = 10000.00;
$transaction_ref = "xxx";//Some unique reference to the transaction
$narrative = "xxx"; //A description of the transaction
$successCallbackUrl = "https://example.com/success";//A call back once the transaction is successful
 

try {

    $response = $wallet->withdraw($phone_number, $amount, $transaction_ref, $narrative, $successCallback);
    //
}catch(\Exception $e){
    //Something wrong happened
    echo "Exception: ". $e->getMessage();
}