PaymentTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace app\api\controller\tests;
  3. use AdaPay;
  4. use AdaPaySdk;
  5. use PHPUnit\Framework\TestCase;
  6. class PaymentTest extends TestCase
  7. {
  8. public function testCreate()
  9. {
  10. $obj = new AdaPaySdk\Payment();
  11. $adaPay = new AdaPay\AdaPay();
  12. $adaPay->gateWayType = 'api';
  13. $obj_params = array(
  14. 'app_id' => 'app_7d87c043-aae3-4357-9b2c-269349a980d6',
  15. // 'app_id'=> 'app_f7841d17-8d4e-469f-82da-1c3f43c3e470',
  16. 'order_no' => "PY_" . date("YmdHis") . rand(100000, 999999),
  17. 'pay_channel' => 'alipay',
  18. 'time_expire' => date("YmdHis", time() + 86400),
  19. 'pay_amt' => '0.01',
  20. 'goods_title' => 'subject',
  21. 'goods_desc' => 'body',
  22. 'description' => 'description',
  23. 'device_id' => ['device_id' => "1111"],
  24. 'expend' => [
  25. 'buyer_id' => '1111111', // 支付宝卖家账号ID
  26. 'buyer_logon_id' => '22222222222', // 支付宝卖家账号
  27. 'promotion_detail' => [ // 优惠信息
  28. 'cont_price' => '100.00', // 订单原价格
  29. 'receipt_id' => '123', // 商家小票ID
  30. 'goodsDetail' => [ // 商品信息集合
  31. ['goods_id' => "111", "goods_name" => "商品1", "quantity" => 1, "price" => "1.00"],
  32. ['goods_id' => "112", "goods_name" => "商品2", "quantity" => 1, "price" => "1.01"]
  33. ]
  34. ]
  35. ]
  36. );
  37. $obj->create($obj_params);
  38. print("创建支付对象" . $obj->isError() . '=>' . json_encode($obj->result) . "\n");
  39. $this->assertEquals('succeeded', $obj->result['status']);
  40. // $this->assertTrue($obj->isError());
  41. }
  42. public function testQuery()
  43. {
  44. $obj = new AdaPaySdk\Payment();
  45. $adaPay = new AdaPay\AdaPay();
  46. $adaPay->gateWayType = 'api';
  47. $obj_params = array(
  48. 'payment_id' => '002112020102614582910166695202499047424'
  49. );
  50. $obj->query($obj_params);
  51. print("查询支付对象" . $obj->isError() . '=>' . json_encode($obj->result) . "\n");
  52. $this->assertEquals('succeeded', $obj->result['status']);
  53. // $this->assertTrue($account->isError());
  54. }
  55. public function testQueryList()
  56. {
  57. $obj = new AdaPaySdk\Payment();
  58. $adaPay = new AdaPay\AdaPay();
  59. $adaPay->gateWayType = 'api';
  60. $obj_params = array(
  61. "app_id" => "app_7d87c043-aae3-4357-9b2c-269349a980d6",
  62. "payment_id" => "002112020102614582910166695202499047424",
  63. "order_no" => "PY_20201026145829830248",
  64. "page_index" => "",
  65. "page_size" => "",
  66. "created_gte" => "",
  67. "created_lte" => ""
  68. );
  69. $obj->queryList($obj_params);
  70. print("查询支付对象列表" . $obj->isError() . '=>' . json_encode($obj->result) . "\n");
  71. $this->assertEquals('succeeded', $obj->result['status']);
  72. // $this->assertTrue($account->isError());
  73. }
  74. public function testClose()
  75. {
  76. $obj = new AdaPaySdk\Payment();
  77. $adaPay = new AdaPay\AdaPay();
  78. $adaPay->gateWayType = 'api';
  79. $obj_params = array(
  80. # 设置支付对象ID
  81. 'payment_id' => '002112019101517084010030107738472407040',
  82. # 设置描述
  83. 'reason' => '关单描述',
  84. # 设置扩展域
  85. 'expend' => '{"key": "1233"}'
  86. );
  87. $obj->close($obj_params);
  88. print("支付关单" . $obj->isError() . '=>' . json_encode($obj->result) . "\n");
  89. $this->assertEquals('succeeded', $obj->result['status']);
  90. // $this->assertEquals('succeeded', $obj->result['status']);
  91. // $this->assertTrue($account->isError());
  92. }
  93. }