Handle an updated subscription.

@param array $data

@throws \Throwable
514752
private function _handleSubscriptionUpdated(array $data)
    {
        $stripeSubscription = $data['data']['object'];
        $canceledAt = $data['data']['object']['canceled_at'];

        $subscription = Subscription::find()->reference($stripeSubscription['id'])->one();

        if (!$subscription) {
            Craft::warning('Subscription with the reference “' . $stripeSubscription['id'] . '” not found when processing webhook ' . $data['id'], 'stripe');

            return;
        }

        // See if we care about this subscription at all
        if ($subscription) {

            $subscription->isCanceled = (bool)$canceledAt;
            $subscription->dateCanceled = $canceledAt ? DateTimeHelper::toDateTime($canceledAt) : null;
            $subscription->nextPaymentDate = DateTimeHelper::toDateTime($data['data']['object']['current_period_end']);

            $planReference = $data['data']['object']['plan']['id'];
            $plan = Commerce::getInstance()->getPlans()->getPlanByReference($planReference);

            if ($plan) {
                $subscription->planId = $plan->id;
            } else {
                Craft::warning($subscription->reference . ' was switched to a plan on Stripe that does not exist on this Site. (event "' . $data['id'] . '")', 'stripe');
            }

            Commerce::getInstance()->getSubscriptions()->updateSubscription($subscription);
        }
    }
101005
protected function onInput($data)
    {
        //Process data here
        foreach ($this->params as $column) {
            unset($data[$column]);
        }
        $this->next($data);
    }
1279258
public function handleArray(array $data = []): void
    {
        $this->getForm()->submit($data);
        $this->handleForm($data['page'] ?? null);
    }
484130
public function resetData(array $data)
    {
        $this->data = $data;
        if ($this->existsKey('uid')) {
            if (!$this->hasUid()) {
                $this->setUid((int)$this->data['uid']);
            }
            unset($this->data['uid']);
        }

        $this->markAsLoaded();
        if ($this->hasUid()) {
            $this->markAsClean();
        } else {
            $this->markAsDirty();
        }
    }
185141
public function replace($data) {

		if (! is_array($data)) {
			$data = $this->makeArray($data);
		}
		
		$this->_data = array_replace($this->_data, $data);
	}
1352024
public function replace(array $data) {

		$this->data = array();

		foreach ($data as $k => $v) {
			$this->data[$k] = $v;
		}

	}
422017
final public function update(array $data)
    {
        $this->query->setStartUpdate($data);

        $this->query->prepare()->bindSetForUpdate($data)->bindWhere()->bindLimit()->execute();

        $this->setRowCount();

        $this->query->close();
    }
818696
protected function postUnserialize(array $data)
    {
        $this->repoPath = array_pop($data);
        $this->path = array_pop($data);
    }
453646
private function _handleInvoiceCreated(array $data)
    {
        $stripeInvoice = $data['data']['object'];

        if ($this->hasEventHandlers(self::EVENT_CREATE_INVOICE)) {
            $this->trigger(self::EVENT_CREATE_INVOICE, new CreateInvoiceEvent([
                'invoiceData' => $stripeInvoice
            ]));
        }

        $canBePaid = empty($stripeInvoice['paid']) && $stripeInvoice['billing'] === 'charge_automatically';

        if (StripePlugin::getInstance()->getSettings()->chargeInvoicesImmediately && $canBePaid) {
            /** @var StripeInvoice $invoice */
            $invoice = StripeInvoice::retrieve($stripeInvoice['id']);
            $invoice->pay();
        }
    }
704452
protected function onInput($data)
    {
        if (is_array($this->params)) {
            foreach ($this->params as $columnName => $columnInfo) {
                if (isset($columnInfo["name"])) {
                    $columnValue = $data[$columnName];
                    unset($data[$columnName]);
                    $data[$columnInfo["name"]] = $columnValue;
                }
            }
        } else {
            foreach ($this->nameMap as $oldName => $newName) {
                $value = $data[$oldName];
                unset($data[$oldName]);
                $data[$newName] = $value;
            }
        }
        $this->next($data);
    }
344446
public function updateNewsletter(array $data)
    {
        $user = $this->getAuthService()->getIdentity();
        $optinChange = false;
        $optin2Change = false;
        $optinPartnerChange = false;

        // I trigger an optin event before updating user if it has changed .
        if (isset($data['optin']) && $user->getOptin() != $data['optin']) {
            $optinChange = true;
            $this->getEventManager()->trigger(__FUNCTION__.'.pre', $this, array('user' => $user, 'data' => $data));
            $user->setOptin($data['optin']);
        }

        // I trigger an optin2 event before updating user if it has changed .
        if (isset($data['optin2']) && $user->getOptin2() != $data['optin2']) {
            $optin2Change = true;
            $this->getEventManager()->trigger(__FUNCTION__.'.pre', $this, array('user' => $user, 'data' => $data));
            $user->setOptin2($data['optin2']);
        }

        // I trigger an optinPartner event before updating user if it has changed
        if (isset($data['optinPartner']) && $user->getOptinPartner() != $data['optinPartner']) {
            $optinPartnerChange = true;
            $this->getEventManager()->trigger(__FUNCTION__.'Partner.pre', $this, array('user' => $user, 'data' => $data));
            $user->setOptinPartner($data['optinPartner']);
        }

        $form  = $this->getServiceManager()->get('playgrounduser_newsletter_form');
        $form->bind($user);
        $form->setData($data);

        /*if (!$form->isValid()) {
            return false;
        }*/

        $user = $this->getUserMapper()->update($user);
        if ($optinChange) {
            $this->getEventManager()->trigger(__FUNCTION__.'.post', $this, array('user' => $user, 'data' => $data));
        }

        if ($optin2Change) {
            $this->getEventManager()->trigger(__FUNCTION__.'.optin2.post', $this, array('user' => $user, 'data' => $data));
        }

        if ($optinPartnerChange) {
            $this->getEventManager()->trigger(__FUNCTION__.'Partner.post', $this, array('user' => $user, 'data' => $data));
        }

        return $user;
    }
906817
public function update(array $data)
    {
        $this->manager->postPendingQuery(
            new PendingQuery(
                $this->entity,
                PendingQuery::TYPE_UPDATE,
                $this->getUpdateQuery($data),
                $this->parameters
            )
        );
    }
743197
public function sendData($data)
    {
        $response = $this->gocardless->subscriptions()->get($this->getSubscriptionId());

        return $this->response = new SubscriptionResponse($this, $response);
    }
54795
public function handle(Throwable $exception) : void
    {
        foreach ($this->handlers as $handler) {
            $result = $handler($exception);

            if ($result instanceof Throwable) {
                $exception = $result;
            }
        }

        throw $exception;
    }
310589
public function update(array $data = [])
    {
        $this->parseOptions();

        $this->options['data'] = array_merge($this->options['data'], $data);

        return $this->connection->update($this);
    }
896418
protected function onInput($data)
    {
        $func = $this->params;

        $data = $func($data);
        if ($data) {
            $this->next($data);
        }
    }
592208
protected function internalUpdateFromData(array $data) {
        $initializing = $this->initializing;
        $this->initializing = true;
        $this->readOnlyOverride(function() use ($data) {
            return $this->updateFromData($data);
        });
        $this->initializing = $initializing;
    }