Пример #1
0
 /**
  * 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 the refund
      */
     $refundRequest = new RefundRequest($this->config);
     $refundRequest->setOrderID($orderId)->setCaptureID($captureId)->setRefundDescription("Test Refund for integration tests")->setAmount($this->getAmount());
     $refundApi = new RefundApi($this->config, $refundRequest);
     $result = $refundApi->sendRequest();
     $this->assertEquals(0, $result->getData('resultCode'));
     $this->assertEmpty($result->getData('message'));
     $this->assertNotEmpty($result->getData('salt'));
 }
Пример #2
0
 public function testRefundValidationRefundDescription()
 {
     $request = new Refund($this->config);
     $request->setOrderID(1)->setCaptureID(1)->setAmount($this->getAmount());
     $validation = new Validation();
     $validation->getValidator($request);
     $data = $validation->performValidation();
     $this->assertValidationReturned('Upg\\Library\\Request\\Refund', 'refundDescription', 'refundDescription is required', $data, "refundDescription is required failed to trigger");
     /**
      * Length test
      */
     $request->setRefundDescription($this->veryLongString);
     $validation->getValidator($request);
     $data = $validation->performValidation();
     $this->assertValidationReturned('Upg\\Library\\Request\\Refund', 'refundDescription', 'refundDescription must be between 1 and 256 characters', $data, "refundDescription must be between 1 and 256 characters failed to trigger");
 }