localeResolver = $localeResolver; $this->config = $configFactory->create(); $this->currentCustomer = $currentCustomer; $this->paypalHelper = $paypalHelper; $this->paymentHelper = $paymentHelper; $this->urlBuilder = $urlBuilder; $this->smartButtonConfig = $smartButtonConfig; foreach ($this->methodCodes as $code) { $this->methods[$code] = $this->paymentHelper->getMethodInstance($code); } } /** * @inheritdoc */ public function getConfig() { $locale = $this->localeResolver->getLocale(); $config = [ 'payment' => [ 'paypalExpress' => [ 'paymentAcceptanceMarkHref' => $this->config->getPaymentMarkWhatIsPaypalUrl( $this->localeResolver ), 'paymentAcceptanceMarkSrc' => $this->config->getPaymentMarkImageUrl( $locale ), 'isContextCheckout' => false, 'inContextConfig' => [] ] ] ]; $isInContext = $this->isInContextCheckout(); if ($isInContext) { $config['payment']['paypalExpress']['isContextCheckout'] = $isInContext; $config['payment']['paypalExpress']['inContextConfig'] = [ 'inContextId' => self::IN_CONTEXT_BUTTON_ID, 'merchantId' => $this->config->getValue('merchant_id'), ]; $clientConfig = [ 'button' => [ self::IN_CONTEXT_BUTTON_ID ], 'getTokenUrl' => $this->urlBuilder->getUrl('paypal/express/getTokenData'), 'onAuthorizeUrl' => $this->urlBuilder->getUrl('paypal/express/onAuthorization'), 'onCancelUrl' => $this->urlBuilder->getUrl('paypal/express/cancel') ]; $clientConfig = array_replace_recursive($clientConfig, $this->smartButtonConfig->getConfig('checkout')); $config['payment']['paypalExpress']['inContextConfig']['clientConfig'] = $clientConfig; } foreach ($this->methodCodes as $code) { if ($this->methods[$code]->isAvailable()) { $config['payment']['paypalExpress']['redirectUrl'][$code] = $this->getMethodRedirectUrl($code); $config['payment']['paypalExpress']['billingAgreementCode'][$code] = $this->getBillingAgreementCode($code); } } return $config; } /** * Return setting value for in context checkout * * @return bool */ protected function isInContextCheckout() { $this->config->setMethod(Config::METHOD_EXPRESS); return (bool)(int) $this->config->getValue('in_context'); } /** * Return redirect URL for method * * @param string $code * @return mixed */ protected function getMethodRedirectUrl($code) { return $this->methods[$code]->getCheckoutRedirectUrl(); } /** * Return billing agreement code for method * * @param string $code * @return null|string */ protected function getBillingAgreementCode($code) { $customerId = $this->currentCustomer->getCustomerId(); $this->config->setMethod($code); return $this->paypalHelper->shouldAskToCreateBillingAgreement($this->config, $customerId) ? Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT : null; } }