/** * Form constructor. * * @param string $action * @param string $method * @param string $name * @param bool $disableStartup * @param bool $enableCsrf */ public function __construct($action = null, $method = 'post', $name = null, $disableStartup = false, $enableCsrf = true) { if ($name === null) { $name = 'Form-' . Strings::randomString(4); } $this->_options['action'] = $action; $this->_options['method'] = $method; $this->_options['name'] = $name; $this->_id = Strings::urlize($name); $this->_enableCsrf = $enableCsrf; if (!$disableStartup) { $this->_startup(); } }
/** * @return ISafeHtmlProducer */ public function render() { $output = new Div(); $groups = $this->getMethods(); foreach ($groups as $group => $methods) { $output->appendContent(Div::create(new HeadingOne(Strings::titleize($group)))->addClass('content-container')); foreach ($methods as $method) { $reflect = new \ReflectionMethod($this, $method); $parsed = DocBlockParser::fromMethod($this, $method); $code = $this->_getCode($reflect); $id = Strings::randomString(4); $toggledCode = new Div(); $toggledCode->appendContent(new HeadingFour((new Link('#', Strings::titleize($method)))->setAttribute('onclick', '$(\'#code-' . $id . '\')' . '.toggleClass(\'' . Ui::HIDE . '\');' . 'return false;'))); $code = new SafeHtml(str_replace('<span style="color: #0000BB"><?php </span>', '', highlight_string('<?php ' . $code, true))); $toggledCode->appendContent(Div::create()->appendContent(HtmlTag::createTag('pre', [], $code))->addClass(Ui::HIDE)->setId('code-' . $id)); $methRow = Div::create()->addClass('content-container'); $methRow->appendContent($toggledCode); $methRow->appendContent(new Paragraph($parsed->getSummary())); $methRow->appendContent($this->{$method}()); $output->appendContent($methRow); } } return $output; }
<?php require_once dirname(__DIR__) . '/vendor/autoload.php'; use Fortifi\Sdk\Fortifi; use Packaged\Helpers\Strings; //Create a fortifi instance $fortifi = Fortifi::getInstance('ORG:DC:1448:6f535', 'ZGVmZWViNDI3-SDKT-MDNiOTc0OTVh', 'MjgyYjRmMzdhODM0Y2U2YmZhYTM5NTYyY2I1OWQ2'); $ref = Strings::randomString(3); var_dump(Strings::jsonPretty($fortifi->visitor('VIS:' . $ref)->triggerAction('FID:COMP:1427472077:4b37c88345e0', 'lead', 'LEAD-' . $ref))); //Create a new customer $customer = $fortifi->customer()->create('*****@*****.**', 'John', 'Smith', '036486346', 'TEST-' . $ref); //Customer FID applied to this customer object, for future requests do: $customer = $fortifi->customer('CustomerFid'); //Get any pixels required for this visitor $pixels = $fortifi->visitor()->getPixels(); if ($pixels) { foreach ($pixels as $pixel) { //Output $pixel to page var_dump(Strings::jsonPretty($pixel)); } } //Mark Customer Conversion to paid account $customer->purchase('ORDER-' . $ref, 12.98, ['product_id' => 'SUBSCRIP', 'product_name' => 'Account Subscription']); //Customer purchased an account addon (upsell) $customer->purchaseUpsell('UPS-' . $ref, 1.95, ['products' => ['PREMIUM_SUPPORT']]); //Mark Renewals $customer->renewed('RENEWAL-' . $ref, 15.98, ['renewal_count' => 1]); $customer->renewed('RENEWAL-' . $ref, 15.98, ['renewal_count' => 2]); //Customer cancelled their renewal $customer->cancel('RENEWAL-' . $ref); //Customer did a chargeback on their first renewal
public static function generate($time = null) { return (ValueAs::nonempty($time, time()) << 32) + Arrays::first(unpack('L', Strings::randomString(4))); }
public function testRandomString() { foreach ([1, 10, 50, 100, 500] as $length) { $this->assertEquals($length, strlen(\Packaged\Helpers\Strings::randomString($length))); } $types = [\Packaged\Helpers\Strings::RANDOM_STRING_MCRYPT, \Packaged\Helpers\Strings::RANDOM_STRING_OPENSSL, \Packaged\Helpers\Strings::RANDOM_STRING_URANDOM, \Packaged\Helpers\Strings::RANDOM_STRING_CUSTOM, 'invalid']; foreach ($types as $type) { $this->assertEquals(40, strlen(\Packaged\Helpers\Strings::randomString(40, $type))); } }