TransactionServiceTest.php 2.6 KB

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