PayPlugin.php 1.2 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\Exception\ContainerException;
  7. use Yansongda\Pay\Exception\ServiceNotFoundException;
  8. use Yansongda\Pay\Logger;
  9. use Yansongda\Pay\Rocket;
  10. use Yansongda\Pay\Traits\SupportServiceProviderTrait;
  11. /**
  12. * @see https://opendocs.alipay.com/open/02fkat?ref=api&scene=common
  13. */
  14. class PayPlugin implements PluginInterface
  15. {
  16. use SupportServiceProviderTrait;
  17. /**
  18. * @throws ContainerException
  19. * @throws ServiceNotFoundException
  20. */
  21. public function assembly(Rocket $rocket, Closure $next): Rocket
  22. {
  23. Logger::debug('[alipay][PayPlugin] 插件开始装载', ['rocket' => $rocket]);
  24. $this->loadAlipayServiceProvider($rocket);
  25. $rocket->mergePayload([
  26. 'method' => 'alipay.trade.pay',
  27. 'biz_content' => array_merge(
  28. [
  29. 'product_code' => 'FACE_TO_FACE_PAYMENT',
  30. 'scene' => 'bar_code',
  31. ],
  32. $rocket->getParams(),
  33. ),
  34. ]);
  35. Logger::info('[alipay][PayPlugin] 插件装载完毕', ['rocket' => $rocket]);
  36. return $next($rocket);
  37. }
  38. }