3

I am trying to Make a request on MasterCard's sandbox for payment through MoneySend api. here is the sample code which can also be found here for c#

Problem Statement:

When I am trying to make request through directly visual studio it works perfectly, but when I deployed this service at IIS this show an error

The remote name could not be resolved: 'sandbox.api.mastercard.com'

Further Explanation:

Created Solution in VS 2017, Created 2 projects in it, One of services and other for testing same services in console. By pointing service reference of services in console, it worked fine. When I deployed services on IIS and replaced endpoint of services from local VS link to deployed IIS link in console app, I got above error.

Update:

I am working in a corporation where internet service has its own dns and proxy settings.

Full Exception:

MasterCard.Core.Exceptions.ApiException: The remote name could not be resolved: 'sandbox.api.mastercard.com' ---> System.Net.WebException: The remote name could not be resolved: 'sandbox.api.mastercard.com' at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream() at RestSharp.Http.WriteRequestBody(HttpWebRequest webRequest) at RestSharp.Http.PostPutInternal(String method) at RestSharp.RestClient.Execute(IRestRequest request, String httpMethod, Func`3 getResponse) --- End of inner exception stack trace --- at MasterCard.Core.ApiController.Execute(OperationConfig config, OperationMetadata metadata, BaseObject requestMap) at MasterCard.Core.Model.BaseObject.Execute[T](String operationUUID, T inputObject) at MasterCard.Api.Moneysend.Payment.Create(RequestMap map) at MasterCardWebService.MoneySend.testService() in C:\Users\name\Documents\My Received Files\MasterCardWebService\MasterCardWebService\MasterCardWebService\MoneySend.svc.cs:line 128

public class PaymentTest
    {
        public static void Main()
        {
            string consumerKey = "your consumer key";   // You should copy this from "My Keys" on your project page e.g. UTfbhDCSeNYvJpLL5l028sWL9it739PYh6LU5lZja15xcRpY!fd209e6c579dc9d7be52da93d35ae6b6c167c174690b72fa
            string keyAlias = "keyalias";   // For production: change this to the key alias you chose when you created your production key
            string keyPassword = "keystorepassword";   // For production: change this to the key alias you chose when you created your production key
            var path = MasterCard.Core.Util.GetCurrenyAssemblyPath(); // This returns the path to your assembly so it be used to locate your cert
            string certPath = "mypath"; // e.g. /Users/yourname/project/sandbox.p12 | C:\Users\yourname\project\sandbox.p12

            ApiConfig.SetAuthentication(new OAuthAuthentication(consumerKey, certPath, keyAlias, keyPassword));   // You only need to set this once
            ApiConfig.SetDebug(true);   // Enable http wire logging
            ApiConfig.SetSandbox(true);

            try {
                RequestMap map = new RequestMap();
                map.Set ("PaymentRequestV3.LocalDate", "0817");
                map.Set ("PaymentRequestV3.LocalTime", "150149");
                map.Set ("PaymentRequestV3.TransactionReference", "1091774875227082093");
                map.Set ("PaymentRequestV3.SenderName.First", "Test");
                map.Set ("PaymentRequestV3.SenderName.Middle", "T");
                map.Set ("PaymentRequestV3.SenderName.Last", "Test");
                map.Set ("PaymentRequestV3.SenderPhone", "7031234567");
                map.Set ("PaymentRequestV3.SenderDateOfBirth", "08061977");
                map.Set ("PaymentRequestV3.SenderAddress.Line1", "123 Main Street");
                map.Set ("PaymentRequestV3.SenderAddress.Line2", "5A");
                map.Set ("PaymentRequestV3.SenderAddress.City", "Arlington");
                map.Set ("PaymentRequestV3.SenderAddress.CountrySubdivision", "VA");
                map.Set ("PaymentRequestV3.SenderAddress.PostalCode", "22207");
                map.Set ("PaymentRequestV3.SenderAddress.Country", "USA");
                map.Set ("PaymentRequestV3.FundingCard.AccountNumber", "5184680470000023");
                map.Set ("PaymentRequestV3.FundingSource", "03");
                map.Set ("PaymentRequestV3.AdditionalMessage", "Test");
                map.Set ("PaymentRequestV3.ParticipationID", "Test");
                map.Set ("PaymentRequestV3.LanguageIdentification", "Tes");
                map.Set ("PaymentRequestV3.LanguageData", "Test");
                map.Set ("PaymentRequestV3.ReceivingCard.AccountNumber", "5184680430000006");
                map.Set ("PaymentRequestV3.ReceiverName.Middle", "B");
                map.Set ("PaymentRequestV3.ReceiverName.Last", "Lopez");
                map.Set ("PaymentRequestV3.ReceiverAddress.Line1", "Pueblo Street");
                map.Set ("PaymentRequestV3.ReceiverAddress.Line2", "PO BOX 12");
                map.Set ("PaymentRequestV3.ReceiverAddress.City", "El PASO");
                map.Set ("PaymentRequestV3.ReceiverAddress.CountrySubdivision", "TX");
                map.Set ("PaymentRequestV3.ReceiverAddress.PostalCode", "79906");
                map.Set ("PaymentRequestV3.ReceiverAddress.Country", "USA");
                map.Set ("PaymentRequestV3.ReceiverPhone", "1800639426");
                map.Set ("PaymentRequestV3.ReceiverDateOfBirth", "06211977");
                map.Set ("PaymentRequestV3.ReceivingAmount.Value", "842");
                map.Set ("PaymentRequestV3.ReceivingAmount.Currency", "840");
                map.Set ("PaymentRequestV3.ICA", "009674");
                map.Set ("PaymentRequestV3.ProcessorId", "9000000442");
                map.Set ("PaymentRequestV3.RoutingAndTransitNumber", "990442082");
                map.Set ("PaymentRequestV3.CardAcceptor.Name", "THE BEST BANK");
                map.Set ("PaymentRequestV3.CardAcceptor.City", "ANYTOWN");
                map.Set ("PaymentRequestV3.CardAcceptor.State", "MO");
                map.Set ("PaymentRequestV3.CardAcceptor.PostalCode", "99999-1234");
                map.Set ("PaymentRequestV3.CardAcceptor.Country", "USA");
                map.Set ("PaymentRequestV3.TransactionDesc", "P2P");
                map.Set ("PaymentRequestV3.MerchantId", "123456");
                map.Set ("PaymentRequestV3.ReceiverIdentification.Type", "01");
                map.Set ("PaymentRequestV3.ReceiverIdentification.Number", "2147483647");
                map.Set ("PaymentRequestV3.ReceiverIdentification.CountryCode", "USA");
                map.Set ("PaymentRequestV3.ReceiverIdentification.ExpirationDate", "10102017");
                map.Set ("PaymentRequestV3.ReceiverNationality", "USA");
                map.Set ("PaymentRequestV3.ReceiverCountryOfBirth", "USA");
                map.Set ("PaymentRequestV3.SenderIdentification.Type", "01");
                map.Set ("PaymentRequestV3.SenderIdentification.Number", "2147483647");
                map.Set ("PaymentRequestV3.SenderIdentification.CountryCode", "USA");
                map.Set ("PaymentRequestV3.SenderIdentification.ExpirationDate", "10102017");
                map.Set ("PaymentRequestV3.SenderNationality", "USA");
                map.Set ("PaymentRequestV3.SenderCountryOfBirth", "USA");
                map.Set ("PaymentRequestV3.TransactionPurpose", "01");
                Payment response = Payment.Create(map);

                Console.WriteLine("Transfer.RequestId--> {0}", response["Transfer.RequestId"]); //Transfer.RequestId-->1413236
                Console.WriteLine("Transfer.TransactionReference--> {0}", response["Transfer.TransactionReference"]); //Transfer.TransactionReference-->1091774875227082093
                Console.WriteLine("Transfer.TransactionHistory.Transaction[0].Type--> {0}", response["Transfer.TransactionHistory.Transaction[0].Type"]); //Transfer.TransactionHistory.Transaction[0].Type-->PAYMENT
                Console.WriteLine("Transfer.TransactionHistory.Transaction[0].SystemTraceAuditNumber--> {0}", response["Transfer.TransactionHistory.Transaction[0].SystemTraceAuditNumber"]); //Transfer.TransactionHistory.Transaction[0].SystemTraceAuditNumber-->212849
                Console.WriteLine("Transfer.TransactionHistory.Transaction[0].NetworkReferenceNumber--> {0}", response["Transfer.TransactionHistory.Transaction[0].NetworkReferenceNumber"]); //Transfer.TransactionHistory.Transaction[0].NetworkReferenceNumber-->313371112
                Console.WriteLine("Transfer.TransactionHistory.Transaction[0].SettlementDate--> {0}", response["Transfer.TransactionHistory.Transaction[0].SettlementDate"]); //Transfer.TransactionHistory.Transaction[0].SettlementDate-->0818
                Console.WriteLine("Transfer.TransactionHistory.Transaction[0].Response.Code--> {0}", response["Transfer.TransactionHistory.Transaction[0].Response.Code"]); //Transfer.TransactionHistory.Transaction[0].Response.Code-->00
                Console.WriteLine("Transfer.TransactionHistory.Transaction[0].Response.Description--> {0}", response["Transfer.TransactionHistory.Transaction[0].Response.Description"]); //Transfer.TransactionHistory.Transaction[0].Response.Description-->Approved or completed successfully
                Console.WriteLine("Transfer.TransactionHistory.Transaction[0].SubmitDateTime--> {0}", response["Transfer.TransactionHistory.Transaction[0].SubmitDateTime"]); //Transfer.TransactionHistory.Transaction[0].SubmitDateTime-->2016-08-17T09:31:54Z

            } catch (ApiException e) {
                Console.Error.WriteLine("HttpStatus: {0}", e.HttpStatus);
                Console.Error.WriteLine("Message: {0}", e.Message);
                Console.Error.WriteLine("ReasonCode: {0}", e.ReasonCode);
                Console.Error.WriteLine("Source: {0}", e.Source);
            }

        }
    }
OrionMD
  • 389
  • 1
  • 7
  • 13
Abdul
  • 1,416
  • 9
  • 26
  • 57
  • When you say deployed at IIS, do you mean your web hosting provider? If so it’s probably blocked from making outgoing calls –  Nov 08 '18 at 06:39
  • 1
    That’s a dreadful looking “API” by the way. –  Nov 08 '18 at 06:41
  • @MickyD not on the webhosting on local IIS at my machine – Abdul Nov 08 '18 at 06:44
  • 1
    Hmm well I'm guessing that MasterCard doesn't allow you to make a copy of their service on your local machine. Kinda makes sense –  Nov 08 '18 at 06:51
  • then why I am able to make request directly from visual studio ? @MickyD – Abdul Nov 08 '18 at 06:54
  • Because you are using `their` API which defaults to their data centre I suspect. I see no where in your example where a destination server is mentioned. `It makes zero sense for a Mastercard; VISA; Amex service to run on your computer`. –  Nov 08 '18 at 07:16
  • I'm voting to close this question as off-topic because what the OP is asking doesn't make sense in practice –  Nov 08 '18 at 07:17
  • please suggest as I have updated and edited my question with explanation – Abdul Nov 14 '18 at 10:49
  • 1
    @MickyD You completely misunderstand the issue I think. According to OP, above code works when running the application using the VS debugger (so using IIS Express), but it fails when running the application in IIS. – user247702 Nov 14 '18 at 10:49
  • 2
    @Stijn the error message has nothing to do with the code posted here or IIS. That's a plain old DNS error message. It says that `sandbox.api.mastercard.com` can't be found. – Panagiotis Kanavos Nov 14 '18 at 10:52
  • @PanagiotisKanavos I am working in a corporate sector where it has its own DNS and proxy settings – Abdul Nov 14 '18 at 10:53
  • @trighati the error you posted has nothing to do with IIS or C#. It's a DNS error saying that the domain name`sandbox.api.mastercard.com` can't be found. That means there's a problem with the DNS service used by the machine. You can't fix that in code, only the *network* administrator can fix that. Can you run `nslookup sandbox.api.mastercard.com` on that server? If you don't get a response it's definitely a network error – Panagiotis Kanavos Nov 14 '18 at 10:54
  • @PanagiotisKanavos it's the same machine according to OP (their local machine). – user247702 Nov 14 '18 at 10:55
  • @PanagiotisKanavos then how it is working in visual studio directly ? – Abdul Nov 14 '18 at 10:55
  • 1
    @Stijn and that's a DNS error. No matter what anyone says, that's still a DNS error saying that `sandbox.api.mastercard.com` can't be resolved – Panagiotis Kanavos Nov 14 '18 at 10:56
  • @Stijn yes, of course, it is same machine where hosted on IIS – Abdul Nov 14 '18 at 10:56
  • @PanagiotisKanavos I didn't say it's not a DNS error. I was explaining to MickyD that OP is not trying to run their own copy of the MasterCard API on their local machine. – user247702 Nov 14 '18 at 10:56
  • @trighati does it? Your code catches only `ApiException` – Panagiotis Kanavos Nov 14 '18 at 10:57
  • @PanagiotisKanavos yes,running on VS give me success with all details in response. what more exceptions are required to catch ? – Abdul Nov 14 '18 at 11:00
  • @trighati post the full exception, not just the message. You can get it easily with `Exception.ToString()`. This will show what the actual exception is and which method threw it. It will also show any inner exceptions. – Panagiotis Kanavos Nov 14 '18 at 11:00
  • 1
    @trighati **all** of them. You need to add a `catch(Exception e)` clause. When you work with Visual Studio you make all calls using *your* account. When deployed to production or IIS (not express) the code runs using the application pool's account. If your environment has per-user network settings the app pool account may be using a different DNS server than you – Panagiotis Kanavos Nov 14 '18 at 11:02
  • @PanagiotisKanavos updated full exception in question – Abdul Nov 14 '18 at 11:05
  • Possible duplicate [The remote name could not be resolved: 'api-3t.sandbox.paypal.com'](https://stackoverflow.com/questions/23522306/the-remote-name-could-not-be-resolved-api-3t-sandbox-paypal-com). – Panagiotis Kanavos Nov 14 '18 at 11:13
  • 3
    From the duplicate's answer `Your machine is using a DNS server that filters queries. This is common in corporate environments; filtering is done to try to stop malware from working.`. The real solution is to communicate with the administrator to find out how DNS is configured and what gets filtered. You'll *have* to do that before production deployment anyway. The app pool may have to run under a specific account. In the meantime, a hack would be to configure the IIS App pool to run with your account. Another hack could be to edit the `hosts` file and enter the target's IP – Panagiotis Kanavos Nov 14 '18 at 11:18
  • @PanagiotisKanavos can you help in a way around to bypass DNS at coding level, from config or any other way except changing dns setting of machine – Abdul Nov 14 '18 at 11:51
  • @Stijn The comment matched the fidelity of the question at the time. Like I said _"it’s probably `blocked from making outgoing calls`"_. I notice Mr Kanavos has mentioned _"filtering"_ so I will defer to his wisdom –  Nov 14 '18 at 12:39

2 Answers2

3

Solved by adding proxy to web.config of service project

<system.net>
    <defaultProxy useDefaultCredentials="false">
      <proxy
        proxyaddress="http://myurladdress:myport"
        bypassonlocal="True"
        usesystemdefault="False"
      />
    </defaultProxy>
</system.net>
Abdul
  • 1,416
  • 9
  • 26
  • 57
0

Seems like your DNS is not resolving. You can force it like this:

Open Notepad as Administrator on your server. Browse and open C:\Windows\System32\drivers\etc\hosts

At the bottom add: 88.221.244.150 sandbox.api.mastercard.com

Save the file.

The application should now find sandbox.api.mastercard.com.

Sean Thorburn
  • 1,728
  • 17
  • 31
  • got an exception: `Unable to connect to the remote server` Inner Exception: `A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 88.221.244.150:443` – Abdul Nov 15 '18 at 09:10
  • When i run this `sandbox.api.mastercard.com` in browser it says Service Unavailable and `The server is temporarily unable to service your request. Please try again later.` with reference number – Abdul Nov 15 '18 at 09:13