This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Mohsin
Mohsin

This is very much similar to a problem I found on StackOverflow and I am looking for the OctoberCMS way of doing it. So, I have a form like…

<div id=“checkoutForm”>
  <form data-request=“onCheckout”>
    // Inputs to get name, address, etc.
  </form> 
</div>

Right now, the solution I came up with is that in the onCheckout function I return the same form with all hidden fields (and any additional fields the payment gateway needs) as shown in the stackoverflow question. I use this..

function onCheckout()
{
  $data = post();
  // Validation stuff goes here
  $data[‘checksum’] = calculateChecksum($data);
  return [
      '#checkoutForm' => $this->renderPartial('@checkout', ['data' => $data])
  ];
}

And in the partial checkout I use:

<form method="post" action="https://URL_TOPAYMENT_GATEWAY">
    <input type="hidden" name="MNT_ID" value="{{ data.id }}">
    <input type="hidden" name="MNT_TRANSACTION_ID" value="{{ data.txnid }}">
    <input type="hidden" name="MNT_CURRENCY_CODE" value="{{ data.currency }}">
    <input type="hidden" name="MNT_AMOUNT" value="{{ data.amount }}">
    <input type="submit" value="Confirm Payment">
</form>

I want to eliminate the last step and instead of returning a partial with hidden fields for the user to confirm, I want to redirect the user directly with the POST request to the external payment URL. I see that October’s Rain library has some network function for doing Post requests but how can I use that in the handler onCheckout so that the page redirects to the payment gateway with POST data?

I tried the solution on stackoverflow i.e. using Redirect::away('https://URL_TOPAYMENT_GATEWAY')->withInputs(post()); but as the person commented, it performs a GET request than POST so the payment gateway rejects the request and gives an error instead.

Last updated

1-1 of 1

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.