Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- api::checkHTTPMethod('POST');
- $user_id = api::getCurrentUserId();
- $reciept = getRequest('reciept');
- $shared = (getRequest('shared'));
- $validator = new iosRecieptCheck(iosRecieptCheck::ENDPOINT_SANDBOX);
- $sharedSecret = "54ab1296cf314267bf71dba3349f63a2";
- if ($shared) $sharedSecret = $shared;
- try {
- $response = $validator
- ->setSharedSecret($sharedSecret)
- ->setReceiptData($reciept)
- ->setExcludeOldTransactions(true)
- ->validate();
- } catch (Exception $e) {
- api::returnError($e->getMessage());
- }
- // если нет ответа, создаем, если есть - заменяем
- $latest_receipt = $response->latest_receipt_info[0];
- $tr_id = $latest_receipt->original_transaction_id;
- $sel = new selector('objects');
- $sel->types('object-type')->name('api', 'user_reciepts');
- $sel->where('name')->equals($tr_id);
- if (!$sel->first) {
- $objectTypeId = umiObjectTypesCollection::getInstance()->getBaseType("api", "user_reciepts");
- $objectId = umiObjectsCollection::getInstance()->addObject($tr_id, $objectTypeId);
- $object = umiObjectsCollection::getInstance()->getObject($objectId);
- api::setValue($object, "reciept", $response->latest_receipt);
- api::setValue($object, "date", time());
- api::setValue($object, "user_id", $user_id);
- $object->setOwnerId($user_id);
- $object->commit();
- }else{
- $object = $sel->first;
- if($object->user_id != $user_id)api::returnError("Транзакция не принедлежит данному пользователю.");
- }
- $user = api::getCurrentUser();
- $expires_date = round($latest_receipt->expires_date_ms / 1000);
- if ($expires_date > time()) $user->setValue("pro", 1);
- $user->setValue("expires_date", $expires_date);
- $user->commit();
- $res = ['result' => 'success'];
- api::returnJson($res);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement