定制 kajuzi/paynow-laravel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

kajuzi/paynow-laravel

Composer 安装命令:

composer require kajuzi/paynow-laravel

包简介

Laravel package for the Paynow Zimbabwe payment API

README 文档

README

Laravel package for integrating with the Paynow Zimbabwe payment API.

Disclaimer: This is an unofficial community package and is not affiliated with or endorsed by Paynow Zimbabwe.

Requirements

  • PHP 8.2+
  • Laravel 11 or 12
  • ext-mbstring

Installation

composer require kajuzi/paynow-laravel

Publish the configuration file:

php artisan vendor:publish --tag=paynow-config

Add your credentials to .env:

PAYNOW_ID=your-integration-id
PAYNOW_KEY=your-integration-key
PAYNOW_RETURN_URL="${APP_URL}/paynow/return"
PAYNOW_RESULT_URL="${APP_URL}/paynow/webhook"
PAYNOW_BASE_URL=https://www.paynow.co.zw/interface

Usage

Web checkout

use Paynow\Facades\Paynow;

$payment = Paynow::createPayment('Invoice 35', 'user@example.com')
    ->addItem('Bananas', 2.50)
    ->addItem('Apples', 3.40);

$response = Paynow::send($payment);

if ($response->success()) {
    return redirect()->away($response->redirectUrl());
    // or: return $response->redirect();
}

Save the poll URL if you want to check payment status later:

$pollUrl = $response->pollUrl();

Per-transaction return URLs

Override config URLs at runtime when you need query parameters on the return URL:

Paynow::setReturnUrl(route('paynow.return', ['order' => $order->id]));
Paynow::setResultUrl(route('paynow.webhook'));

Mobile express (EcoCash / OneMoney)

use Paynow\Enums\MobileMoneyMethod;
use Paynow\Facades\Paynow;

$payment = Paynow::createPayment('Invoice 35', 'user@example.com')
    ->addItem('Sadza and Beans', 1.25);

$response = Paynow::sendMobile($payment, '0777777777', MobileMoneyMethod::Ecocash);

if ($response->success()) {
    $instructions = $response->instructions();
    $pollUrl = $response->pollUrl();
}

Poll transaction status

$status = Paynow::poll($pollUrl);

if ($status->paid()) {
    // Payment completed
}

Webhook handling

Define your own route and verify the callback with the package:

use Illuminate\Http\Request;
use Paynow\Facades\Paynow;

Route::post('/paynow/webhook', function (Request $request) {
    $status = Paynow::processWebhook($request);

    if ($status->paid()) {
        // Fulfill the order
    }

    return response('OK', 200);
});

The webhook handler always verifies the Paynow hash using POST body fields only (query parameters are ignored).

Dependency injection

You can also inject the client contract directly:

use Paynow\Contracts\PaynowClient;

public function checkout(PaynowClient $paynow)
{
    $payment = $paynow->createPayment('Invoice 35', 'user@example.com')
        ->addItem('Bananas', 2.50);

    return $paynow->send($payment);
}

Migration from paynow/php-sdk (Paynow's Official SDK)

Official SDKThis package
Paynow\Payments\PaynowPaynow\PaynowClient or Paynow facade
FluentBuilderPaynow\Data\Payment
$payment->add()$payment->add() (single or batch array) or addItem()
$payment->setDescription()$payment->setDescription() or description()
InitResponsePaynow\Responses\InitiatePaymentResponse
StatusResponsePaynow\Responses\PaymentStatusResponse
processStatusUpdate()processWebhook($request)
pollTransaction($url)poll($url)
Constructor credentialsconfig/paynow.php
setReturnUrl() / setResultUrl()Same methods on the client
$response->redirectLink()redirectUrl() (alias: redirectLink())
$response->redirect()redirect() returns a RedirectResponse
$response->success (property)success() method
$response->errorerrors() (string) or errors(false) (array)
send(array $payment)Not supported — use Payment DTO

Example migration:

// Before
$paynow = new Paynow\Payments\Paynow($id, $key, $returnUrl, $resultUrl);
$payment = $paynow->createPayment('Invoice 35', 'user@example.com');
$payment->add('Bananas', 2.50);
$response = $paynow->send($payment);
$response->redirect();

// After
$payment = Paynow::createPayment('Invoice 35', 'user@example.com')
    ->add('Bananas', 2.50);
$response = Paynow::send($payment);
return $response->redirect();

Behavioral notes

  • Outbound request hashes use the same field order and SHA-512 algorithm as the legacy SDK.
  • Init/poll responses verify the hash when present; webhooks always require a valid hash.
  • amount() returns -1.0 when missing, matching legacy behavior.
  • Unknown status values are returned as lowercased strings (not forced into an enum).

Testing

composer install
./vendor/bin/phpunit

License

This package is open-source software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固