function testWrongPwd()
 {
     $this->expectException(new Errors\NetworkError($this->credentials->paymentHost . '/payment', 401, 'The requested URL returned error: 401'));
     Config::set($this->credentials->user, 'wrong password', Config::ENV_SANDBOX);
     $data = $this->fixture('wpf_payment_request_simple.json');
     $payment = Payment::wpf($data);
 }
示例#2
0
 /**
  * @param string $mode \Hypercharge\Config::ENV_LIVE or ::ENV_SANDBOX
  * @param string|array $path e.g. 'scheduler' or an array of string e.g. array('scheduler', '<UNIQUE_ID>', 'transactions')
  * @param array|object $params GET params as key-value hash e.g. array('page'=>1, 'per_page'=>30) examples see unittest
  */
 function __construct($mode, $path, $params = array())
 {
     if (!\Hypercharge\Config::isValidMode($mode)) {
         throw new \Exception('mode must be "sandbox" or "live"');
     }
     $this->mode = $mode;
     $this->path = $path;
     $this->params = $params;
 }
 function testCall()
 {
     XmlSerializer::$sort = true;
     $data = $this->schemaRequest('WpfPayment.json');
     $requestXml = $this->schemaRequest('WpfPayment.xml');
     $responseXml = $this->schemaResponse('WpfPayment_new.xml');
     $this->curlMock()->shouldReceive('xmlPost')->with('https://testpayment.hypercharge.net/payment', $requestXml)->once()->andReturn($responseXml);
     $request = new PaymentRequest($data['payment']);
     $url = new PaymentUrl(Config::getMode());
     $ws = new XmlWebservice();
     $response = $ws->call($url, $request);
     $this->assertIsA($response, 'Hypercharge\\Payment');
     $this->assertEqual($response->type, 'WpfPayment');
 }
 function mockV2Url($path, $params = null)
 {
     if (!method_exists(Config::getFactory(), 'shouldReceive')) {
         return;
     }
     // mocking in php is pain in the arxx
     if ($params === null) {
         $url = m::mock('Hypercharge\\v2\\Url[getUrl]', array('sandbox', $path));
         $url->shouldReceive('getUrl')->andReturn($this->credentials->gatewayHost . '/v2');
         Config::getFactory()->shouldReceive('createUrl')->with($path)->andReturn($url);
     } else {
         $url = m::mock('Hypercharge\\v2\\Url[getUrl]', array('sandbox', $path, $params));
         $url->shouldReceive('getUrl')->andReturn($this->credentials->gatewayHost . '/v2');
         Config::getFactory()->shouldReceive('createUrl')->with($path, $params)->andReturn($url);
     }
 }
 function testNotificationMissingPasswordThrows()
 {
     $postData = $this->schemaNotification('transaction_notification.json');
     Config::set('username', '', Config::ENV_SANDBOX);
     $this->assertEqual('', Config::getPassword());
     try {
         Transaction::notification($postData);
         $this->fail('Errors\\ArgumentError expected!');
     } catch (Errors\ArgumentError $exe) {
         $this->assertEqual('password is not configured! See Hypercharge\\Config::set()', $exe->getMessage());
         return;
     } catch (Exception $exe) {
         $this->fail('unexpected Exception: ' . $exe->toString());
     }
 }
 function tearDown()
 {
     m::close();
     Config::setFactory(new Factory());
 }
 function expect_Curl_jsonRequest()
 {
     $curl = m::mock('Hypercharge\\Curl[jsonRequest][close]', array(Config::getUser(), Config::getPassword()));
     $curl->shouldReceive('close');
     $factory = m::mock('Hypercharge\\Factory[createHttpsClient]');
     $factory->shouldReceive('createHttpsClient')->andReturn($curl);
     Config::setFactory($factory);
     return $curl->shouldReceive('jsonRequest');
 }