コード例 #1
0
ファイル: subscribe.php プロジェクト: uakfdotb/oneapp
function addSubscription($user_id, $club_id)
{
    //make sure this user isn't already subscribed
    if (!checkSubscription($user_id, $club_id)) {
        $user_id = escape($user_id);
        $club_id = escape($club_id);
        //make sure club exists
        $result = mysql_query("SELECT COUNT(*) FROM clubs WHERE id = '{$club_id}'");
        $row = mysql_fetch_row($result);
        if ($row[0] > 0) {
            mysql_query("INSERT INTO subscriptions (user_id, club_id) VALUES ('{$user_id}', '{$club_id}')");
        }
    }
}
コード例 #2
0
ファイル: index.php プロジェクト: kvirella/magrocket-api
// Purchases List
// *Returns a list of Purchased Product ID's
$app->get('/purchases/:app_id/:user_id', function ($app_id, $user_id) {
    global $dbContainer;
    $db = $dbContainer['db'];
    $purchased_product_ids = array();
    if (isInDevelopmentMode($app_id) == "TRUE") {
        logMessage(LogType::Info, "Checking purchases for APP ID: " . $app_id . " USER ID: " . $user_id);
    }
    try {
        $subscribed = false;
        // Retrieve latest receipt for Auto-Renewable-Subscriptions for the APP_ID, USER_ID combination
        $result = $db->query("SELECT BASE64_RECEIPT FROM RECEIPTS\n\t\t\t\t\t\t\t\t\t     WHERE APP_ID = '{$app_id}' AND USER_ID = '{$user_id}' AND TYPE = 'auto-renewable-subscription'\n\t\t\t\t\t\t\t\t\t     ORDER BY TRANSACTION_ID DESC LIMIT 0, 1");
        $base64_latest_receipt = $result->fetchColumn();
        if ($base64_latest_receipt) {
            $userSubscription = checkSubscription($app_id, $user_id);
            $dateLastValidated = new DateTime($userSubscription["LAST_VALIDATED"]);
            $dateExpiration = new DateTime($userSubscription["EXPIRATION_DATE"]);
            $dateCurrent = new DateTime('now');
            $interval = $dateCurrent->diff($dateLastValidated);
            if (isInDevelopmentMode($app_id) == "TRUE") {
                logMessage(LogType::Info, "Time since last validating receipt for APP ID: " . $app_id . " USER ID: " . $user_id . " = " . $interval->format('%h hours %i minutes'));
            }
            // Only refresh and re-verify receipt if greater than the iTunesCachingDuration - or greater than 1 whole day
            if (getiTunesCachingDuration($app_id) == -1 || $interval->format('%h') > getiTunesCachingDuration($app_id) || $interval->format('%a') > 1) {
                // Check the latest receipt from the subscription table
                if ($base64_latest_receipt) {
                    // Verify Receipt - with logic to fall back to Sandbox test if Production Receipt fails (error code 21007)
                    try {
                        $data = verifyReceipt($base64_latest_receipt, $app_id, $user_id);
                    } catch (Exception $e) {