alex-nguetcha/intouch

Intouch支付库是一个PHP库,它提供了一个简单的接口,用于通过Intouch平台支持的手机钱包服务提供商进行支付。该库处理与Intouch API交互的复杂性,让您能够专注于构建您的应用程序。

1.0.2 2023-03-21 11:56 UTC

This package is auto-updated.

Last update: 2024-09-19 12:19:48 UTC


README

Intouch支付库是一个PHP库,它提供了一个简单的接口,用于通过Intouch平台支持的手机钱包服务提供商进行支付。该库处理与Intouch API交互的复杂性,让您能够专注于构建您的应用程序。

安装

要安装Intouch支付库,您可以使用Composer,PHP的包管理器。在您的项目目录中运行以下命令

composer require alex-nguetcha/intouch

完整示例

以下是一个用例的完整示例

$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'];
}

用法

要使用Intouch支付库,您必须首先从Intouch平台获取凭证。这些凭证包括用户名、密码、登录代理、密码代理和Intouch ID。然后,您可以通过传递凭证创建一个Intouch类的实例

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'
);

启动支付

一旦创建了Intouch类的实例,您就可以使用makeMerchantPayment方法启动支付。此方法接受一个包含付款信息的数组,包括付款金额、要扣除的手机钱包账户和收款人信息

在启动支付之前,您需要使用以下方法设置付款详情

$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');

回调

当支付完成时,Intouch会向您的应用程序发送通知。您可以使用callback方法设置回调URL。Intouch将调用此URL,并带有包含完成支付信息的有效负载

$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');

处理响应

您可以使用isInitiated方法检查是否成功启动了支付。如果启动了支付,您可以使用getResult方法访问响应。如果出现问题,您可以使用getError方法访问错误信息

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'];
}

结论

Intouch支付库提供了一个简单便捷的方式与Intouch API交互并执行手机钱包支付。通过遵循本文档中的说明,您可以轻松地将手机钱包支付集成到PHP应用程序中。