'https://openapi.alipay.com/gateway.do?charset=utf-8', Pay::MODE_SANDBOX => 'https://openapi-sandbox.dl.alipaydev.com/gateway.do?charset=utf-8', Pay::MODE_SERVICE => 'https://openapi.alipay.com/gateway.do?charset=utf-8', ]; /** * @throws ContainerException * @throws InvalidParamsException * @throws ServiceNotFoundException */ public function __call(string $shortcut, array $params): null|Collection|MessageInterface|Rocket { $plugin = '\Yansongda\Pay\Shortcut\Alipay\\'.Str::studly($shortcut).'Shortcut'; return Artful::shortcut($plugin, ...$params); } /** * @throws ContainerException * @throws InvalidParamsException */ public function pay(array $plugins, array $params): null|Collection|MessageInterface|Rocket { return Artful::artful($plugins, $params); } /** * @throws ContainerException * @throws InvalidParamsException * @throws ServiceNotFoundException */ public function query(array $order): Collection|Rocket { Event::dispatch(new MethodCalled('alipay', __METHOD__, $order, null)); return $this->__call('query', [$order]); } /** * @throws ContainerException * @throws InvalidParamsException * @throws ServiceNotFoundException */ public function cancel(array $order): Collection|Rocket { Event::dispatch(new MethodCalled('alipay', __METHOD__, $order, null)); return $this->__call('cancel', [$order]); } /** * @throws ContainerException * @throws InvalidParamsException * @throws ServiceNotFoundException */ public function close(array $order): Collection|Rocket { Event::dispatch(new MethodCalled('alipay', __METHOD__, $order, null)); return $this->__call('close', [$order]); } /** * @throws ContainerException * @throws InvalidParamsException * @throws ServiceNotFoundException */ public function refund(array $order): Collection|Rocket { Event::dispatch(new MethodCalled('alipay', __METHOD__, $order, null)); return $this->__call('refund', [$order]); } /** * @throws ContainerException * @throws InvalidParamsException */ public function callback(null|array|ServerRequestInterface $contents = null, ?array $params = null): Collection { $request = $this->getCallbackParams($contents); Event::dispatch(new CallbackReceived('alipay', $request->all(), $params, null)); return $this->pay([CallbackPlugin::class], $request->merge($params)->all()); } /** * @throws ContainerException * @throws InvalidParamsException */ public function appCallback(null|array|ServerRequestInterface $contents = null, ?array $params = null): Collection { $request = $this->getCallbackParams($contents); return $this->pay([AppCallbackPlugin::class], $request->merge($params)->all()); } public function success(): ResponseInterface { return new Response(200, [], 'success'); } public function mergeCommonPlugins(array $plugins): array { return array_merge( [StartPlugin::class], $plugins, [FormatPayloadBizContentPlugin::class, AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, ParserPlugin::class], ); } protected function getCallbackParams(null|array|ServerRequestInterface $contents = null): Collection { if (is_array($contents)) { return Collection::wrap($contents); } if ($contents instanceof ServerRequestInterface) { return Collection::wrap('GET' === $contents->getMethod() ? $contents->getQueryParams() : $contents->getParsedBody()); } $request = ServerRequest::fromGlobals(); return Collection::wrap( array_merge($request->getQueryParams(), $request->getParsedBody()) ); } }