Net Xml Subscriptions

Knowledge Base

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

.NET XML Subscriptions

The sample code below require the .NET XML API.

Subscription registration:

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 secret = "";				// Shared Secret as configured in the Terminal Setup in your WoldNet SelfCare System
            Boolean testAccount = true;
 
            String subscriptionMerchantRef = '';	// Unique merchant identifier for the subscription. Length is limited to 48 chars.
            String storedSubscriptionMerchantRef = '';	// Merchant reference for the Stored Subscription under which this Subscription is to be created.
            String secureCardMerchantRef = '';		// Merchant reference for the SecureCard entry that you want to use to set up the subscription.
            DateTime subscriptionStartDate = '';	// Date on which the subscription should start (setup payment is processed immediately, and does not obey this). Format: DD-MM-YYYY.
 
            DateTime endDate;				// (optional) set an end date for the subscription.  Format: DD-MM-YYYY.
            String eDCCDecision = '';			// (optional) if eDCC was offered and accepted, you should set this to 'Y'.
 
            String name = '';				// (optional) 
            String description = '';			// (optional) 
            String periodType = '';			// (optional) 
            int length = -1;				// (optional) 
            String currency = '';			// (optional) 
            double recurringAmount = -1.00;		// (optional) 
            double initialAmount = -1.00;		// (optional) 
            String type = '';				// (optional) 
            String onUpdate = '';			// (optional) 
            String onDelete = '';			// (optional) 
 
            XmlSubscriptionRegRequest subreg = new XmlSubscriptionRegRequest(secureCardMerchantRef, terminalId, storedSubscriptionMerchantRef, secureCardMerchantRef, subscriptionStartDate);
 
            if(!String.IsNullOrEmpty(name) || !String.IsNullOrEmpty(description) || !String.IsNullOrEmpty(periodType) || length>0 || !String.IsNullOrEmpty(type) || !String.IsNullOrEmpty(onUpdate) || !String.IsNullOrEmpty(onDelete)) subreg->SetNewStoredSubscriptionValues(name, description, periodType, length, currency, recurringAmount, initialAmount, type, onUpdate, onDelete);
            else if(recurringAmount>0 || initialAmount>0) subreg->SetSubscriptionAmounts(recurringAmount, initialAmount);
            if(endDate.HasValue) subreg->SetEndDate(endDate);
            if(!String.IsNullOrEmpty(eDCCDecision)) subreg->EDCCDecision(eDCCDecision);
 
            XmlSubscriptionRegResponse response = subreg.ProcessRequest(secret, testAccount, gateway);
 
            String expectedResponseHash = Response.GetResponseHash(terminalId + response.MerchantReference + 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("Subscription successfully setup and setup payment processed succesfully.");
                //Handle Response
            }
        }
    }
}

Subscription payment:

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 secret = "";				// Shared Secret as configured in the Terminal Setup in your WoldNet SelfCare System
            Boolean testAccount = true;
 
            String subscriptionMerchantRef = '';	// Unique merchant identifier for the subscription. Length is limited to 48 chars.
            String secureCardMerchantRef = '';		// Merchant reference for the SecureCard entry that you want to use to set up the subscription.
 
            String storedSubscriptionMerchantRef = '';	// (optional) Merchant reference for the Stored Subscription under which this Subscription is to be created.
            DateTime subscriptionStartDate = '';	// (optional) Date on which the subscription should start (setup payment is processed immediately, and does not obey this). Format: DD-MM-YYYY.
            DateTime endDate;				// (optional) set an end date for the subscription.  Format: DD-MM-YYYY.
            String eDCCDecision = '';			// (optional) if eDCC was offered and accepted, you should set this to 'Y'.
 
            String name = '';				// (optional) 
            String description = '';			// (optional) 
            String periodType = '';			// (optional) 
            int length = -1;				// (optional) 
            double recurringAmount = -1.00;		// (optional) 
            String type = '';				// (optional) 
 
            XmlSubscriptionUpdRequest subupd = new XmlSubscriptionUpdRequest($subscriptionMerchantRef, $terminalId, $secureCardMerchantRef);
            if(!String.IsNullOrEmpty(name)) subupd->SetSubName(name);
            if(!String.IsNullOrEmpty(description)) subupd->SetDescription(description);
            if(!String.IsNullOrEmpty(periodType)) subupd->SetPeriodType(periodType);
            if(length>0) subupd->SetLength(length);
            if(recurringAmount>0) subupd->SetRecurringAmount(recurringAmount);
            if(!String.IsNullOrEmpty(type)) subupd->SetSubType(type);
            if(subscriptionStartDate.HasValue) subreg->SetStartDate(subscriptionStartDate);
            if(endDate.HasValue) subreg->SetEndDate(endDate);
            if(!String.IsNullOrEmpty(eDCCDecision)) subupd->EDCCDecision(eDCCDecision);
 
            XmlSubscriptionUpdResponse response = subupd->ProcessRequestToGateway(secret, testAccount, gateway);
 
            String expectedResponseHash = Response.GetResponseHash(terminalId + response.MerchantReference + 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("Subscription successfully updated.");
                //Handle Response
            }
        }
    }
}

Subscription deletion:

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 secret = "";				// Shared Secret as configured in the Terminal Setup in your WoldNet SelfCare System
            Boolean testAccount = true;
 
            String subscriptionMerchantRef = '';	// Unique merchant identifier for the subscription. Length is limited to 48 chars.
 
            XmlSubscriptionDelRequest subdel = new XmlSubscriptionDelRequest(subscriptionMerchantRef, terminalId);
            XmlSubscriptionDelResponse response = subdel->ProcessRequestToGateway(secret, testAccount, gateway);
            String expectedResponseHash = Response.GetResponseHash(terminalId + response.MerchantReference + 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("Subscription successfully deleted.");
                //Handle Response
            }
        }
    }
}
Copyright © 2017 Worldnet Knowledge Base | Powered by DokuWiki
developer/sample_codes/net_xml_subscriptions.txt · Last modified: 2016/11/11 09:31 by elizas