Exemplo n.º 1
0
 */
function sampleUserGift(ECheepAPIInterface $api)
{
    $promotions = sampleOrganizationPromotions($api);
    $user = sampleUserByPhone($api);
    $gift = new Gift();
    $gift->setValue(20)->setUser($user)->setPromotion($promotions[0])->setAuthData('some-auth-data')->setExpiresAt(new \DateTime('+4 days'));
    return $api->createUserGift($gift);
}
$api = new ECheepAPI('echeep.mayakdev.ru', '0d07d369421aa301160f11fbc928fe46');
$phone = '+70000000000';
$code = 12345;
//$api->closeImportSession();
$api->getUserByPhoneRequest($phone);
$user = $api->getUserByPhoneConfirm($phone, $code);
$user->setPhone(Phone::createFromString($phone));
$userPromotions = $api->getUserPromotions($user);
$importData = new UserImportData();
foreach ($userPromotions as $userPromotion) {
    /** @var UserPromotion $userPromotion */
    $userPromotion->setRealValue($userPromotion->getRealValue() + 7);
}
$importData->setUserPromotions($userPromotions)->setUser($user);
try {
    $api->openImportSession();
} catch (BaseException $e) {
    if ($e->getApiStatus() !== 'ImportSessionAlreadyOpened') {
        throw $e;
    } else {
        $api->closeImportSession();
        $api->openImportSession();
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function getNewUsers(Phone $from = null, $count = null)
 {
     $response = $this->prepareRequest(Http::GET, $this->getUrl(self::NEW_USERS, ['from' => $from ? $from->getValue() : null, 'count' => $count ?: null]))->send();
     $data = $this->getSuccessData($response);
     $result = [];
     foreach ($data as $phoneValue) {
         $user = new User();
         $result[] = $user->setPhone(Phone::createFromString($phoneValue));
     }
     return $result;
 }