PPExpressGatewayTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace Omnipay\UnionPay\Tests;
  3. use Omnipay\Omnipay;
  4. use Omnipay\Tests\GatewayTestCase;
  5. use Omnipay\UnionPay\ExpressGateway;
  6. use Omnipay\UnionPay\Message\CreateOrderResponse;
  7. use Omnipay\UnionPay\Message\ExpressPurchaseResponse;
  8. class PPExpressGatewayTest extends GatewayTestCase
  9. {
  10. /**
  11. * @var ExpressGateway $gateway
  12. */
  13. protected $gateway;
  14. protected $options;
  15. public function setUp()
  16. {
  17. parent::setUp();
  18. $this->gateway = Omnipay::create('UnionPay_Express');
  19. $this->gateway->setMerId(UNIONPAY_MER_ID);
  20. $this->gateway->setCertId(UNIONPAY_CERT_ID);
  21. $this->gateway->setPrivateKey(UNIONPAY_PRIVATE_KEY);
  22. $this->gateway->setPublicKey(UNIONPAY_PUBLIC_KEY);
  23. $this->gateway->setReturnUrl('http://example.com/return');
  24. $this->gateway->setNotifyUrl('http://example.com/notify');
  25. }
  26. public function testPurchase()
  27. {
  28. $order = array(
  29. 'orderId' => date('YmdHis'), //Your order ID
  30. 'txnTime' => date('YmdHis'), //Should be format 'YmdHis'
  31. 'title' => 'My order title', //Order Title
  32. 'txnAmt' => '100', //Order Total Fee
  33. );
  34. /**
  35. * @var ExpressPurchaseResponse $response
  36. */
  37. $response = $this->gateway->purchase($order)->send();
  38. $this->assertTrue($response->isSuccessful());
  39. $this->assertTrue($response->isRedirect());
  40. $this->assertNotEmpty($response->getRedirectHtml());
  41. }
  42. public function testCreateOrder()
  43. {
  44. $order = array(
  45. 'orderId' => date('YmdHis'), //Your order ID
  46. 'txnTime' => date('YmdHis'), //Should be format 'YmdHis'
  47. 'title' => 'My order title', //Order Title
  48. 'txnAmt' => '100', //Order Total Fee
  49. );
  50. /**
  51. * @var CreateOrderResponse $response
  52. */
  53. $response = $this->gateway->createOrder($order)->send();
  54. $this->assertFalse($response->isSuccessful());
  55. $this->assertFalse($response->isRedirect());
  56. }
  57. public function testCompletePurchase()
  58. {
  59. $options = array(
  60. 'request_params' => array(
  61. 'certId' => UNIONPAY_CERT_ID,
  62. 'signature' => 'xxxxxxx'
  63. ),
  64. );
  65. /**
  66. * @var ExpressPurchaseResponse $response
  67. */
  68. $response = $this->gateway->completePurchase($options)->send();
  69. $this->assertFalse($response->isSuccessful());
  70. }
  71. public function testQuery()
  72. {
  73. $options = array(
  74. 'certId' => UNIONPAY_CERT_ID,
  75. 'orderId' => 'xxxxxxx',
  76. 'txnTime' => date('YmdHis'),
  77. 'txnAmt' => '100',
  78. );
  79. /**
  80. * @var ExpressPurchaseResponse $response
  81. */
  82. $response = $this->gateway->query($options)->send();
  83. $this->assertFalse($response->isSuccessful());
  84. }
  85. public function testConsumeUndo()
  86. {
  87. $options = array(
  88. 'certId' => UNIONPAY_CERT_ID,
  89. 'orderId' => 'xxxxxxx',
  90. 'txnAmt' => '100',
  91. 'queryId' => 'XXXXX',
  92. 'txnTime' => date('YmdHis'),
  93. );
  94. /**
  95. * @var ExpressPurchaseResponse $response
  96. */
  97. $response = $this->gateway->consumeUndo($options)->send();
  98. $this->assertFalse($response->isSuccessful());
  99. }
  100. public function testRefund()
  101. {
  102. $options = array(
  103. 'certId' => UNIONPAY_CERT_ID,
  104. 'orderId' => '222222',
  105. 'queryId' => '333333',
  106. 'txnTime' => date('YmdHis'),
  107. 'txnAmt' => '100',
  108. );
  109. /**
  110. * @var ExpressPurchaseResponse $response
  111. */
  112. $response = $this->gateway->refund($options)->send();
  113. $this->assertFalse($response->isSuccessful());
  114. }
  115. public function testFileTransfer()
  116. {
  117. $options = array(
  118. 'certId' => UNIONPAY_CERT_ID,
  119. 'txnTime' => date('YmdHis'),
  120. 'fileType' => '00',
  121. 'settleDate' => '0815',
  122. );
  123. /**
  124. * @var ExpressPurchaseResponse $response
  125. */
  126. $response = $this->gateway->fileTransfer($options)->send();
  127. $this->assertFalse($response->isSuccessful());
  128. }
  129. }