Saturday, 14 September 2013

Collect Form Data, insert in xml fields to post to Payment Gateway

Collect Form Data, insert in xml fields to post to Payment Gateway

I need to take payment information from a form and place it in XML and
then post it to the payment gateway server. I am rather a novice at best
and I am not sure of the easiest way to do this.
I have successfully been able to post to the payment gateway by manually
entering the info into the XML on a static php file, so I know the XML is
correct, the only real issue for me would be finding the easiest way to
take form data and place into the XML.
Below is a sample of the php file and the XML.
<?php
$TransactionId = intval( date(Yms). rand(1,9) . rand(0,9) . rand(0,9) .
rand(0,9) . rand(0,9). rand(0,9) );
$MerchantId="111111";
$TerminalId="111111";
$ApiPassword="111111";
$private_key="asdfasghgfdhggdfgs";
$ApiPassword_encrypt=hash('sha256',$ApiPassword);
$xmlReq='<?xml version="1.0" encoding="UTF-8" ?>
<TransactionRequest
xmlns="https://test.processing.com/securePayments/direct/v1/processor.php">
<Language>ENG</Language>
<Credentials>
<MerchantId>'.$MerchantId.'</MerchantId>
<TerminalId>'.$TerminalId.'</TerminalId>
<TerminalPassword>'.$ApiPassword_encrypt.'</TerminalPassword>
</Credentials>
<TransactionType>LP001</TransactionType>
<TransactionId>'.$TransactionId.'</TransactionId>
<ReturnUrl page="http://www.website.net/response.php">
<Param>
<Key>inv</Key>
<Value>'.$TransactionId.'</Value>
</Param>
</ReturnUrl>
<CurrencyCode>USD</CurrencyCode>
<TotalAmount>44450</TotalAmount>
<CardDetails>
<CardHolderName>John Smith</CardHolderName>
<CardNumber>4653111111111111</CardNumber>
<CardExpireMonth>01</CardExpireMonth>
<CardExpireYear>15</CardExpireYear>
<CardType>VI</CardType>
<CardSecurityCode>030</CardSecurityCode>
<CardIssuingBank>UNKNOWN</CardIssuingBank>
<CardIssueNumber></CardIssueNumber>
</CardDetails>
</TransactionRequest>';
$signature_key=trim($private_key.$ApiPassword.$TransactionId);
$signature=base64_encode(hash_hmac("sha256", trim($xmlReq),
$signature_key, True));
$encodedMessage=base64_encode($xmlReq);

No comments:

Post a Comment