codevirtus/pesepay 问题修复 & 功能扩展

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

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

codevirtus/pesepay

Composer 安装命令:

composer require codevirtus/pesepay

包简介

Pesepay online payment integration package

README 文档

README

A simple PHP SDK for integrating PesePay payments into your application.

Installation

Install the package via Composer:

composer require codevirtus/pesepay

Getting Started

1. Import the SDK

require_once 'vendor/autoload.php';

use Codevirtus\Payments\Pesepay;

2. Initialize the Client

Create a new Pesepay instance using the credentials provided by PesePay.

$pesepay = new Pesepay(
    "INTEGRATION_KEY",
    "ENCRYPTION_KEY"
);

3. Configure Callback URLs

Set the URLs that PesePay will use after processing a payment.

$pesepay->returnUrl = "https://example.com/gateway/return";
$pesepay->resultUrl = "https://example.com/gateway/result";
  • returnUrl – Where the customer is redirected after completing payment.
  • resultUrl – Endpoint that receives the payment result.

Seamless Payments

Seamless payments allow customers to complete payment directly within your application.

Step 1: Create a Payment

Note: Either the customer's email address or phone number must be provided.

$payment = $pesepay->createPayment(
    'CURRENCY_CODE',
    'PAYMENT_METHOD_CODE',
    'CUSTOMER_EMAIL',          // Optional
    'CUSTOMER_PHONE_NUMBER',   // Optional
    'CUSTOMER_NAME'            // Optional
);

Step 2: Provide Required Payment Fields

Different payment methods require different fields.

Visa

$requiredFields = [
    "creditCardExpiryDate" => "09/23",
    "creditCardNumber" => "4867960000005461",
    "creditCardSecurityNumber" => "608"
];

Mobile Money (EcoCash, InnBucks, etc.)

$requiredFields = [
    "customerPhoneNumber" => "0712345678"
];

Step 3: Submit the Payment

$response = $pesepay->makeSeamlessPayment(
    $payment,
    'Online Transaction',
    $AMOUNT,
    $requiredFields,
    'MERCHANT_REFERENCE' // Optional
);

if ($response->success()) {

    // Store these values to check payment status later
    $referenceNumber = $response->referenceNumber();
    $pollUrl = $response->pollUrl();

    // Transaction details
    $amount = $response->amount();
    $currencyCode = $response->currencyCode();
    $transactionFee = $response->transactionServiceFee();
    $metaData = $response->transactionMetadata();

    // Full API response
    $data = $response->rawData();

    // InnBucks-specific data
    $code = $response->metadataCode();
    $qrcode = $response->metadataQrCode();

} else {

    $errorMessage = $response->message();

}

Redirect Payments

Redirect payments send the customer to the PesePay checkout page to complete payment.

Step 1: Create a Transaction

$transaction = $pesepay->createTransaction(
    $amount,
    'CURRENCY_CODE',
    'PAYMENT_REASON',
    'MERCHANT_REFERENCE' // Optional
);

Step 2: Initiate the Transaction

$response = $pesepay->initiateTransaction($transaction);

if ($response->success()) {

    // Save these values for future payment status checks
    $referenceNumber = $response->referenceNumber();
    $pollUrl = $response->pollUrl();

    // Redirect the customer
    $redirectUrl = $response->redirectUrl();

} else {

    $errorMessage = $response->message();

}

Checking Payment Status

You can verify a payment using either the transaction reference number or the poll URL returned when the payment was created.

Option 1: Check by Reference Number

$response = $pesepay->checkPayment($referenceNumber);

if ($response->success()) {

    if ($response->paid()) {
        // Payment successful
    }

} else {

    $errorMessage = $response->message();

}

Option 2: Check by Poll URL

$response = $pesepay->pollTransaction($pollUrl);

if ($response->success()) {

    if ($response->paid()) {
        // Payment successful
    }

} else {

    $errorMessage = $response->message();

}

Response Methods

Most SDK responses provide the following helper methods:

Method Description
success() Returns true if the request completed successfully.
message() Returns the error message if the request failed.
referenceNumber() Returns the PesePay transaction reference.
pollUrl() Returns the polling URL used to check payment status.
amount() Returns the transaction amount.
currencyCode() Returns the transaction currency.
transactionServiceFee() Returns the service fee charged.
transactionMetadata() Returns additional transaction metadata.
rawData() Returns the complete API response.
metadataCode() Returns the InnBucks payment code (where applicable).
metadataQrCode() Returns the InnBucks QR code (where applicable).
redirectUrl() Returns the checkout URL for redirect payments.
paid() Returns true if the payment has been completed successfully.

codevirtus/pesepay 适用场景与选型建议

codevirtus/pesepay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.16k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 10 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「codevirtus」 「pesepay」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 codevirtus/pesepay 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 codevirtus/pesepay 我们能提供哪些服务?
定制开发 / 二次开发

基于 codevirtus/pesepay 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

与 codevirtus/pesepay 相关的其它包

同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:

统计信息

  • 总下载量: 9.16k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-22