I am using the CyberSource API for Payment Gateway. I went through all the documentations that are available and came up with the following code:
First I added the service reference to CyberSource using url https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.60.wsdl /omeglzechat
Then I added the following code for making a transaction and then cancelling it. But somehow, cancelling does not seem to work. I am not sure what I am doing wrong as there is very little documentation available on the net.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; using PaymentGatewayConsole.CyberSourceTest; namespace PaymentGatewayConsole { class Program { private const String MERCHANT_ID = "removed"; private const String TRANSACTION_KEY = "removed"; private static string REQUEST_TOKEN = string.Empty; private static string REQUEST_ID = string.Empty; static void Main(string[] args) { MakePayment(); RequestRefund(); } private static void MakePayment() { RequestMessage request = new RequestMessage(); request.merchantID = MERCHANT_ID; // replace request.merchantReferenceCode with reference number for the current transaction. request.merchantReferenceCode = "123"; request.clientLibrary = ".NET WCF"; request.clientLibraryVersion = Environment.Version.ToString(); request.clientEnvironment = Environment.OSVersion.Platform + Environment.OSVersion.Version.ToString(); request.ccAuthService = new CCAuthService(); request.ccAuthService.run = "true"; BillTo billTo = new BillTo(); billTo.firstName = "John"; billTo.lastName = "Doe"; billTo.street1 = "1295 Charleston Road"; billTo.city = "Mountain View"; billTo.state = "CA"; billTo.postalCode = "94043"; billTo.country = "US"; billTo.email = "null@cybersource.com"; billTo.ipAddress = "10.7.111.111"; request.billTo = billTo; Card card = new Card(); card.accountNumber = "4111111111111111"; card.expirationMonth = "12"; card.expirationYear = "2020"; card.cardType = "Visa"; request.card = card; PurchaseTotals purchaseTotals = new PurchaseTotals(); purchaseTotals.currency = "USD"; request.purchaseTotals = purchaseTotals; request.item = new Item[1]; Item item = new Item(); item.id = "0"; item.unitPrice = "49.00"; request.item[0] = item; try { TransactionProcessorClient proc = new TransactionProcessorClient(); proc.ChannelFactory.Credentials.UserName.UserName = request.merchantID; proc.ChannelFactory.Credentials.UserName.Password = TRANSACTION_KEY; ReplyMessage reply = proc.runTransaction(request); REQUEST_ID = reply.requestID; REQUEST_TOKEN = reply.requestToken; Console.WriteLine("decision = " + reply.decision); Console.WriteLine("reasonCode = " + reply.reasonCode); Console.WriteLine("requestID = " + reply.requestID); Console.WriteLine("requestToken = " + reply.requestToken); Console.WriteLine("ccAuthReply.reasonCode = " + reply.ccAuthReply.reasonCode); } catch (TimeoutException e) { Console.WriteLine("TimeoutException: " + e.Message + "\n" + e.StackTrace); } catch (FaultException e) { Console.WriteLine("FaultException: " + e.Message + "\n" + e.StackTrace); } catch (CommunicationException e) { Console.WriteLine("CommunicationException: " + e.Message + "\n" + e.StackTrace); } Console.ReadLine(); } /// <summary> /// Method for requesting refund /// </summary> private static void RequestRefund() { RequestMessage request = new RequestMessage(); request.merchantID = MERCHANT_ID; request.merchantReferenceCode = "123"; request.clientLibrary = ".NET WCF"; request.clientLibraryVersion = Environment.Version.ToString(); request.clientEnvironment = Environment.OSVersion.Platform + Environment.OSVersion.Version.ToString(); request.ccAuthService = new CCAuthService(); request.ccAuthService.run = "true"; //request.ccAuthReversalService = new CCAuthReversalService(); //request.ccAuthReversalService.run = "true"; //request.ccAuthReversalService.authRequestID = REQUEST_ID; //request.orderRequestToken = REQUEST_TOKEN; //request.purchaseTotals = new PurchaseTotals(); //request.purchaseTotals.currency = "USD"; //request.purchaseTotals.grandTotalAmount = "10"; VoidService reqVoid = new VoidService(); reqVoid.voidRequestID = REQUEST_ID; reqVoid.voidRequestToken = REQUEST_TOKEN; reqVoid.run = "true"; request.voidService = reqVoid; try { TransactionProcessorClient proc = new TransactionProcessorClient(); proc.ChannelFactory.Credentials.UserName.UserName = request.merchantID; proc.ChannelFactory.Credentials.UserName.Password = TRANSACTION_KEY; ReplyMessage reply = proc.runTransaction(request); Console.WriteLine("decision = " + reply.decision); Console.WriteLine("reasonCode = " + reply.reasonCode); Console.WriteLine("requestID = " + reply.requestID); Console.WriteLine("requestToken = " + reply.requestToken); } catch (TimeoutException e) { Console.WriteLine("TimeoutException: " + e.Message + "\n" + e.StackTrace); } catch (FaultException e) { Console.WriteLine("FaultException: " + e.Message + "\n" + e.StackTrace); } catch (CommunicationException e) { Console.WriteLine("CommunicationException: " + e.Message + "\n" + e.StackTrace); } Console.ReadLine(); } } }
In method request refund, i am actually getting the response as Request.ReasonCode = 102 which means an error. Ideally it should be 100. 102 means "One or more fields in the request contains invalid data.".
Help is deeply appreciated...
09-23-2022 04:12 AM
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; using PaymentGatewayConsole.CyberSourceTest; namespace PaymentGatewayConsole { class Program { private const String MERCHANT_ID = "removed"; private const String TRANSACTION_KEY = "removed"; private static string REQUEST_TOKEN = string.Empty; private static string REQUEST_ID = string.Empty; static void Main(string[] args) { MakePayment(); RequestRefund(); } private static void MakePayment() { RequestMessage request = new RequestMessage(); request.merchantID = MERCHANT_ID; // replace request.merchantReferenceCode with reference number for the current transaction. request.merchantReferenceCode = "123"; request.clientLibrary = ".NET WCF"; request.clientLibraryVersion = Environment.Version.ToString(); request.clientEnvironment = Environment.OSVersion.Platform + Environment.OSVersion.Version.ToString(); request.ccAuthService = new CCAuthService();
09-24-2022 06:32 AM
Hi, @MurbiesWalto : Could you please share your request and response ?
09-26-2022 01:32 PM