public function Redirect::execute in PayPal for Payment 8
Same name and namespace in other branches
- 2.0.x src/Controller/Redirect.php \Drupal\paypal_payment\Controller\Redirect::execute()
PayPal is redirecting the visitor here after the payment process. At this point we don't know the status of the payment yet so we can only load the payment and give control back to the payment context.
Parameters
PaymentInterface $payment:
Return value
1 string reference to 'Redirect::execute'
File
- src/
Controller/ Redirect.php, line 75
Class
- Redirect
- Handles the "redirect" route.
Namespace
Drupal\paypal_payment\ControllerCode
public function execute(PaymentInterface $payment) : Response {
$paymentId = $this->request
->get('paymentId');
$payerID = $this->request
->get('PayerID');
/** @var PayPalBasic $payment_method */
$payment_method = $payment
->getPaymentMethod();
/** @var ApiContext $api_context */
$api_context = $payment_method
->getApiContext($payment_method::PAYPAL_CONTEXT_TYPE_REDIRECT);
$p = Payment::get($paymentId, $api_context);
$execution = new PaymentExecution();
$execution
->setPayerId($payerID);
try {
$p
->execute($execution, $api_context);
$payment_method
->doCapturePayment();
} catch (Exception $ex) {
// TODO: Error handling
}
return $this
->getResponse($payment);
}