This commit is contained in:
yansongda 2019-03-30 12:30:49 +08:00
parent 67fa2d974e
commit 026505537e
23 changed files with 132 additions and 73 deletions

View File

@ -2,6 +2,9 @@
namespace Yansongda\Pay\Contracts;
use Symfony\Component\HttpFoundation\Response;
use Yansongda\Supports\Collection;
interface GatewayApplicationInterface
{
/**
@ -12,7 +15,7 @@ interface GatewayApplicationInterface
* @param string $gateway
* @param array $params
*
* @return \Yansongda\Supports\Collection|\Symfony\Component\HttpFoundation\Response
* @return Collection|Response
*/
public function pay($gateway, $params);
@ -24,7 +27,7 @@ interface GatewayApplicationInterface
* @param string|array $order
* @param bool $refund
*
* @return \Yansongda\Supports\Collection
* @return Collection
*/
public function find($order, $refund);
@ -35,7 +38,7 @@ interface GatewayApplicationInterface
*
* @param array $order
*
* @return \Yansongda\Supports\Collection
* @return Collection
*/
public function refund($order);
@ -46,7 +49,7 @@ interface GatewayApplicationInterface
*
* @param string|array $order
*
* @return \Yansongda\Supports\Collection
* @return Collection
*/
public function cancel($order);
@ -57,7 +60,7 @@ interface GatewayApplicationInterface
*
* @param string|array $order
*
* @return \Yansongda\Supports\Collection
* @return Collection
*/
public function close($order);
@ -69,7 +72,7 @@ interface GatewayApplicationInterface
* @param string|null $content
* @param bool $refund
*
* @return \Yansongda\Supports\Collection
* @return Collection
*/
public function verify($content, $refund);
@ -78,7 +81,7 @@ interface GatewayApplicationInterface
*
* @author yansongda <me@yansongda.cn>
*
* @return \Symfony\Component\HttpFoundation\Response
* @return Response
*/
public function success();
}

View File

@ -2,6 +2,9 @@
namespace Yansongda\Pay\Contracts;
use Symfony\Component\HttpFoundation\Response;
use Yansongda\Supports\Collection;
interface GatewayInterface
{
/**
@ -12,7 +15,7 @@ interface GatewayInterface
* @param string $endpoint
* @param array $payload
*
* @return \Yansongda\Supports\Collection|\Symfony\Component\HttpFoundation\Response
* @return Collection|Response
*/
public function pay($endpoint, array $payload);
}

View File

@ -2,6 +2,7 @@
namespace Yansongda\Pay;
use Exception;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -84,7 +85,7 @@ class Events
* @param string $method
* @param array $args
*
* @throws \Exception
* @throws Exception
*
* @return mixed
*/
@ -101,7 +102,7 @@ class Events
* @param string $method
* @param array $args
*
* @throws \Exception
* @throws Exception
*
* @return mixed
*/

View File

@ -11,9 +11,10 @@ class GatewayException extends Exception
*
* @param string $message
* @param array|string $raw
* @param int $code
*/
public function __construct($message, $raw = [])
public function __construct($message, $raw = [], $code = self::ERROR_GATEWAY)
{
parent::__construct('ERROR_GATEWAY: '.$message, $raw, self::ERROR_GATEWAY);
parent::__construct('ERROR_GATEWAY: '.$message, $raw, $code);
}
}

View File

