public function testGetUrl()
 {
     $request = new RegisterUserPaymentInstrument($this->config);
     $api = new RegisterUserPaymentInstrumentApi($this->config, $request);
     $this->assertEquals('http://www.something.com/registerUserPaymentInstrument', $api->getUrl());
 }
 /**
  * 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();
     $getTransactionStatusRequest = new GetTransactionStatusRequest($this->config);
     $getTransactionStatusRequest->setOrderID($orderId);
     /**
      * Now test the getTransactionStatus call
      */
     $getTransactionStatusApi = new GetTransactionStatusApi($this->config, $getTransactionStatusRequest);
     $result = $getTransactionStatusApi->sendRequest();
     $this->assertEquals(0, $result->getData('resultCode'));
     $this->assertEmpty($result->getData('message'));
     $this->assertNotEmpty($result->getData('salt'));
     $this->assertEquals('MERCHANTPENDING', $result->getData('transactionStatus'));
     $additionalData = $result->getData('additionalData');
     $this->assertEquals('CC', $additionalData['paymentMethod']);
     $this->assertEquals(100, $additionalData['transactionAmount']);
     $this->assertEquals($this->getUser()->getEmail(), $additionalData['customerEmail']);
 }
 /**
  * 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;
     }
     $userId = "REGISTED:" . hash('md5', microtime());
     $billingRecipient = $this->faker->name;
     $shippingRecipient = $this->faker->name;
     $registerRequest = new RegisterUserRequest($this->config);
     $registerRequest->setUserID($userId)->setUserType(\Upg\Library\User\Type::USER_TYPE_PRIVATE)->setUserRiskClass(RiskClass::RISK_CLASS_DEFAULT)->setUserData($this->getUser())->setBillingAddress($this->getAddress())->setBillingRecipient($billingRecipient)->setShippingAddress($this->getAddress())->setShippingRecipient($shippingRecipient)->setLocale(Codes::LOCALE_EN);
     $registerUserApi = new RegisterUserApi($this->config, $registerRequest);
     $registerUserResult = $registerUserApi->sendRequest();
     $this->assertEquals(0, $registerUserResult->getData('resultCode'));
     $this->assertEmpty($registerUserResult->getData('message'));
     $this->assertNotEmpty($registerUserResult->getData('salt'));
     $registerUserPaymentInstrumentRequest = new RegisterUserPaymentInstrumentRequest($this->config);
     $registerUserPaymentInstrumentRequest->setUserID($userId)->setPaymentInstrument($this->getPaymentInstrument());
     $registerUserPaymentInstrument = new RegisterUserPaymentInstrumentApi($this->config, $registerUserPaymentInstrumentRequest);
     $registerUserPaymentInstrumentResult = $registerUserPaymentInstrument->sendRequest();
     $paymentId = $registerUserPaymentInstrumentResult->getData('paymentInstrumentID');
     $deleteUserPaymentInstrumentRequest = new DeleteUserPaymentInstrumentRequest($this->config);
     $deleteUserPaymentInstrumentRequest->setPaymentInstrumentID($paymentId);
     $deleteUserPaymentInstrumentApi = new DeleteUserPaymentInstrumentApi($this->config, $deleteUserPaymentInstrumentRequest);
     $result = $deleteUserPaymentInstrumentApi->sendRequest();
     $this->assertEquals(0, $result->getData('resultCode'));
     $this->assertEmpty($result->getData('message'));
     $this->assertNotEmpty($result->getData('salt'));
 }
 /**
  * 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());
     $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 updateTransaction test
      */
     $updateTransactionRequest = new UpdateTransactionRequest($this->config);
     $updateTransactionRequest->setOrderID($orderId)->setCaptureID($captureId)->setInvoiceNumber($orderId . ':1')->setInvoiceDate(new \DateTime())->setOriginalInvoiceAmount($this->getAmount())->setShippingDate(new \DateTime())->setInvoicePDF($this->getPDF())->setTrackingID("111222");
     $updateTransactionApi = new UpdateTransactionApi($this->config, $updateTransactionRequest);
     $result = $updateTransactionApi->sendRequest();
     $this->assertEquals(0, $result->getData('resultCode'));
     $this->assertEmpty($result->getData('message'));
     $this->assertNotEmpty($result->getData('salt'));
     return true;
 }