Net Xml Payments

Knowledge Base

Get help for payment solutions. Search our articles or browse by category below.

.NET XML Payments

The sample code below require the .NET XML API.

Authorisation:

using System;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Text;
using WorldnetClient;
 
namespace ApiTest
{
    class Program
    {
        static void Main(string[] args)
        {
            String gateway = "";		// Gateway that will process the transaction. "worldnet" or "cashflows"
            String terminalId = "";		// Terminal ID Supplied by WorldNet
            String currency = "";		// EUR/GBP/USD etc.
 
// These values are specific to the cardholder.
            String cardNumber = "";		// The cardholders PAN (or SecureCard Card Reference);
            String cardType = "";		// See our Integrator Guide for a list of valid Card Type parameters
            String email = "";			// (optional) Cardholders e-mail address for sending of a receipt
            String mobileNumber = "";			// (optional) Cardholders mobile phone number for sending of a receipt. Digits only, Include international prefix.
            String cardExpiry = "";		// Format: MMYY
            String cardHolderName = "";		// Cardholders name
            String cvv = "";			// (optional) 3 digit (4 for AMEX cards) security digit on the back of the card.
            String issueNo = "";			// (optional) Issue number for Switch and Solo cards.
 
// These fields are for AVS (Address Verification Check). This is only appropriate in the UK and the US.
            String address1 = '';		// (optional) This is the first line of the cardholders address.
            String address2 = '';		// (optional) This is the second line of the cardholders address.
            String postcode = '';		// (optional) This is the cardholders post code.
            String country = '';		// (optional) This is the cardholders country name.
            String phone = '';		// (optional) This is the cardholders home phone number.
 
// These values are specific to the transaction.
            String orderId = "";		// Unique Order ID for the transaction (max 12 chars). Used to identify the transaction in future.
            Double amount = 0.00;		// Amount of transaction (should include the decimal point and decimal places)
            Boolean isMailOrder = false;	// If true the transaction will be processed as a Mail Order transaction. This is only for use with Mail Order enabled Terminal IDs.
 
            String description = "";		// (optional) Transaction description
 
// eDCC fields. Populate these if you have retreived a rate for the transaction, offered it to the cardholder and they have accepted that rate.
            String cardCurrency = '';		// (optional) This is the three character ISO currency code returned in the rate request.
            Double cardAmount = '';		// (optional) This is the foreign currency transaction amount returned in the rate request.
            Double conversionRate = '';		// (optional) This is the currency conversion rate returned in the rate request.
 
# 3D Secure reference. Only include if you have verified 3D Secure throuugh the WorldNet MPI and received an MPIREF back.
            String mpiref = '';			// This should be blank unless instructed otherwise by WorldNet.
            String deviceId = '';			// This should be blank unless instructed otherwise by WorldNet.
 
            String autoReady = '';		// (optional) Y or N. Automatically set the transaction to a status of Ready in the batch. If not present the terminal default will be used.
            Boolean multicur = false;		// This should be false unless instructed otherwise by WorldNet.
 
            String secret = "";			// Shared Secret as configured in the Terminal Setup in your WoldNet SelfCare System
 
            Boolean testAccount = true;
 
            XmlAuthRequest request = new XmlAuthRequest(terminalId, orderId, currency, amount, cardNumber, cardType);
 
            if (!String.IsNullOrEmpty(cardExpiry) && !String.IsNullOrEmpty(cardHolderName)) { request.SetNonSecureCardCardInfo(cardExpiry,cardHolderName); }
            if (!String.IsNullOrEmpty(cvv)) { request.SetCvv(cvv); }
            if (!String.IsNullOrEmpty(cardCurrency) && !String.IsNullOrEmpty(cardAmount) && !String.IsNullOrEmpty(conversionRate)) { request.SetForeignCurrencyInformation(cardCurrency,cardAmount,conversionRate); }
            if (!String.IsNullOrEmpty(email)) { request.SetEmail(email); }
            if (!String.IsNullOrEmpty(mobileNumber)) { request.SetMobileNumber(mobileNumber); }
            if (!String.IsNullOrEmpty(description)) { request.SetDescription(description); }
 
            if (!String.IsNullOrEmpty(issueNo)) { request.SetIssueNo(issueNo); }
            if (!String.IsNullOrEmpty(address1) && !String.IsNullOrEmpty(postcode)) { request.SetAvs(address1,address2,postcode); }
            if (!String.IsNullOrEmpty(country)) { request.SetCountry(country); }
            if (!String.IsNullOrEmpty(phone)) { request.SetPhone(phone); }
 
            if (!String.IsNullOrEmpty(deviceId)) { request.SetDeviceId(deviceId); }
 
            if (isMailOrder) { request.SetMotoTrans(); }
            if (multicur) { request.SetMultiCur(); }
            if (!String.IsNullOrEmpty(autoReady)) { request.SetAutoReady(autoReady); }
 
            XmlAuthResponse response = request.ProcessRequest(secret, testAccount, gateway);
 
            String expectedResponseHash = Response.GetResponseHash(terminalId + orderId + amount.ToString(CultureInfo.InvariantCulture) + response.DateTimeHashString + response.ResponseCode + response.ResponseText + secret);
 
            if (response.IsError == true)
            {
                Console.Out.WriteLine("ERROR : " + response.ErrorString);
                //Handle Error Response
            }
            else if (response.Hash != expectedResponseHash)
            {
                Console.Out.WriteLine("ERROR : Response HASH parameter not as expected. If live possible man-in-the-middle attack.");
                //Handle Invalid Hash scenario - inform merchant that transaction may have to be voided.
            }
            else
            {
                Console.Out.WriteLine("RESPONSECODE : " + response.ResponseCode);
                if (response.ResponseCode.Equals("A"))
                {
                    //Handle success response
                }
                else
                {
                    //Handle declined response
                }
                Console.Out.WriteLine("RESPONSETEXT : " + response.ResponseText);
                Console.Out.WriteLine("APPROVALCODE : " + response.ApprovalCode);
                Console.Out.WriteLine("DATETIME : " + response.DateTimeHashString);
                Console.Out.WriteLine("AVSRESPONSE : " + response.AvsResponse);
                Console.Out.WriteLine("CVVRESPONSE : " + response.CvvResponse);
                Console.Out.WriteLine("UNIQUEREF : " + response.UniqueRef);
                Console.Out.WriteLine("HASH : " + response.Hash);
                //Handle Response
            }
        }
    }
}

