Advertisement
Guest User

Untitled

a guest
Sep 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. api::checkHTTPMethod('POST');
  2. $user_id = api::getCurrentUserId();
  3. $reciept = getRequest('reciept');
  4.  
  5. $shared = (getRequest('shared'));
  6. $validator = new iosRecieptCheck(iosRecieptCheck::ENDPOINT_SANDBOX);
  7. $sharedSecret = "54ab1296cf314267bf71dba3349f63a2";
  8. if ($shared) $sharedSecret = $shared;
  9. try {
  10. $response = $validator
  11. ->setSharedSecret($sharedSecret)
  12. ->setReceiptData($reciept)
  13. ->setExcludeOldTransactions(true)
  14. ->validate();
  15.  
  16. } catch (Exception $e) {
  17. api::returnError($e->getMessage());
  18. }
  19.  
  20. // если нет ответа, создаем, если есть - заменяем
  21. $latest_receipt = $response->latest_receipt_info[0];
  22.  
  23. $tr_id = $latest_receipt->original_transaction_id;
  24.  
  25. $sel = new selector('objects');
  26. $sel->types('object-type')->name('api', 'user_reciepts');
  27. $sel->where('name')->equals($tr_id);
  28.  
  29. if (!$sel->first) {
  30. $objectTypeId = umiObjectTypesCollection::getInstance()->getBaseType("api", "user_reciepts");
  31. $objectId = umiObjectsCollection::getInstance()->addObject($tr_id, $objectTypeId);
  32. $object = umiObjectsCollection::getInstance()->getObject($objectId);
  33. api::setValue($object, "reciept", $response->latest_receipt);
  34. api::setValue($object, "date", time());
  35. api::setValue($object, "user_id", $user_id);
  36.  
  37. $object->setOwnerId($user_id);
  38. $object->commit();
  39. }else{
  40. $object = $sel->first;
  41. if($object->user_id != $user_id)api::returnError("Транзакция не принедлежит данному пользователю.");
  42. }
  43.  
  44. $user = api::getCurrentUser();
  45.  
  46. $expires_date = round($latest_receipt->expires_date_ms / 1000);
  47. if ($expires_date > time()) $user->setValue("pro", 1);
  48. $user->setValue("expires_date", $expires_date);
  49. $user->commit();
  50. $res = ['result' => 'success'];
  51. api::returnJson($res);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement