TransactionServiceTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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: '20251201110113130266241823831000', outTradeNo: '20251119161738023242',
  54. );
  55. dump($response);
  56. }
  57. #[Test]
  58. public function refund()
  59. {
  60. $response = $this->transactionService->refund(
  61. refundTradeNo: '20251119215114025260',
  62. refundAmount: .01,
  63. locationInfo: new LocationInfo(requestIP: '183.214.109.50'),
  64. originOutTradeNo: '20251119215114025260',
  65. refundReason: '测试退款',
  66. );
  67. dump($response);
  68. }
  69. }