示例#1
0
文件: Retrieve.php 项目: arbi/MyCode
 /**
  * @param $creditCardId
  * @return CompleteData
  */
 public function getCreditCard($creditCardId)
 {
     $localData = $this->getLocalData($creditCardId);
     $token = $localData->getToken();
     $remoteData = $this->getRemoteData($token);
     $completeData = new CompleteData();
     $completeData->setPan($localData->getFirstDigits() . $remoteData->getLast10());
     $completeData->setSecurityCode($remoteData->getSecurityCode());
     $completeData->setExpirationMonth($remoteData->getExpirationMonth());
     $completeData->setExpirationYear($remoteData->getExpirationYear());
     $completeData->setHolder($remoteData->getHolder());
     $completeData->setBrand($localData->getBrand());
     return $completeData;
 }
示例#2
0
 public function storeCardAction()
 {
     /**
      * @var StoreService $storeService
      */
     $storeService = $this->getServiceLocator()->get('service_store_cc');
     $ccRawData = new CompleteData();
     $ccRawData->setPan('4111111111111111');
     $ccRawData->setExpirationMonth('01');
     $ccRawData->setExpirationYear('16');
     $ccRawData->setSecurityCode('123');
     $ccRawData->setHolder('Some VISA dddddddd Holder');
     $ccRawData->setCustomerId(1);
     $ccRawData->setPartnerId(0);
     $ccRawData->setBrand(1);
     $ccRawData->setSource(0);
     $ccRawData->setStatus(0);
     $token = $storeService->store($ccRawData);
     echo $token;
     $ccRawData = new CompleteData();
     $ccRawData->setPan('378282246310005');
     $ccRawData->setExpirationMonth('01');
     $ccRawData->setExpirationYear('16');
     $ccRawData->setSecurityCode('123');
     $ccRawData->setHolder('Some AMEX dddddddddddddddddddddd Holder');
     $ccRawData->setBrand(2);
     $token = $storeService->store($ccRawData);
     echo $token;
     $ccRawData = new CompleteData();
     $ccRawData->setPan('30569309025904');
     $ccRawData->setExpirationMonth('01');
     $ccRawData->setExpirationYear('16');
     $ccRawData->setSecurityCode('123');
     $ccRawData->setHolder('Some DINNERS CLUBddddddddddddddddddddddddddddddd Holder');
     $ccRawData->setBrand(2);
     $token = $storeService->store($ccRawData);
     echo $token;
     die;
 }
