Client.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /*
  3. * This file is part of the overtrue/wechat.
  4. *
  5. * (c) overtrue <i@overtrue.me>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace EasyWeChat\Payment\Reverse;
  11. use EasyWeChat\Payment\Kernel\BaseClient;
  12. class Client extends BaseClient
  13. {
  14. /**
  15. * Reverse order by out trade number.
  16. *
  17. * @param string $outTradeNumber
  18. *
  19. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  20. *
  21. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  22. */
  23. public function byOutTradeNumber(string $outTradeNumber)
  24. {
  25. return $this->reverse($outTradeNumber, 'out_trade_no');
  26. }
  27. /**
  28. * Reverse order by transaction_id.
  29. *
  30. * @param string $transactionId
  31. *
  32. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  33. *
  34. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  35. */
  36. public function byTransactionId(string $transactionId)
  37. {
  38. return $this->reverse($transactionId, 'transaction_id');
  39. }
  40. /**
  41. * Reverse order.
  42. *
  43. * @param string $number
  44. * @param string $type
  45. *
  46. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  47. *
  48. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  49. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  50. * @throws \GuzzleHttp\Exception\GuzzleException
  51. */
  52. protected function reverse(string $number, string $type)
  53. {
  54. $params = [
  55. 'appid' => $this->app['config']->app_id,
  56. $type => $number,
  57. ];
  58. return $this->safeRequest($this->wrap('secapi/pay/reverse'), $params);
  59. }
  60. }