LegacyMobileGatewayTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Omnipay\UnionPay\Tests;
  3. use Omnipay\Omnipay;
  4. use Omnipay\Tests\GatewayTestCase;
  5. use Omnipay\UnionPay\LegacyMobileGateway;
  6. use Omnipay\UnionPay\Message\LegacyMobilePurchaseResponse;
  7. class LegacyMobileGatewayTest extends GatewayTestCase
  8. {
  9. /**
  10. * @var LegacyMobileGateway $gateway
  11. */
  12. protected $gateway;
  13. protected $options;
  14. public function setUp()
  15. {
  16. parent::setUp();
  17. $this->gateway = Omnipay::create('UnionPay_LegacyMobile');
  18. $this->gateway->setMerId(UNIONPAY_MER_ID);
  19. $this->gateway->setSecretKey('xxxxxxx');
  20. $this->gateway->setReturnUrl('http://example.com/return');
  21. $this->gateway->setNotifyUrl('http://example.com/notify');
  22. $this->gateway->setEnvironment('production');
  23. }
  24. public function testPurchase()
  25. {
  26. $order = array(
  27. 'orderNumber' => date('YmdHis'), //Your order ID
  28. 'orderTime' => date('YmdHis'), //Should be format 'YmdHis'
  29. 'title' => 'My order title', //Order Title
  30. 'orderAmount' => '100', //Order Total Fee
  31. );
  32. /**
  33. * @var LegacyMobilePurchaseResponse $response
  34. */
  35. $response = $this->gateway->purchase($order)->send();
  36. $this->assertTrue($response->isSuccessful());
  37. $this->assertFalse($response->isRedirect());
  38. $this->assertNull($response->getTradeNo());
  39. }
  40. public function testCompletePurchase()
  41. {
  42. $options = array(
  43. 'request_params' => array(
  44. 'certId' => UNIONPAY_CERT_ID,
  45. 'signature' => 'xxxxxxx'
  46. ),
  47. );
  48. /**
  49. * @var LegacyMobilePurchaseResponse $response
  50. */
  51. $response = $this->gateway->completePurchase($options)->send();
  52. $this->assertFalse($response->isSuccessful());
  53. }
  54. }