I want to implement an offsite payment method and everything is going well except the fact that I can't find how to redirect the user to the offsite payment gateway after submitting the cart checkout review
When the user submits the checkout review, the orderSubmit
function is called. Inside this function I create the array with all the parameters required in the request, but I don't know how to send this request
public function orderSubmit(OrderInterface $order) {
$fields = array(
'version' => $this->configuration['version'],
'TPE' => $this->configuration['tpe'],
'date' => date('d/m/Y:H:i:s', time()),
'montant' => round($order->getTotal(), 2).\Drupal::state()->get('uc_currency_code', 'USD'),
'reference' => $order->id(),
'texte-libre' => md5(uniqid(rand(), TRUE)),
'mail' => $order->getEmail(),
'lgue' => 'FR',
'societe' => $this->configuration['company'],
'url_retour' => Url::fromRoute('uc_cmic.cancel', array('absolute' => TRUE)),
'url_retour_ok' => Url::fromRoute('uc_cmic.success', array('absolute' => TRUE)),
'url_retour_err' => Url::fromRoute('uc_cmic.return', array('absolute' => TRUE)),
'MAC' => "",
'options' => ""
);
$fields = uc_cmcic_complete_request($this->configuration['security_key'], $fields); // This function fills the 'MAC' key by using the security key
$host = UC_CMCIC_URL_CM_TEST;
//TODO send the request and redirect the user to the offsite payment gateway here
}
What I tried to do and didn't work :
$response = \Drupal::httpClient()->request('POST', $host, [
'form_params' => $fields,
]);
I tried some other variations of this too (like returning the $response
after), which didn't work either
Question : What can I do to redirect the user to the offsite payment gateway while sending POST data in the request ?