src/CoreBundle/Ecommerce/Payment/Paypal/PaypalExecutePaymentTrait.php line 26

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Ecommerce\Payment\Paypal;
  3. use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
  4. use Snk\PaypalApiWrapper\ExecutePayment;
  5. trait PaypalExecutePaymentTrait
  6. {
  7.     /**
  8.      * Call PayPal API Wrapper to execute the payment.
  9.      *
  10.      * If the payment status is successful manually commit the Order (because we're not using Pimcore's PayPal
  11.      * implementation, instead we're using our own) and set the Order ID so the CheckoutController can handle
  12.      * inside it's completed action.
  13.      *
  14.      * @param string $paymentID
  15.      * @param string $payerID
  16.      * @return array
  17.      * @throws \Exception
  18.      */
  19.     public function executePayment($paymentID$payerID)
  20.     {
  21.         $cart $this->getCart();
  22.         $checkoutManager Factory::getInstance()->getCheckoutManager($cart);
  23.         $checkoutManager->startOrderPayment();
  24.         $order $checkoutManager->getOrder();
  25.     $executePayment = new ExecutePayment($this->auth());
  26.         $response $executePayment->execute($paymentID$payerID);
  27.         if ($response['status'] == 1) {
  28.             $orderCompleteService $this->get('core.payment_save_order_send_email');
  29.             $order $orderCompleteService->saveOrder($cart$response);
  30.             $orderCompleteService->updateStockOfProduct($order);
  31.             $url $this->generateUrl('shopHandlerCheckout', ['action' => 'completed']);
  32.             $response['successUrl'] = $url;
  33.         } elseif ($response['status'] == && $order->getOrderState() == $order::ORDER_STATE_PAYMENT_PENDING) {
  34.             // Payment will be cancelled, order state will be resetted and cart will we writable again
  35.             $checkoutManager->cancelStartedOrderPayment();
  36.         }
  37.         return $response;
  38.     }
  39. }