Пример #1
0
 /**
  * Returns an instance of class
  *
  * @return BOL_BillingSaleDao
  */
 public static function getInstance()
 {
     if (self::$classInstance === null) {
         self::$classInstance = new self();
     }
     return self::$classInstance;
 }
Пример #2
0
 public function getTotalIncome()
 {
     $currList = $this->getSalesCurrencies();
     $incomeArr = array();
     foreach ($currList as $currency) {
         $sum = $this->billingSaleDao->getSalesSumByCurrency($currency['currency']);
         if ($sum != 0) {
             $incomeArr[$currency['currency']] = floatval($sum);
         }
     }
     return $incomeArr;
 }
Пример #3
0
 public function verifySale($params)
 {
     if (empty($params['receipt'])) {
         throw new ApiResponseErrorException();
     }
     $userId = !empty($params['userId']) ? $params['userId'] : null;
     $receipt = trim($params['receipt']);
     $logger = OW::getLogger('skadateios');
     $logger->addEntry(print_r($params, true), 'receipt.data');
     $configs = OW::getConfig()->getValues("skadateios");
     $validator = new SKADATEIOS_ACLASS_ItunesReceiptValidator($configs["itunes_mode"], $configs["itunes_secret"]);
     $data = $validator->validateReceipt($receipt);
     $logger->addEntry(print_r($data, true), 'receipt.validation');
     $logger->writeLog();
     if (!isset($data['status'])) {
         $this->assign('registered', false);
         $this->assign('error', 'Receipt validation failed');
         return;
     }
     if ($data['status'] == 0) {
         $environment = $data['environment'];
         $bundleId = $data['receipt']['bundle_id'];
         $inAppData = $data['receipt']['in_app'];
         foreach ($inAppData as $inApp) {
             $productId = $inApp['product_id'];
             $transactionId = $inApp['transaction_id'];
             $billingService = BOL_BillingService::getInstance();
             $service = SKADATEIOS_ABOL_Service::getInstance();
             $sale = $billingService->getSaleByGatewayTransactionId(SKADATEIOS_ACLASS_InAppPurchaseAdapter::GATEWAY_KEY, $transactionId);
             if ($sale) {
                 continue;
             }
             $originalTransactionId = isset($inApp['original_transaction_id']) ? $inApp['original_transaction_id'] : null;
             if ($originalTransactionId) {
                 $originalSale = $billingService->getSaleByGatewayTransactionId(SKADATEIOS_ACLASS_InAppPurchaseAdapter::GATEWAY_KEY, $originalTransactionId);
                 if ($originalSale && !$userId) {
                     $userId = $originalSale->userId;
                 }
             }
             $purchaseTime = $inApp['purchase_date_ms'] / 1000;
             $product = $service->findProductByItunesProductId($productId);
             if (!$product) {
                 $this->assign('registered', false);
                 $this->assign('error', 'Product not found');
             } else {
                 // sale object
                 $sale = new BOL_BillingSale();
                 $sale->pluginKey = $product['pluginKey'];
                 $sale->entityDescription = $product['entityDescription'];
                 $sale->entityKey = $product['entityKey'];
                 $sale->entityId = $product['entityId'];
                 $sale->price = $product['price'];
                 $sale->period = $product['period'];
                 $sale->userId = $userId;
                 $sale->recurring = $product['recurring'];
                 $saleId = $billingService->initSale($sale, SKADATEIOS_ACLASS_InAppPurchaseAdapter::GATEWAY_KEY);
                 $sale = $billingService->getSaleById($saleId);
                 $sale->timeStamp = $purchaseTime;
                 $sale->transactionUid = $transactionId;
                 BOL_BillingSaleDao::getInstance()->save($sale);
                 $productAdapter = null;
                 switch ($sale->pluginKey) {
                     case 'membership':
                         $productAdapter = new MEMBERSHIP_CLASS_MembershipPlanProductAdapter();
                         break;
                     case 'usercredits':
                         $productAdapter = new USERCREDITS_CLASS_UserCreditsPackProductAdapter();
                         break;
                 }
                 $billingService->deliverSale($productAdapter, $sale);
                 $this->assign('registered', true);
             }
             return;
         }
     }
     $this->assign('registered', false);
     $this->assign('error', 'Receipt validation failed');
 }
