PagePayPlugin.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. declare(strict_types=1);
  3. namespace Yansongda\Pay\Plugin\Alipay\Trade;
  4. use Closure;
  5. use Yansongda\Pay\Contract\PluginInterface;
  6. use Yansongda\Pay\Direction\ResponseDirection;
  7. use Yansongda\Pay\Exception\ContainerException;
  8. use Yansongda\Pay\Exception\ServiceNotFoundException;
  9. use Yansongda\Pay\Logger;
  10. use Yansongda\Pay\Rocket;
  11. use Yansongda\Pay\Traits\SupportServiceProviderTrait;
  12. /**
  13. * @see https://opendocs.alipay.com/open/028r8t?scene=22
  14. */
  15. class PagePayPlugin implements PluginInterface
  16. {
  17. use SupportServiceProviderTrait;
  18. /**
  19. * @throws ContainerException
  20. * @throws ServiceNotFoundException
  21. */
  22. public function assembly(Rocket $rocket, Closure $next): Rocket
  23. {
  24. Logger::debug('[alipay][PagePayPlugin] 插件开始装载', ['rocket' => $rocket]);
  25. $this->loadAlipayServiceProvider($rocket);
  26. $rocket->setDirection(ResponseDirection::class)
  27. ->mergePayload([
  28. 'method' => 'alipay.trade.page.pay',
  29. 'biz_content' => array_merge(
  30. ['product_code' => 'FAST_INSTANT_TRADE_PAY'],
  31. $rocket->getParams()
  32. ),
  33. ])
  34. ;
  35. Logger::info('[alipay][PagePayPlugin] 插件装载完毕', ['rocket' => $rocket]);
  36. return $next($rocket);
  37. }
  38. }