@ -5,6 +5,7 @@ namespace Yansongda\Pay\Gateways\Alipay;
use Symfony\Component\HttpFoundation\Response;
use Yansongda\Pay\Contracts\GatewayInterface;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\InvalidConfigException;
class AppGateway implements GatewayInterface
{
@ -16,7 +17,7 @@ class AppGateway implements GatewayInterface
* @param string $endpoint
* @param array $payload
*
* @throws \Yansongda\Pay\Exceptions\InvalidConfigException
* @throws InvalidConfigException
*
* @return Response
*/

View File

@ -4,6 +4,10 @@ namespace Yansongda\Pay\Gateways\Alipay;
use Yansongda\Pay\Contracts\GatewayInterface;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidArgumentException;
use Yansongda\Pay\Exceptions\InvalidConfigException;
use Yansongda\Pay\Exceptions\InvalidSignException;
use Yansongda\Supports\Collection;
class MiniGateway implements GatewayInterface
@ -16,10 +20,10 @@ class MiniGateway implements GatewayInterface
* @param string $endpoint
* @param array $payload
*
* @throws \Yansongda\Pay\Exceptions\GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws \Yansongda\Pay\Exceptions\InvalidConfigException
* @throws \Yansongda\Pay\Exceptions\InvalidSignException
* @throws GatewayException
* @throws InvalidArgumentException
* @throws InvalidConfigException
* @throws InvalidSignException
*
* @link https://docs.alipay.com/mini/introduce/pay
*
@ -28,7 +32,7 @@ class MiniGateway implements GatewayInterface
public function pay($endpoint, array $payload): Collection
{
if (empty(json_decode($payload['biz_content'], true)['buyer_id'])) {
throw new \Yansongda\Pay\Exceptions\InvalidArgumentException('buyer_id required');
throw new InvalidArgumentException('buyer_id required');
}
$payload['method'] = 'alipay.trade.create';

View File

@ -4,6 +4,9 @@ namespace Yansongda\Pay\Gateways\Alipay;
use Yansongda\Pay\Contracts\GatewayInterface;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidConfigException;
use Yansongda\Pay\Exceptions\InvalidSignException;
use Yansongda\Supports\Collection;
class PosGateway implements GatewayInterface
@ -16,9 +19,9 @@ class PosGateway implements GatewayInterface
* @param string $endpoint
* @param array $payload
*
* @throws \Yansongda\Pay\Exceptions\GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidConfigException
* @throws \Yansongda\Pay\Exceptions\InvalidSignException
* @throws GatewayException
* @throws InvalidConfigException
* @throws InvalidSignException
*
* @return Collection
*/

View File

@ -4,6 +4,9 @@ namespace Yansongda\Pay\Gateways\Alipay;
use Yansongda\Pay\Contracts\GatewayInterface;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidConfigException;
use Yansongda\Pay\Exceptions\InvalidSignException;
use Yansongda\Supports\Collection;
class ScanGateway implements GatewayInterface
@ -16,9 +19,9 @@ class ScanGateway implements GatewayInterface
* @param string $endpoint
* @param array $payload
*
* @throws \Yansongda\Pay\Exceptions\GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidConfigException
* @throws \Yansongda\Pay\Exceptions\InvalidSignException
* @throws GatewayException
* @throws InvalidConfigException
* @throws InvalidSignException
*
* @return Collection
*/

View File

@ -4,6 +4,9 @@ namespace Yansongda\Pay\Gateways\Alipay;
use Yansongda\Pay\Contracts\GatewayInterface;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidConfigException;
use Yansongda\Pay\Exceptions\InvalidSignException;
use Yansongda\Supports\Collection;
class TransferGateway implements GatewayInterface
@ -16,9 +19,9 @@ class TransferGateway implements GatewayInterface
* @param string $endpoint
* @param array $payload
*
* @throws \Yansongda\Pay\Exceptions\GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidConfigException
* @throws \Yansongda\Pay\Exceptions\InvalidSignException
* @throws GatewayException
* @throws InvalidConfigException
* @throws InvalidSignException
*
* @return Collection
*/

View File

@ -6,6 +6,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Yansongda\Pay\Contracts\GatewayInterface;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\InvalidConfigException;
class WebGateway implements GatewayInterface
{
@ -17,7 +18,7 @@ class WebGateway implements GatewayInterface
* @param string $endpoint
* @param array $payload
*
* @throws \Yansongda\Pay\Exceptions\InvalidConfigException
* @throws InvalidConfigException
*
* @return Response
*/

View File

@ -2,6 +2,7 @@
namespace Yansongda\Pay\Gateways;
use Exception;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@ -9,6 +10,7 @@ use Yansongda\Pay\Contracts\GatewayApplicationInterface;
use Yansongda\Pay\Contracts\GatewayInterface;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidArgumentException;
use Yansongda\Pay\Exceptions\InvalidGatewayException;
use Yansongda\Pay\Exceptions\InvalidSignException;
use Yansongda\Pay\Gateways\Wechat\Support;
@ -87,7 +89,7 @@ class Wechat implements GatewayApplicationInterface
*
* @param Config $config
*
* @throws \Exception
* @throws Exception
*/
public function __construct(Config $config)
{
@ -163,7 +165,7 @@ class Wechat implements GatewayApplicationInterface
* @param bool $refund
*
* @throws InvalidSignException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws InvalidArgumentException
*
* @return Collection
*/
@ -200,7 +202,7 @@ class Wechat implements GatewayApplicationInterface
*
* @throws GatewayException
* @throws InvalidSignException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws InvalidArgumentException
*
* @return Collection
*/
@ -229,7 +231,7 @@ class Wechat implements GatewayApplicationInterface
*
* @throws GatewayException
* @throws InvalidSignException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws InvalidArgumentException
*
* @return Collection
*/
@ -255,7 +257,7 @@ class Wechat implements GatewayApplicationInterface
*
* @throws GatewayException
* @throws InvalidSignException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws InvalidArgumentException
*
* @return Collection
*/
@ -283,7 +285,7 @@ class Wechat implements GatewayApplicationInterface
*
* @throws GatewayException
* @throws InvalidSignException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws InvalidArgumentException
*
* @return Collection
*/
@ -303,7 +305,7 @@ class Wechat implements GatewayApplicationInterface
*
* @author yansongda <me@yansongda.cn>
*
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws InvalidArgumentException
*
* @return Response
*/
@ -326,7 +328,7 @@ class Wechat implements GatewayApplicationInterface
* @param array $params
*
* @throws GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws InvalidArgumentException
*
* @return string
*/

View File

@ -2,9 +2,13 @@
namespace Yansongda\Pay\Gateways\Wechat;
use Exception;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidArgumentException;
use Yansongda\Pay\Exceptions\InvalidSignException;
use Yansongda\Pay\Gateways\Wechat;
use Yansongda\Supports\Str;
@ -18,10 +22,10 @@ class AppGateway extends Gateway
* @param string $endpoint
* @param array $payload
*
* @throws \Yansongda\Pay\Exceptions\GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws \Yansongda\Pay\Exceptions\InvalidSignException
* @throws \Exception
* @throws GatewayException
* @throws InvalidArgumentException
* @throws InvalidSignException
* @throws Exception
*
* @return Response
*/

View File

@ -4,6 +4,9 @@ namespace Yansongda\Pay\Gateways\Wechat;
use Yansongda\Pay\Contracts\GatewayInterface;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidArgumentException;
use Yansongda\Pay\Exceptions\InvalidSignException;
use Yansongda\Supports\Collection;
abstract class Gateway implements GatewayInterface
@ -20,7 +23,7 @@ abstract class Gateway implements GatewayInterface
*
* @author yansongda <me@yansongda.cn>
*
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws InvalidArgumentException
*/
public function __construct()
{
@ -55,9 +58,9 @@ abstract class Gateway implements GatewayInterface
*
* @param array $payload
*
* @throws \Yansongda\Pay\Exceptions\GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws \Yansongda\Pay\Exceptions\InvalidSignException
* @throws GatewayException
* @throws InvalidArgumentException
* @throws InvalidSignException
*
* @return Collection
*/

View File

@ -3,6 +3,9 @@
namespace Yansongda\Pay\Gateways\Wechat;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidArgumentException;
use Yansongda\Pay\Exceptions\InvalidSignException;
use Yansongda\Pay\Gateways\Wechat;
use Yansongda\Supports\Collection;
@ -16,9 +19,9 @@ class GroupRedpackGateway extends Gateway
* @param string $endpoint
* @param array $payload
*
* @throws \Yansongda\Pay\Exceptions\GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws \Yansongda\Pay\Exceptions\InvalidSignException
* @throws GatewayException
* @throws InvalidArgumentException
* @throws InvalidSignException
*
* @return Collection
*/

View File

@ -2,6 +2,9 @@
namespace Yansongda\Pay\Gateways\Wechat;
use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidArgumentException;
use Yansongda\Pay\Exceptions\InvalidSignException;
use Yansongda\Pay\Gateways\Wechat;
use Yansongda\Supports\Collection;
@ -15,9 +18,9 @@ class MiniappGateway extends MpGateway
* @param string $endpoint
* @param array $payload
*
* @throws \Yansongda\Pay\Exceptions\GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws \Yansongda\Pay\Exceptions\InvalidSignException
* @throws GatewayException
* @throws InvalidArgumentException
* @throws InvalidSignException
*
* @return Collection
*/

View File

@ -2,7 +2,11 @@
namespace Yansongda\Pay\Gateways\Wechat;
use Exception;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidArgumentException;
use Yansongda\Pay\Exceptions\InvalidSignException;
use Yansongda\Supports\Collection;
use Yansongda\Supports\Str;
@ -21,10 +25,10 @@ class MpGateway extends Gateway
* @param string $endpoint
* @param array $payload
*
* @throws \Yansongda\Pay\Exceptions\GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws \Yansongda\Pay\Exceptions\InvalidSignException
* @throws \Exception
* @throws GatewayException
* @throws InvalidArgumentException
* @throws InvalidSignException
* @throws Exception
*
* @return Collection
*/

View File

@ -3,6 +3,9 @@
namespace Yansongda\Pay\Gateways\Wechat;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidArgumentException;
use Yansongda\Pay\Exceptions\InvalidSignException;
use Yansongda\Supports\Collection;
class PosGateway extends Gateway
@ -15,9 +18,9 @@ class PosGateway extends Gateway
* @param string $endpoint
* @param array $payload
*
* @throws \Yansongda\Pay\Exceptions\GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws \Yansongda\Pay\Exceptions\InvalidSignException
* @throws GatewayException
* @throws InvalidArgumentException
* @throws InvalidSignException
*
* @return Collection
*/

View File

@ -4,6 +4,9 @@ namespace Yansongda\Pay\Gateways\Wechat;
use Symfony\Component\HttpFoundation\Request;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidArgumentException;
use Yansongda\Pay\Exceptions\InvalidSignException;
use Yansongda\Pay\Gateways\Wechat;
use Yansongda\Supports\Collection;
@ -17,9 +20,9 @@ class RedpackGateway extends Gateway
* @param string $endpoint
* @param array $payload
*
* @throws \Yansongda\Pay\Exceptions\GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws \Yansongda\Pay\Exceptions\InvalidSignException
* @throws GatewayException
* @throws InvalidArgumentException
* @throws InvalidSignException
*
* @return Collection
*/

View File

@ -4,6 +4,9 @@ namespace Yansongda\Pay\Gateways\Wechat;
use Symfony\Component\HttpFoundation\Request;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidArgumentException;
use Yansongda\Pay\Exceptions\InvalidSignException;
use Yansongda\Supports\Collection;
class ScanGateway extends Gateway
@ -16,9 +19,9 @@ class ScanGateway extends Gateway
* @param string $endpoint
* @param array $payload
*
* @throws \Yansongda\Pay\Exceptions\GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws \Yansongda\Pay\Exceptions\InvalidSignException
* @throws GatewayException
* @throws InvalidArgumentException
* @throws InvalidSignException
*
* @return Collection
*/

View File

@ -2,6 +2,7 @@
namespace Yansongda\Pay\Gateways\Wechat;
use Exception;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\BusinessException;
use Yansongda\Pay\Exceptions\GatewayException;
@ -439,7 +440,7 @@ class Support
* @throws GatewayException
* @throws InvalidArgumentException
* @throws InvalidSignException
* @throws \Exception
* @throws Exception
*
* @return Support
*/

View File

@ -4,6 +4,9 @@ namespace Yansongda\Pay\Gateways\Wechat;
use Symfony\Component\HttpFoundation\Request;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidArgumentException;
use Yansongda\Pay\Exceptions\InvalidSignException;
use Yansongda\Pay\Gateways\Wechat;
use Yansongda\Supports\Collection;
@ -17,9 +20,9 @@ class TransferGateway extends Gateway
* @param string $endpoint
* @param array $payload
*
* @throws \Yansongda\Pay\Exceptions\GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws \Yansongda\Pay\Exceptions\InvalidSignException
* @throws GatewayException
* @throws InvalidArgumentException
* @throws InvalidSignException
*
* @return Collection
*/

View File

@ -4,6 +4,9 @@ namespace Yansongda\Pay\Gateways\Wechat;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidArgumentException;
use Yansongda\Pay\Exceptions\InvalidSignException;
class WapGateway extends Gateway
{
@ -15,9 +18,9 @@ class WapGateway extends Gateway
* @param string $endpoint
* @param array $payload
*
* @throws \Yansongda\Pay\Exceptions\GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws \Yansongda\Pay\Exceptions\InvalidSignException
* @throws GatewayException
* @throws InvalidArgumentException
* @throws InvalidSignException
*
* @return RedirectResponse
*/

View File

@ -2,6 +2,7 @@
namespace Yansongda\Pay;
use Exception;
use Yansongda\Pay\Contracts\GatewayApplicationInterface;
use Yansongda\Pay\Exceptions\InvalidGatewayException;
use Yansongda\Pay\Gateways\Alipay;
@ -31,7 +32,7 @@ class Pay
*
* @param array $config
*
* @throws \Exception
* @throws Exception
*/
public function __construct(array $config)
{
@ -50,7 +51,7 @@ class Pay
* @param array $params
*
* @throws InvalidGatewayException
* @throws \Exception
* @throws Exception
*
* @return GatewayApplicationInterface
*/
@ -110,7 +111,7 @@ class Pay
*
* @author yansongda <me@yansongda.cn>
*
* @throws \Exception
* @throws Exception
*/
protected function registerLogService()
{