feat : Bridge pay
This commit is contained in:
45
app/Service/Test/Bridge/Pay/Lib/AlipayPayment.php
Normal file
45
app/Service/Test/Bridge/Pay/Lib/AlipayPayment.php
Normal 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,
|
||||
];
|
||||
}
|
||||
}
|
||||
45
app/Service/Test/Bridge/Pay/Lib/CreditCardPayment.php
Normal file
45
app/Service/Test/Bridge/Pay/Lib/CreditCardPayment.php
Normal 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,
|
||||
];
|
||||
}
|
||||
}
|
||||
53
app/Service/Test/Bridge/Pay/PaymentGateway.php
Normal file
53
app/Service/Test/Bridge/Pay/PaymentGateway.php
Normal 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;
|
||||
}
|
||||
37
app/Service/Test/Bridge/Pay/PremiumPaymentService.php
Normal file
37
app/Service/Test/Bridge/Pay/PremiumPaymentService.php
Normal 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);
|
||||
}
|
||||
}
|
||||
35
app/Service/Test/Bridge/Pay/StandardPaymentService.php
Normal file
35
app/Service/Test/Bridge/Pay/StandardPaymentService.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user