x3llo
Epic Member
- Joined
- Jul 12, 2014
- Messages
- 347
- Reaction score
- 100
- Points
- 3,285
hey guys wondering if there are any developers here that can help me?
I'm currently stuck with a problem, i have an API and i need to post data to a payment gateway but they only have PHP examples and i'm struggling to convert it to .net core.. are there any developers that can help solve this for me?
i have all the needed data i just dont know how to create the post request within .net core my code so far =
StringBuilder builder = new StringBuilder();
builder.Append(@"<? xml version = ""1.0"" encoding = ""UTF-8"" ?>");
builder.Append("\n");
builder.Append("<Auth>");
builder.Append("\n");
builder.Append("<BatchReference>" + "Ref1" + "</BatchReference>");
builder.Append("\n");
builder.Append("<NotificationUrl>" + "mywebsite.com - mywebsite Resources and Information." + "</NotificationUrl>");
builder.Append("\n");
builder.Append("<BatchData>");
builder.Append("<BatchLine>" + Transactions[0].TRANSACTION_TYPE + ", " + Transactions[0].REFERENCE + ", " + "NetrecTest" + ", " + Transactions[0].VAUILT_ID + ", " + Transactions[0].BUDGET_PERIOD + ", " + Transactions[0].AMOUNT + "</BatchLine>");
builder.Append("\n");
builder.Append("</BatchData>");
builder.Append("\n");
builder.Append("</Auth>");
var content = new StringContent(builder.ToString(), Encoding.UTF8, "application/xml");
// this is required it gets the correct paygateId stored in the databse
string paygateId = _context.PaygateInfos.Select(s => s.Paygate_Id).FirstOrDefault();
// this is required it creates the authorisation header for
var byteArray = Encoding.ASCII.GetBytes(paygateId + ":" + "test");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
var response = await client.PostAsync("https://secure.paygate.co.za/paybatch/1.2/process.trans", content);
var responseContent = await response.Content.ReadAsStringAsync();
var results = Dictionary.ToDictionary(responseContent);
how the request is suppose to look =
<Auth>
<BatchReference>batch_reference</BatchReference>
<NotificationUrl>mywebsite.com - mywebsite Resources and Information.</NotificationUrl>
<BatchData>
(BatchLine)
</BatchData>
</Auth>
the php code is =
<?php
$batchReference = 'AuthBatch201800101';
$notificationUrl = 'http://yourserver.co.za/notifylocation/';
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
try {
//use SimpleXmlElement for better control of children
$xml = new SimpleXMLElement('<Auth />');
$xml->addChild('BatchReference', $batchReference);
$xml->addChild('NotificationUrl', $notificationUrl);
$batchData = $xml->addChild('BatchData');
$batchData->addChild('BatchLine', 'A, test1, PayGate Test, 18566ddc-b13b-4c9f-9e88-9a2f9a9dd64a, 00, 100');
//use DomDocument to remove XML headers
$dom = new DOMDocument();
$dom->loadXML($xml->asXML());
$soap = $dom->saveXML($dom->documentElement);
//Remove Auth tag because we pass it in the __soapCall
$childrenOnly = str_replace(['<Auth>', '</Auth>'], '', $soap);
} catch(Exception $e){
error_log($e->getMessage());
}
// array containing login and password for basic http auth, along with trace option for debugging
$options = array(
'login' => '10011072130', //Your PayGate ID
'password' => 'test', //Your encryption key (set in the PayXML configuration section of the PayGate Back Office)
'trace' => 1
);
try {
$soapClient = new SoapClient("https://secure.paygate.co.za/PayBatch/1.2/PayBatch.wsdl", $options); //point to WSDL and set options
$soapClient->__setLocation("https://secure.paygate.co.za/PayBatch/1.2/process.trans"); //actual location data is processed
$result = $soapClient->__soapCall('Auth', array(
new SoapVar($childrenOnly, XSD_ANYXML)
));
// $result is an object of AuthResponse
var_dump($result);
} catch(SoapFault $sf){
var_dump($sf->getMessage());
} catch(Exception $e){
error_log($e->getMessage());
}
the reference documentation = DPO PayGate Documentation
its the PayBatch section..
Any help will be much appreciated!!!
Thanks.
I'm currently stuck with a problem, i have an API and i need to post data to a payment gateway but they only have PHP examples and i'm struggling to convert it to .net core.. are there any developers that can help solve this for me?
i have all the needed data i just dont know how to create the post request within .net core my code so far =
StringBuilder builder = new StringBuilder();
builder.Append(@"<? xml version = ""1.0"" encoding = ""UTF-8"" ?>");
builder.Append("\n");
builder.Append("<Auth>");
builder.Append("\n");
builder.Append("<BatchReference>" + "Ref1" + "</BatchReference>");
builder.Append("\n");
builder.Append("<NotificationUrl>" + "mywebsite.com - mywebsite Resources and Information." + "</NotificationUrl>");
builder.Append("\n");
builder.Append("<BatchData>");
builder.Append("<BatchLine>" + Transactions[0].TRANSACTION_TYPE + ", " + Transactions[0].REFERENCE + ", " + "NetrecTest" + ", " + Transactions[0].VAUILT_ID + ", " + Transactions[0].BUDGET_PERIOD + ", " + Transactions[0].AMOUNT + "</BatchLine>");
builder.Append("\n");
builder.Append("</BatchData>");
builder.Append("\n");
builder.Append("</Auth>");
var content = new StringContent(builder.ToString(), Encoding.UTF8, "application/xml");
// this is required it gets the correct paygateId stored in the databse
string paygateId = _context.PaygateInfos.Select(s => s.Paygate_Id).FirstOrDefault();
// this is required it creates the authorisation header for
var byteArray = Encoding.ASCII.GetBytes(paygateId + ":" + "test");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
var response = await client.PostAsync("https://secure.paygate.co.za/paybatch/1.2/process.trans", content);
var responseContent = await response.Content.ReadAsStringAsync();
var results = Dictionary.ToDictionary(responseContent);
how the request is suppose to look =
<Auth>
<BatchReference>batch_reference</BatchReference>
<NotificationUrl>mywebsite.com - mywebsite Resources and Information.</NotificationUrl>
<BatchData>
(BatchLine)
</BatchData>
</Auth>
the php code is =
<?php
$batchReference = 'AuthBatch201800101';
$notificationUrl = 'http://yourserver.co.za/notifylocation/';
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
try {
//use SimpleXmlElement for better control of children
$xml = new SimpleXMLElement('<Auth />');
$xml->addChild('BatchReference', $batchReference);
$xml->addChild('NotificationUrl', $notificationUrl);
$batchData = $xml->addChild('BatchData');
$batchData->addChild('BatchLine', 'A, test1, PayGate Test, 18566ddc-b13b-4c9f-9e88-9a2f9a9dd64a, 00, 100');
//use DomDocument to remove XML headers
$dom = new DOMDocument();
$dom->loadXML($xml->asXML());
$soap = $dom->saveXML($dom->documentElement);
//Remove Auth tag because we pass it in the __soapCall
$childrenOnly = str_replace(['<Auth>', '</Auth>'], '', $soap);
} catch(Exception $e){
error_log($e->getMessage());
}
// array containing login and password for basic http auth, along with trace option for debugging
$options = array(
'login' => '10011072130', //Your PayGate ID
'password' => 'test', //Your encryption key (set in the PayXML configuration section of the PayGate Back Office)
'trace' => 1
);
try {
$soapClient = new SoapClient("https://secure.paygate.co.za/PayBatch/1.2/PayBatch.wsdl", $options); //point to WSDL and set options
$soapClient->__setLocation("https://secure.paygate.co.za/PayBatch/1.2/process.trans"); //actual location data is processed
$result = $soapClient->__soapCall('Auth', array(
new SoapVar($childrenOnly, XSD_ANYXML)
));
// $result is an object of AuthResponse
var_dump($result);
} catch(SoapFault $sf){
var_dump($sf->getMessage());
} catch(Exception $e){
error_log($e->getMessage());
}
the reference documentation = DPO PayGate Documentation
its the PayBatch section..
Any help will be much appreciated!!!
Thanks.