feat : Bridge pay

This commit is contained in:
2025-09-07 18:22:41 +08:00
parent cb7e8842d6
commit 33cd767477
11 changed files with 369 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
* @web_site https://ctexthuang.com
*/
declare(strict_types=1);
namespace App\Service\Test\Bridge\Pay\Lib;
use App\Interface\Test\Bridge\PaymentInterface;
class AlipayPayment implements PaymentInterface
{
/**
* @param float $amount
* @return array
*/
public function pay(float $amount): array
{
return [
'type' => 'pay',
'price' => $amount,
'pay_type' => 'alipay',
'msg' => 'Processing credit card payment of ' . $amount . PHP_EOL,
];
}
/**
* @param float $amount
* @return array
*/
public function refund(float $amount): array
{
return [
'type' => 'refund',
'price' => $amount,
'pay_type' => 'alipay',
'msg' => 'Processing credit card refund of ' . $amount . PHP_EOL,
];
}
}

View File

@@ -0,0 +1,45 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
* @web_site https://ctexthuang.com
*/
declare(strict_types=1);
namespace App\Service\Test\Bridge\Pay\Lib;
use App\Interface\Test\Bridge\PaymentInterface;
class CreditCardPayment implements PaymentInterface
{
/**
* @param float $amount
* @return array
*/
public function pay(float $amount): array
{
return [
'type' => 'pay',
'price' => $amount,
'pay_type' => 'credit_card',
'msg' => 'Processing credit card payment of ' . $amount . PHP_EOL,
];
}
/**
* @param float $amount
* @return array
*/
public function refund(float $amount): array
{
return [
'type' => 'refund',
'price' => $amount,
'pay_type' => 'credit_card',
'msg' => 'Processing credit card refund of ' . $amount . PHP_EOL,
];
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
* @web_site https://ctexthuang.com
*/
declare(strict_types=1);
namespace App\Service\Test\Bridge\Pay;
use App\Interface\Test\Bridge\PaymentInterface;
use App\Interface\Test\Decorator\LoggerInterface;
abstract class PaymentGateway
{
/**
* @var PaymentInterface
*/
protected PaymentInterface $payment;
/**
* @var LoggerInterface
*/
protected LoggerInterface $logger;
/**
* 构造函数
* @param PaymentInterface $payment
* @param LoggerInterface $logger
*/
public function __construct(PaymentInterface $payment, LoggerInterface $logger)
{
$this->payment = $payment;
$this->logger = $logger;
}
/**
* 抽象支付类
* @param float $amount
* @return array
*/
abstract public function processPayment(float $amount): array;
/**
* 抽象退款类
* @param float $amount
* @return array
*/
abstract public function processRefund(float $amount): array;
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
* @web_site https://ctexthuang.com
*/
declare(strict_types=1);
namespace App\Service\Test\Bridge\Pay;
class PremiumPaymentService extends PaymentGateway
{
/**
* @param float $amount
* @return array
*/
public function processPayment(float $amount): array
{
$fee = $amount * 0.02; // 2%手续费
$this->logger->debug('Premium payment processing with fee: ' . $fee);
return $this->payment->pay($amount + $fee);
}
/**
* @param float $amount
* @return array
*/
public function processRefund(float $amount): array
{
$fee = $amount * 0.01; // 1%手续费
$this->logger->debug('Premium payment processing with refund: ' . $fee);
return $this->payment->refund($amount - $fee);
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
* @web_site https://ctexthuang.com
*/
declare(strict_types=1);
namespace App\Service\Test\Bridge\Pay;
class StandardPaymentService extends PaymentGateway
{
/**
* @param float $amount
* @return array
*/
public function processPayment(float $amount): array
{
$this->logger->debug('Standard payment processing');
return $this->payment->pay($amount);
}
/**
* @param float $amount
* @return array
*/
public function processRefund(float $amount): array
{
$this->logger->debug('Standard refund processing');
return $this->payment->refund($amount);
}
}