xente/xentepayment-php-sdk

官方Xente支付API的PHP包装器

1.2 2020-01-10 14:49 UTC

This package is auto-updated.

Last update: 2024-09-11 00:38:00 UTC


README

安装

您可以通过Composer安装,运行以下命令

composer require xente/xentepayment-php-sdk

使用方法

使用SDK编写应用程序

  • 注册开发者账户,并在Xente开发者门户获取您的apikey。

  • 安装后,您需要要求Composer的自动加载器

    require_once('vendor/autoload.php');
    
  • 从XentePaymentSDK命名空间引入XentePayment类

    use XentePaymentSDK\XentePayment;
    
  • 创建认证凭证,参数为(apikey、密码和模式)。

  • 创建认证凭证参数

  $apikey = '6A19EA2A706041A599375CC95FF08809';
  $password = 'Demo123456';
  $mode = 'sandbox'; // 'production' 
  • 使用上述认证凭证初始化XentePayment类
  $xentePaymentGateway = new XentePayment($apikey, $password, $mode);
  • 创建交易请求关联数组,元数据是可选参数,customerReference是交易发起时的电话号码
  $transactionRequest = [
                          'paymentProvider' => 'MTNMOBILEMONEYUG',
                          'amount' => '50000',
                          'message' => 'Web Development Ebook',
                          'customerId' => 'string',
                          'customerPhone' => '256757476805',
                          'customerEmail' => 'customer1@gmail.com',
                          'customerReference' => '256782872845',
                          'batchId' => 'batch001',
                          'requestId' => md5(time()),
                          'metadata' => 'Extra information about the transaction'
                        ];
  • 使用上述交易请求创建交易
 $transactionProcessingResponse = $xentePaymentGateway
                                  ->transactions
                                  ->createTransaction($transactionRequest);
 
 print_r($transactionProcessingResponse);

  • 使用特定交易ID获取交易详情
$transactionId = '9F38AB020C394EA5BC642C25A5CB16BF-256784378515';

$transactionDetailsResponse = $xentePaymentGateway
                             ->transactions
                             ->getTransactionDetailsById($transactionId);
print_r($transactionDetailsResponse);

  • 使用请求ID获取交易详情
$transactionDetailsResponse2 = $xentePaymentGateway
                                ->transactions
                                ->getTransactionDetailsByRequestId("4a651febdb515cd6ba02b00ab3c6dd61");
print_r($transactionDetailsResponse2);
  • 通过账户ID获取账户详情
  $accountId = '256784378515';
  $accountDetailsResponse = xentePaymentGateway
                            ->accounts
                            ->getAcountDetailsById($accountId);

  print_r($accountDetailsResponse);
  • 列出所有支付提供者
$paymentProvidersResponse = $xentePaymentGateway
                            ->paymentProviders
                            ->getAllPaymentProviders();
print_r($paymentProvidersResponse);

贡献

  • 如果您想贡献,请分支仓库并发送pull请求。

重构团队Xentes

  1. Olive Nakiyemba
  2. Kintu Declan Trevor
  3. Oketayot Julius Peter