ScanGateway.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Yansongda\Pay\Gateways\Wechat;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Yansongda\Pay\Events;
  5. use Yansongda\Pay\Exceptions\GatewayException;
  6. use Yansongda\Pay\Exceptions\InvalidArgumentException;
  7. use Yansongda\Pay\Exceptions\InvalidSignException;
  8. use Yansongda\Supports\Collection;
  9. class ScanGateway extends Gateway
  10. {
  11. /**
  12. * Pay an order.
  13. *
  14. * @author yansongda <me@yansongda.cn>
  15. *
  16. * @param string $endpoint
  17. *
  18. * @throws GatewayException
  19. * @throws InvalidArgumentException
  20. * @throws InvalidSignException
  21. */
  22. public function pay($endpoint, array $payload): Collection
  23. {
  24. $payload['spbill_create_ip'] = Request::createFromGlobals()->server->get('SERVER_ADDR');
  25. $payload['trade_type'] = $this->getTradeType();
  26. Events::dispatch(new Events\PayStarted('Wechat', 'Scan', $endpoint, $payload));
  27. return $this->preOrder($payload);
  28. }
  29. /**
  30. * Get trade type config.
  31. *
  32. * @author yansongda <me@yansongda.cn>
  33. */
  34. protected function getTradeType(): string
  35. {
  36. return 'NATIVE';
  37. }
  38. }