You are here

public function PayPalPaymentECPaymentMethodController::setExpressCheckout in PayPal for Payment 7

Sets up a PayPal payment.

Parameters

Payment $payment:

Return value

PayPalPaymentECAuthentication|false A PayPal checkout token or FALSE in case of failure.

1 call to PayPalPaymentECPaymentMethodController::setExpressCheckout()
PayPalPaymentECPaymentMethodController::execute in paypal_payment_ec/includes/PayPalPaymentECPaymentMethodController.inc
Execute a payment.

File

paypal_payment_ec/includes/PayPalPaymentECPaymentMethodController.inc, line 161

Class

PayPalPaymentECPaymentMethodController
A PayPal Express Checkout payment method.

Code

public function setExpressCheckout(Payment $payment) {
  global $user;
  $return_url = url('paypal_payment_ec/return', array(
    'absolute' => TRUE,
  ));
  $nvp_request = array(
    'METHOD' => 'SetExpressCheckout',
    'RETURNURL' => $return_url,
    'CANCELURL' => $return_url,
    'LOCALECODE' => strtoupper(variable_get('site_default_country', 'US')),
    'EMAIL' => !empty($user->mail) ? $user->mail : '',
  ) + $this
    ->paymentNVP($payment);
  $nvp_response = $this
    ->NVPAPIRequest($nvp_request, $payment);
  if (isset($nvp_response['TOKEN']) && isset($nvp_response['TIMESTAMP'])) {
    $created = DateTime::createFromFormat(DateTime::ISO8601, $nvp_response['TIMESTAMP'])
      ->getTimestamp();
    return new PayPalPaymentECAuthentication($nvp_response['TOKEN'], $created, $payment->pid);
  }
  return FALSE;
}