דוקומנטציה ו API

להורדת הדוקומנטציה - לחצו כאן
 
חלק זה מפרט את ממשק ה-API שנבנה לצורך הכנסת רשומות לטבלה במסך הדו"חות.
הקוד ב-C# , נכתב בפרויקט Winforms , ומכין חלק XML האחראי להגדרת פורמט עסקה.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

using System.IO;

using System.Net;

 

namespace anti_fraud_tester

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void CheckTransactionButton_Click(object sender, EventArgs e)

        {

            //Check transaction

 

            string xml = @"<?xml version=""1.0""?>

<Transaction xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">

  <TerminalName>0963169012</TerminalName>

  <ClientIPAddress>127.0.0.1</ClientIPAddress>

  <ServerIPAddress>127.0.0.1</ServerIPAddress>

  <CardNumber>4580458045804580</CardNumber>

  <ExpDate>1208</ExpDate>

  <Amount>100</Amount>

  <CardHolderID>029442449</CardHolderID>

  <Created></Created>

  <UserField01></UserField01>

  <UserField02></UserField02>

  <UserField03></UserField03>

  <UserField04></UserField04>

  <UserField05></UserField05>

  <UserField06></UserField06>

  <UserField07></UserField07>

  <UserField08></UserField08>

  <UserField09></UserField09>

  <UserField10></UserField10>

  <UserField11></UserField11>

  <UserField12></UserField12>

  <UserField13></UserField13>

  <UserField14></UserField14>

  <UserField15></UserField15>

  <UserField16></UserField16>

  <UserField17></UserField17>

  <UserField18></UserField18>

  <UserField19></UserField19>

  <UserField20></UserField20>

</Transaction>";

 

            byte[] xmlBytes = Encoding.UTF8.GetBytes(xml);

 

 

            HttpWebRequest request = WebRequest.Create("http://antifraud.mpage.co.il/api/transactions/check") as HttpWebRequest;

            request.Headers.Add("username", "tester");

            request.Headers.Add("password", "a123456");

            request.ContentLength = xmlBytes.Length;

            request.Method = "POST";

            request.ContentType = "text/xml";

 

            Stream dataStream = request.GetRequestStream();

            dataStream.Write(xmlBytes, 0, xmlBytes.Length);

            dataStream.Close();

            WebResponse response = request.GetResponse();

 

            Stream responseStream = response.GetResponseStream();

            List<byte> bytes = new List<byte>();

            int b;

            do

            {

                b = responseStream.ReadByte();

                bytes.Add((byte)b);

            } while (b > -1);

 

            responseStream.Close();

 

            response.Close();

 

            string responseXml = Encoding.UTF8.GetString(bytes.ToArray());

            //TODO: parse responseXml

 

        }

 

        private void InsertTransactionButton_Click(object sender, EventArgs e)

        {

            //Insert transaction

            string xml = @"<?xml version=""1.0""?>

<Transaction xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">

  <TerminalName>0963169012</TerminalName>

  <ClientIPAddress>127.0.0.1</ClientIPAddress>

  <ServerIPAddress>127.0.0.1</ServerIPAddress>

  <CardNumber>4580458045804580</CardNumber>

  <ExpDate>1208</ExpDate>

  <Amount>100</Amount>

  <Response>0</Response>

  <ActionID>1</ActionID>

  <ErrorMessage>Valid</ErrorMessage>

  <CardHolderID>029442449</CardHolderID>

  <UserField01></UserField01>

  <UserField02></UserField02>

  <UserField03></UserField03>

  <UserField04></UserField04>

  <UserField05></UserField05>

  <UserField06></UserField06>

  <UserField07></UserField07>

  <UserField08></UserField08>

  <UserField09></UserField09>

  <UserField10></UserField10>

  <UserField11></UserField11>

  <UserField12></UserField12>

  <UserField13></UserField13>

  <UserField14></UserField14>

  <UserField15></UserField15>

  <UserField16></UserField16>

  <UserField17></UserField17>

  <UserField18></UserField18>

  <UserField19></UserField19>

  <UserField20></UserField20>

</Transaction>";

 

            byte[] xmlBytes = Encoding.UTF8.GetBytes(xml);

 

 

            HttpWebRequest request = WebRequest.Create("http://antifraud.mpage.co.il/api/transactions/insert") as HttpWebRequest;

            request.Headers.Add("username", "tester");

            request.Headers.Add("password", "a123456");

            request.ContentLength = xmlBytes.Length;

            request.Method = "POST";

            request.ContentType = "text/xml";

 

            Stream dataStream = request.GetRequestStream();

            dataStream.Write(xmlBytes, 0, xmlBytes.Length);

            dataStream.Close();

 

        &, nbsp;   WebResponse response = request.GetResponse();

 

            Stream responseStream = response.GetResponseStream();

            List<byte> bytes = new List<byte>();

            int b;

            do

            {

                b = responseStream.ReadByte();

                bytes.Add((byte)b);

            } while (b > -1);

 

            responseStream.Close();

 

            response.Close();

 

            string responseXml = Encoding.UTF8.GetString(bytes.ToArray());

            //TODO: parse responseXml

 

        }

 

 

 

 

    }

}

 

לאומי קארד ישראקרט Master Card ויזה אמריקן אקספרס דיינרס Microsoft