public function getExpressCheckoutDetails($token)
{
$paypalTransaction = PaypalTransactionQuery::create()->findOneByToken($token);
if (!$paypalTransaction) {
\App::abort('Fatal Error');
}
$payment = $paypalTransaction->getPayment();
$getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($token);
$getExpressCheckoutRequest = new GetExpressCheckoutDetailsReq();
$getExpressCheckoutRequest->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
try {
$getExpressCheckoutResponse = $this->payPalApi->GetExpressCheckoutDetails($getExpressCheckoutRequest);
} catch (PPConnectionException $e) {
$paymentError = new PaymentError('Error Connecting to PayPal.', $e);
return $this->paymentBus->getFailedHandler($payment, $paymentError)->redirect();
}
if ($getExpressCheckoutResponse->Ack != 'Success') {
$paymentError = new PaymentError('Error Connecting to PayPal.');
return $this->paymentBus->getFailedHandler($payment, $paymentError)->redirect();
}
try {
$payPalFinalResponse = $this->doExpressCheckout($getExpressCheckoutResponse->GetExpressCheckoutDetailsResponseDetails->PayerInfo->PayerID, $getExpressCheckoutResponse->GetExpressCheckoutDetailsResponseDetails->Token, $getExpressCheckoutResponse->GetExpressCheckoutDetailsResponseDetails->PaymentDetails[0]->OrderTotal);
} catch (PPConnectionException $e) {
$paymentError = new PaymentError('Error Connecting to PayPal.', $e);
return $this->paymentBus->getFailedHandler($payment, $paymentError)->redirect();
}
if ($payPalFinalResponse->Ack != "Success") {
$this->logPayPalErrors($payment, $payPalFinalResponse);
$paymentError = new PaymentError('PayPal transaction failed.');
return $this->paymentBus->getFailedHandler($payment, $paymentError)->redirect();
}
$paymentStatus = $payPalFinalResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->PaymentStatus;
if ($paymentStatus != "Completed") {
$paymentError = new PaymentError('PayPal transaction pending');
return $this->paymentBus->getPendingHandler($payment, $paymentError)->redirect();
}
$paypalTransaction->setStatus($paymentStatus);
$paypalTransaction->save();
return $this->paymentBus->getCompletedHandler($payment)->redirect();
}