示例#3
0
文件: Store.php 项目: arbi/MyCode
 /**
  * @param  CompleteData $creditCardRawData
  * @return string
  * @throws \CreditCard\Rest\Exception
  * @throws \CreditCard\Rest\InvalidArgumentException
  * @throws \Exception
  */
 public function store($creditCardRawData)
 {
     /**
      * @var Logger $logger
      * @var Booking $bookingDao
      * @var \DDD\Domain\Booking\Booking $reservation
      * @var Encrypt $encryptService
      * @var SaltGenerator $saltGenerator
      */
     $logger = $this->getServiceLocator()->get('ActionLogger');
     $bookingDao = $this->getServiceLocator()->get('dao_booking_booking');
     $encryptService = $this->getServiceLocator()->get('service_encrypt');
     $saltGenerator = $this->getServiceLocator()->get('service_salt_generator');
     $pan = $encryptService->decrypt($creditCardRawData->getPan(), '');
     $panLength = strlen($pan);
     $last10Digits = substr($pan, -10);
     $firstDigitsCount = $panLength - 10;
     $firstDigits = substr($pan, 0, $firstDigitsCount);
     $holder = $encryptService->decrypt($creditCardRawData->getHolder(), '');
     $securityCode = $encryptService->decrypt($creditCardRawData->getSecurityCode(), '');
     $expirationMonth = $encryptService->decrypt($creditCardRawData->getExpirationMonth(), '');
     $expirationYear = $encryptService->decrypt($creditCardRawData->getExpirationYear(), '');
     /**
      * @var TokenDAO $tokenDao
      */
     $tokenDao = $this->getServiceLocator()->get('dao_cc_token');
     $reservation = $bookingDao->fetchOne(['customer_id' => $creditCardRawData->getCustomerId()], ['id', 'guest_first_name', 'guest_last_name']);
     if (DomainConstants::BO_DOMAIN_NAME != "backoffice.ginosi.com") {
         $salt = 'sample_sal';
         $token = 'sample_token';
         $encrypted = $encryptService->encrypt($firstDigits, $salt);
         $tokenDao->insert(['first_digits' => $encrypted, 'brand' => $creditCardRawData->getBrand(), 'partner_id' => $creditCardRawData->getPartnerId(), 'customer_id' => $creditCardRawData->getCustomerId(), 'source' => $creditCardRawData->getSource(), 'status' => $creditCardRawData->getStatus(), 'is_default' => is_null($creditCardRawData->getIsDefault()) ? 0 : $creditCardRawData->getIsDefault(), 'date_provided' => $creditCardRawData->getDateProvided(), 'salt' => $salt, 'token' => $token]);
         return $token;
     } else {
         $salt = $saltGenerator->generateSalt();
         $encrypted = $encryptService->encrypt($firstDigits, $salt);
         $request = new RestRequest('PUT', ['last10' => $last10Digits, 'security_code' => $securityCode, 'holder' => $holder, 'exp_month' => $expirationMonth, 'exp_year' => $expirationYear]);
         $config = $this->getServiceLocator()->get('Config');
         $apiEndpoint = $config['vault-configuration']['storage_api_endpoint'];
         $apiPort = $config['vault-configuration']['storage_api_port'];
         $apiKey = $config['vault-configuration']['storage_api_key'];
         $request->setUrl($apiEndpoint);
         $request->setPort($apiPort);
         $request->setApiKey($apiKey);
         $request->execute();
         $responseInfo = $request->getResponseInfo();
         if ($responseInfo['http_code'] == 201) {
             $responseBody = $request->getResponseBody();
             $responseArray = json_decode($responseBody);
             $token = $responseArray->token;
             $tokenDao->insert(['token' => $token, 'first_digits' => $encrypted, 'brand' => $creditCardRawData->getBrand(), 'partner_id' => $creditCardRawData->getPartnerId(), 'customer_id' => $creditCardRawData->getCustomerId(), 'source' => $creditCardRawData->getSource(), 'status' => $creditCardRawData->getStatus(), 'is_default' => is_null($creditCardRawData->getIsDefault()) ? 0 : $creditCardRawData->getIsDefault(), 'date_provided' => $creditCardRawData->getDateProvided(), 'salt' => $salt]);
             $ccId = $tokenDao->getLastInsertValue();
             $newCreditCardAction = 0;
             switch ($creditCardRawData->getSource()) {
                 case Card::CC_SOURCE_CHANNEL_RESERVATION_SYSTEM:
                     $newCreditCardAction = Logger::ACTION_NEW_CC_CHANNEL_RESERVATION_SYSTEM;
                     break;
                 case Card::CC_SOURCE_CHANNEL_MODIFICATION_SYSTEM:
                     $newCreditCardAction = Logger::ACTION_NEW_CC_FROM_CHANNEL_MODIFICATION_SYSTEM;
                     break;
                 case Card::CC_SOURCE_WEBSITE_GUEST:
                     $newCreditCardAction = Logger::ACTION_NEW_CC_FROM_WEBSITE_GUEST;
                     break;
                 case Card::CC_SOURCE_WEBSITE_EMPLOYEE:
                     $newCreditCardAction = Logger::ACTION_NEW_CC_FROM_WEBSITE_EMPLOYEE;
                     break;
                 case Card::CC_SOURCE_WEBSITE_RESERVATION_GUEST:
                     $newCreditCardAction = Logger::ACTION_NEW_CC_FROM_WEBSITE_RESERVATION_GUEST;
                     break;
                 case Card::CC_SOURCE_WEBSITE_RESERVATION_EMPLOYEE:
                     $newCreditCardAction = Logger::ACTION_NEW_CC_FROM_WEBSITE_RESERVATION_EMPLOYEE;
                     break;
                 case Card::CC_SOURCE_FRONTIER_DASHBOARD_EMPLOYEE:
                     $newCreditCardAction = Logger::ACTION_NEW_CC_FROM_FRONTIER_DASHBOARD_EMPLOYEE;
                     break;
             }
             if ($reservation) {
                 $logger->save(Logger::MODULE_BOOKING, $reservation->getId(), $newCreditCardAction, $ccId);
             }
             /**
              * @var \DDD\Service\Fraud $serviceFraud
              */
             $serviceFraud = $this->getServiceLocator()->get('service_fraud');
             // CC fraud check
             $serviceFraud->saveFraudForCreditCard($reservation, ['id' => $ccId, 'number' => $pan, 'year' => $expirationMonth, 'month' => $expirationYear, 'holder' => $holder]);
             /**
              * @var \DDD\Service\Booking\ReservationIssues $reservationIssuesService
              */
             $reservationIssuesService = $this->getServiceLocator()->get('service_booking_reservation_issues');
             $expirationDate = (strlen($expirationYear) === 2 ? '20' . $expirationYear : $expirationYear) . '-' . $expirationMonth;
             // check CC issues
             $reservationIssuesService->checkReservationIssues($reservation->getId(), ['cc_date' => $expirationDate, 'clear_old_cc_issue' => true]);
             return $token;
         } else {
             $this->gr2crit("Cannot store new credit card in KAS", ['reservation_id' => $reservation->getId(), 'response_status' => $responseInfo['http_code']]);
             return false;
         }
     }
 }
