You are here

public function PayPalPaymentECPaymentMethodController::execute in PayPal for Payment 7

Execute a payment.

Note that payments may be executed even if their owner is not logged into the site. This means that if you need to do access control in your execute() method, you cannot use global $user.

Parameters

Payment $payment:

Return value

boolean Whether the payment was successfully executed or not.

Overrides PaymentMethodController::execute

File

paypal_payment_ec/includes/PayPalPaymentECPaymentMethodController.inc, line 82

Class

PayPalPaymentECPaymentMethodController
A PayPal Express Checkout payment method.

Code

public function execute(Payment $payment) {

  // Prepare the PayPal checkout token.
  $authentication = NULL;
  if ($payment->pid) {
    $authentication = $this
      ->loadAuthentication($payment->pid);
  }
  if (!$authentication) {
    entity_save('payment', $payment);
    $authentication = $this
      ->setExpressCheckout($payment);
    if ($authentication) {
      $this
        ->saveAuthentication($authentication);
    }
  }

  // Start checkout.
  if ($authentication) {
    $url = $this
      ->checkoutURL($payment->method->controller_data['server'], $authentication->token);
    if (!empty($payment->contextObj)) {

      // Support for payment_context.
      $payment->contextObj
        ->redirect($url);
    }
    else {
      drupal_goto($url);
    }
  }
  else {
    $payment
      ->setStatus(new PaymentStatusItem(PAYMENT_STATUS_FAILED));
  }
}