PaymentTest.php 3.8 KB

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