Start a free trial to the system

@param  Companies $company
@return Subscription
547365
public static function startFreeTrial(Companies $company): Suscriptions
    {
        $subscription = new self();
        $subscription->plans_id = self::FREE_TRIAL;
        $subscription->users_id = $company->users_id;
        $subscription->apps_id = self::DEFAULT_APP;
        $subscription->stripe_id = '';
        $subscription->company_id = $company->getId();
        $subscription->stripe_plan = 'Free Trial';
        $subscription->quantity = 1;
        $subscription->trial_ends_at = date('Y-m-d H:i:s', strtotime('+30 days'));
        $subscription->ends_at = date('Y-m-d H:i:s', strtotime('+30 days'));

        if (!$subscription->save()) {
            throw new Exception(current($subscription->getMessages()));
        }

        return $subscription;
    }
1365513
def subscription!
      @subscription = PayuLatam::Subscription.new(@plan, @client, 'http://10d2e1a2.ngrok.io/payu/api/v1/subscriptions.json')
      @subscription.create!
      if @subscription.success?
        puts "Subscription creada!"
        @current_user.payu_subscriptions.create(subscription_params)
        @subscription
      else
        raise StandardError, "Error generando la subscripción: #{@subscription.error}"
      end
    end
942358
public function loadByBrandName(string $name): CompanyInterface
    {
        foreach ($this->companies as $key => $companyData) {
            if ($name !== $companyData['brandname']) {
                continue;
            }

            return $this->load($key);
        }

        throw new NotFoundException('the company with brand name "' . $name . '" was not found');
    }
44326
public function create($token = null, array $options = [])
    {
        $customer = $this->getStripeCustomer($token, $options);

        $subscription = $customer->subscriptions->create($this->buildPayload());

        if (in_array($subscription->status, ['incomplete', 'incomplete_expired'])) {
            $subscription->cancel();

            throw SubscriptionCreationFailed::incomplete($subscription);
        }

        if ($this->skipTrial) {
            $trialEndsAt = null;
        } else {
            $trialEndsAt = $this->trialExpires;
        }

        return $this->owner->subscriptions()->create([
            'name' => $this->name,
            'stripe_id' => $subscription->id,
            'stripe_plan' => $this->plan,
            'quantity' => $this->quantity,
            'trial_ends_at' => $trialEndsAt,
            'ends_at' => null,
        ]);
    }
814870
public function preSaveValidation(CompanyResponseTransfer $companyResponseTransfer): CompanyResponseTransfer
    {
        $companyTransfer = $companyResponseTransfer->getCompanyTransfer();

        if (!$companyTransfer) {
            return $companyResponseTransfer;
        }

        $externalReference = $companyTransfer->getExternalReference();

        if (!$externalReference) {
            $companyResponseTransfer->setIsSuccessful(false);
            $companyResponseTransfer->addMessage(
                $this->createResponseMessageTransfer(static::COMPANY_EXTERNAL_REFERENCE_INVALID)
            );

            return $companyResponseTransfer;
        }

        $tempCompanyTransfer = $this->getRepository()->findCompanyByExternalReference($externalReference);

        if ($tempCompanyTransfer === null) {
            return $companyResponseTransfer;
        }

        if ($tempCompanyTransfer && $tempCompanyTransfer->getIdCompany() === $companyTransfer->getIdCompany()) {
            return $companyResponseTransfer;
        }

        $companyResponseTransfer->setIsSuccessful(false);
        $companyResponseTransfer->addMessage(
            $this->createResponseMessageTransfer(static::COMPANY_EXTERNAL_REFERENCE_ALREADY_USED)
        );

        return $companyResponseTransfer;
    }