Пример #4
0
 public function verifySale($params)
 {
     if (!SKANDROID_ABOL_Service::getInstance()->isBillingEnabled()) {
         throw new ApiResponseErrorException();
     }
     if (empty($params['purchase'])) {
         throw new ApiResponseErrorException();
     }
     if (empty($params['signature'])) {
         throw new ApiResponseErrorException();
     }
     $logger = OW::getLogger('skadateandroid');
     $logger->addEntry(print_r($params, true), ' purchase data');
     $valid = $this->verifyMarketInApp($params['purchase'], $params['signature'], trim(OW::getConfig()->getValue('skandroid', 'public_key')));
     $purchase = json_decode($params['purchase'], true);
     if (empty($purchase['developerPayload'])) {
         throw new ApiResponseErrorException();
     }
     $developerPayload = json_decode(base64_decode($purchase['developerPayload']), true);
     $userId = !empty($developerPayload['userId']) ? $developerPayload['userId'] : null;
     $purchaseProductId = !empty($purchase['productId']) ? $purchase['productId'] : null;
     $payloadProductId = !empty($developerPayload['productId']) ? $developerPayload['productId'] : null;
     $purchaseHash = $this->generateHash(OW::getUser()->getId(), $purchaseProductId);
     $payloadHash = !empty($developerPayload['hash']) ? $developerPayload['hash'] : null;
     $logger->addEntry(print_r($params['purchase'], true), 'purchase.validation');
     $logger->writeLog();
     $this->assign('error', null);
     if (!isset($userId) || OW::getUser()->getId() != $userId) {
         $this->assign('registered', false);
         $this->assign('error', 'Undefined user id');
         return;
     }
     if (!isset($valid)) {
         $this->assign('registered', false);
         $this->assign('error', 'Purchase validation failed');
         return;
     }
     if (!isset($valid)) {
         $this->assign('registered', false);
         $this->assign('error', 'Purchase validation failed');
         return;
     }
     if (!isset($purchaseProductId) || !isset($payloadProductId) || $payloadProductId != $purchaseProductId) {
         $this->assign('registered', false);
         $this->assign('error', 'Payload validation faild.  Invalid product Id');
         return;
     }
     if (!isset($purchaseHash) || !isset($payloadHash) || $payloadHash != $purchaseHash) {
         $this->assign('registered', false);
         $this->assign('error', 'Payload validation faild.');
         return;
     }
     $billingService = BOL_BillingService::getInstance();
     $service = SKANDROID_ABOL_Service::getInstance();
     $orderId = isset($purchase['orderId']) ? $purchase['orderId'] : null;
     $productId = isset($purchase['productId']) ? $purchase['productId'] : null;
     $purchaseTime = isset($purchase['purchaseTime']) ? $purchase['purchaseTime'] : null;
     $sale = $billingService->getSaleByGatewayTransactionId(SKANDROID_ACLASS_InAppPurchaseAdapter::GATEWAY_KEY, md5($orderId));
     if ($sale) {
         // sale already registered
         $this->assign('registered', false);
         $this->assign('error', 'Sale already registered');
         return;
     }
     $product = $service->findProductByItunesProductId($productId);
     if (!$product) {
         $this->assign('registered', false);
         $this->assign('error', 'Product not found');
     } else {
         // sale object
         $sale = new BOL_BillingSale();
         $sale->pluginKey = $product['pluginKey'];
         $sale->entityDescription = $product['entityDescription'];
         $sale->entityKey = $product['entityKey'];
         $sale->entityId = $product['entityId'];
         $sale->price = $product['price'];
         $sale->period = $product['period'];
         $sale->userId = $userId;
         $sale->recurring = $product['recurring'];
         $saleId = $billingService->initSale($sale, SKANDROID_ACLASS_InAppPurchaseAdapter::GATEWAY_KEY);
         $sale = $billingService->getSaleById($saleId);
         $sale->timeStamp = $purchaseTime / 1000;
         $sale->transactionUid = md5($orderId);
         $sale->extraData = json_encode(array('orderId' => $orderId, 'extra' => $purchase['developerPayload']));
         BOL_BillingSaleDao::getInstance()->save($sale);
         $productAdapter = null;
         switch ($sale->pluginKey) {
             case 'membership':
                 $productAdapter = new MEMBERSHIP_CLASS_MembershipPlanProductAdapter();
                 break;
             case 'usercredits':
                 $productAdapter = new USERCREDITS_CLASS_UserCreditsPackProductAdapter();
                 break;
         }
         $billingService->deliverSale($productAdapter, $sale);
         $this->assign('registered', true);
     }
     return;
 }
Пример #5
0
 /**
  * Returns list of sales that were not tracked by the affiliate system
  *
  * @param $limit
  * @return array
  */
 public function getUntrackedSales($limit)
 {
     $saleDao = BOL_BillingSaleDao::getInstance();
     $affiliateUserDao = OCSAFFILIATES_BOL_AffiliateUserDao::getInstance();
     $sql = "SELECT `bs`.* FROM `" . $saleDao->getTableName() . "` AS `bs`\n            INNER JOIN `" . $affiliateUserDao->getTableName() . "` AS `au` ON (`bs`.`userId` = `au`.`userId`)\n            LEFT JOIN `" . $this->getTableName() . "` AS `as` ON(`bs`.`id`=`as`.`saleId`)\n            WHERE `bs`.`status` = 'delivered' AND `as`.`id` IS NULL\n            ORDER BY `bs`.`timeStamp` ASC\n            LIMIT :limit";
     return $this->dbo->queryForObjectList($sql, BOL_BillingSaleDao::getInstance()->getDtoClassName(), array('limit' => $limit));
 }