refund.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /*
  3. * The file is part of the payment lib.
  4. *
  5. * (c) Leo <dayugog@gmail.com>
  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. require_once __DIR__ . '/../../vendor/autoload.php';
  11. date_default_timezone_set('Asia/Shanghai');
  12. $wxConfig = require_once __DIR__ . '/../wxconfig.php';
  13. $refundNo = time() . rand(1000, 9999);
  14. $data = [
  15. 'trade_no' => '15805490027722',
  16. 'transaction_id' => '4988319909620200201172451651106',
  17. 'total_fee' => '5.52',
  18. 'refund_fee' => '5.52',
  19. 'refund_no' => $refundNo,
  20. 'refund_account' => 'REFUND_SOURCE_REC', // REFUND_RECHARGE:可用余额退款 REFUND_UNSETTLED:未结算资金退款(默认)
  21. ];
  22. // 使用
  23. try {
  24. $client = new \Payment\Client(\Payment\Client::WECHAT, $wxConfig);
  25. $res = $client->refund($data);
  26. } catch (InvalidArgumentException $e) {
  27. echo $e->getMessage();
  28. exit;
  29. } catch (\Payment\Exceptions\GatewayException $e) {
  30. echo $e->getMessage();
  31. exit;
  32. } catch (\Payment\Exceptions\ClassNotFoundException $e) {
  33. echo $e->getMessage();
  34. exit;
  35. }
  36. var_dump($res);