PHP code example of iredcap / payment

1. Go to this page and download the library: Download iredcap/payment library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

iredcap / payment example snippets




namespace App\Http\Controllers;

use Iredcap\Payment\Payment;

class PayController
{
    protected $config = [
        'wxpay' => [
            'app_id'              => 'wxc90xxxx34c', // 微信支付MCHID 商户收款账号
            'mch_id'              => '149xxxx22', // 微信支付MCHID 商户收款账号
            'mch_key'             => 'a50e731409xxxxxxx50b254e62a', // 微信支付KEY
            'notify_url'          => 'https://www.baidu.cn/payment/notify', // 接收支付结果通知
        ],
        
        'alipay' => [
            'app_id'    => '2019021863254220', // 支付宝应用appid
            // 支付宝应用私钥
            'private_key'   => 'MIIEpAIBAAKCAxxxxxxx',
            // 支付宝公钥
            'public_key'    => 'MIIBIjANBgkqhxxxxxxxxxxxxx',
            'notify_url'    => 'https://www.baidu.cn/payment/notify',// 接收支付结果通知
        ],
    ];

    public function index()
    {
        $payload = [
            'out_trade_no' => uniqid(),
            'subject' =>  '技能购买',
            'amount' => '0.01',
            'extra' => [
                'openid'    => 'farhbuthnjfgyhsbtfhngfyj'
            ]
        ];
        
        $payment = Payment::createPayment('alipay', $this->config['alipay'], $payload);
        
        //$result = $payment->native();
        //$result = $payment->wap();
        //$result = $payment->app();
        //$result = $payment->mini();
        //$result = $payment->jsapi();
        //$result = $payment->query();
    }

    public function notify()
    {
        $payment = Payment::createPayment('alipay', $this->config['alipay']);

        try{
            $data = $payment->notify();

            //$data['out_trade_no'];
        } catch (\Exception $e) {
            // $e->getMessage();
        }
        
        return $payment->success();
    }
}