简体   繁体   中英

Integration with paygate in asp.net

So I have added the service reference to my project which is

https://secure.paygate.co.za/payhost/process.trans?wsdl

My PaygateRef is the web service reference Name(namespace)

PaygateRef.SinglePaymentRequest1 PaygatePayment = new PaygateRef.SinglePaymentRequest1();
PaygateRef.CardPaymentRequestType Request = new PaygateRef.CardPaymentRequestType();
Request.Account = new PaygateRef.PayGateAccountType();
Request.Account.PayGateId = "000000000";   //my PaygateID
Request.Account.Password = "mypassword";       //my Encryption key

Request.Customer = new PaygateRef.PersonType();
Request.Customer.Title = "Mr";
Request.Customer.FirstName = "Rich";
Request.Customer.LastName = "Buyer";
Request.Customer.Mobile = new string[]{"0830000001"}; //My cell number

Request.CardIssueNumber = "500000000000008";//card number
Request.CardIssueDate = "012020";//january 2020
Request.CVV = "001";// card ccv

Request.Order = new PaygateRef.OrderType();
Request.Order.MerchantOrderId = "115422488465";//a random test orderID
Request.Order.Currency = PaygateRef.CurrencyType.ZAR;
Request.Order.Amount = 100;  //R1

PaygatePayment.SinglePaymentRequest = new PaygateRef.SinglePaymentRequest();
PaygatePayment.SinglePaymentRequest.Item = Request;

PaygateRef.PayHOST myPaygateinterface = new PaygateRef.PayHOSTClient();

myPaygateinterface.SinglePayment(PaygatePayment);


The error I am getting is

Validation error

I tested with multiple cards that work on other sites and this account was used on the website previously written in PHP where it was working.
So everything on Paygate side is set up correctly as per my understanding

Why am i getting this error and how do I solve it?

Edited
I did try

Request.ItemsElementName = new PaygateRef.ItemsChoiceType[]
{
    PaygateRef.ItemsChoiceType.CardExpiryDate,
    PaygateRef.ItemsChoiceType.CardNumber
};

Request.Items = new string[] { "012020", "500000000000008" };

I was able to resolve my issue by changing the order of card details. In your case, you have put cardexpirydate above cardnumber. I reversed the order and also ensured that the cvv comes after card details. This will be your code.

Request.ItemsElementName = new PaygateRef.ItemsChoiceType[]
{
    PaygateRef.ItemsChoiceType.CardNumber,
    PaygateRef.ItemsChoiceType.CardExpiryDate

};

Request.Items = new string[] { "500000000000008", "012020" };

Request.CVV = "001";// card ccv

Hope it helps!!!

Also I did not use cardissuedate or cardissuenumber as these are optional and i didn't need.

In addition, you can also check the Details node of the exception that you get. In the details node, it will clearly define the cause of the error.

CardIssuenumber is actually not the card's number and it's optional. had to scratch my head a bit for payhost structure : here is some of the validation you missing? hope this help

request.ItemsElementName = new payhostReference.ItemsChoiceType[] 
{
    payhostReference.ItemsChoiceType.CardExpiryDate,
    payhostReference.ItemsChoiceType.CardNumber
};

request.Items = new string[] { "122017", "4000000000000002"};

A much simplier approach with very easy code to follow do the following.

  1. import Nuget restsharp

    Imports RestSharp Imports System Imports System.Data Imports System.Configuration Imports System.Linq Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.HtmlControls Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Xml.Linq Imports System.Net Imports System.Collections.Specialized Imports System.Text Imports WebApplication1.ServiceReference1

    Public Class _Default 'Inherits Page Inherits System.Web.UI.Page Dim CheckSum As String Dim PaymentRequestId As String Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

     End Sub Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Paygate() Response.Write(PaygateForm().ToString) Me.PaygatePostScript(Page) End Sub Private Sub PaygatePostScript(ByVal Page As System.Web.UI.Page) 'This registers Javascript to the page which is used to post the Netcash Form details Dim strScript As New StringBuilder() strScript.Append("<script language='javascript'>") strScript.Append("var ctlForm = document.getElementById('Paygate');") strScript.Append("ctlForm.submit();") strScript.Append("</script>") ClientScript.RegisterClientScriptBlock(Me.GetType, "PPSubmit", strScript.ToString) End Sub Private Function PaygateForm() Dim client = New RestClient("https://secure.paygate.co.za/payweb3/process.trans") client.Timeout = -1 Dim request = New RestRequest(Method.POST) request.AddHeader("Content-Type", "application/x-www-form-urlencoded") request.AddHeader("Cookie", "paygate_payweb3=u9tjr031eluc6jsflq952uatup") request.AddParameter("PAY_REQUEST_ID", PaymentRequestId) request.AddParameter("CHECKSUM", CheckSum) Dim response As IRestResponse = client.Execute(request) Dim ppForm As New StringBuilder '<form action="https://secure.paygate.co.za/payweb3/process.trans" method="POST" > ppForm.Append("<Form method=" + """" + "post" + """" + """" + " id=" + """" + "Paygate" + """" + " action=" + """" + "https://secure.paygate.co.za/payweb3/process.trans" + """" + ">") ppForm.Append(response.Content.ToString) Return ppForm.ToString End Function Private Sub Paygate() Dim client = New RestClient("https://secure.paygate.co.za/payweb3/initiate.trans") client.Timeout = -1 Dim request = New RestRequest(Method.POST) request.AddHeader("Content-Type", "application/x-www-form-urlencoded") request.AddHeader("Cookie", "paygate_payweb3=u9tjr031eluc6jsflq952uatup") request.AddParameter("PAYGATE_ID", "10011072130") request.AddParameter("REFERENCE", "pgtest_123456789") request.AddParameter("AMOUNT", "3299") request.AddParameter("CURRENCY", "ZAR") request.AddParameter("RETURN_URL", "https://my.return.url/page") request.AddParameter("TRANSACTION_DATE", "2018-01-01 12:00:00") request.AddParameter("LOCALE", "en-za") request.AddParameter("COUNTRY", "ZAF") request.AddParameter("EMAIL", "customer@paygate.co.za") request.AddParameter("CHECKSUM", "59229d9c6cb336ae4bd287c87e6f0220") Dim response As IRestResponse = client.Execute(request) CheckSum = response.Content.ToString Dim array1 As String() = CheckSum.Split("&") CheckSum = array1(3) CheckSum = Replace(CheckSum, "CHECKSUM=", "") PaymentRequestId = array1(1) PaymentRequestId = Replace(PaymentRequestId, "PAY_REQUEST_ID=", "") ' GetCheckSumPayGate() End Sub

    End Class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM