/** * @throws NotEnoughDataException * * @return array */ public function serialize() { $parentData = parent::serialize(); $parentData['expires_at'] = $this->expiresAt !== null && $this->expiresAt instanceof \DateTime ? $this->expiresAt->getTimestamp() : $this->expiresAt; return $parentData; }
/** * @param ECheepAPIInterface $api * * @return \MayakRed\ECheepIntegration\Model\UserPromotion */ function sampleUserPromotionIssuance(ECheepAPIInterface $api) { $promotions = sampleOrganizationPromotions($api); $user = sampleUserByPhone($api); $userPromotionIssuance = new UserPromotionIssuance(); $userPromotionIssuance->setValue(20)->setUser($user)->setPromotion($promotions[0])->setAuthData('some-auth-data'); return $api->createUserPromotion($userPromotionIssuance); }
/** * {@inheritdoc} */ public function createUserPromotion(UserPromotionIssuance $issuance) { if ($issuance->getUser() === null || $issuance->getUser()->getId() === null) { throw new NotEnoughDataException('user is null or user->id is null'); } $promotionsUrl = sprintf(self::USER_PROMOTIONS, $issuance->getUser()->getId()); $response = $this->prepareRequest(Http::POST, $this->getUrl($promotionsUrl))->body($issuance->serialize(), 'application/json')->send(); return UserPromotion::createFromStdClass($this->getSuccessData($response)); }