-1

I have been integrating a payment gateway in Cakephp. Below are the versions used:

  • Cakephp: 3.4.13

  • PHP: 5.6.15

Problem:

I need to submit a form using POST request to payment gateway website but some fields contains confidential data(merchant id etc) so I cannot show them in the form. Otherwise someone can read them using developer tools(inspecting element). Also I need to add some custom fields before submit the form.

So I would like to redirect the user to payment gateway website with required fields using POST request from the Controller's action.

I tried to find solution but couldn't succeeded. Found a similar question here but there is no answer. Is there any way to do the same in Cakephp 3.x?

Payment gateway form:

<?= $this->Form->create(false, ['url' => <URL>, 'id'=>'payForm']) ?>
<?= $this->Form->hidden('payment_notification_url', ['value'=> $this->Url->build('/payment/notify', true)]); ?>
<?= $this->Form->hidden('payment_redirect_url', ['value'=>$this->Url->build('/payment/getMoney', true)]); ?>
<?= $this->Form->hidden('merchant_id', ['value'=> <merchant_id>]); ?>
<?= $this->Form->hidden('reference', ['value'=> <reference>]); ?>
<?= $this->Form->hidden('email', ['value'=> <email>]); ?>
<?= $this->Form->hidden('fname', ['value'=> <first_name>]); ?>
<?= $this->Form->hidden('lname', ['value'=> <last_name>]); ?>
<?= $this->Form->hidden('address', ['value'=> <address>]); ?>
<?= $this->Form->hidden('town', ['value'=> <state>]); ?>
<?= $this->Form->hidden('country', ['value'=> <country>]); ?>
<?= $this->Form->hidden('postcode', ['value'=> <zipcode>]); ?>
<?= $this->Form->hidden('amount', ['class' => 'amount', 'value'=> <amount>]); ?>
<?= $this->Form->hidden('currency', ['value'=> 'US']); ?>

<?php echo $this->Form->end() ?>
piet.t
  • 11,718
  • 21
  • 43
  • 52
Sehdev
  • 5,486
  • 3
  • 11
  • 34
  • 1
    Not possible, neither in CakePHP nor plain PHP. Please read https://stackoverflow.com/a/5576700/7996420 for more info. – Szymon Sep 17 '18 at 13:45
  • 1
    Even if that _would_ be possible, a redirect is of course inspectable too. If you need to send secrets that must be hidden from the user agent, then you either cannot use the user agent to send them, or they must be encrypted. So if the API doesn't support encryption and it expects that user agents submit the data, then the data isn't confidential. – ndm Sep 17 '18 at 13:52

1 Answers1

0

Read the documentation this might help. You can submit a form to particular action then from there you can make http request using the below code.

For full documentation Http Client

use Cake\Http\Client;

$http = new Client();

// Simple get
$response = $http->get('http://example.com/test.html');

// Simple get with querystring
$response = $http->get('http://example.com/search', ['q' => 'widget']);

// Simple get with querystring & additional headers
$response = $http->get('http://example.com/search', ['q' => 'widget'], [
  'headers' => ['X-Requested-With' => 'XMLHttpRequest']
]);

To redirect to external url you can use this

$this->redirect('http://www.google.com');
Exterminator
  • 1,221
  • 7
  • 14