Perform a Refund (standard refunds can only be performed against authorised sale transactions that have already been put through the same account system. Also, the Order ID of the original sale must be unique.):

using System;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Text;
using WorldnetClient;
 
namespace ApiTest
{
    class Program
    {
        static void Main(string[] args)
        {
            String gateway = "";		// Gateway that will process the transaction. "worldnet" or "cashflows"
            String terminalId = "";		// Terminal ID Supplied by WorldNet
            String uniqueRef = "";		// Unique Reference of the transaction that you are looking to refund. This was returned in the auth response
            Double amount = ;			// Amount of transaction
            String operator = "";		// Administrative operator performing the refund
            String reason = "";			// The reason why the refund was necessary
            String secret = "";			// Shared Secret as configured in the Terminal Setup in your WoldNet SelfCare System
 
            Boolean testAccount = true;
 
            XmlRefundRequest request = new XmlRefundRequest(terminalId, amount.ToString(CultureInfo.InvariantCulture), operator, reason);
            request.SetUniqueRef(uniqueRef);
 
            XmlRefundResponse response = request.ProcessRequest(secret, testAccount, gateway);
 
            String expectedResponseHash = Response.GetResponseHash(terminalId + response.UniqueRef + amount.ToString(CultureInfo.InvariantCulture) + response.DateTimeHashString + response.ResponseCode + response.ResponseText + secret);
 
            if (response.IsError == true)
            {
                Console.Out.WriteLine("ERROR : " + response.ErrorString);
                //Handle Error Response
            }
            else if (response.Hash != expectedResponseHash)
            {
                Console.Out.WriteLine("ERROR : Response HASH parameter not as expected. If live possible man-in-the-middle attack.");
                //Handle Invalid Hash scenario - inform merchant that transaction may have to be voided.
            }
            else
            {
                Console.Out.WriteLine("RESPONSECODE : " + response.ResponseCode);
                if (response.ResponseCode.Equals("A"))
                {
                    //Handle success response
                }
                else
                {
                    //Handle declined response
                }
                Console.Out.WriteLine("RESPONSETEXT : " + response.ResponseText);
                Console.Out.WriteLine("DATETIME : " + response.DateTimeHashString);
                Console.Out.WriteLine("HASH : " + response.Hash);
                //Handle Response
            }
        }
    }
}

Perform a eDCC rate request:

using System;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Text;
using WorldnetClient;
 
namespace ApiTest
{
    class Program
    {
        static void Main(string[] args)
        {
            String gateway = "";		// Gateway that will process the transaction. "worldnet" or "cashflows"
            String terminalId = "";		// Terminal ID Supplied by WorldNet
            String cardBin = "";		// First 6 digits of the card number
            Double baseAmount = ;			// (optional) Amount of transaction in the base currency. If included the host will calculate and return the foreign currency amount
            String secret = "";			// Shared Secret as configured in the Terminal Setup in your WoldNet SelfCare System
 
            Boolean testAccount = true;
 
            XmlRateRequest request = new XmlRateRequest(terminalId, cardBin);
 
            if (!String.IsNullOrEmpty(baseAmount)) { request.SetBaseAmount(baseAmount); )
 
            XmlRateResponse response = request.ProcessRequest(secret, testAccount, gateway);
 
            String expectedResponseHash = Response.GetResponseHash(response.TerminalCurrency + response.CardCurrency + response.ConversionRate.ToString(CultureInfo.InvariantCulture) + response.DateTimeHashString + secret);
 
            if (response.IsError == true)
            {
                Console.Out.WriteLine("ERROR : " + response.ErrorString);
                //Handle Error Response
            }
            else if (response.Hash != expectedResponseHash)
            {
                Console.Out.WriteLine("ERROR : Response HASH parameter not as expected. If live possible man-in-the-middle attack.");
                //Handle Invalid Hash scenario - inform merchant that transaction may have to be voided.
            }
            else
            {
                Console.Out.WriteLine("TERMINALCURRENCY : " + response.TerminalCurrency);
                Console.Out.WriteLine("CARDCURRENCY : " + response.CardCurrency);
                Console.Out.WriteLine("CONVERSIONRATE : " + response.ConversionRate.ToString(CultureInfo.InvariantCulture));
                Console.Out.WriteLine("EXCHANGERATESOURCENAME : " + response.ExchangeRateSourceName);
                Console.Out.WriteLine("MARGINPERCENTAGE : " + response.MargineRatePercentage);
                Console.Out.WriteLine("COMMISSIONPERCENTAGE : " + response.CommissionPercentage);
                Console.Out.WriteLine("FOREIGNAMOUNT : " + response.ForeignAmount.ToString(CultureInfo.InvariantCulture));
                Console.Out.WriteLine("DATETIME : " + response.DateTimeHashString);
                Console.Out.WriteLine("HASH : " + response.Hash);
                //Handle Response
            }
        }
    }
}
Copyright © 2017 Worldnet Knowledge Base | Powered by DokuWiki
developer/sample_codes/net_xml_payments.txt · Last modified: 2016/07/26 10:55 (external edit)