PaymentTest.php 3.5 KB

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