GatewayTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. namespace Omnipay\WechatPay;
  3. use Omnipay\Omnipay;
  4. use Omnipay\Tests\TestCase;
  5. use Omnipay\WechatPay\Message\CloseOrderResponse;
  6. use Omnipay\WechatPay\Message\CompletePurchaseResponse;
  7. use Omnipay\WechatPay\Message\CreateOrderResponse;
  8. use Omnipay\WechatPay\Message\QueryOrderResponse;
  9. use Omnipay\WechatPay\Message\RefundOrderResponse;
  10. class GatewayTest extends TestCase
  11. {
  12. /**
  13. * @var Gateway $gateway
  14. */
  15. protected $gateway;
  16. protected $options;
  17. protected $fuckTimeout = false;
  18. public function setUp()
  19. {
  20. parent::setUp();
  21. $this->gateway = Omnipay::create('WechatPay');
  22. $this->gateway->setAppId('123456789');
  23. $this->gateway->setMchId('4567891011');
  24. $this->gateway->setApiKey('XXSXXXSXXSXXSX');
  25. $this->gateway->setNotifyUrl('http://example.com/notify');
  26. $this->gateway->setTradeType('APP');
  27. }
  28. public function testPurchase()
  29. {
  30. if ($this->fuckTimeout) {
  31. return;
  32. }
  33. $order = array(
  34. 'outTrade_No' => '1112',//date('YmdHis'), //Should be format 'YmdHis'
  35. 'totalfee' => '0.01', //Order Title
  36. 'body' => 'test', //Your order ID
  37. 'spbill_create_ip' => '114.119.110.120', //Order Total Fee
  38. );
  39. /**
  40. * @var CreateOrderResponse $response
  41. */
  42. $response = $this->gateway->purchase($order)->send();
  43. $this->assertFalse($response->isSuccessful());
  44. $this->assertFalse($response->isRedirect());
  45. }
  46. public function testCompletePurchase()
  47. {
  48. if ($this->fuckTimeout) {
  49. return;
  50. }
  51. $options = array(
  52. 'request_params' => array(
  53. 'appid' => '123456',
  54. 'mch_id' => '789456',
  55. 'result_code' => 'SUCCESS'
  56. ),
  57. );
  58. /**
  59. * @var CompletePurchaseResponse $response
  60. */
  61. $response = $this->gateway->completePurchase($options)->send();
  62. $this->assertFalse($response->isSuccessful());
  63. }
  64. public function testQuery()
  65. {
  66. if ($this->fuckTimeout) {
  67. return;
  68. }
  69. $options = array(
  70. 'transaction_id' => '3474813271258769001041842579301293446',
  71. );
  72. /**
  73. * @var QueryOrderResponse $response
  74. */
  75. $response = $this->gateway->query($options)->send();
  76. $this->assertFalse($response->isSuccessful());
  77. }
  78. public function testClose()
  79. {
  80. if ($this->fuckTimeout) {
  81. return;
  82. }
  83. $options = array(
  84. 'out_trade_no' => '1234567891023',
  85. );
  86. /**
  87. * @var CloseOrderResponse $response
  88. */
  89. $response = $this->gateway->query($options)->send();
  90. $this->assertFalse($response->isSuccessful());
  91. }
  92. public function testRefund()
  93. {
  94. if ($this->fuckTimeout) {
  95. return;
  96. }
  97. $options = array(
  98. 'transaction_id' => '1234567891023',
  99. 'out_refund_no' => '1234567891023',
  100. 'total_fee' => '100',
  101. 'refund_fee' => '100',
  102. );
  103. /**
  104. * @var RefundOrderResponse $response
  105. */
  106. $response = $this->gateway->query($options)->send();
  107. $this->assertFalse($response->isSuccessful());
  108. }
  109. public function testQueryRefund()
  110. {
  111. if ($this->fuckTimeout) {
  112. return;
  113. }
  114. $options = array(
  115. 'transaction_id' => '1234567891023',
  116. );
  117. /**
  118. * @var RefundOrderResponse $response
  119. */
  120. $response = $this->gateway->query($options)->send();
  121. $this->assertFalse($response->isSuccessful());
  122. }
  123. }