refund.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. $aliConfig = require_once __DIR__ . '/../aliconfig.php';
  13. $refundNo = time() . rand(1000, 9999);
  14. $refundData = [
  15. 'trade_no' => '15806490592761',
  16. 'transaction_id' => '', // 支付宝交易号, 与 trade_no 必须二选一
  17. 'refund_fee' => '0.01',
  18. 'reason' => '我要退款',
  19. 'refund_no' => $refundNo,
  20. ];
  21. var_dump($refundData);
  22. // 使用
  23. try {
  24. $client = new \Payment\Client(\Payment\Client::ALIPAY, $aliConfig);
  25. $res = $client->refund($refundData);
  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. } catch (Exception $e) {
  36. echo $e->getMessage();
  37. exit;
  38. }
  39. var_dump($res);