1

I hope you guys can help me out. When we make an invoice I would like to include a link that enables our customers to pay their invoice online. We have a merchant account at a Danish gateway called ePay (a part of Bambora).

Our billing system can't build the URL I need, so I figured that with a PHP script on our webserver I could request the data, orderid and amount, and then add the rest via the php script. However I cannot get it to work.

Also a md5 checksum from our md5 key should be sent along with the data ie. "secret123'. So it should be submittet as a form.

Is it possible to build a form and automatically submit it via PHP? - So it works just like a redirect.

I followed user5214530 advice, but the page returns a 500 error? And I can't spot it?

<?php
$hash = 'secrethash';
$accepturl = 'https://www.asd.dk/dinbetaling.html#accept';
$cancelurl = 'https://www.asd.dk/dinbetaling.html#cancelurl';
$callbackurl = 'https://www.asd.dk/dinbetaling.html#callbackurl';
$mnumber = '123456';
$wid = '3';
 
$parameters = array
  (
   'merchantnumber' => $mnumber,
   'windowid' => $wid,
   'amount' => get_option('total_price'),
   'currency' => get_option('currency'),
   'windowstate' => 3,
   'orderid' => get_option('orderid'),
   'accepturl' => $accepturl,
   'cancelurl' => $cancelurl,
   'callbackurl' => $callback
  );
?>
<html>
<head>
<title>Epay payment redirect</title>
</head>
<!--<body onload="autosubmit()">-->

<form method="post" action="script.php" name="betaling" id="betaling">
 <input type="hidden" name="merchantnumber" value="<?php echo $merchantnumber; ?>">
 <input type="hidden" name="windowid" value="<?php echo $windowid; ?>">
 <input type="hidden" name="amount" value="<?php echo $amount; ?>">
 <input type="hidden" name="currency" value="<?php echo $currency; ?>">
 <input type="hidden" name="windowstate" value="<?php echo $windowstate; ?>">
 <input type="hidden" name="orderid" value="<?php echo $orderid; ?>">
 <input type="hidden" name="accepturl" value="<?php echo $accepturl; ?>">
 <input type="hidden" name="cancelurl" value="<?php echo $cancelurl; ?>">
 <input type="hidden" name="callbackurl" value="<?php echo $callbackurl; ?>">
 <input type="hidden" name="hash" value="<?php md5(implode("", array_values($parameters)) . $hash); ?>">
</form>
<!--<script> 
function autosubmit()
    {
        document.betaling.submit()
    }</script>
-->
</body>
</html>

2 Answers2

0

You can do this via. Curl

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://yourControolerUrl"); your controller or api to handle this request at backend
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);

$data = array(  // data in associative array
    'foo' => 'foo foo foo',
    'bar' => 'bar bar bar',
    'baz' => 'baz baz baz'
);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
Dinesh Ghule
  • 3,423
  • 4
  • 19
  • 39
0

You can submit your form automatically with JS:

<html>
<head>
<script>
    function autosubmit()
    {
        document.form1.submit()
    }
</script>
</head>

<body onload="autosubmit()">
    <form action="script.php" method="POST" id="form1" name="form1">
        <input type="text" value="" />
    </form>
</body>
</html> 

But, you can also generate request and send it with CURL in PHP directly (see few possibilities out here How do I send a POST request with PHP?):

user5214530
  • 467
  • 5
  • 11