1359126
function createFreebusy() {
    $cnt = count( $this->freebusy );
    if( 0 >= $cnt )
      return;
    $output = null;
    foreach( $this->freebusy as $freebusyPart ) {
      $attributes = $content = null;
      if( isset( $freebusyPart['value']['fbtype'] )) {
        $attributes .= $this->intAttrDelimiter.'FBTYPE='.$freebusyPart['value']['fbtype'];
        unset( $freebusyPart['value']['fbtype'] );
        $freebusyPart['value'] = array_values( $freebusyPart['value'] );
      }
      else
        $attributes .= $this->intAttrDelimiter.'FBTYPE=BUSY';
      $attributes .= $this->_createParams( $freebusyPart['params'] );
      $fno = 1;
      $cnt = count( $freebusyPart['value']);
      foreach( $freebusyPart['value'] as $periodix => $freebusyPeriod ) {
        $formatted   = $this->_format_date_time( $freebusyPeriod[0] );
        $content .= $formatted;
        $content .= '/';
        $cnt2 = count( $freebusyPeriod[1]);
        if( array_key_exists( 'year', $freebusyPeriod[1] ))      // date-time
          $cnt2 = 7;
        elseif( array_key_exists( 'week', $freebusyPeriod[1] ))  // duration
          $cnt2 = 5;
        if(( 7 == $cnt2 )   &&    // period=  -> date-time
            isset( $freebusyPeriod[1]['year'] )  &&
            isset( $freebusyPeriod[1]['month'] ) &&
            isset( $freebusyPeriod[1]['day'] )) {
          $content .= $this->_format_date_time( $freebusyPeriod[1] );
        }
        else {                                  // period=  -> dur-time
          $content .= $this->_format_duration( $freebusyPeriod[1] );
        }
        if( $fno < $cnt )
          $content .= ',';
        $fno++;
      }
      $output .= $this->_createElement( 'FREEBUSY', $attributes, $content );
    }
    return $output;
  }
884371
public function load(string $key, string $useragent = ''): CompanyInterface
    {
        if (!$this->initData->hasItem($key)) {
            throw new NotFoundException('the company with key "' . $key . '" was not found');
        }

        $companyData = $this->initData->getItem($key);

        if (null === $companyData) {
            throw new NotFoundException('the company with key "' . $key . '" was not found');
        }

        return new Company(
            $key,
            $companyData->name,
            $companyData->brandname
        );
    }
685250
public function from($table, ...$tables)
    {
        $instance = $this->fromStrategyInstance();

        $instance->fromStrategy()->from($table, ...$tables);

        return $instance;
    }
904696
public function create(
        RestCompanyBusinessUnitsRequestAttributesTransfer $restCompanyBusinessUnitsRequestAttributesTransfer
    ): RestCompanyBusinessUnitsResponseTransfer {
        $companyBusinessUnitTransfer = new CompanyBusinessUnitTransfer();

        foreach ($this->companyBusinessUnitMapperPlugins as $companyBusinessUnitMapperPlugin) {
            $companyBusinessUnitTransfer = $companyBusinessUnitMapperPlugin->map(
                $restCompanyBusinessUnitsRequestAttributesTransfer,
                $companyBusinessUnitTransfer
            );
        }

        try {
            $companyBusinessUnitResponseTransfer = $this->companyBusinessUnitFacade->create($companyBusinessUnitTransfer);
        } catch (PropelException $e) {
            return $this->createCompanyBusinessUnitDataInvalidErrorResponse();
        }

        if (!$companyBusinessUnitResponseTransfer->getIsSuccessful()) {
            return $this->createCompanyBusinessUnitDataInvalidErrorResponse();
        }

        return $this->createCompanyBusinessUnitResponseTransfer(
            $companyBusinessUnitResponseTransfer->getCompanyBusinessUnitTransfer()
        );
    }
728041
public function getCompanyBusinessUnitStoreById(CompanyBusinessUnitStoreTransfer $companyBusinessUnitStoreTransfer): ?CompanyBusinessUnitStoreTransfer
    {
        return $this->getFactory()
            ->createCompanyBusinessUnitStoreReader()
            ->findCompanyBusinessUnitStoreById($companyBusinessUnitStoreTransfer->getIdCompanyBusinessUnitStore());
    }
