public function setAddressHandler($args) { $this->state->addressLine1 = $args['addressLine1']; $this->state->addressLine2 = $args['addressLine2']; $this->state->townOrCity = $args['townOrCity']; $this->state->stateOrRegion = $args['stateOrRegion']; $this->state->postCode = $args['postCode']; $this->state->countryCode = strtoupper($args['countryCode']); $this->state->countryString = $this->getCountriesByISO()[strtoupper($args['countryCode'])]; foreach ($this->state->requiredFields as $req => $label) { if (!$args[$req]) { $this->setFlashError($label . " is a required field."); $this->parent->updateState(); return $this->parent->render(); } } $this->state->mode = 'view'; $this->parent->setAddressStatus($this->isReady(), $this->state->countryCode, $this->state->__toString()); $this->parent->updateState(); return $this->parent->render(); }
/** * @param LineItem $lineItem * @param $successOutput * @param $billingAddress * @param string $chargeMode * @return array */ private function prepareBasket(LineItem $lineItem, &$successOutput, $billingAddress, $chargeMode = "immediate") { // This would usually come from a config source $configArray = ['localVatRate' => 0.2, 'remoteIp' => "212.58.244.20", 'currencyCode' => "GBP", 'currencySymbol' => "£", 'countryCode' => "GB", 'briefDescription' => "Brief description of basket contents.", 'intro' => "Optional intro HTML for page.", 'paymentProviders' => ['Stripe' => ['name' => 'stripe', 'componentClass' => "\\PatternSeek\\ECommerce\\Stripe", 'conf' => ['testApiPubKey' => 'pk_test_abc123', 'testApiPrivKey' => 'sk_test_abc123', 'liveApiPubKey' => 'pk_live_abc123', 'liveApiPrivKey' => 'sk_live_abc123', 'siteName' => 'example.com', 'currency' => 'GBP', 'siteLogo' => '//example.com/logo.png']]], 'billingAddress' => $billingAddress]; file_put_contents("/tmp/cnf", yaml_emit($configArray, YAML_UTF8_ENCODING)); /** @var BasketConfig $config */ $config = BasketConfig::fromArray($configArray); $config->intro = "An intro"; $config->outro = "An outro"; $config->validate(); $vatRates = $this->getVatRates(); // $initConfig = [ // 'config' => $config, // 'vatRates' => $vatRates, // 'lineItems' => [ $lineItem ], // 'testMode' => true // ]; /** @var \PatternSeek\ECommerce\Basket $view */ $view = new Basket(); $this->successCallback = new TestSuccess(); $this->delayedSuccessCallback = new TestDelayedSuccess(); $view->updateView(['config' => $config, 'vatRates' => $vatRates, 'lineItems' => [$lineItem], 'testMode' => true, 'chargeMode' => $chargeMode, 'transactionSuccessCallback' => $this->successCallback, 'delayedTransactionSuccessCallback' => $this->delayedSuccessCallback]); $view->render(); return $view; }