示例#4
0
文件: Card.php 项目: arbi/MyCode
 /**
  * @param $rawData
  * @return int
  */
 public function processCreditCardData($rawData)
 {
     $partnerId = Partners::PARTNER_WEBSITE;
     /**
      * @var \CreditCard\Service\Encrypt $encryptService
      */
     $encryptService = $this->getServiceLocator()->get('service_encrypt');
     // Detect partner business model
     if (isset($rawData['partner_id']) && $rawData['partner_id']) {
         /**
          * @var \DDD\Dao\Partners\Partners $partnerDao
          */
         $partnerDao = $this->getServiceLocator()->get('dao_partners_partners');
         $partnerData = $partnerDao->getPartnerModel($rawData['partner_id']);
         if ($partnerData && $partnerData->getBusinessModel() == Partners::BUSINESS_MODEL_GINOSI_COLLECT_PARTNER) {
             $partnerId = $rawData['partner_id'];
         }
     }
     // Save CC Details
     $creditCard = new CompleteData();
     $pan = isset($rawData['number']) ? $rawData['number'] : '';
     $creditCard->setPan($encryptService->encrypt($pan, ''));
     $holder = isset($rawData['holder']) ? $rawData['holder'] : '';
     $creditCard->setHolder($encryptService->encrypt($holder, ''));
     $cvc = isset($rawData['cvc']) ? $rawData['cvc'] : '';
     $creditCard->setSecurityCode($encryptService->encrypt($cvc, ''));
     if (isset($rawData['year']) && strlen($rawData['year']) == 4) {
         $rawData['year'] = substr($rawData['year'], 2, 2);
     }
     $year = isset($rawData['year']) ? $rawData['year'] : '';
     $creditCard->setExpirationYear($encryptService->encrypt($year, ''));
     $month = isset($rawData['month']) ? $rawData['month'] : '';
     $creditCard->setExpirationMonth($encryptService->encrypt($month, ''));
     // Card Type
     $creditCardValidator = new CreditCardValidator();
     $cardType = $creditCardValidator->getCardTypeByNumber(substr($pan, 0, 6));
     $creditCard->setBrand(0);
     if ($cardType) {
         $creditCardType = Objects::getCreditCardId($cardType);
         $creditCard->setBrand($creditCardType);
     }
     $creditCard->setSource($rawData['source']);
     $creditCard->setStatus(self::CC_STATUS_UNKNOWN);
     $creditCard->setPartnerId($partnerId);
     $creditCard->setCustomerId($rawData['customer_id']);
     $creditCard->setDateProvided(date('Y-m-d h:i:s'));
     // Save cc details locally
     //        $this->gr2info('Successfully created CC data from ' . ucfirst($params['source_provider']), ['module' => 'Finance']);
     //        $ccId = $creditCard->getId();
     /**
      * @var Queue $creditCardCreationQueueService
      */
     $creditCardCreationQueueService = $this->getServiceLocator()->get('service_card_creation_queue');
     $cardId = $creditCardCreationQueueService->insert($creditCard);
     return $cardId;
     //        $this->gr2info('Successfully send to Processing Queue from ' . ucfirst($params['source_provider']), ['module' => 'Finance']);
     //
     //        $this->gr2info('Customer or CC create/update end from ' . ucfirst($params['source_provider']), ['module' => 'Finance']);
     //
     //        $logger->save(Logger::MODULE_BOOKING, $reservationId, Logger::ACTION_NEW_CC_DETAILS, $cardId);
     //        $this->gr2logException($e, 'Cannot update CC data from Frontier');
     //        $this->gr2debug($e->getMessage(), [
     //            'reservation_id'              => $reservationId,
     //            'customer_id'                 => $reservationData['customer_id'],
     //            'credit_card_source_provider' => 'frontier'
     //        ]);
 }