800886
public function start()
    {
        $sVoucherNr = trim(\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("voucherNr"));
        $bRandomNr = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("randomVoucherNr");
        $controllerId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestControllerId();

        if ($controllerId == 'voucherserie_generate' && !$bRandomNr && empty($sVoucherNr)) {
            return;
        }

        $this->_aViewData['refresh'] = 0;
        $this->_aViewData['iStart'] = 0;
        $iEnd = $this->prepareExport();
        \OxidEsales\Eshop\Core\Registry::getSession()->setVariable("iEnd", $iEnd);
        $this->_aViewData['iEnd'] = $iEnd;

        // saving export info
        \OxidEsales\Eshop\Core\Registry::getSession()->setVariable("voucherid", \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("voucherid"));
        \OxidEsales\Eshop\Core\Registry::getSession()->setVariable("voucherAmount", abs((int) \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("voucherAmount")));
        \OxidEsales\Eshop\Core\Registry::getSession()->setVariable("randomVoucherNr", $bRandomNr);
        \OxidEsales\Eshop\Core\Registry::getSession()->setVariable("voucherNr", $sVoucherNr);
    }
1360393
protected function createCompanyBusinessUnitSavedResponse(
        RestCompanyBusinessUnitsResponseTransfer $restCompanyBusinessUnitsResponseTransfer
    ): RestResponseInterface {
        $restCompanyBusinessUnitsResponseAttributesTransfer = $restCompanyBusinessUnitsResponseTransfer->getRestCompanyBusinessUnitsResponseAttributes();

        $restResource = $this->restResourceBuilder->createRestResource(
            CompanyBusinessUnitsRestApiConfig::RESOURCE_COMPANY_BUSINESS_UNITS,
            $restCompanyBusinessUnitsResponseAttributesTransfer->getExternalReference(),
            $restCompanyBusinessUnitsResponseAttributesTransfer
        );

        return $this->restResourceBuilder
            ->createRestResponse()
            ->addResource($restResource);
    }
391915
public function getCompanyBusinessUnitStoreAddressById(CompanyBusinessUnitStoreAddressTransfer $companyBusinessUnitStoreAddressTransfer): ?CompanyBusinessUnitStoreAddressTransfer
    {
        return $this->getFactory()
            ->createCompanyBusinessUnitStoreAddressReader()
            ->findCompanyBusinessUnitStoreAddressById($companyBusinessUnitStoreAddressTransfer->getIdCompanyBusinessUnitStoreAddress());
    }
732263
public void registerManufacturerSpecificBuilder(int companyId, ADManufacturerSpecificBuilder builder)
    {
        if (companyId < 0 || 0xFFFF < companyId)
        {
            String message = String.format("'companyId' is out of the valid range: %d", companyId);
            throw new IllegalArgumentException(message);
        }

        if (builder == null)
        {
            return;
        }

        // Use the company ID as the key for the builder.
        Integer key = Integer.valueOf(companyId);

        // Get the existing list of builders for the company ID.
        List<ADManufacturerSpecificBuilder> builders = mMSBuilders.get(key);

        // If no builder has been registered for the company ID yet.
        if (builders == null)
        {
            builders = new ArrayList<ADManufacturerSpecificBuilder>();
            mMSBuilders.put(key, builders);
        }

        // Register the builder at the beginning of the builder list.
        builders.add(0, builder);
    }
1205326
protected function getIdCompanyByKey(string $companyKey): int
    {
        if (!isset($this->idCompanyListCache[$companyKey])) {
            $idCompany = $this->getCompanyQuery()
                ->filterByKey($companyKey)
                ->select(SpyCompanyTableMap::COL_ID_COMPANY)
                ->findOne();

            if (!$idCompany) {
                throw new EntityNotFoundException(sprintf('Could not find company by key "%s"', $companyKey));
            }

            $this->idCompanyListCache[$companyKey] = $idCompany;
        }

        return $this->idCompanyListCache[$companyKey];
    }
133164
public function patchCompany(CompanyPatchMessage $message): Company
    {
        $path = sprintf('companies/%d', $message->getId());
        $data = ['api_company' => $message->build()];

        $response = $this->getClient()->sendRequest('PATCH', $path, $data);

        /** @var Company $model */
        $model = $this->getModelFactory()->create(Company::class, $response);

        return $model;
    }
961215
public OvhCompany register_company_companyId_GET(String companyId) throws IOException {
		String qPath = "/partners/register/company/{companyId}";
		StringBuilder sb = path(qPath, companyId);
		String resp = exec(qPath, "GET", sb.toString(), null);
		return convertTo(resp, OvhCompany.class);
	}