Пример #1
0
 /**
  * {@inheritDoc}
  *
  * @param string $secret
  *
  * @return bool
  */
 public function isHashValid($secret)
 {
     $hashValid = false;
     //check for any null values and set them to empty $for hashing
     $timeStamp = null == $this->timeStamp ? "" : $this->timeStamp;
     $merchantId = null == $this->merchantId ? "" : $this->merchantId;
     $orderId = null == $this->orderId ? "" : $this->orderId;
     $result = null == $this->result ? "" : $this->result;
     $message = null == $this->message ? "" : $this->message;
     $paymentsReference = null == $this->paymentsReference ? "" : $this->paymentsReference;
     $authCode = null == $this->authCode ? "" : $this->authCode;
     //create $to hash
     $toHash = $timeStamp . "." . $merchantId . "." . $orderId . "." . $result . "." . $message . "." . $paymentsReference . "." . $authCode;
     //check if calculated hash matches returned value
     $expectedHash = GenerationUtils::generateHash($toHash, $secret);
     if ($expectedHash == $this->hash) {
         $hashValid = true;
     }
     return $hashValid;
 }
 /**
  * Creates the security hash from a number of fields and the shared secret.
  *
  * @param string $secret
  *
  * @return PaymentRequest
  */
 public function hash($secret)
 {
     //check for any null values and set them to empty string for hashing
     $timeStamp = null == $this->timestamp ? "" : $this->timestamp;
     $merchantId = null == $this->merchantId ? "" : $this->merchantId;
     $orderId = null == $this->orderId ? "" : $this->orderId;
     $amount = "";
     $currency = "";
     $token = null == $this->token ? "" : $this->token;
     if ($this->amount != null) {
         $amount = null == $this->amount->getAmount() ? "" : $this->amount->getAmount();
         $currency = null == $this->amount->getCurrency() ? "" : $this->amount->getCurrency();
     }
     $cardNumber = "";
     if ($this->card != null) {
         $cardNumber = null == $this->card->getNumber() ? "" : $this->card->getNumber();
     }
     //create String to hash
     if ($this->type == PaymentType::AUTH_MOBILE) {
         $toHash = $timeStamp . "." . $merchantId . "." . $orderId . "..." . $token;
     } else {
         $toHash = $timeStamp . "." . $merchantId . "." . $orderId . "." . $amount . "." . $currency . "." . $cardNumber;
     }
     $this->hash = GenerationUtils::generateHash($toHash, $secret);
     return $this;
 }
 /**
  * Creates the security hash from a number of fields and the shared secret.
  *
  * @param string $secret
  *
  * @return $this
  */
 public function hash($secret)
 {
     //check for any null values and set them to empty string for hashing
     $timeStamp = null == $this->timeStamp ? "" : $this->timeStamp;
     $merchantId = null == $this->merchantId ? "" : $this->merchantId;
     $orderId = null == $this->orderId ? "" : $this->orderId;
     $payerRef = null == $this->payerRef ? "" : $this->payerRef;
     $amount = "";
     $currency = "";
     if ($this->amount != null) {
         $amount = null == $this->amount->getAmount() ? "" : $this->amount->getAmount();
         $currency = null == $this->amount->getCurrency() ? "" : $this->amount->getCurrency();
     }
     $cardNumber = "";
     if ($this->card != null) {
         $cardNumber = null == $this->card->getNumber() ? "" : $this->card->getNumber();
     }
     //create String to hash
     $toHash = "";
     if ($this->type == ThreeDSecureType::VERIFY_STORED_CARD_ENROLLED) {
         $toHash = $timeStamp . "." . $merchantId . "." . $orderId . "." . $amount . "." . $currency . "." . $payerRef;
     } else {
         $toHash = $timeStamp . "." . $merchantId . "." . $orderId . "." . $amount . "." . $currency . "." . $cardNumber;
     }
     $this->hash = GenerationUtils::generateHash($toHash, $secret);
     return $this;
 }
 /**
  * Creates the security hash from a number of fields and the shared secret.
  *
  * @param string $secret
  *
  * @return PaymentRequest
  */
 public function hash($secret)
 {
     //check for any null values and set them to empty string for hashing
     $timeStamp = null == $this->timestamp ? "" : $this->timestamp;
     $merchantId = null == $this->merchantId ? "" : $this->merchantId;
     $orderId = null == $this->orderId ? "" : $this->orderId;
     $amount = "";
     $currency = "";
     $token = null == $this->token ? "" : $this->token;
     $payerRef = null == $this->payerRef ? "" : $this->payerRef;
     if ($this->amount != null) {
         $amount = null == $this->amount->getAmount() ? "" : $this->amount->getAmount();
         $currency = null == $this->amount->getCurrency() ? "" : $this->amount->getCurrency();
     }
     $cardNumber = "";
     if ($this->card != null) {
         $cardNumber = null == $this->card->getNumber() ? "" : $this->card->getNumber();
     }
     $payerNewRef = "";
     if ($this->payer != null) {
         $payerNewRef = null == $this->payer->getRef() ? "" : $this->payer->getRef();
     }
     $cardHolderName = "";
     if ($this->card != null) {
         $cardHolderName = null == $this->card->getCardHolderName() ? "" : $this->card->getCardHolderName();
     }
     $cardPayerRef = "";
     if ($this->card != null) {
         $cardPayerRef = null == $this->card->getPayerReference() ? "" : $this->card->getPayerReference();
     }
     $cardRef = "";
     if ($this->card != null) {
         $cardRef = null == $this->card->getReference() ? "" : $this->card->getReference();
     }
     $cardExpiryDate = "";
     if ($this->card != null) {
         $cardExpiryDate = null == $this->card->getExpiryDate() ? "" : $this->card->getExpiryDate();
     }
     //create String to hash
     if ($this->type == PaymentType::AUTH_MOBILE) {
         $toHash = $timeStamp . "." . $merchantId . "." . $orderId . "..." . $token;
     } elseif ($this->type == PaymentType::OTB) {
         $toHash = $timeStamp . "." . $merchantId . "." . $orderId . "." . $cardNumber;
     } elseif ($this->type == PaymentType::RECEIPT_IN || $this->type == PaymentType::PAYMENT_OUT || $this->type == PaymentType::STORED_CARD_DCC_RATE) {
         $toHash = $timeStamp . "." . $merchantId . "." . $orderId . "." . $amount . "." . $currency . "." . $payerRef;
     } elseif ($this->type == PaymentType::PAYER_NEW || $this->type == PaymentType::PAYER_EDIT) {
         $toHash = $timeStamp . "." . $merchantId . "." . $orderId . "." . $amount . "." . $currency . "." . $payerNewRef;
     } elseif ($this->type == PaymentType::CARD_NEW) {
         $toHash = $timeStamp . "." . $merchantId . "." . $orderId . "." . $amount . "." . $currency . "." . $cardPayerRef . "." . $cardHolderName . "." . $cardNumber;
     } elseif ($this->type == PaymentType::CARD_UPDATE) {
         $toHash = $timeStamp . "." . $merchantId . "." . $cardPayerRef . "." . $cardRef . "." . $cardExpiryDate . "." . $cardNumber;
     } elseif ($this->type == PaymentType::CARD_CANCEL) {
         $toHash = $timeStamp . "." . $merchantId . "." . $cardPayerRef . "." . $cardRef;
     } elseif ($this->type == PaymentType::RECEIPT_IN_OTB) {
         $toHash = $timeStamp . "." . $merchantId . "." . $orderId . "." . $payerRef;
     } else {
         $toHash = $timeStamp . "." . $merchantId . "." . $orderId . "." . $amount . "." . $currency . "." . $cardNumber;
     }
     $this->hash = GenerationUtils::generateHash($toHash, $secret);
     return $this;
 }