. */ /* */ /*************************************************************************************/ 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; } }