WtzGatewayTest.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <?php
  2. namespace Omnipay\UnionPay\Tests;
  3. use Omnipay\Omnipay;
  4. use Omnipay\Tests\GatewayTestCase;
  5. use Omnipay\UnionPay\WtzGateway;
  6. class WtzGatewayTest extends GatewayTestCase
  7. {
  8. /**
  9. * @var WtzGateway $gateway
  10. */
  11. protected $gateway;
  12. protected $options;
  13. public function setUp()
  14. {
  15. parent::setUp();
  16. $this->gateway = Omnipay::create('UnionPay_Wtz');
  17. $this->gateway->setMerId(UNIONPAY_MER_ID);
  18. $this->gateway->setEncryptCert(UNIONPAY_TWZ_ENCRYPT_CERT);
  19. $this->gateway->setMiddleCert(UNIONPAY_TWZ_MIDDLE_CERT);
  20. $this->gateway->setRootCert(UNIONPAY_TWZ_ROOT_CERT);
  21. $this->gateway->setCertPath(UNIONPAY_TWZ_SIGN_CERT);
  22. $this->gateway->setCertPassword(UNIONPAY_CERT_PASSWORD);
  23. $this->gateway->setReturnUrl('http://example.com/return');
  24. $this->gateway->setNotifyUrl('http://example.com/notify');
  25. }
  26. private function open($content)
  27. {
  28. return $file = sprintf('./%s.html', md5(uniqid()));
  29. $fh = fopen($file, 'w');
  30. fwrite($fh, $content);
  31. fclose($fh);
  32. exec(sprintf('open %s -a "/Applications/Google Chrome.app" && rm %s', $file, $file));
  33. }
  34. public function testFrontOpenConsume()
  35. {
  36. date_default_timezone_set('PRC');
  37. $orderId = date('YmdHis');
  38. $params = array(
  39. 'orderId' => $orderId,
  40. 'txnTime' => date('YmdHis'),
  41. 'txnAmt' => '100',
  42. 'trId' => '62000000001',
  43. 'accNo' => '6226090000000048',
  44. 'payTimeout' => date('YmdHis', strtotime('+15 minutes')),
  45. 'customerInfo' => array(
  46. 'phoneNo' => '18100000000', //Phone Number
  47. 'certifTp' => '01', //ID Card
  48. 'certifId' => '510265790128303', //ID Card Number
  49. 'customerNm' => '张三', // Name
  50. //'cvn2' => '248', //cvn2
  51. //'expired' => '1912', // format YYMM
  52. ),
  53. );
  54. /**
  55. * @var \Omnipay\UnionPay\Message\WtzFrontOpenConsumeResponse $response
  56. */
  57. $response = $this->gateway->frontOpenConsume($params)->send();
  58. $this->assertTrue($response->isSuccessful());
  59. $form = $response->getRedirectForm();
  60. $this->open($form);
  61. }
  62. public function testFrontOpen()
  63. {
  64. date_default_timezone_set('PRC');
  65. $orderId = date('YmdHis');
  66. $params = array(
  67. 'orderId' => $orderId,
  68. 'txnTime' => date('YmdHis'),
  69. 'trId' => '62000000001',
  70. 'accNo' => '6226090000000048',
  71. 'payTimeout' => date('YmdHis', strtotime('+15 minutes'))
  72. );
  73. /**
  74. * @var \Omnipay\UnionPay\Message\WtzFrontOpenResponse $response
  75. */
  76. $response = $this->gateway->frontOpen($params)->send();
  77. $this->assertTrue($response->isSuccessful());
  78. $form = $response->getRedirectForm();
  79. $this->open($form);
  80. }
  81. public function testBackOpen()
  82. {
  83. date_default_timezone_set('PRC');
  84. $params = array(
  85. 'orderId' => date('YmdHis'),
  86. 'txnTime' => date('YmdHis'),
  87. 'trId' => '62000000001',
  88. 'accNo' => '6226090000000048',
  89. 'customerInfo' => array(
  90. 'phoneNo' => '18100000000', //Phone Number
  91. 'certifTp' => '01', //ID Card
  92. 'certifId' => '510265790128303', //ID Card Number
  93. 'customerNm' => '张三', // Name
  94. //'cvn2' => '248', //cvn2
  95. //'expired' => '1912', // format YYMM
  96. ),
  97. 'payTimeout' => date('YmdHis', strtotime('+15 minutes'))
  98. );
  99. /**
  100. * @var \Omnipay\UnionPay\Message\WtzFrontOpenResponse $response
  101. */
  102. $response = $this->gateway->backOpen($params)->send();
  103. $this->assertFalse($response->isSuccessful());
  104. }
  105. public function testSmsOpen()
  106. {
  107. date_default_timezone_set('PRC');
  108. $params = array(
  109. 'orderId' => date('YmdHis'),
  110. 'txnTime' => date('YmdHis'),
  111. 'trId' => '62000000001',
  112. 'accNo' => '6226090000000048',
  113. 'customerInfo' => array(
  114. 'phoneNo' => '18100000000', //Phone Number
  115. 'certifTp' => '01', //ID Card
  116. 'certifId' => '510265790128303', //ID Card Number
  117. 'customerNm' => '张三', // Name
  118. //'cvn2' => '248', //cvn2
  119. //'expired' => '1912', // format YYMM
  120. ),
  121. 'payTimeout' => date('YmdHis', strtotime('+15 minutes'))
  122. );
  123. /**
  124. * @var \Omnipay\UnionPay\Message\WtzSmsOpenResponse $response
  125. */
  126. $response = $this->gateway->smsOpen($params)->send();
  127. $this->assertFalse($response->isSuccessful());
  128. }
  129. public function testCompleteFrontOpen()
  130. {
  131. parse_str(file_get_contents(UNIONPAY_DATA_DIR . '/WtzCompleteFrontOpen.txt'), $data);
  132. /**
  133. * @var \Omnipay\UnionPay\Message\WtzCompleteFrontOpenResponse $response
  134. */
  135. $response = $this->gateway->completeFrontOpen(array('request_params' => $data))->send();
  136. $this->assertFalse($response->isSuccessful());
  137. }
  138. public function testOpenQuery()
  139. {
  140. $params = array(
  141. 'orderId' => '20171030223623',
  142. 'txnTime' => date('YmdHis'),
  143. );
  144. /**
  145. * @var \Omnipay\UnionPay\Message\WtzOpenQueryResponse $response
  146. */
  147. $response = $this->gateway->openQuery($params)->send();
  148. $this->assertFalse($response->isSuccessful());
  149. }
  150. public function testSmsConsume()
  151. {
  152. $params = array(
  153. 'orderId' => '20171030223623',
  154. 'txnTime' => date('YmdHis'),
  155. 'txnAmt' => 100,
  156. 'trId' => '62000000001',
  157. 'token' => '6235240000020757577',
  158. );
  159. /**
  160. * @var \Omnipay\UnionPay\Message\WtzSmsConsumeResponse $response
  161. */
  162. $response = $this->gateway->smsConsume($params)->send();
  163. $this->assertFalse($response->isSuccessful());
  164. }
  165. public function testConsume()
  166. {
  167. $params = array(
  168. 'orderId' => '20171030223623',
  169. 'txnTime' => date('YmdHis'),
  170. 'txnAmt' => 100,
  171. 'trId' => '62000000001',
  172. 'token' => '6235240000020757577',
  173. );
  174. /**
  175. * @var \Omnipay\UnionPay\Message\WtzConsumeResponse $response
  176. */
  177. $response = $this->gateway->consume($params)->send();
  178. $this->assertFalse($response->isSuccessful());
  179. }
  180. public function testRefund()
  181. {
  182. $params = array(
  183. 'orderId' => date('YmdHis'),
  184. 'origQryId' => 'xxxxxxxxxxxxxx',
  185. 'txnTime' => date('YmdHis'),
  186. 'txnAmt' => 100,
  187. 'trId' => '62000000001',
  188. 'token' => '6235240000020757577',
  189. );
  190. /**
  191. * @var \Omnipay\UnionPay\Message\WtzRefundResponse $response
  192. */
  193. $response = $this->gateway->refund($params)->send();
  194. $this->assertFalse($response->isSuccessful());
  195. }
  196. public function testQuery()
  197. {
  198. $params = array(
  199. 'orderId' => '20171031035544',
  200. 'txnTime' => date('YmdHis'),
  201. );
  202. /**
  203. * @var \Omnipay\UnionPay\Message\WtzQueryResponse $response
  204. */
  205. $response = $this->gateway->query($params)->send();
  206. $this->assertFalse($response->isSuccessful());
  207. }
  208. public function testApplyToken()
  209. {
  210. $params = array(
  211. 'orderId' => '20171031035544',
  212. 'txnTime' => date('YmdHis'),
  213. 'trId' => '62000000001',
  214. );
  215. /**
  216. * @var \Omnipay\UnionPay\Message\WtzApplyTokenResponse $response
  217. */
  218. $response = $this->gateway->applyToken($params)->send();
  219. $this->assertFalse($response->isSuccessful());
  220. }
  221. public function testUpdateToken()
  222. {
  223. $params = array(
  224. 'orderId' => '20171031035544',
  225. 'txnTime' => date('YmdHis'),
  226. 'trId' => '62000000001',
  227. 'token' => '6235240000020757577',
  228. );
  229. /**
  230. * @var \Omnipay\UnionPay\Message\WtzApplyTokenResponse $response
  231. */
  232. $response = $this->gateway->applyToken($params)->send();
  233. $this->assertFalse($response->isSuccessful());
  234. }
  235. public function testDeleteToken()
  236. {
  237. $params = array(
  238. 'orderId' => '20171031035544',
  239. 'txnTime' => date('YmdHis'),
  240. 'trId' => '62000000001',
  241. 'token' => '6235240000020757577',
  242. );
  243. /**
  244. * @var \Omnipay\UnionPay\Message\WtzDeleteTokenResponse $response
  245. */
  246. $response = $this->gateway->deleteToken($params)->send();
  247. $this->assertFalse($response->isSuccessful());
  248. }
  249. }