kiplingkelvin/chpter-laravel-sdk

chpter.co PHP SDK,轻松实现支付和退款集成

v1.0.8 2023-06-22 15:20 UTC

This package is auto-updated.

Last update: 2024-09-22 18:08:15 UTC


README

Laravel Logo

Chpter Laravel SDK

Scrutinizer build (GitHub/Bitbucket) Packagist Version Packagist Downloads Scrutinizer code quality (GitHub/Bitbucket) GitHub issues GitHub

安装

通过composer安装

composer require kiplingkelvin/chpter-laravel-sdk

在您的laravel项目中运行vendor:publish命令

php artisan vendor:publish --provider="KiplingKelvin\ChpterLaravelSdk\ChpterServiceProvider"

发布后,您将找到config/chpter.php配置文件。现在您可以适当调整配置。另外,出于安全考虑,将配置添加到您的.env文件中。

将以下文件添加到您的.env

CLIENT_DOMAIN=
CHPTER_TOKEN=

eg.

CLIENT_DOMAIN=chpter.co
CHPTER_TOKEN=chpter_pk_2b4037c1c8

用法

支付

Mpesa支付(STK推送)

        $chpter= new \KiplingKelvin\ChpterLaravelSdk\Chpter();

        $customer = array( 
            "payment_method"=> "MPesa",
            "full_name"=> "John Doe",
            "location"=> "Nairobi",
            "phone_number"=> "254700123123",
            "email"=> "johndoe@mail.com"  );

        $products = array(  array( 
                "product_id"=> "08",
                "product_name"=> "HoodEez",
                "quantity"=> "1",
                "unit_price"=> "1" ));

        $amount = array( 
                "delivery_fee"=> "0",
                "discount_fee"=> "0",
                "total"=> "1",
                "currency"=> "kes");

        $callback_details = array( 
                "transaction_reference"=>  "123456789123",
                "callback_url"=>  "https://df02-197-232-140-206.in.ngrok.io/api/chpter_mpesa_payment_callback_url" );

        $response = $chpter->mpesaPayment($customer, $products, $amount, $callback_details);

        //Response Is in json
        return $response;

重定向支付(托管会话)

        $chpter= new \KiplingKelvin\ChpterLaravelSdk\Chpter();

        $customer = array( 
            "full_name"=> "John Doe",
            "location"=> "Nairobi",
            "phone_number"=> "254706347307",
            "email"=> "johndoe@mail.com"  );

        $products = array(  array( 
                "product_name"=> "HoodEez",
                "quantity"=> "1",
                "unit_price"=> "1" ));

        $amount = array( 
                 "order_id"=> "859",
                "delivery_fee"=> 0,
                "discount_fee"=> 0,
                "total"=> 500,
                "currency"=> "kes");

        $callback_details = array( 
                "success_url" => "https://www.url.com",
                "failed_url" => "https://www.url.com",
                "callback_url" => "https://yourcallback.com/url"
        )

        
        Log::info('********Starting Redirect Api Request**********');
        $response = $chpter->hostedRedirectPayment($customer, $amount, $callback_details);

        //The response is in json
        Log::alert('Chpter Redirect API Response');
        return $response;

退款

创建移动退款目的地

        $chpter= new \KiplingKelvin\ChpterLaravelSdk\Chpter();

        $type = "Mpesa";
        $phoneNumber = "254700000000";
        
        Log::info('********Starting Api Request**********');
        $response = $chpter->createMobilePayoutDestination($type, $phoneNumber);
        //The response is in json
        Log::alert('Chpter API Response');
        return $response;

创建银行退款目的地

        $chpter= new \KiplingKelvin\ChpterLaravelSdk\Chpter();

        $bankName = "KCB";
        $bankAccountName = "ALBERT CHELA";
        $bankAccountNumber = "123451267";
        
        Log::info('********Starting Api Request**********');
        $response = $chpter->createBankPayoutDestination($bankName, $bankAccountName, $bankAccountNumber);
        //The response is in json
        Log::alert('Chpter API Response');
        return $response;

资源

作者

@kiplingkelvin