merge from v3

This commit is contained in:
yansongda 2021-07-05 23:10:59 +08:00
commit 183c745458
3 changed files with 27 additions and 8 deletions

View File

@ -8,14 +8,25 @@ use Throwable;
class InvalidResponseException extends Exception
{
/**
* @var \Throwable|null
*/
public $exception = null;
/**
* @var array
*/
public $response;
public $response = [];
public function __construct(int $code = self::RESPONSE_ERROR, string $message = 'Provider response Error', array $extra = [], Throwable $previous = null)
public function __construct(
int $code = self::RESPONSE_ERROR,
string $message = 'Provider response Error',
array $extra = [],
?Throwable $exception = null,
Throwable $previous = null)
{
$this->response = $extra;
$this->exception = $exception;
parent::__construct($message, $code, $extra, $previous);
}

View File

@ -21,13 +21,21 @@ class QueryPlugin extends GeneralPlugin
$config = get_wechat_config($rocket->getParams());
$payload = $rocket->getPayload();
if (is_null($payload->get('transaction_id'))) {
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
if (!is_null($payload->get('transaction_id'))) {
return 'v3/pay/transactions/id/'.
$payload->get('transaction_id').
'?mchid='.$config->get('mch_id', '');
}
return 'v3/pay/transactions/id/'.
$payload->get('transaction_id').
'?mchid='.$config->get('mch_id', '');
if (!is_null($payload->get('out_trade_no'))) {
return 'v3/pay/transactions/out-trade-no/'.
$payload->get('out_trade_no').
'?mchid='.$config->get('mch_id', '');
}
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
}
protected function getMethod(): string

View File

@ -108,7 +108,7 @@ abstract class AbstractProvider implements ProviderInterface
} catch (Throwable $e) {
Logger::error('[AbstractProvider] 请求支付服务商 API 出错', ['message' => $e->getMessage(), 'rocket' => $rocket->toArray(), 'trace' => $e->getTrace()]);
throw new InvalidResponseException(InvalidResponseException::REQUEST_RESPONSE_ERROR, $e->getMessage());
throw new InvalidResponseException(InvalidResponseException::REQUEST_RESPONSE_ERROR, $e->getMessage(), [], $e);
}
Logger::info('[AbstractProvider] 请求支付服务商 API 成功', ['response' => $response, 'rocket' => $rocket->toArray()]);