定制 hydrogenafrica/hydrogenpay-ci4 二次开发

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

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

hydrogenafrica/hydrogenpay-ci4

最新稳定版本:v1.0.1

Composer 安装命令:

composer require hydrogenafrica/hydrogenpay-ci4

包简介

Hydrogenpay SDK integration for CodeIgniter 4 applications

README 文档

README

Hydrogenpay PHP SDK for CodeIgniter 4 makes it easy to connect your apps to the Hydrogenpay APIs.
It simplifies integration, so you can quickly collect payments, handle payouts, and more — all in just a few lines of code.

Features

Operation Description
Single Payment Create a one-time payment request using either card or bank transfer.
Recurring Payment Set up a subscription-based payment request for card payments.
Cancel Recurring Cancel a recurring transaction or deactivate a card token associated with a recurring payment.
Simulate Transfer To test the bank transfer functionality during the development phase of integrating the Payment Gateway.
Initiate Transfer Generate unique account details to receive transfer-only payment requests.
Payment Confirmation Confirm and validate the status of a completed card or transfer payment.
Payment Webhook The webhook allows you to receive instant notifications about payment status from the payment gateway.

Table of Contents

  1. Requirements
  2. Installation
  3. Usage
  4. Contributing
  5. License
  6. API References

Requirements

Installation

Install via Composer:

composer require hydrogenafrica/hydrogenpay-ci4

Then copy the provided .env.example file to .env and update with your Hydrogenpay credentials:

cp .env.example .env

Example .env settings:

LIVE_API_KEY=SK_LIVE_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
SANDBOX_KEY=PK_TEST_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
MODE=TEST
  • LIVE_API_KEY: Your HydrogenPay live API key obtained from the dashboard. (Required)
  • SANDBOX_KEY: Your HydrogenPay sandbox API key obtained from the dashboard. (Required)
  • MODE: Defines the environment mode. Set to LIVE to use the LIVE_API_KEY or TEST to use the SANDBOX_KEY. (Required)

Usage

Single Payment

Create a one-time payment request using either card or bank transfer.

First, import the class:

use HydrogenAfrica\HydrogenpayCi4\Hydrogenpay\CollectPayment;

Then initiate a payment:

 $data = [
            'amount'          => 50,
            'customer_name'   => 'Dev Test',
            'customer_email'  => 'devtest@randomuser.com',
            'currency'        => 'NGN',
            'description'     => 'test desc',
            'meta'            => 'test meta',
            'callback'        => base_url('verify'), // must match your app's route
        ];

        # return CollectPayment::standard($data); 
        $result = CollectPayment::recurring($data); // get JSON string
        $decoded = json_decode($result);

        echo "\n==== Raw decoded response ====\n";
        var_dump($decoded);

Recurring Payment

Set up a subscription-based payment request for card payments.

First, import the class:

use HydrogenAfrica\HydrogenpayCi4\Hydrogenpay\CollectPayment;
$data = [
            'amount'          => 50,
            'customer_name'   => 'Dev Test',
            'customer_email'  => 'devtest@randomuser.com',
            'currency'        => 'NGN',
            'description'     => 'Weekly subscription',
            'meta'            => 'subscription_id:5678',
            'callback'        => base_url('verify'), // must match your app's route
            'frequency'       => 1,
            'is_recurring'    => true,
            'end_date'        => '2025-08-14T23:59:59Z',
        ];


        return CollectPayment::recurring($data);

Cancel Recurring

Cancel a recurring transaction or deactivate a card token associated with a recurring payment.

First, import the class:

use HydrogenAfrica\HydrogenpayCi4\Hydrogenpay\CollectPayment;
        $transactionRef = '36934683_76927e4cf6'; // Replace this with a real transactionRef

        if (empty($transactionRef)) {
            $this->fail('transactionRef is empty. Please replace with a real transactionRef to test cancelRecurring.');
        }

        $result = CollectPayment::cancelRecurring([
            'transactionRef' => $transactionRef,
            'token' => '2c382ed1-b5e5-4050-81fb-1b4d61443429',
        ]);

        $decoded = json_decode($result);

        echo "\n==== Cancel Recurring Response ====\n";
        var_dump($decoded);

Initiate Transfer

Generate unique account details to receive transfer-only payment requests.

First, import the class:

use HydrogenAfrica\HydrogenpayCi4\Hydrogenpay\CollectPayment;
        $data = [
            'amount'         => 50,
            'customer_name'  => 'Dev Test',
            'email'          => 'devtest@randomuser.com',
            'currency'       => 'NGN',
            'description'    => 'Bank transfer test',
            'meta'           => 'order_id:1234',
            'callback'       => base_url('verify'),
        ];

        $result = CollectPayment::bankTransfer($data);
        $decoded = json_decode($result);

        echo "\n==== Bank Transfer Response ====\n";
        var_dump($decoded);

Simulate Transfer

To test the bank transfer functionality during the development phase of integrating the Payment Gateway. Developers are required to select the bank transfer method at the payment checkout stage before making the request

First, import the class:

use HydrogenAfrica\HydrogenpayCi4\Hydrogenpay\CollectPayment;
         $data = [
            'clientTransactionRef' => '36934683_774526591e', // A unique trax ref for the client’s transaction
            'currency'             => 'NGN',
            'amount'               => 50,
        ];

        $result = CollectPayment::simulateBankTransfer($data);
        $decoded = json_decode($result);

        echo "\n==== Raw decoded response ====\n";
        var_dump($decoded);

Payment Confirmation

Confirm and validate the status of a completed card or transfer payment.

First, import the class:

use HydrogenAfrica\HydrogenpayCi4\Hydrogenpay\CollectPayment;
   
        $transactionRef = '36934683_76927e4cf6'; // Replace with a real transaction ref

        try {
            $verification = Verification::transaction($transactionRef);

            // Dump some fields so you can see
            echo "\nVerified Transaction Ref: " . $verification->transactionRef() . "\n";
            echo "Status: " . $verification->status() . "\n";
            echo "Amount: " . $verification->amount() . "\n";

        } catch (Exception $e) {
            // Fail the test with the exception message
            $this->fail('Verification failed: ' . $e->getMessage());
        }

Payment Webhook

The webhook allows you to receive instant notifications about payment status from the payment gateway.

First, import the class:

use HydrogenAfrica\HydrogenpayCi4\Hydrogenpay\CollectPayment;
   
   //Verify Webhook
if (Webhook::verifyWebhook())
   {
      // Continue reading the webhook data
      Webhook::data()->status();

   }

API References

Contributing

Feel free to add more test cases, edge scenarios, or submit improvements! Pull requests are welcome.

License

© HydrogenPay – All rights reserved.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-16