/**
  * Validates OTB
  *
  * @param HppRequest $hppRequest
  * @param Constraint $constraint
  *
  * @api
  */
 public function validate($hppRequest, Constraint $constraint)
 {
     //if validate card only flag is true (1), then ensure the amount is set to 0
     if (Flag::TRUE == $hppRequest->getValidateCardOnly()) {
         if ($hppRequest->getAmount() != "0") {
             $this->context->buildViolation($constraint->message)->atPath('amount')->addViolation();
         }
     }
 }
Exemplo n.º 2
0
 /**
  *
  * Receives a domain object and generates a Json string
  *
  * @param HppRequest $hppRequest
  *
  * @return string
  */
 public function WriteValueAsString($hppRequest)
 {
     $prop = array('MERCHANT_ID' => $hppRequest->getMerchantId(), 'ACCOUNT' => $hppRequest->getAccount(), 'ORDER_ID' => $hppRequest->getOrderId(), 'AMOUNT' => $hppRequest->getAmount(), 'CURRENCY' => $hppRequest->getCurrency(), 'TIMESTAMP' => $hppRequest->getTimeStamp(), 'SHA1HASH' => $hppRequest->getHash(), 'AUTO_SETTLE_FLAG' => $hppRequest->getAutoSettleFlag(), 'COMMENT1' => $hppRequest->getCommentOne(), 'COMMENT2' => $hppRequest->getCommentTwo(), 'RETURN_TSS' => $hppRequest->getReturnTss(), 'SHIPPING_CODE' => $hppRequest->getShippingCode(), 'SHIPPING_CO' => $hppRequest->getShippingCountry(), 'BILLING_CODE' => $hppRequest->getBillingCode(), 'BILLING_CO' => $hppRequest->getBillingCountry(), 'CUST_NUM' => $hppRequest->getCustomerNumber(), 'VAR_REF' => $hppRequest->getVariableReference(), 'PROD_ID' => $hppRequest->getProductId(), 'HPP_LANG' => $hppRequest->getLanguage(), 'CARD_PAYMENT_BUTTON' => $hppRequest->getCardPaymentButtonText(), 'CARD_STORAGE_ENABLE' => $hppRequest->getCardStorageEnable(), 'OFFER_SAVE_CARD' => $hppRequest->getOfferSaveCard(), 'PAYER_REF' => $hppRequest->getPayerReference(), 'PMT_REF' => $hppRequest->getPaymentReference(), 'PAYER_EXIST' => $hppRequest->getPayerExists(), 'VALIDATE_CARD_ONLY' => $hppRequest->getValidateCardOnly(), 'DCC_ENABLE' => $hppRequest->getDccEnable());
     $supplementaryData = $hppRequest->getSupplementaryData();
     if (is_array($supplementaryData)) {
         foreach ($supplementaryData as $key => $value) {
             $prop[$key] = $value;
         }
     }
     return json_encode($prop);
 }
 /**
  * Checks expected and converted {@link HppRequest} objects.
  *
  * @param HppRequest $hppRequestExpected
  * @param HppRequest $hppRequestConverted
  * @param bool $defaultsGenerated
  * @param PHPUnit_Framework_TestCase $testCase
  */
 public static function checkValidHppRequest(HppRequest $hppRequestExpected, HppRequest $hppRequestConverted, $defaultsGenerated, PHPUnit_Framework_TestCase $testCase)
 {
     $testCase->assertEquals($hppRequestExpected->getAccount(), $hppRequestConverted->getAccount(), "Json conversion incorrect Account");
     $testCase->assertEquals($hppRequestExpected->getAmount(), $hppRequestConverted->getAmount(), "Json conversion incorrect Amount");
     $testCase->assertEquals($hppRequestExpected->getAutoSettleFlag(), $hppRequestConverted->getAutoSettleFlag(), "Json conversion incorrect Auto Settle Flag");
     $testCase->assertEquals($hppRequestExpected->getBillingCode(), $hppRequestConverted->getBillingCode(), "Json conversion incorrect Billing Code");
     $testCase->assertEquals($hppRequestExpected->getBillingCountry(), $hppRequestConverted->getBillingCountry(), "Json conversion incorrect Billing Country");
     $testCase->assertEquals($hppRequestExpected->getCardPaymentButtonText(), $hppRequestConverted->getCardPaymentButtonText(), "Json conversion incorrect Card Payment Button Text");
     $testCase->assertEquals($hppRequestExpected->getCardStorageEnable(), $hppRequestConverted->getCardStorageEnable(), "Json conversion incorrect Card Storage Enable");
     $testCase->assertEquals($hppRequestExpected->getCommentOne(), $hppRequestConverted->getCommentOne(), "Json conversion incorrect Comment One");
     $testCase->assertEquals($hppRequestExpected->getCommentTwo(), $hppRequestConverted->getCommentTwo(), "Json conversion incorrect Comment Two");
     $testCase->assertEquals($hppRequestExpected->getCurrency(), $hppRequestConverted->getCurrency(), "Json conversion incorrect Currency");
     $testCase->assertEquals($hppRequestExpected->getCustomerNumber(), $hppRequestConverted->getCustomerNumber(), "Json conversion incorrect Customer Number");
     $testCase->assertEquals($hppRequestExpected->getLanguage(), $hppRequestConverted->getLanguage(), "Json conversion incorrect HPP Language");
     $testCase->assertEquals($hppRequestExpected->getMerchantId(), $hppRequestConverted->getMerchantId(), "Json conversion incorrect Merchant ID");
     $testCase->assertEquals($hppRequestExpected->getOfferSaveCard(), $hppRequestConverted->getOfferSaveCard(), "Json conversion incorrect Offer Save Card");
     $testCase->assertEquals($hppRequestExpected->getPayerExists(), $hppRequestConverted->getPayerExists(), "Json conversion incorrect Payer Exists");
     $testCase->assertEquals($hppRequestExpected->getPayerReference(), $hppRequestConverted->getPayerReference(), "Json conversion incorrect Payer Reference");
     $testCase->assertEquals($hppRequestExpected->getPaymentReference(), $hppRequestConverted->getPaymentReference(), "Json conversion incorrect Payment Reference");
     $testCase->assertEquals($hppRequestExpected->getProductId(), $hppRequestConverted->getProductId(), "Json conversion incorrect Product ID");
     $testCase->assertEquals($hppRequestExpected->getReturnTss(), $hppRequestConverted->getReturnTss(), "Json conversion incorrect Return TSS");
     $testCase->assertEquals($hppRequestExpected->getShippingCode(), $hppRequestConverted->getShippingCode(), "Json conversion incorrect Shipping Code");
     $testCase->assertEquals($hppRequestExpected->getShippingCountry(), $hppRequestConverted->getShippingCountry(), "Json conversion incorrect Shipping Country");
     $testCase->assertEquals($hppRequestExpected->getVariableReference(), $hppRequestConverted->getVariableReference(), "Json conversion incorrect Variable Reference");
     if (!$defaultsGenerated) {
         $testCase->assertEquals($hppRequestExpected->getTimeStamp(), $hppRequestConverted->getTimeStamp(), "Json conversion incorrect Time Stamp");
         $testCase->assertEquals($hppRequestExpected->getHash(), $hppRequestConverted->getHash(), "Json conversion incorrect Hash");
         $testCase->assertEquals($hppRequestExpected->getOrderId(), $hppRequestConverted->getOrderId(), "Json conversion incorrect Order ID");
     } else {
         $testCase->assertNotNull($hppRequestConverted->getTimeStamp(), "Time Stamp failed to generate");
         $testCase->assertNotNull($hppRequestConverted->getHash(), "Hash failed to generate");
         $testCase->assertNotNull($hppRequestConverted->getOrderId(), "Order ID failed to generate");
     }
     $testCase->assertEquals($hppRequestExpected->getValidateCardOnly(), $hppRequestConverted->getValidateCardOnly(), "Json conversion incorrect Validate Card Only");
     $testCase->assertEquals($hppRequestExpected->getDccEnable(), $hppRequestConverted->getDccEnable(), "Json conversion incorrect DCC Enable");
 }