ExpressGatewayTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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\ExpressPurchaseResponse;
  7. class ExpressGatewayTest extends GatewayTestCase
  8. {
  9. /**
  10. * @var ExpressGateway
  11. */
  12. protected $gateway;
  13. protected $options;
  14. public function setUp()
  15. {
  16. parent::setUp();
  17. $this->gateway = Omnipay::create('UnionPay_Express');
  18. $this->gateway->setMerId(UNIONPAY_MER_ID);
  19. $this->gateway->setCertDir(UNIONPAY_CERT_DIR); // .pfx file
  20. $this->gateway->setCertPath(UNIONPAY_CERT_PATH); // .pfx file
  21. $this->gateway->setCertPassword(UNIONPAY_CERT_PASSWORD);
  22. $this->gateway->setReturnUrl('http://example.com/return');
  23. $this->gateway->setNotifyUrl('http://example.com/notify');
  24. $this->gateway->setEnvironment('sandbox');
  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
  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 testCompletePurchase()
  43. {
  44. $options = array(
  45. 'request_params' => array(
  46. 'certId' => '68759585097',
  47. 'signature' => 'xxxxxxx',
  48. ),
  49. );
  50. /**
  51. * @var ExpressPurchaseResponse
  52. */
  53. $response = $this->gateway->completePurchase($options)->send();
  54. $this->assertFalse($response->isSuccessful());
  55. }
  56. public function testQuery()
  57. {
  58. $options = array(
  59. 'certId' => UNIONPAY_CERT_ID,
  60. 'orderId' => 'xxxxxxx',
  61. 'txnTime' => date('YmdHis'),
  62. 'txnAmt' => '100',
  63. );
  64. /**
  65. * @var ExpressPurchaseResponse
  66. */
  67. $response = $this->gateway->query($options)->send();
  68. $this->assertFalse($response->isSuccessful());
  69. }
  70. public function testConsumeUndo()
  71. {
  72. $options = array(
  73. 'certId' => UNIONPAY_CERT_ID,
  74. 'orderId' => 'xxxxxxx',
  75. 'txnAmt' => '100',
  76. 'queryId' => 'XXXXX',
  77. 'txnTime' => date('YmdHis'),
  78. );
  79. /**
  80. * @var ExpressPurchaseResponse
  81. */
  82. $response = $this->gateway->consumeUndo($options)->send();
  83. $this->assertFalse($response->isSuccessful());
  84. }
  85. public function testRefund()
  86. {
  87. $options = array(
  88. 'certId' => UNIONPAY_CERT_ID,
  89. 'orderId' => '222222',
  90. 'queryId' => '333333',
  91. 'txnTime' => date('YmdHis'),
  92. 'txnAmt' => '100',
  93. );
  94. /**
  95. * @var ExpressPurchaseResponse
  96. */
  97. $response = $this->gateway->refund($options)->send();
  98. $this->assertFalse($response->isSuccessful());
  99. }
  100. public function testFileTransfer()
  101. {
  102. $options = array(
  103. 'certId' => UNIONPAY_CERT_ID,
  104. 'txnTime' => date('YmdHis'),
  105. 'fileType' => '00',
  106. 'settleDate' => '0815',
  107. );
  108. $response = $this->gateway->fileTransfer($options)->send();
  109. $this->assertFalse($response->isSuccessful());
  110. }
  111. }