public function PayflowLink::getRedirectUrl in Commerce PayPal 8
Gets the redirect url.
Parameters
\Drupal\commerce_order\Entity\OrderInterface|null $order: (Optional) The order.
Return value
string The URL according selected 'mode' and 'redirect_method' settings.
Overrides PayflowLinkInterface::getRedirectUrl
1 call to PayflowLink::getRedirectUrl()
- PayflowLink::apiRequest in src/
Plugin/ Commerce/ PaymentGateway/ PayflowLink.php - Submits an API request to Payflow.
File
- src/
Plugin/ Commerce/ PaymentGateway/ PayflowLink.php, line 614
Class
- PayflowLink
- Provides the PayPal Payflow Link payment gateway.
Namespace
Drupal\commerce_paypal\Plugin\Commerce\PaymentGatewayCode
public function getRedirectUrl(OrderInterface $order = NULL) {
$configuration = $this
->getConfiguration();
$mode = $configuration['mode'];
$redirect_mode = $configuration['redirect_mode'];
$url = '';
switch ($mode) {
case 'test':
$url = 'https://pilot-payflowlink.paypal.com/';
break;
case 'live':
$url = 'https://payflowlink.paypal.com/';
break;
}
if ($redirect_mode === 'get' && !empty($order)) {
$commerce_payflow_data = $order
->getData('commerce_payflow');
if (empty($commerce_payflow_data['token']) || empty($commerce_payflow_data['tokenid'])) {
return '';
}
// Build a query array using information from the order object.
$query = [
'SECURETOKEN' => $commerce_payflow_data['token'],
'SECURETOKENID' => $commerce_payflow_data['tokenid'],
];
// Set the MODE parameter if the URL is for the test server.
if ($mode === 'test') {
$query['MODE'] = 'TEST';
}
// Grab the base URL of the appropriate API server.
$url = Url::fromUri($url, [
'query' => $query,
])
->toString();
}
return $url;
}