You are here

public function PayPalPaymentNVPAPIPaymentMethodControllerBase::NVPAPIRequest in PayPal for Payment 7

Executes an API request.

Parameters

array $nvp_request: NVP variables to POST.

Payment $payment:

Return value

array|false The NVP response data or FALSE in case of failure.

3 calls to PayPalPaymentNVPAPIPaymentMethodControllerBase::NVPAPIRequest()
PayPalPaymentECPaymentMethodController::doExpressCheckoutPayment in paypal_payment_ec/includes/PayPalPaymentECPaymentMethodController.inc
Executes a checkout.
PayPalPaymentECPaymentMethodController::getExpressCheckoutDetails in paypal_payment_ec/includes/PayPalPaymentECPaymentMethodController.inc
Gets checkout information.
PayPalPaymentECPaymentMethodController::setExpressCheckout in paypal_payment_ec/includes/PayPalPaymentECPaymentMethodController.inc
Sets up a PayPal payment.

File

paypal_payment/includes/PayPalPaymentNVPAPIPaymentMethodControllerBase.inc, line 101

Class

PayPalPaymentNVPAPIPaymentMethodControllerBase
A base class for payment method controllers that talk to PayPal's NVP API.

Code

public function NVPAPIRequest(array $nvp_request, Payment $payment) {
  $nvp_request = array(
    'USER' => $payment->method->controller_data['username'],
    'PWD' => $payment->method->controller_data['password'],
    'SIGNATURE' => $payment->method->controller_data['signature'],
    'VERSION' => self::NVP_API_PAYPAL_VERSION,
  ) + $nvp_request;
  $post_data = array();
  foreach ($nvp_request as $name => $value) {
    $post_data[] = $name . '=' . urlencode($value);
  }
  $post_data = implode('&', $post_data);
  $response = chr_curl_http_request($this
    ->NVPAPIServerURL($payment->method->controller_data['server']), array(
    'method' => 'POST',
    'data' => $post_data,
    'curl_opts' => [
      CURLOPT_SSL_VERIFYPEER => TRUE,
      CURLOPT_SSL_VERIFYHOST => 2,
    ],
  ));
  if (isset($response->error)) {
    watchdog('paypal_payment_ec', 'An API request failed with error @code: %error.', array(
      '@code' => $response->code,
      '%error' => $response->error,
    ), WATCHDOG_ERROR);
    return FALSE;
  }
  else {
    $nvp_response = $this
      ->NVPAPIParseResponse($response->data);
    if ($nvp_response && isset($nvp_response['ACK']) && in_array($nvp_response['ACK'], array(
      'Success',
      'SuccessWithWarning',
    ))) {
      return $nvp_response;
    }
  }
  return FALSE;
}