TransactionServiceTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. declare(strict_types=1);
  3. namespace SixShop\Lakala\Service;
  4. use PHPUnit\Framework\Attributes\Test;
  5. use PHPUnit\Framework\TestCase;
  6. use SixShop\Lakala\Dto\LocationInfo;
  7. use SixShop\Lakala\OpenAPISDK\V3\Model\TradePreorderWechaAccBusiFields;
  8. use SixShop\Lakala\OpenAPISDK\V3\Model\TradePreorderWechaDetail;
  9. use SixShop\Lakala\OpenAPISDK\V3\Model\TradePreorderWechaGoodsDetail;
  10. use SixShop\Payment\Enum\NumberBizEnum;
  11. class TransactionServiceTest extends TestCase
  12. {
  13. private TransactionService $transactionService;
  14. protected function setUp(): void
  15. {
  16. $this->transactionService = app(TransactionService::class);
  17. }
  18. #[Test]
  19. public function preOrder()
  20. {
  21. $totalAmount = 500;
  22. // 微信主扫场景 - 账户端业务信息
  23. $accBusiFields = new TradePreorderWechaAccBusiFields();
  24. $accBusiFields->setTimeoutExpress(15);
  25. $accBusiFields->setSubAppid('wx1308d811d01639eb');
  26. $accBusiFields->setUserId('oPuRO15wmxv3AwRyEznRfuDLehrk');
  27. $detail = new TradePreorderWechaDetail();
  28. $detail->setCostPrice($totalAmount);
  29. $detail->setReceiptId('');
  30. $goodsDetail = new TradePreorderWechaGoodsDetail();
  31. $goodsDetail->setGoodsId('3452234');
  32. $goodsDetail->setWxpayGoodsId('');
  33. $goodsDetail->setGoodsName('纯礼 脚臭粉*2+沐浴皂液*1+氨基酸洁面液*1+羊奶皂*6');
  34. $goodsDetail->setQuantity(1);
  35. $goodsDetail->setPrice($totalAmount);
  36. $detail->setGoodsDetail([$goodsDetail]);
  37. // $accBusiFields->setDetail($detail);
  38. $response = $this->transactionService->preOrder(
  39. outTradeNo: generate_number(NumberBizEnum::ORDER_PAY),
  40. totalAmount: $totalAmount,
  41. locationInfo: new LocationInfo(requestIP: '183.214.109.50'),
  42. subject: '测试订单',
  43. settleType: "1",
  44. remark: "纯礼 脚臭粉*2+沐浴皂液*1+氨基酸洁面液*1+羊奶皂*6",
  45. accBusiFields: $accBusiFields,
  46. );
  47. dump($response);
  48. }
  49. #[Test]
  50. public function queryTrade()
  51. {
  52. $response = $this->transactionService->queryTrade(
  53. // tradeNo: '20251119110113130266202252424725',
  54. outTradeNo: '20251119145747020294',
  55. );
  56. dump($response);
  57. }
  58. #[Test]
  59. public function refund()
  60. {
  61. $response = $this->transactionService->refund(
  62. refundTradeNo: '20251119215114025260',
  63. refundAmount: .01,
  64. locationInfo: new LocationInfo(requestIP: '183.214.109.50'),
  65. originOutTradeNo: '20251119215114025260',
  66. refundReason: '测试退款',
  67. );
  68. dump($response);
  69. }
  70. }