PHP code example of simplecms / payment

1. Go to this page and download the library: Download simplecms/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/ */

    

simplecms / payment example snippets


// config/app.php
'providers' => [
    SimpleCMS\Payment\PaymentServiceProvider::class,
],

'aliases' => [
    'Payment' => SimpleCMS\Payment\Facades\Payment::class,
],

use SimpleCMS\Payment\Enums\ChannelEnum;

ChannelEnum::Wechat->value;    // 1
ChannelEnum::Alipay->value;    // 2
ChannelEnum::Paypal->value;    // 3
ChannelEnum::Stripe->value;     // 4
ChannelEnum::USDTTRC20->value; // 5
ChannelEnum::USDTERC20->value; // 6
ChannelEnum::BTC->value;        // 7
ChannelEnum::ETH->value;        // 8



namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use SimpleCMS\Payment\HasPayment;

class Order extends Model implements HasPayment
{
    public function payment(): MorphOne
    {
        return $this->morphOne(\SimpleCMS\Payment\Models\Payment::class, 'order');
    }

    public function getOrderKey(): string
    {
        return 'order_no';
    }
}

use SimpleCMS\Payment\Enums\ChannelEnum;
use SimpleCMS\Payment\Facades\Payment;

$result = Payment::create($order, 99.99, ChannelEnum::Wechat->value, 'Test order');

use SimpleCMS\Payment\Facades\Payment;

$transfer = Payment::transferCreate([
    'order_no' => 'TXN-1001',
    'amount' => 199.99,
    'channel' => 'wechat',
]);

$approval = Payment::approvalRun('withdrawal', [
    'amount' => 15000,
    'channel' => 'wechat',
]);

$reconciliation = Payment::reconciliationRun('wechat', '2024-06-30');

// config/app.php
'providers' => [
    SimpleCMS\Payment\PaymentServiceProvider::class,
],

'aliases' => [
    'Payment' => SimpleCMS\Payment\Facades\Payment::class,
],

use SimpleCMS\Payment\Facades\Payment;

public function dispatchWithdrawal(): array
{
    return Payment::transferCreate([
        'order_no' => 'WITHDRAW-2026-001',
        'amount' => 2500,
        'channel' => 'wechat',
        'direction' => 'out',
    ]);
}

use SimpleCMS\Payment\Models\Payment;

Event::listen('plugin.payment.created', function (Payment $payment) {
    // created
});

Event::listen('plugin.payment.pending', function (Payment $payment) {
    // awaiting payment
});

Event::listen('plugin.payment.paid', function (Payment $payment) {
    // payment succeeded
});

Event::listen('plugin.payment.refunding', function (Payment $payment) {
    // refund in progress
});

Event::listen('plugin.payment.refunded', function (Payment $payment) {
    // refund succeeded
});

Event::listen('plugin.payment.close', function (Payment $payment) {
    // payment closed
});