<?xml version="1.0"?><!-- generator="bbPress" -->

<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
>

<channel>
<title>MachForm Community Forums Topic: Add payment method through php</title>
<link>https://www.machform.com/forums/</link>
<description>MachForm Community Forums Topic: Add payment method through php</description>
<language>en</language>
<pubDate>Mon, 04 May 2026 01:07:28 +0000</pubDate>

<item>
<title>alainalexanderhervs on "Add payment method through php"</title>
<link>https://www.machform.com/forums/topic/add-payment-method-through-php#post-22132</link>
<pubDate>Tue, 04 Nov 2014 02:00:20 +0000</pubDate>
<dc:creator>alainalexanderhervs</dc:creator>
<guid isPermaLink="false">22132@https://www.machform.com/forums/</guid>
<description>&#60;p&#62;Hi redemptor,&#60;/p&#62;
&#60;p&#62;Have you got some reply about this? We would like to do that :) Could you help us?
&#60;/p&#62;</description>
</item>
<item>
<title>redemptor on "Add payment method through php"</title>
<link>https://www.machform.com/forums/topic/add-payment-method-through-php#post-21068</link>
<pubDate>Sun, 18 May 2014 21:07:13 +0000</pubDate>
<dc:creator>redemptor</dc:creator>
<guid isPermaLink="false">21068@https://www.machform.com/forums/</guid>
<description>&#60;p&#62;Hi guys,&#60;/p&#62;
&#60;p&#62;I'm portuguese and here in Portugal we have a payment method that is a generated reference to intantly pay anything without need of upload any receipt.&#60;/p&#62;
&#60;p&#62;There are a company that offers this service and gives me the PHP code needed to send the automatic reference.&#60;/p&#62;
&#60;p&#62;What I'm looking for is the files where I should include that PHP and where to add the info in the confirmation e-mail. I must identify the entry ID and the ammount to pay and define them as the variables.&#60;br /&#62;
The code has two functions:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;function format_number($number)
	{
		$verifySepDecimal = number_format(99,2);

		$valorTmp = $number;

		$sepDecimal = substr($verifySepDecimal, 2, 1);

		$hasSepDecimal = True;

		$i=(strlen($valorTmp)-1);

		for($i;$i!=0;$i-=1)
		{
			if(substr($valorTmp,$i,1)==&#38;quot;.&#38;quot; &#124;&#124; substr($valorTmp,$i,1)==&#38;quot;,&#38;quot;){
				$hasSepDecimal = True;
				$valorTmp = trim(substr($valorTmp,0,$i)).&#38;quot;@&#38;quot;.trim(substr($valorTmp,1+$i));
				break;
			}
		}

		if($hasSepDecimal!=True){
			$valorTmp=number_format($valorTmp,2);

			$i=(strlen($valorTmp)-1);

			for($i;$i!=1;$i--)
			{
				if(substr($valorTmp,$i,1)==&#38;quot;.&#38;quot; &#124;&#124; substr($valorTmp,$i,1)==&#38;quot;,&#38;quot;){
					$hasSepDecimal = True;
					$valorTmp = trim(substr($valorTmp,0,$i)).&#38;quot;@&#38;quot;.trim(substr($valorTmp,1+$i));
					break;
				}
			}
		}

		for($i=1;$i!=(strlen($valorTmp)-1);$i++)
		{
			if(substr($valorTmp,$i,1)==&#38;quot;.&#38;quot; &#124;&#124; substr($valorTmp,$i,1)==&#38;quot;,&#38;quot; &#124;&#124; substr($valorTmp,$i,1)==&#38;quot; &#38;quot;){
				$valorTmp = trim(substr($valorTmp,0,$i)).trim(substr($valorTmp,1+$i));
				break;
			}
		}

		if (strlen(strstr($valorTmp,&#38;#39;@&#38;#39;))&#38;gt;0){
			$valorTmp = trim(substr($valorTmp,0,strpos($valorTmp,&#38;#39;@&#38;#39;))).trim($sepDecimal).trim(substr($valorTmp,strpos($valorTmp,&#38;#39;@&#38;#39;)+1));
		}

		return $valorTmp;
	}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;//and//&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;function GenerateMbRef($ent_id, $subent_id, $order_id, $order_value)
	{
		$chk_val = 0;

		$order_id =&#38;quot;0000&#38;quot;.$order_id;

		if(strlen($ent_id)&#38;lt;5)
		{
			echo &#38;quot;Lamentamos mas tem de indicar uma entidade válida&#38;quot;;
			return;
		}else if(strlen($ent_id)&#38;gt;5){
			echo &#38;quot;Lamentamos mas tem de indicar uma entidade válida&#38;quot;;
			return;
		}if(strlen($subent_id)==0){
			echo &#38;quot;Lamentamos mas tem de indicar uma subentidade válida&#38;quot;;
			return;
		}

		$order_value= sprintf(&#38;quot;%01.2f&#38;quot;, $order_value);

		$order_value =  format_number($order_value);

		if ($order_value &#38;lt; 1){
			echo &#38;quot;Lamentamos mas é impossível gerar uma referência MB para valores inferiores a 1 Euro&#38;quot;;
			return;
		}
		if ($order_value &#38;gt;= 1000000){
			echo &#38;quot;&#38;lt;b&#38;gt;AVISO:&#38;lt;/b&#38;gt; Pagamento fraccionado por exceder o valor limite para pagamentos no sistema Multibanco&#38;lt;br&#38;gt;&#38;quot;;
		}

		if(strlen($subent_id)==1){
			//Apenas sao considerados os 6 caracteres mais a direita do order_id
			$order_id = substr($order_id, (strlen($order_id) - 6), strlen($order_id));
			$chk_str = sprintf(&#38;#39;%05u%01u%06u%08u&#38;#39;, $ent_id, $subent_id, $order_id, round($order_value*100));
		}else if(strlen($subent_id)==2){
			//Apenas sao considerados os 5 caracteres mais a direita do order_id
			$order_id = substr($order_id, (strlen($order_id) - 5), strlen($order_id));
			$chk_str = sprintf(&#38;#39;%05u%02u%05u%08u&#38;#39;, $ent_id, $subent_id, $order_id, round($order_value*100));
		}else {
			//Apenas sao considerados os 4 caracteres mais a direita do order_id
			$order_id = substr($order_id, (strlen($order_id) - 4), strlen($order_id));
			$chk_str = sprintf(&#38;#39;%05u%03u%04u%08u&#38;#39;, $ent_id, $subent_id, $order_id, round($order_value*100));
		}

		//cálculo dos check digits

		$chk_array = array(3, 30, 9, 90, 27, 76, 81, 34, 49, 5, 50, 15, 53, 45, 62, 38, 89, 17, 73, 51);

		for ($i = 0; $i &#38;lt; 20; $i++)
		{
			$chk_int = substr($chk_str, 19-$i, 1);
			$chk_val += ($chk_int%10)*$chk_array[$i];
		}

		$chk_val %= 97;

		$chk_digits = sprintf(&#38;#39;%02u&#38;#39;, 98-$chk_val);

		echo &#38;quot;&#38;lt;pre&#38;gt;&#38;quot;;
		echo &#38;quot;\n\n&#38;lt;b&#38;gt;Entidade:    &#38;lt;/b&#38;gt;&#38;quot;.$ent_id;
		echo &#38;quot;\n\n&#38;lt;b&#38;gt;Referência:  &#38;lt;/b&#38;gt;&#38;quot;.substr($chk_str, 5, 3).&#38;quot; &#38;quot;.substr($chk_str, 8, 3).&#38;quot; &#38;quot;.substr($chk_str, 11, 1).$chk_digits;
		echo &#38;quot;\n\n&#38;lt;b&#38;gt;Valor: &#38;amp;euro;&#38;amp;nbsp;&#38;lt;/b&#38;gt;&#38;quot;.number_format($order_value, 2,&#38;#39;,&#38;#39;, &#38;#39; &#38;#39;);
		echo &#38;quot;&#38;lt;/pre&#38;gt;&#38;quot;;
	}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;$ent_id and $subent_id are given to me by the company. $order_id and $order_value should be entry_id and ammount. and this last echo's should be sent in the confirmation e-mail. &#60;/p&#62;
&#60;p&#62;I'm trully lost in this. sorry any english mistake.&#60;/p&#62;
&#60;p&#62;best regards.
&#60;/p&#62;</description>
</item>

</channel>
</rss>
