/** * @param StripeFacade $stripe * @param $stripeToken * @param $paymentCountryCode * @param string $paymentType * @return \PatternSeek\ComponentView\Response */ private function getDelayedOrRepeatPaymentTransaction($stripe, $stripeToken, $paymentCountryCode, $paymentType) { $params = ["source" => $stripeToken, "description" => $this->state->email]; $customer = $stripe->customerCreate($params); if ($this->state->email) { $params['receipt_email'] = $this->state->email; } $futureTxn = new DelayedOrRepeatTransaction(); $futureTxn->paymentCountryCode = $paymentCountryCode; $futureTxn->paymentType = $paymentType; $this->parent->populateTransactionDetails($futureTxn); $futureTxn->storedToken = $customer->id; $futureTxn->providerClass = "\\PatternSeek\\ECommerce\\Stripe"; $this->state->complete = true; $ret = $this->parent->delayedTransactionSuccess($futureTxn); return $ret; }
protected function updateState() { $props = $this->props; $this->testInputs(['state' => ['PatternSeek\\ECommerce\\ViewState\\AddressState', null]], $props); // Init if (!isset($this->state)) { $this->state = $props['state']; $this->state->countryString = static::getCountriesByISO()[strtoupper($this->state->countryCode)]; // Allow the caller to set mode, but default to 'view' if (null === $this->state->mode) { $this->state->mode = 'view'; } } // Update $ready = $this->isReady(); $this->parent->setAddressStatus($ready, $this->state->countryCode, $this->state->__toString()); if (!$ready) { $this->state->mode = 'edit'; } }
/** * @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; }