davidnsai/davidnsai-broadpay-php

这是一个用于Broadpay API的PHP库

v1 2024-02-13 11:55 UTC

This package is auto-updated.

Last update: 2024-09-10 08:33:21 UTC


README

这是一个用于Broadpay赞比亚金融科技API的PHP包。API允许商家将其网站和应用程序添加在线支付功能。API允许商家通过移动货币和借记/信用卡收款。此包简化了PHP Web应用程序的新手开发人员的集成过程。

安装

可以使用以下composer命令将此包安装到您的项目中

composer require davidnsai/davidnsai-broadpay-php

如果在安装过程中遇到任何错误,请运行以下命令

composer config minimum-stability dev
composer config prefer-stable true

上述命令将更改您项目中的composer.json中的最低稳定性

用法

目前,该包支持使用REST API从和向移动钱包收款和付款。它还支持创建托管结账链接。

托管支付

以下代码示例展示了如何创建托管结账链接:以下代码假定您正在使用具有自动加载功能的框架,如CodeIgniter或Laravel。

<?php
    namespace YourNamespace;
    use Broadpay\HostedPayments\Checkout;
    
    class YourClassNameHere 
    {    	    
	    public function paymentMethod()
	    {
    	    $checkout = new Checkout(
	    	    $public_key, //string
	    	    $transction_name, //string
	    	    $amount, //float
	    	    $currency, //string
	    	    $unique_merchant_reference, //string
	    	    $customer_email, //string
		    $customer_firstname, //string
		    $customer_lastname, //string
		    $customer_phone, //string
		    $customer_address, //string
		    $customer_city, //string
		    $customer_state, //string
		    $customer_country_code, //string
		    $customer_postal_address, //string
		    $webhook_url, //string, optional
		    $redirect_url, //string, optional
		    $auto_redirect, //bool, optional
		);
		$checkout_details  =  $checkout->createCheckoutLink();
	    }   		
    }

以下是在成功调用服务器后分配给$checkout_details的数据的预期结构

        //json
        {
	     "isError": false,
	      "message": "",
	      "paymentUrl":"https://checkout.sparco.io/eyJpZCI6IDEsICJtZXJjaGFudFB1YmxpY0tleSI6ICIyZmJmMTgyYzZmYzE0NTAwYjI4ZmRjOGM4M2VhYjczNCJ9",
	      "reference": "7b226964223a20312c20226d6964223a20317d"
	}

REST API

API还允许通过REST API调用收集资金。以下示例代码展示了如何执行此操作

<?php
	namespace  YourNamespace;        
	use Broadpay\MobileMoney\Debit;
	class  YourClassName
	{
    public  function  index()
    {

	    $payment = new Debit(
		    privateKey: 'YourPrivateKey',
		    publicKey: 'YourPublicKey',
		    amount: 100,
		    currency: 'ZMW',
		    customerEmail: 'david@davidnsai.com',
		    customerFirstName: 'david',
		    customerLastName: 'nsai',
		    customerPhone: ''+260977123456,
		    transactionName: 'Transaction name here',
		    transactionReference: 'Unique Transaction Reference',
		    wallet: '0977123456'
		   );
			
	     $payment_result = $payment->initialiseCollection();
	 }
}

以下是在成功调用服务器后分配给$checkout_details的数据的预期结构

//json
{
  "isError": false,
  "mesasge": "Wating for wallet holder to authorize debit transaction.",
  "message": "",
  "reference": "7b226964223a20332c20226d6964223a20317d",
  "status": "PENDING_AUTH"
}

希望您在用Broadpay构建PHP应用程序时找到此包很有用。祝您编码愉快!!