Initial Commit

This commit is contained in:
2019-11-21 12:25:31 +01:00
commit f4aabcb9b1
13959 changed files with 787761 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program 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; either version 3 of the License */
/* */
/* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Paypal\Classes\NVP\Operations;
/**
* Class NvpOperationInterface
*/
interface PaypalNvpOperationInterface
{
/**
* Generate NVP request message
*
* @return string
*/
public function getRequest();
/**
* Get Operation Name
*
* @return string Operation name
*/
public function getOperationName();
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* Created by JetBrains PhpStorm.
* Date: 8/12/13
* Time: 2:17 PM
*
* @author Guillaume MOREL <gmorel@openstudio.fr>
*/
namespace Paypal\Classes\NVP\Operations;
use Paypal\Classes\API\PaypalApiManager;
abstract class PaypalNvpOperationsBase implements PaypalNvpOperationInterface
{
/** @var \Paypal\Classes\API\PaypalApiCredentials API Credentials (3T) */
protected $credentials = null;
/** @var string operation name */
protected $operationName = null;
/** @var array Payload with optional parameters */
protected $payload = null;
/**
* Generate NVP request message
*
* @return string NVP string
*/
public function getRequest()
{
$request = 'METHOD=' . $this->operationName;
$request .= '&VERSION=' . PaypalApiManager::API_VERSION;
$request .= '&USER=' . urlencode($this->credentials->getApiUsername());
$request .= '&PWD=' . urlencode($this->credentials->getApiPassword());
$request .= '&SIGNATURE=' . urlencode($this->credentials->getApiSignature());
return $request;
}
/**
* Get Operation Name
*
* @return string Operation name
*/
public function getOperationName()
{
return $this->operationName;
}
}

View File

@@ -0,0 +1,108 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program 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; either version 3 of the License */
/* */
/* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Paypal\Classes\NVP\Operations;
use Paypal\Classes\API\PaypalApiCredentials;
/**
* Class PaypalNvpOperationsDoExpressCheckoutPayment
* Manage NVP DoExpressCheckoutPayment Operation
*/
class PaypalNvpOperationsDoExpressCheckoutPayment extends PaypalNvpOperationsBase
{
/** @var string Payer ID returned by PayPal when it redirects the buyer's browser to your site */
protected $payerId = null;
/** @var string SetExpressCheckout API Token */
protected $token = null;
/** @var string Transaction amount
* Must be specified as 2000.00 or 2,000.00.
* The specified amount cannot exceed USD $10,000.00, regardless of the currency used.
*/
protected $amount = null;
/** @var string Currency id ex: EUR */
protected $currencyId = null;
/** @var string Payment action ex: sale/order */
protected $paymentAction = null;
/** @var string URL IPN listener */
protected $ipnListenerUrl = null;
/** @var string Button Source for Thelia_Cart */
protected $buttonSource;
/**
* Constructor
*
* @param PaypalApiCredentials $credentials API Credentials (3T)
* @param string $amount Transaction amount. Must be specified as 2000.00 or 2,000.00. The specified amount cannot exceed USD $10,000.00, regardless of the currency used.
* @param string $currencyId Currency id ex: EUR
* @param string $payerId Payer ID returned by PayPal when it redirects the buyer's browser to your site
* @param string $paymentAction Payment action ex: sale/order
* @param string $token Token returned by PayPal SetExpressCheckout API when it redirects the buyer's browser to your site.
* @param string $ipnListenerUrl Url Paypal will call in order to confirm payment
* @param $buttonSource
*/
public function __construct(
PaypalApiCredentials $credentials,
$amount,
$currencyId,
$payerId,
$paymentAction,
$token,
$ipnListenerUrl,
$buttonSource = null
) {
$this->operationName = 'DoExpressCheckoutPayment';
$this->token = $token;
$this->amount = $amount;
$this->payerId = $payerId;
$this->credentials = $credentials;
$this->currencyId = $currencyId;
$this->paymentAction = $paymentAction;
$this->ipnListenerUrl = $ipnListenerUrl;
$this->buttonSource = $buttonSource;
}
/**
* {@inheritdoc}
*/
public function getRequest()
{
$request = parent::getRequest();
$request .= '&TOKEN=' . $this->token;
$request .= '&PAYERID=' . $this->payerId;
$request .= '&PAYMENTREQUEST_0_AMT=' . $this->amount;
$request .= '&PAYMENTREQUEST_0_CURRENCYCODE=' . $this->currencyId;
$request .= '&PAYMENTREQUEST_0_PAYMENTACTION=' . $this->paymentAction;
if (null !== $this->buttonSource) {
$request .='&BUTTONSOURCE=' . $this->buttonSource;
}
return $request;
}
}

View File

@@ -0,0 +1,60 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program 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; either version 3 of the License */
/* */
/* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Paypal\Classes\NVP\Operations;
use Paypal\Classes\API\PaypalApiCredentials;
/**
* Class GetExpressCheckoutDetails
* Manage NVP GetExpressCheckoutDetails Operation
*/
class PaypalNvpOperationsGetExpressCheckoutDetails extends PaypalNvpOperationsBase
{
/** @var string SetExpressCheckout API Token */
protected $token = null;
/**
* Constructor
*
* @param PaypalApiCredentials $credentials API Credentials (3T)
* @param string $token Token from SetExpressCheckout API
*/
public function __construct(PaypalApiCredentials $credentials, $token)
{
$this->operationName = 'GetExpressCheckoutDetails';
$this->credentials = $credentials;
$this->token = $token;
}
/**
* {@inheritdoc }
*/
public function getRequest()
{
$request = parent::getRequest();
$request .= '&TOKEN=' . $this->token;
return $request;
}
}

View File

@@ -0,0 +1,163 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program 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; either version 3 of the License */
/* */
/* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Paypal\Classes\NVP\Operations;
use Paypal\Classes\API\PaypalApiCredentials;
use Paypal\Classes\API\PaypalApiManager;
/**
* Class PaypalNvpOperationsSetExpressCheckout
* Manage NVP SetExpressCheckout Operation
*/
class PaypalNvpOperationsSetExpressCheckout extends PaypalNvpOperationsBase
{
/** @var string Transaction amount
* Must be specified as 2000.00 or 2,000.00.
* The specified amount cannot exceed USD $10,000.00, regardless of the currency used.
*/
protected $amount = null;
/** @var string Currency id ex: EUR */
protected $currencyId = null;
/** @var string URL when operation is successful */
protected $returnUrl = null;
/** @var string URL when operation is cancelled */
protected $cancelUrl = null;
/** @var string allowing the shortcut transaction */
protected $billingAgreement = null;
/** @var bool If Paypal has to use Thelia Customer Address */
protected $isPaypalAddressOverrided = false;
/** @var string Delivery Address */
protected $name = null;
/** @var string Delivery Address */
protected $street = null;
/** @var string Delivery Address */
protected $street2 = null;
/** @var string Delivery Address */
protected $city = null;
/** @var string Delivery Address */
protected $state = null;
/** @var string Delivery Address */
protected $zip = null;
/** @var string Delivery Address */
protected $countryCode = null;
/**
* Constructor
*
* @param PaypalApiCredentials $credentials API Credentials (3T)
* @param string $amount Transaction amount (<USD $10,000.00)
* @param string $currencyId Currency id ex: EUR
* @param string $returnUrl URL when operation is successful
* @param string $cancelUrl URL when operation is cancelled
* @param int $billingAgreement Billing agreement allowing reference transaction
* @param array $payload Operation extra args
*/
public function __construct(
PaypalApiCredentials $credentials,
$amount,
$currencyId,
$returnUrl,
$cancelUrl,
$billingAgreement = 0,
array $payload = null
) {
$this->operationName = 'SetExpressCheckout';
$this->credentials = $credentials;
$this->amount = $amount;
$this->cancelUrl = $cancelUrl;
$this->currencyId = $currencyId;
$this->returnUrl = $returnUrl;
$this->billingAgreement = $billingAgreement;
$this->payload = $payload;
}
/**
* Set customer delivery address
*
* @param string $name Name
* @param string $street Street
* @param string $street2 Street 2
* @param string $city City
* @param string $state State
* @param string $zip Zip
* @param string $countryCode CountryCode FR|US|UK
*
* @return $this
*/
public function setCustomerDeliveryAddress($name, $street, $street2, $city, $state, $zip, $countryCode)
{
$this->isPaypalAddressOverrided = true;
$this->name = $name;
$this->street = $street;
$this->street2 = $street2;
$this->city = $city;
$this->state = $state;
$this->zip = $zip;
$this->countryCode = $countryCode;
return $this;
}
/**
* {@inheritdoc }
*/
public function getRequest()
{
$request = parent::getRequest();
$request .= '&PAYMENTREQUEST_0_AMT=' . urlencode(PaypalApiManager::convertFloatToNvpFormat($this->amount));
$request .= '&PAYMENTREQUEST_0_CURRENCYCODE=' . urlencode($this->currencyId);
$request .= '&RETURNURL=' . urlencode($this->returnUrl);
$request .= '&CANCELURL=' . urlencode($this->cancelUrl);
if ($this->isPaypalAddressOverrided) {
$request .= '&ADDROVERRIDE=1';
$request .= '&PAYMENTREQUEST_0_SHIPTONAME=' . urlencode($this->name);
$request .= '&PAYMENTREQUEST_0_SHIPTOSTREET=' . urlencode($this->street);
$request .= '&PAYMENTREQUEST_0_SHIPTOSTREET2=' . urlencode($this->street2);
$request .= '&PAYMENTREQUEST_0_SHIPTOCITY=' . urlencode($this->city);
$request .= '&PAYMENTREQUEST_0_SHIPTOSTATE=' . urlencode($this->state);
$request .= '&PAYMENTREQUEST_0_SHIPTOZIP=' . urlencode($this->zip);
$request .= '&PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=' . urlencode($this->countryCode);
}
if ($this->billingAgreement != 0) {
$request .= '&L_BILLINGTYPE0=MerchantInitiatedBillingSingleAgreement';
}
if (!empty($this->payload)) {
$request .= '&' . PaypalApiManager::arrayToNvp($this->payload);
}
return $request;
}
}

View File

@@ -0,0 +1,92 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program 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; either version 3 of the License */
/* */
/* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Paypal\Classes\NVP;
use Paypal\Classes\API\PaypalApiManager;
use Paypal\Classes\NVP\Operations\PaypalNvpOperationInterface;
/**
* Class PaypalNvpMessageSender
*
* Send NVP requests via Curl
*
* Example for the API SetExpressCheckout call on the SandBox:
* $paypal = new Paypal();
* $nvpSetExpressCheckout = new PaypalNvpOperationsSetExpressCheckout(
* new PaypalApiCredentials(new PayPalVariableRepository($paypal->link)),
* $amount,
* $currencyID,
* $return_url,
* $cancel_url,
* );
* $nvpMessageSender = new PaypalNvpMessageSender($nvpSetExpressCheckout, true);
* $response = $nvpMessageSender->send();
*/
class PaypalNvpMessageSender
{
/** @var string message to send */
protected $message = null;
/** @var bool if sandbox mode is enabled */
protected $isSandbox = true;
/**
* Constructor
*
* @param PaypalNvpOperationInterface $nvpMessage NVP message to send
* @param bool $isSandbox if sandbox mode enabled
*/
public function __construct(PaypalNvpOperationInterface $nvpMessage, $isSandbox = true)
{
$this->isSandbox = $isSandbox;
$this->message = $nvpMessage->getRequest();
}
/**
* Send request via Curl
*
* @return string APÏ response
*/
public function send()
{
$paypalApiManager = new PaypalApiManager();
$url = $paypalApiManager->getApiUrl();
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->message);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
return $response;
}
}