First upload

This commit is contained in:
Nikolai Fesenko
2025-02-02 13:37:56 +01:00
commit 8d227c9191
3281 changed files with 362319 additions and 0 deletions

View File

@@ -0,0 +1,374 @@
<?php
/**
* This file is part of O3-Shop Paypal module.
*
* O3-Shop is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* O3-Shop is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
*
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
*/
namespace OxidEsales\PayPalModule\Model\PayPalRequest;
/**
* PayPal request builder class for do express checkout payment
*/
class DoExpressCheckoutPaymentRequestBuilder
{
/**
* @var \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
*/
protected $request = null;
/**
* @var \OxidEsales\PayPalModule\Core\Config
*/
protected $payPalConfig = null;
/**
* @var \OxidEsales\Eshop\Application\Model\Basket
*/
protected $basket = null;
/**
* @var \OxidEsales\Eshop\Application\Model\User
*/
protected $user = null;
/**
* @var \OxidEsales\Eshop\Core\Session
*/
protected $session = null;
/**
* @var sTransactionMode : Sale or Authorization
*/
protected $transactionMode;
/**
* @var \OxidEsales\Eshop\Application\Model\Order
*/
protected $order = null;
/**
* @var \OxidEsales\Eshop\Core\Language
*/
protected $lang = null;
/**
* Sets request object.
*
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request
*/
public function setRequest($request)
{
$this->request = $request;
}
/**
* Returns request object.
*
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
*/
public function getRequest()
{
if ($this->request === null) {
$this->request = oxNew(\OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest::class);
}
return $this->request;
}
/**
* Returns request object
*
* @param \OxidEsales\PayPalModule\Core\Config $config
*/
public function setPayPalConfig($config)
{
$this->payPalConfig = $config;
}
/**
* Returns \OxidEsales\PayPalModule\Core\Config object.
*
* @return \OxidEsales\PayPalModule\Core\Config
*/
public function getPayPalConfig()
{
return $this->payPalConfig;
}
/**
* Sets basket.
*
* @param \OxidEsales\Eshop\Application\Model\Basket $basket
*/
public function setBasket($basket)
{
$this->basket = $basket;
}
/**
* Returns basket object.
*
* @return \OxidEsales\Eshop\Application\Model\Basket
*
* @throws \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException
*/
public function getBasket()
{
if (is_null($this->basket)) {
/**
* @var \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException $exception
*/
$exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException::class);
throw $exception;
}
return $this->basket;
}
/**
* Sets order object.
*
* @param \OxidEsales\Eshop\Application\Model\Order $order
*/
public function setOrder($order)
{
$this->order = $order;
}
/**
* Tries to return basket object, but if fails throws exception.
*
* @return \OxidEsales\Eshop\Application\Model\Order
*
* @throws \OxidEsales\PayPalModule\Core\Exception\PayPalResponseException
*/
public function getOrder()
{
if (is_null($this->order)) {
/** @var \OxidEsales\PayPalModule\Core\Exception\PayPalResponseException $exception */
$exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalResponseException::class, 'OEPAYPAL_ORDER_ERROR');
throw $exception;
}
return $this->order;
}
/**
* Sets session.
*
* @param \OxidEsales\Eshop\Core\Session $session
*/
public function setSession($session)
{
$this->session = $session;
}
/**
* Returns session.
*
* @return \OxidEsales\Eshop\Core\Session
*/
public function getSession()
{
return $this->session;
}
/**
* Returns request object.
*
* @param \OxidEsales\Eshop\Core\Language $lang
*/
public function setLang($lang)
{
$this->lang = $lang;
}
/**
* Returns request object.
*
* @return \OxidEsales\Eshop\Core\Language
*/
public function getLang()
{
if ($this->lang === null) {
$this->lang = $this->getPayPalConfig()->getLang();
}
return $this->lang;
}
/**
* Sets transaction mode.
*
* @param string $transactionMode
*/
public function setTransactionMode($transactionMode)
{
$this->transactionMode = $transactionMode;
}
/**
* Returns transaction mode.
*
* @return string $transactionMode
*/
public function getTransactionMode()
{
return $this->transactionMode;
}
/**
* Sets User object.
*
* @param \OxidEsales\PayPalModule\Model\User $user
*/
public function setUser($user)
{
$this->user = $user;
}
/**
* Returns User object
*
* @return \OxidEsales\Eshop\Application\Model\User
*
* @throws \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException
*/
public function getUser()
{
if (is_null($this->user)) {
/**
* @var \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException $exception
*/
$exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException::class);
throw $exception;
}
return $this->user;
}
/**
* Sets base parameters to request.
*
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
*/
public function buildRequest()
{
$this->addBaseParams();
$this->addAddressParams();
return $this->getRequest();
}
/**
* Sets Address parameters to request.
*
* @return null
*/
public function addAddressParams()
{
$user = $this->getUser();
if (!$user) {
return;
}
$request = $this->getRequest();
$addressId = $user->getSelectedAddressId();
if ($addressId) {
$address = oxNew(\OxidEsales\Eshop\Application\Model\Address::class);
$address->load($addressId);
$request->setParameter("PAYMENTREQUEST_0_SHIPTONAME", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($address->oxaddress__oxfname->value . " " . $address->oxaddress__oxlname->value));
$request->setParameter("PAYMENTREQUEST_0_SHIPTOSTREET", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($address->oxaddress__oxstreet->value . " " . $address->oxaddress__oxstreetnr->value));
$request->setParameter("PAYMENTREQUEST_0_SHIPTOCITY", $address->oxaddress__oxcity->value);
$request->setParameter("PAYMENTREQUEST_0_SHIPTOZIP", $address->oxaddress__oxzip->value);
$request->setParameter("PAYMENTREQUEST_0_SHIPTOPHONENUM", $address->oxaddress__oxfon->value);
$country = oxNew(\OxidEsales\Eshop\Application\Model\Country::class);
$country->load($address->oxaddress__oxcountryid->value);
$request->setParameter("PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE", $country->oxcountry__oxisoalpha2->value);
if ($address->oxaddress__oxstateid->value) {
$state = oxNew(\OxidEsales\Eshop\Application\Model\State::class);
$state->load($address->oxaddress__oxstateid->value);
$request->setParameter("PAYMENTREQUEST_0_SHIPTOSTATE", $state->oxstates__oxisoalpha2->value);
}
} else {
$request->setParameter("PAYMENTREQUEST_0_SHIPTONAME", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($user->oxuser__oxfname->value . " " . $user->oxuser__oxlname->value));
$request->setParameter("PAYMENTREQUEST_0_SHIPTOSTREET", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($user->oxuser__oxstreet->value . " " . $user->oxuser__oxstreetnr->value));
$request->setParameter("PAYMENTREQUEST_0_SHIPTOCITY", $user->oxuser__oxcity->value);
$request->setParameter("PAYMENTREQUEST_0_SHIPTOZIP", $user->oxuser__oxzip->value);
$request->setParameter("PAYMENTREQUEST_0_SHIPTOPHONENUM", $user->oxuser__oxfon->value);
$country = oxNew(\OxidEsales\Eshop\Application\Model\Country::class);
$country->load($user->oxuser__oxcountryid->value);
$request->setParameter("PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE", $country->oxcountry__oxisoalpha2->value);
if ($user->oxuser__oxstateid->value) {
$state = oxNew(\OxidEsales\Eshop\Application\Model\State::class);
$state->load($user->oxuser__oxstateid->value);
$request->setParameter("PAYMENTREQUEST_0_SHIPTOSTATE", $state->oxstates__oxisoalpha2->value);
}
}
}
/**
* Sets basic parameters to request.
*/
public function addBaseParams()
{
$order = $this->getOrder();
$config = $this->getPayPalConfig();
$basket = $this->getBasket();
$session = \OxidEsales\Eshop\Core\Registry::getSession();
$lang = $this->getLang();
$request = $this->getRequest();
$request->setParameter("TOKEN", $session->getVariable("oepaypal-token"));
$request->setParameter("PAYERID", $session->getVariable("oepaypal-payerId"));
$request->setParameter("PAYMENTREQUEST_0_PAYMENTACTION", $this->getTransactionMode());
$request->setParameter("PAYMENTREQUEST_0_AMT", $this->formatFloat($basket->getPrice()->getBruttoPrice()));
$request->setParameter("PAYMENTREQUEST_0_CURRENCYCODE", $basket->getBasketCurrency()->name);
// IPN notify URL for PayPal
if (!$config->suppressIPNCallbackUrl()) {
$request->setParameter("PAYMENTREQUEST_0_NOTIFYURL", $config->getIPNCallbackUrl());
}
// payment description
$subj = sprintf($lang->translateString("OEPAYPAL_ORDER_CONF_SUBJECT"), $order->oxorder__oxordernr->value);
$request->setParameter("PAYMENTREQUEST_0_DESC", $subj);
$request->setParameter("PAYMENTREQUEST_0_CUSTOM", $subj);
// Please do not change this place.
// It is important to guarantee the future development of this O3-Shop extension and to keep it free of charge.
// Thanks!
$request->setParameter("BUTTONSOURCE", $config->getPartnerCode());
}
/**
* Formats given float/int value into PayPal friendly form
*
* @param float $in value to format
*
* @return string
*/
protected function formatFloat($in)
{
return sprintf("%.2f", $in);
}
}

