承接 blessdarah/php-campay 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

blessdarah/php-campay

Composer 安装命令:

composer require blessdarah/php-campay

包简介

PHP package wrapper for campay momo integration

README 文档

README

This is a php wrapper for the campay API that enables a seemless integration of momo with PHP and Campay.

Requirements

This package works as from php@7.4 and above. Ensure that you have the latest version of php installed.

How to install this package

To install this package, run:

composer require blessdarah/php-campay

Usage

The package automatically manages your tokens for all transactions with campay.

Configuration

This packages uses the dotenv package and thus if you're not using something like laravel which automatically loads env variables, you can set it up like this:

  1. Create a .env file in the root of your project if you don't already have one
  2. Copy your application username and password from your campay dashboard and add them like this:
CAMPAY_USERNAME="YOUR CAMPAY APPLICATION USERNAME"
CAMPAY_PASSWORD="YOUR CAMPAY APPLICATION PASSWORD"
  1. In your index.php file or your root application entry point, you have to load up the dotenv package
require_once "vendor/autoload.php";
use BlessDarah\PhpCampay\Campay;
use Dotenv\Dotenv;

$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();

If you're not using composer, you can ignore the above steps and set up your .env vars using the php global $_ENV to setup your campay configurations in the location you want as follows:

$_ENV['CAMPAY_USERNAME']="YOUR CAMPAY APPLICATION USERNAME"
$_ENV['CAMPAY_PASSWORD']="YOUR CAMPAY APPLICATION PASSWORD"

Configure campay base url

$_ENV['CAMPAY_BASE_URL']="https://demo.campay.net/api/" # for local testing or
$_ENV['CAMPAY_BASE_URL']="https://campay.net/api/" # for production

Remark: You should make sure that you don't expose your config variables online as it will be a potential security issue for your application

Collect payment

use BlessDarah\PhpCampay\Campay;

$campay = new Campay();

$data = array(
    "amount" => 3,
    "currency" => "XAF",
    "from" => "237******",
    "description" => "test payment"
);
$res = $campay->collect($data);
// handle your response data from here
echo $res;

Withdraw funds

For withdrawal, we use the withdraw function

use BlessDarah\PhpCampay\Campay;

$campay = new Campay();

$data = array(
    "amount" => 3,
    "currency" => "XAF",
    "to" => "237******",
    "description" => "test payment"
);
$res = $campay->withdraw($data);
echo $res;

The above response contains the info and the reference for your transaction that will enable you check its status using the getTransactionStatus function

Check transaction status

For checking transaction status after using the collect or the withdraw functions, you can pass the resulting reference key in order to check your transaction status

use BlessDarah\PhpCampay\Campay;

$campay = new Campay();

/*
* Suppose you have carried out a collection request from user then you can
* collection logic here
* /
$ref = $res->reference; // e.g: b1d44bc7-648d-451b-a3ef-c5807738ec82

$transaction_feedback = $campay->getTransactionStatus($ref) /* your reference code */

if($transaction_feedback->status == 'SUCCESSFUL')
{
    /* success logic here */
}

if($transaction_feedback->status == 'PENDING')
{
    /* Pending logic here */
}

if($transaction_feedback->status == 'FAILED')
{
    /* Erro logic here */
}

Get your application balance

use BlessDarah\PhpCampay\Campay;

$campay = new Campay();
$res = $campay->getAppBalance();

// handle your response data from here
echo $res;

Get transaction history with an interval

By default, your transaction history will return all your app's transactions for the past 7 days or past week

use BlessDarah\PhpCampay\Campay;

$campay = new Campay();
$res = $campay->transactionHistory();

// handle your response data from here
echo $res;

If you want the dates to be specific, you can pass your start and end dates like so:

$start_date = new Date("2022-06-13");
$end_date = new Date("2022-08-13");

$res = $campay->transactionHistory($start_date, $end_date);

Generate payment link

As per the campay documentation, you can generate a payment link or url that can be utilized for payments. Here's how you do it:

use BlessDarah\PhpCampay\Campay;

$campay = new Campay();

$params = [
    "amount" => 4,
    "currency" => "XAF",
    "description" => "Sample description",
    "first_name" =>  "John",
    "last_name" =>  "Doe",
    "email" => "example@mail.com",
    "external_reference" =>  "",
    "redirect_url" =>  "https://example.com",
    "failure_redirect_url" => "https://example.com",
    "payment_options" => "MOMO" // or CARD for credit card payments
];
$res = $campay->generatePaymentUrl($params);

// handle your response data from here
echo $res;

blessdarah/php-campay 适用场景与选型建议

blessdarah/php-campay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 130 次下载、GitHub Stars 达 5, 最近一次更新时间为 2022 年 09 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 blessdarah/php-campay 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-27