public function testCaptureValidationCaptureID()
 {
     $request = new GetCaptureStatus($this->config);
     $request->setOrderID(1);
     $validation = new Validation();
     $validation->getValidator($request);
     $data = $validation->performValidation();
     /**
      * Test the captureID required validation
      */
     $this->assertValidationReturned('Upg\\Library\\Request\\GetCaptureStatus', 'captureID', 'captureID is required', $data, "captureID is required failed to trigger");
     /**
      * Test length
      */
     $request->setCaptureID($this->veryLongString);
     $validation->getValidator($request);
     $data = $validation->performValidation();
     $this->assertValidationReturned('Upg\\Library\\Request\\GetCaptureStatus', 'captureID', 'captureID must be between 1 and 30 characters', $data, "captureID must be between 1 and 30 characters failed to trigger");
 }
 /**
  * Make an successful call
  * Create a transaction then do the reserve call
  */
 public function testSuccessfulApiCall()
 {
     if (is_null($this->config)) {
         $this->markTestSkipped('Config is not set, please set up the required environment variables');
         return false;
     }
     $request = new CreateTransactionRequest($this->config);
     //unique ID for the tests
     $orderId = hash('crc32b', microtime());
     $captureId = hash('crc32b', microtime());
     $userId = "GUEST:" . hash('md5', microtime());
     $paymentInstrumentId = hash('crc32b', microtime());
     $request->setOrderID($orderId)->setUserID($userId)->setIntegrationType(CreateTransactionRequest::INTEGRATION_TYPE_API)->setAutoCapture(false)->setContext(CreateTransactionRequest::CONTEXT_ONLINE)->setMerchantReference("TEST")->setUserType(CreateTransactionRequest::USER_TYPE_PRIVATE)->setUserRiskClass(RiskClass::RISK_CLASS_DEFAULT)->setUserData($this->getUser())->setBillingAddress($this->getAddress())->setAmount($this->getAmount())->addBasketItem($this->getBasketItem())->setLocale(Codes::LOCALE_EN);
     $apiEndPoint = new CreateTransaction($this->config, $request);
     $createTransactionResult = $apiEndPoint->sendRequest();
     $this->assertEquals(0, $createTransactionResult->getData('resultCode'));
     $allowedPayments = $createTransactionResult->getData('allowedPaymentMethods');
     $this->assertTrue(in_array('CC', $createTransactionResult->getData('allowedPaymentMethods')));
     if (!in_array('CC', $allowedPayments)) {
         $this->fail("Allowed payment from CreateTransaction lacks CC can not continue");
     }
     /**
      * Register payment instrument
      */
     $registerUserPaymentInstrumentRequest = new RegisterUserPaymentInstrumentRequest($this->config);
     $registerUserPaymentInstrumentRequest->setUserID($userId)->setPaymentInstrument($this->getPaymentInstrument());
     $registerUserPaymentInstrument = new RegisterUserPaymentInstrumentApi($this->config, $registerUserPaymentInstrumentRequest);
     $registerUserPaymentInstrumentResult = $registerUserPaymentInstrument->sendRequest();
     $paymentInstrumentId = $registerUserPaymentInstrumentResult->getData('paymentInstrumentID');
     $reserveRequest = new ReserveRequest($this->config);
     $reserveRequest->setOrderID($orderId)->setPaymentMethod(Methods::PAYMENT_METHOD_TYPE_CC)->setPaymentInstrumentID($paymentInstrumentId)->setCcv(123);
     $reserveApi = new ReserveApi($this->config, $reserveRequest);
     $reserveApi->sendRequest();
     /**
      * Do the capture
      */
     $captureRequest = new CaptureRequest($this->config);
     $captureRequest->setOrderID($orderId)->setCaptureID($captureId)->setAmount($this->getAmount());
     $captureApi = new CaptureApi($this->config, $captureRequest);
     $captureApi->sendRequest();
     /**
      * Do getCaptureStatus call
      */
     $getCaptureStatusRequest = new GetCaptureStatusRequest($this->config);
     $getCaptureStatusRequest->setOrderID($orderId)->setCaptureID($captureId);
     $getCaptureStatusApi = new GetCaptureStatusApi($this->config, $getCaptureStatusRequest);
     $result = $getCaptureStatusApi->sendRequest();
     $this->assertEquals(0, $result->getData('resultCode'));
     $this->assertEmpty($result->getData('message'));
     $this->assertEquals('PAID', $result->getData('captureStatus'));
     $additionalData = $result->getData('additionalData');
     $this->assertEquals(100, $additionalData['transactionAmount']);
     $this->assertEquals(100, $additionalData['capturedAmount']);
     $this->assertEquals(100, $additionalData['paidAmount']);
     $this->assertEquals('EUR', $additionalData['transactionCurrency']);
 }