View File

@@ -0,0 +1,137 @@
<?php
/**
* This file is part of O3-Shop Paypal module.
*
* O3-Shop is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* O3-Shop is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
*
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
*/
namespace OxidEsales\PayPalModule\Model\PayPalRequest;
/**
* PayPal request builder class for get express checkout details
*/
class GetExpressCheckoutDetailsRequestBuilder
{
/**
* PayPal Request
*
* @var \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
*/
protected $payPalRequest = null;
/**
* Session object
*
* @var \OxidEsales\Eshop\Core\Session
*
* @deprecated Session property is never used in this class
*/
protected $session = null;
/** @var ?string */
protected $token = null;
/**
* Sets PayPal request object.
*
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request
*/
public function setPayPalRequest($request)
{
$this->payPalRequest = $request;
}
/**
* Returns PayPal request object.
*
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
*/
public function getPayPalRequest()
{
if ($this->payPalRequest === null) {
$this->payPalRequest = oxNew(\OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest::class);
}
return $this->payPalRequest;
}
/**
* Sets Session.
*
* @param \OxidEsales\Eshop\Core\Session $session
* @deprecated Use self::setToken to set token or omit this method if it should be taken from session
*/
public function setSession($session)
{
$this->session = $session;
}
/**
* Returns Session.
*
* @return \OxidEsales\Eshop\Core\Session
*
* @throws \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException
*
* @deprecated Session property is never used in this class
*/
public function getSession()
{
if (!$this->session) {
/**
* @var \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException $exception
*/
$exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException::class);
throw $exception;
}
return $this->session;
}
/**
* @return string|null
*/
public function getToken(): ?string
{
if (!$this->token) {
$session = \OxidEsales\Eshop\Core\Registry::getSession();
$this->token = $session->getVariable('oepaypal-token');
}
return $this->token;
}
/**
* @param string|null $token
*/
public function setToken(?string $token)
{
$this->token = $token;
}
/**
* Builds Request.
*
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
*/
public function buildRequest()
{
$request = $this->getPayPalRequest();
$request->setParameter('TOKEN', $this->getToken());
return $request;
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* This file is part of O3-Shop Paypal module.
*
* O3-Shop is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* O3-Shop is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
*
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
*/
namespace OxidEsales\PayPalModule\Model\PayPalRequest;
/**
* PayPal request class
*/
class PayPalRequest
{
/**
* PayPal response data
*
* @var array
*/
protected $data = array();
/**
* Sets value to data by given key.
*
* @param string $key Key of data value.
* @param string $value Data value.
*/
public function setParameter($key, $value)
{
$this->data[$key] = $value;
}
/**
* Returns value by given key.
*
* @param string $key Key of data value.
*
* @return string
*/
public function getParameter($key)
{
return $this->data[$key];
}
/**
* Set request data.
*
* @param array $responseData Response data from PayPal.
*/
public function setData($responseData)
{
$this->data = $responseData;
}
/**
* Return request data.
*
* @return array
*/
public function getData()
{
return $this->data;
}
/**
* Return value from data by given key.
*
* @param string $key Key of data value.
* @param string $value Data value.
*/
protected function setValue($key, $value)
{
$this->data[$key] = $value;
}
}

View File

@@ -0,0 +1,124 @@
<?php
/**
* This file is part of O3-Shop Paypal module.
*
* O3-Shop is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* O3-Shop is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
*
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
*/
namespace OxidEsales\PayPalModule\Model\PayPalRequest;
/**
* PayPal request builder class
*/
class PayPalRequestBuilder
{
/**
* Request object
*
* @var \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
*/
protected $request = null;
/**
* Sets Authorization id
*
* @param string $authorizationId
*/
public function setAuthorizationId($authorizationId)
{
$this->getRequest()->setParameter('AUTHORIZATIONID', $authorizationId);
}
/**
* Sets Transaction id
*
* @param string $transactionId
*/
public function setTransactionId($transactionId)
{
$this->getRequest()->setParameter('TRANSACTIONID', $transactionId);
}
/**
* Set amount
*
* @param double $amount
* @param string $currencyCode
*/
public function setAmount($amount, $currencyCode = null)
{
$this->getRequest()->setParameter('AMT', $amount);
if (!$currencyCode) {
$currencyCode = \OxidEsales\Eshop\Core\Registry::getConfig()->getActShopCurrencyObject()->name;
}
$this->getRequest()->setParameter('CURRENCYCODE', $currencyCode);
}
/**
* Set Capture type
*
* @param string $type
*/
public function setCompleteType($type)
{
$this->getRequest()->setParameter('COMPLETETYPE', $type);
}
/**
* Set Refund type
*
* @param string $type
*/
public function setRefundType($type)
{
$this->getRequest()->setParameter('REFUNDTYPE', $type);
}
/**
* Set Refund type
*
* @param string $comment
*/
public function setComment($comment)
{
$this->getRequest()->setParameter('NOTE', $comment);
}
/**
* Return request object.
*
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
*/
public function getRequest()
{
if ($this->request === null) {
$this->request = oxNew(\OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest::class);
}
return $this->request;
}
/**
* Sets Request object.
*
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request
*/
public function setRequest($request)
{
$this->request = $request;
}
}

View File

@@ -0,0 +1,648 @@
<?php
/**
* This file is part of O3-Shop Paypal module.
*
* O3-Shop is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* O3-Shop is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
*
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
*/
namespace OxidEsales\PayPalModule\Model\PayPalRequest;
/**
* PayPal request builder class for set express checkout
*/
class SetExpressCheckoutRequestBuilder
{
/**
* PayPal Request.
*
* @var \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
*/
protected $payPalRequest = null;
/**
* PayPal Config.
*
* @var \OxidEsales\PayPalModule\Core\Config
*/
protected $payPalConfig = null;
/**
* Basket object.
*
* @var \OxidEsales\PayPalModule\Model\Basket
*/
protected $basket = null;
/**
* User object.
*
* @var \OxidEsales\PayPalModule\Model\User
*/
protected $user = null;
/**
* Language object.
*
* @var \OxidEsales\Eshop\Core\Language
*/
protected $lang = null;
/**
* Url to return to after PayPal payment is done.
*
* @var string
*/
protected $returnUrl = null;
/**
* Url to return to if PayPal payment was canceled.
*
* @var string
*/
protected $cancelUrl = null;
/**
* Url for PayPal CallBack.
*
* @var string
*/
protected $callBackUrl = null;
/**
* Show basket items in PayPal.
*
* @var bool
*/
protected $showCartInPayPal = false;
/**
* Transaction mode: Sale|Authorization.
*
* @var string
*/
protected $transactionMode;
/**
* Maximum possible delivery costs value.
*
* @var double
*/
protected $maxDeliveryAmount = 0;
/**
* Sets max delivery amount.
*
* @param double $maxDeliveryAmount
*/
public function setMaxDeliveryAmount($maxDeliveryAmount)
{
$this->maxDeliveryAmount = $maxDeliveryAmount;
}
/**
* Return max delivery amount.
*
* @return double
*/
public function getMaxDeliveryAmount()
{
return $this->maxDeliveryAmount;
}
/**
* Sets PayPal request object.
*
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request
*/
public function setPayPalRequest($request)
{
$this->payPalRequest = $request;
}
/**
* Returns PayPal request object; initiates if not set.
*
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
*/
public function getPayPalRequest()
{
if ($this->payPalRequest === null) {
$this->payPalRequest = oxNew(\OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest::class);
}
return $this->payPalRequest;
}
/**
* Returns config object.
*
* @param \OxidEsales\PayPalModule\Core\Config $config
*/
public function setPayPalConfig($config)
{
$this->payPalConfig = $config;
}
/**
* Returns config object.
*
* @return \OxidEsales\PayPalModule\Core\Config
*
* @throws \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException
*/
public function getPayPalConfig()
{
if (!$this->payPalConfig) {
/** @var \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException $exception */
$exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException::class);
throw $exception;
}
return $this->payPalConfig;
}
/**
* Sets Basket object.
*
* @param \OxidEsales\Eshop\Application\Model\Basket $basket
*/
public function setBasket($basket)
{
$this->basket = $basket;
}
/**
* Returns basket object.
*
* @return \OxidEsales\Eshop\Application\Model\Basket
*
* @throws \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException
*/
public function getBasket()
{
if (is_null($this->basket)) {
/** @var \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException $exception */
$exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException::class);
throw $exception;
}
return $this->basket;
}
/**
* Sets User object
*
* @param \OxidEsales\Eshop\Application\Model\User $user
*/
public function setUser($user)
{
$this->user = $user;
}
/**
* Returns User object
*
* @return \OxidEsales\PayPalModule\Model\User
*/
public function getUser()
{
return $this->user;
}
/**
* Sets Language object
*
* @param \OxidEsales\Eshop\Core\Language $lang
*/
public function setLang($lang)
{
$this->lang = $lang;
}
/**
* Returns Language object.
*
* @return \OxidEsales\Eshop\Core\Language
*/
public function getLang()
{
if (is_null($this->lang)) {
$this->lang = $this->getPayPalConfig()->getLang();
}
return $this->lang;
}
/**
* Sets CallBack url.
*
* @param string $callBackUrl
*/
public function setCallBackUrl($callBackUrl)
{
$this->callBackUrl = $callBackUrl;
}
/**
* Returns CallBack url.
*
* @return string
*/
public function getCallBackUrl()
{
return $this->callBackUrl;
}
/**
* Sets Cancel Url.
*
* @param string $cancelUrl
*/
public function setCancelUrl($cancelUrl)
{
$this->cancelUrl = $cancelUrl;
}
/**
* Returns Cancel Url.
*
* @return string
*/
public function getCancelUrl()
{
return $this->cancelUrl;
}
/**
* Sets Return Url.
*
* @param string $returnUrl
*/
public function setReturnUrl($returnUrl)
{
$this->returnUrl = $returnUrl;
}
/**
* Returns Return Url.
*
* @return string
*/
public function getReturnUrl()
{
return $this->returnUrl;
}
/**
* Sets whether to show basket in PayPal.
*
* @param string $showCartInPayPal
*/
public function setShowCartInPayPal($showCartInPayPal)
{
$this->showCartInPayPal = $showCartInPayPal;
}
/**
* Returns whether to show basket in PayPal.
*
* @return string
*/
public function getShowCartInPayPal()
{
return $this->showCartInPayPal;
}
/**
* Sets Transaction mode.
*
* @param string $transactionMode
*/
public function setTransactionMode($transactionMode)
{
$this->transactionMode = $transactionMode;
}
/**
* Returns Transaction mode.
*
* @return string $transactionMode
*/
public function getTransactionMode()
{
return $this->transactionMode;
}
/**
* Builds PayPal request for express checkout.
*
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
*/
public function buildExpressCheckoutRequest()
{
$this->addBaseParams();
$this->addCallBackUrl();
$this->addBasketParams();
$this->addDescriptionParams();
$this->turnOffShippingAddressCollection();
$this->setMaximumOrderAmount();
if ($this->getShowCartInPayPal()) {
$this->addBasketItemParams();
} else {
$this->addBasketGrandTotalParams();
}
$this->addAddressParams();
return $this->getPayPalRequest();
}
/**
* Builds PayPal request for standard checkout.
*
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
*/
public function buildStandardCheckoutRequest()
{
$this->addBaseParams();
$this->addBasketParams();
$this->addDescriptionParams();
$this->disableSelectingDifferentAddressInPayPal();
$this->setMaximumOrderAmount();
if ($this->getShowCartInPayPal()) {
$this->addBasketItemParams();
} else {
$this->addBasketGrandTotalParams();
}
$this->addAddressParams();
return $this->getPayPalRequest();
}
/**
* Sets base parameters to request.
*/
public function addBaseParams()
{
$request = $this->getPayPalRequest();
$payPalConfig = $this->getPayPalConfig();
$request->setParameter("CALLBACKVERSION", "84.0");
$request->setParameter("LOCALECODE", $this->getLang()->translateString("OEPAYPAL_LOCALE"));
// enabled guest buy (Buyer does not need to create a PayPal account to check out)
$request->setParameter("SOLUTIONTYPE", ($payPalConfig->isGuestBuyEnabled() ? "Sole" : "Mark"));
$request->setParameter("BRANDNAME", $payPalConfig->getBrandName());
$request->setParameter("CARTBORDERCOLOR", $payPalConfig->getBorderColor());
$request->setParameter("RETURNURL", $this->getReturnUrl());
$request->setParameter("CANCELURL", $this->getCancelUrl());
if ($logoImage = $payPalConfig->getLogoUrl()) {
$request->setParameter("LOGOIMG", $logoImage);
}
$request->setParameter("PAYMENTREQUEST_0_PAYMENTACTION", $this->getTransactionMode());
}
/**
* Adds callback parameters to request.
*/
public function addCallBackUrl()
{
$request = $this->getPayPalRequest();
$request->setParameter("CALLBACK", $this->getCallbackUrl());
$request->setParameter("CALLBACKTIMEOUT", 6);
}
/**
* Turn off shipping address collection.
*/
public function turnOffShippingAddressCollection()
{
$this->getPayPalRequest()->setParameter("NOSHIPPING", "2");
}
/**
* Disables selecting different address in PayPal side.
*/
public function disableSelectingDifferentAddressInPayPal()
{
$this->getPayPalRequest()->setParameter("ADDROVERRIDE", "1");
}
/**
* Calculating maximum order amount
* and adding all used discounts (needed because of bug in PayPal - somehow it substract discount from MAXAMT)
* additionally +1 as PayPal recommends this value a little bit greater than original.
*/
public function setMaximumOrderAmount()
{
$basket = $this->getBasket();
$request = $this->getPayPalRequest();
$request->setParameter("MAXAMT", $this->formatFloat(($basket->getPrice()->getBruttoPrice() + $basket->getDiscountSumPayPalBasket() + $this->getMaxDeliveryAmount() + 1)));
}
/**
* Sets basket parameters to request.
*/
public function addBasketParams()
{
$request = $this->getPayPalRequest();
$basket = $this->getBasket();
$virtualBasket = $basket->isVirtualPayPalBasket();
// only downloadable products? missing getter on oxBasket yet
$request->setParameter("NOSHIPPING", $virtualBasket ? "1" : "0");
if ($virtualBasket) {
$request->setParameter("REQCONFIRMSHIPPING", "0");
}
// passing basket VAT (tax) value. It is required as in Net mode articles are without VAT, but basket is with VAT.
// PayPal need this value to check if all articles sum match basket sum.
if ($basket->isCalculationModeNetto()) {
$request->setParameter("PAYMENTREQUEST_0_TAXAMT", $this->formatFloat($basket->getPayPalBasketVatValue()));
}
$request->setParameter("PAYMENTREQUEST_0_AMT", $this->formatFloat($basket->getPrice()->getBruttoPrice()));
$request->setParameter("PAYMENTREQUEST_0_CURRENCYCODE", $basket->getBasketCurrency()->name);
$request->setParameter("PAYMENTREQUEST_0_ITEMAMT", $this->formatFloat($basket->getSumOfCostOfAllItemsPayPalBasket()));
$request->setParameter("PAYMENTREQUEST_0_SHIPPINGAMT", $this->formatFloat($basket->getDeliveryCosts()));
$request->setParameter("PAYMENTREQUEST_0_SHIPDISCAMT", $this->formatFloat($basket->getDiscountSumPayPalBasket() * -1));
$delivery = oxNew(\OxidEsales\Eshop\Application\Model\DeliverySet::class);
$deliveryName = ($delivery->load($basket->getShippingId())) ? $delivery->oxdeliveryset__oxtitle->value : "#1";
$request->setParameter("L_SHIPPINGOPTIONISDEFAULT0", "true");
$request->setParameter("L_SHIPPINGOPTIONNAME0", $deliveryName);
$request->setParameter("L_SHIPPINGOPTIONAMOUNT0", $this->formatFloat($basket->getDeliveryCosts()));
}
/**
* Sets transaction description parameters.
*/
public function addDescriptionParams()
{
$basket = $this->getBasket();
$config = $this->getPayPalConfig();
$request = $this->getPayPalRequest();
// description
$shopNameFull = $config->getBrandName();
$shopName = substr($shopNameFull, 0, 70);
if ($shopNameFull != $shopName) {
$shopName .= "...";
}
$subj = sprintf($this->getLang()->translateString("OEPAYPAL_ORDER_SUBJECT"), $shopName, $basket->getFPrice(), $basket->getBasketCurrency()->name);
$request->setParameter("PAYMENTREQUEST_0_DESC", $subj);
$request->setParameter("PAYMENTREQUEST_0_CUSTOM", $subj);
}
/**
* Sets basket items parameters to request.
*/
public function addBasketItemParams()
{
$basket = $this->getBasket();
$lang = $this->getLang();
$request = $this->getPayPalRequest();
$pos = 0;
foreach ($basket->getContents() as $basketItem) {
$request->setParameter("L_PAYMENTREQUEST_0_NAME{$pos}", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($basketItem->getTitle()));
$request->setParameter("L_PAYMENTREQUEST_0_AMT{$pos}", $this->formatFloat($basketItem->getUnitPrice()->getPrice()));
$request->setParameter("L_PAYMENTREQUEST_0_QTY{$pos}", (int) $basketItem->getAmount());
$request->setParameter("L_PAYMENTREQUEST_0_ITEMURL{$pos}", $basketItem->getLink());
$basketProduct = $basketItem->getArticle();
$request->setParameter("L_PAYMENTREQUEST_0_NUMBER{$pos}", $basketProduct->oxarticles__oxartnum->value);
$pos++;
}
//adding payment costs as product
if ($basket->getPayPalPaymentCosts() > 0) {
$paymentTitle = $lang->translateString("OEPAYPAL_SURCHARGE") . " " . $lang->translateString("OEPAYPAL_TYPE_OF_PAYMENT");
$request->setParameter("L_PAYMENTREQUEST_0_NAME{$pos}", $paymentTitle);
$request->setParameter("L_PAYMENTREQUEST_0_AMT{$pos}", $this->formatFloat($basket->getPayPalPaymentCosts()));
$request->setParameter("L_PAYMENTREQUEST_0_QTY{$pos}", 1);
$pos++;
}
//adding wrapping as product
if ($basket->getPayPalWrappingCosts() > 0) {
$request->setParameter("L_PAYMENTREQUEST_0_NAME{$pos}", $lang->translateString("OEPAYPAL_GIFTWRAPPER"));
$request->setParameter("L_PAYMENTREQUEST_0_AMT{$pos}", $this->formatFloat($basket->getPayPalWrappingCosts()));
$request->setParameter("L_PAYMENTREQUEST_0_QTY{$pos}", 1);
$pos++;
}
//adding greeting card as product
if ($basket->getPayPalGiftCardCosts() > 0) {
$request->setParameter("L_PAYMENTREQUEST_0_NAME{$pos}", $lang->translateString("OEPAYPAL_GREETING_CARD"));
$request->setParameter("L_PAYMENTREQUEST_0_AMT{$pos}", $this->formatFloat($basket->getPayPalGiftCardCosts()));
$request->setParameter("L_PAYMENTREQUEST_0_QTY{$pos}", 1);
$pos++;
}
}
/**
* Sets basket Grand Total params to request.
*/
public function addBasketGrandTotalParams()
{
$basket = $this->getBasket();
$request = $this->getPayPalRequest();
$request->setParameter("L_PAYMENTREQUEST_0_NAME0", $this->getLang()->translateString("OEPAYPAL_GRAND_TOTAL"));
$request->setParameter("L_PAYMENTREQUEST_0_AMT0", $this->formatFloat($basket->getSumOfCostOfAllItemsPayPalBasket()));
$request->setParameter("L_PAYMENTREQUEST_0_QTY0", 1);
}
/**
* Sets Address parameters to request.
*
* @return null
*/
public function addAddressParams()
{
$user = $this->getUser();
if (!$user) {
return;
}
$request = $this->getPayPalRequest();
$request->setParameter("EMAIL", $user->oxuser__oxusername->value);
$addressId = $user->getSelectedAddressId();
if ($addressId) {
$address = oxNew(\OxidEsales\Eshop\Application\Model\Address::class);
$address->load($addressId);
$request->setParameter("PAYMENTREQUEST_0_SHIPTONAME", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($address->oxaddress__oxfname->value . " " . $address->oxaddress__oxlname->value));
$request->setParameter("PAYMENTREQUEST_0_SHIPTOSTREET", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($address->oxaddress__oxstreet->value . " " . $address->oxaddress__oxstreetnr->value));
$request->setParameter("PAYMENTREQUEST_0_SHIPTOCITY", $address->oxaddress__oxcity->value);
$request->setParameter("PAYMENTREQUEST_0_SHIPTOZIP", $address->oxaddress__oxzip->value);
$request->setParameter("PAYMENTREQUEST_0_SHIPTOPHONENUM", $address->oxaddress__oxfon->value);
$country = oxNew(\OxidEsales\Eshop\Application\Model\Country::class);
$country->load($address->oxaddress__oxcountryid->value);
$request->setParameter("PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE", $country->oxcountry__oxisoalpha2->value);
if ($address->oxaddress__oxstateid->value) {
$state = oxNew(\OxidEsales\Eshop\Application\Model\State::class);
$state->load($address->oxaddress__oxstateid->value);
$request->setParameter("PAYMENTREQUEST_0_SHIPTOSTATE", $state->oxstates__oxisoalpha2->value);
}
} else {
$request->setParameter("PAYMENTREQUEST_0_SHIPTONAME", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($user->oxuser__oxfname->value . " " . $user->oxuser__oxlname->value));
$request->setParameter("PAYMENTREQUEST_0_SHIPTOSTREET", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($user->oxuser__oxstreet->value . " " . $user->oxuser__oxstreetnr->value));
$request->setParameter("PAYMENTREQUEST_0_SHIPTOCITY", $user->oxuser__oxcity->value);
$request->setParameter("PAYMENTREQUEST_0_SHIPTOZIP", $user->oxuser__oxzip->value);
$request->setParameter("PAYMENTREQUEST_0_SHIPTOPHONENUM", $user->oxuser__oxfon->value);
$country = oxNew(\OxidEsales\Eshop\Application\Model\Country::class);
$country->load($user->oxuser__oxcountryid->value);
$request->setParameter("PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE", $country->oxcountry__oxisoalpha2->value);
if ($user->oxuser__oxstateid->value) {
$state = oxNew(\OxidEsales\Eshop\Application\Model\State::class);
$state->load($user->oxuser__oxstateid->value);
$request->setParameter("PAYMENTREQUEST_0_SHIPTOSTATE", $state->oxstates__oxisoalpha2->value);
}
}
}
/**
* Formats given float/int value into PayPal friendly form
*
* @param float $in value to format
*
* @return string
*/
protected function formatFloat($in)
{
return sprintf("%.2f", $in);
}
}