New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Odd issue when processing a payment #92
Comments
@MLyons10 just curious, but is this happening on sandbox or the live service? Since yesterday, we've been seeing a huge uptick in 500 errors related to overused credit card numbers on sandbox. |
This is actually Live. After finding that the code worked in the sandbox, I moved to Live and that's when I found the issue... It's really very strange, as I can process the card without any issue ever while in the dev environment. Run the program locally however and it fails... I have tried catching the error, but nothing seems to catch it. |
That is strange... Are you getting an HTTP error (e.g. 400, 500) or is a different exception being thrown? Have you tried using an HTTP monitoring tool (I use Fiddler) to view the request & response? |
Thank you for your help. I haven't been able to catch an error, as it just doesn't succeed for some reason. I will try Fiddler and will report back for you. I really appreciate the help with this. I also just downloaded the current version, and realized that the dll's that I am using are different. The .zip includes: Newtonsoft.Json.dll The version that I was using included: Newtonsoft.Json.dll Is this change correct and I have to move my solution to using these new dll's? I duplicated my project and tried these other resources and am working to revise the code to match the needs of these new dll's. The example that I found processes a PayPal payment. Is there an example for processing a credit card payment? It looks like this has changed from the code that I had with the other dll's... |
Yes, the previous DLLs you were using are the older, deprecated version of this SDK. The newer version just requires the two you downloaded. You can view this sample to see how to make a credit card payment using the latest version of this SDK. Let me know if you have any trouble getting the newer library to work with your project. |
Also, since you were using a pre-1.0 version of the SDK, you'll want to check out this wiki page on the breaking pages introduced with the 1.0 release. Mainly, some of the namespaces were changed to avoid namespace conflicts with the older Core SDK (which has since been integrated into this SDK). |
Thank you for your help. I got the code reworked today and will test it thoroughly and report back by the end of the week. Hopefully this will have resolved the issue I was experiencing above, but I will definitely let you know for certain. Will I need to change the Catches that I had previously from: catch (PayPal.PayPalException ex) to: catch (PayPal.PaymentsException ex)? Also, I know that there are two different ID's that a transaction gets. Which one is recommended that I store? I just wanted to ask for clarification, as I honestly wasn't sure. Thanks Again, |
You can, but it's not absolutely necessary. Catching try
{
// ...
}
catch (PayPal.PaymentsException ex)
{
// The API likely returned an error. Check ex.Details for more information.
}
catch (PayPal.PayPalException ex)
{
// Something else went wrong.
}
I'm guessing the two IDs you're referring to are payment ID and the transaction ID, correct? You're welcome to store either one, as each should allow you to access the other. The So it's up to you on which you'd rather store on your end. :) |
Thanks for the help with this. I was able to test a card number today using the new API and the necessary changes and I'm seeing the same thing. Running the program directly the credit card processing just hangs, it never processes, and it never throws an error... If I run it through VS in the debugger in order to determine what's going on and trouble shoot, it works perfectly... The card gets processed, the application reports this accurately, nothing hangs... It's really rather strange and appears as if the issue is actually occurring when the call is being made to process the card...? As some additional information, I built this as a Class that will process the credit card, so from my application, I am calling this class and handling the processing there. This then reports back with the Pass or Fail information and allows me to view the error itself or the Transaction ID and associated information. Originally, I thought the issue was that I was attempting to parse the response too soon, but I have even addressed the potential of that being an issue with a timer that checks to make sure there is a response before the response is parsed... When run from VS, there is a response. When run directly, there is never any response...? Thank you again for your help with this. I am really eager to get this working. |
@MLyons10 would you mind sharing the code you're calling? Also, just to clarify, this is only happening when running against the live service in Release mode? Running against the live service in Debug mode works? |
Sure. Please let me know your thoughts. And correct, it works when debugging, but not when released or the executable is run directly.
|
Those are both classes used for processing the payments through Paypal and getting the access token... If you would like me to post anything else, please let me know. Thanks, |
Hmm, I'm not seeing anything that immediately jumps out at me. Is the hang happening on the |
Hi jziaja, I believe so, but with me being unable to test this in the debugger, it's incredibly difficult to pin down. I don't know how better I can determine where this error is occurring... I want to try to build logging into the class so that I can get a .txt file or something detailing each line that completes, so I will try to do that over the weekend and will report back. But I don't understand what would be causing this given the code looks correct... If you think of anything else, please let me know as I'm willing to try anything at this point. |
Out of curiosity (and something I just noticed when looking back over your code), is there a reason you're running the payment code inside the |
I will try that. I thought that I needed to use a try / catch / finally in order to ensure that the access token was returned before running the payment... If that is not the case, I can try that and report back on that as well. Thanks, |
The If an exception is thrown when attempting to get an access token, or if the access token is an empty string (which is how your |
Alright, thanks. I will try that this weekend and will report back. Thanks, |
I tried removing the code from the Finally and including all of the code in the same try / catch block and get an error that the AccessToken cannot be null... My initial thinking was that the code will attempt to continue to run if all in the same block, so it could attempt to run the transaction before it has returned the AccessToken... That was why I originally had the card processing in the Finally... This is what the code looks like now.
|
When you create an With that said, can you share the exception details for the exception being caught in your private static string GetPayPalAccessToken(string _ClientID, string _Secret)
{
string PaypalClientID = _ClientID;
string PaypalSecret = _Secret;
string AccessToken = "";
try
{
OAuthTokenCredential tokenCredential = new OAuthTokenCredential(PaypalClientID, PaypalSecret);
AccessToken = tokenCredential.GetAccessToken();
}
catch (PayPal.IdentityException ex)
{
// ex.Details provides quick access to the API error information.
}
catch (PayPal.HttpException ex)
{
// Some other error occurred when attempting to send the request to PayPal.
// ex.Response contains the full response from the API which should highlight the error encountered.
}
catch (PayPal.PayPalException ex)
{
// A general exception was thrown from the SDK.
}
catch (System.Exception ex)
{
// Some other general exception occurred.
}
return AccessToken;
} |
Thanks jziaja, I appreciate your help. I added these catches and can confirm that no errors are being caught. When processing a payment now I get the following error: System.ArgumentNullException: Value cannot be null. It appears that it is now trying to process the payment before the AccessToken has been returned? When running the application in the debuger, the payment is able to process because it runs just a bit slower and has the AccessToken returned prior to processing the payment... This is why I initially had the code in a try / catch / finally. However at that time there was of course another issue that I'm still unsure of the cause of. |
Are you saying that the line |
@MLyons10 just checking in - are you still encountering this issue? |
I'm sorry, I haven't had a chance to get the code posted until now. To answer your questions, I am still having this issue, and it does appear to be tied presently to the fact that the AccessToken is returning an empty string. When I had this in a try / catch / finally, the payment processing code would not run until after the accesstoken had already been returned, so that was solving this issue, however then the payment was failing somewhere else. Here is my current code:
|
When the Also, have you tried enabling logging with your application? If you do, then whatever exception the SDK might be encountering will be logged for quick reference. |
I am catching an exception, however it doesn't fire an exception, as when running in the debuger the AccessToken method has adequate time to populate. This is not an issue of the AccessToken not being returned, it has to do with the fact that it is not returned fast enough. That is why structuring this code in a try / catch / finally as I had previously had it worked. I would argue that that is how a call should be structured in order to ensure that the AccessToken has been given adequate time to return a value prior to the card processing being done. I will look into enabling logging, however the current issue, which is easily fixed with a try / catch / finally will only be replaced with the original issue, which appears to be somewhere in the SDK, as the issue is occuring after leaving my code... There has to be something that is affecting the credit card processing only when code execution isn't delayed by the debugger. I have confirmed that all necessary values are properly being passed to the Class and structured properly in the call (Otherwise it would not work when being debugged). It is only when this information is passed to the SDK for payment processing that it fails, and then only when this is not delayed by the debugger. As you can see above, there are no issues with my code. I am unable to see anything that I can fix or change on my end to resolve the initial issue at all. |
Can you explain this a bit more? Even if there is a small delay in getting the Another option for your application - have you considered just getting the |
I'm working on some changes at the moment to try to see if I can get more information about this error. As it is a hang somewhere after submitting the payment, I'm not sure what I can really get here however... I did want to clarify a little bit the process I am using. Here is a detailed step by step through my code structure. Button Click: Now, assuming I handle the AccessToken appropriately and it has a value before the payment gets processed, this all works perfectly up until the payment is processed by the API. Also, I am not processing a bunch of requests at a time, there may be 2 or 3 on a busy day. It really wouldn't make sense to attempt to reuse an AccessToken that would expire before I needed it again anyway. They are larger transactions, ranging from a few hundred to a few thousand... |
Thanks for the clarification, @MLyons10! Does this process employ a single This SDK should be thread-safe; and if there's a specific part that's not, then I'll get that fixed. :) |
Certainly. I will put that together now. How would you like me to get that to you? Thanks, |
A Dropbox (or similar cloud storage) public link would be great! 👍 |
Hi jziaja, I put together that sample and it is exhibiting the same behavior. I built in some logging to log the catches when not being run in the debugger (Not sure why this didn't occur to me prior). Now, keep in mind that this issue is different from the issue I was experiencing prior, but I am logging an error that:
Now, I find this odd that it does still work when being run from within Visual Studio, but looking at my app.config file, I don't see anything that is wrong. But before I sent you over the demo project, I wanted to run this past you to see if anything jumps out at you here. That way I will know that I'm at least sending you something useful... <?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!-- PayPal SDK -->
<configSections>
<section name="paypal" type="PayPal.SDKConfigHandler, PayPal" />
</configSections>
<!-- PayPal account settings-->
<paypal>
<accounts>
<account apiUsername="v43-restpaypal_api1.paypal.com" apiPassword="xxxx"/>
</accounts>
<settings>
<add name="mode" value="live"/>
</settings>
</paypal>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration> The site wouldn't let me post the XML, so I removed the first < from each line to allow it to post... Thanks, |
I updated your comment with markdown tags for posting code and doing the syntax highlighting (here's a handy guide on how to do it). Which version of the SDK are you using? A bug was recently fixed in version 1.4.4 related to loading the config if you also have .NET 4.6 RC installed. |
Thank you for your help. I just updated to 1.4.4, however am still getting that error. Looking at the Config, I don't honestly see an issue... I did just try again, and from within Visual Studio, the credit card processes perfectly without any issues. It didn't even log an error in the error log... Here is a link to the ziped sample project: (removed) I really appreciate your help and hope this can be figured out. It is incredibly frustrating and I really don't know where else to look. I did try on other machines and it doesn't work on those either... Thanks Again, |
@MLyons10, I'm removing the link you posted for the project because I noticed you're using your live account credentials in the sample. I'll be testing this against sandbox. One more question - is your project for a web or desktop application? The sample project you provided is a WinForms application, which is fine for demonstration purposes; however, this SDK is meant to be used in a server environment where full trust can be established with the system. If your production system is considered to be a fully trusted environment, then disregard that question. :) |
Oh, I'm sorry, I meant to remove that... Thank you for removing that link. I am using this in a desktop application. Is that not supported? Do I need to do something differently? I do need to have PayPal Payment Processing in this application. |
If this is for a personal application, then that should be fine. If this is for an application that others will be running on other systems (e.g. POS systems), then that is not supported. The reason is that on a desktop environment (and mobile devices falls under the same umbrella), your account details used by the SDK are not considered to be secure - even if you embed the account credentials in your application. |
@MLyons10, I was able to get your project working, but it required a couple changes:
Also, using the Something else to consider: What happens if Do you mind trying out this version of your project and see if it works correctly for you? It includes the above fixes along with some other refactoring (I also moved the account credentials to the app.config file). I was able to use it to complete a number of test credit card transactions. Also, I hard-coded the test credit card details so I could quickly run it and test it out. |
I'm sorry about the delay. I will take a look at your post tomorrow. Thank you very much for your help. :) |
Closing this issue. Feel free to reopen it if you still feel like there's a problem with the SDK. Thanks! |
protected void Button1_Click(object sender, EventArgs e) Receiver secondaryReceiver = new Receiver((decimal?)2.00); Receiver primaryReceiver = new Receiver((decimal?)10.00); RequestEnvelope requestEnvelope = new RequestEnvelope("en_US"); payRequest.ipnNotificationUrl = "http://replaceIpnUrl.com"; payRequest.feesPayer = "PRIMARYRECEIVER"; string redirectUrl = null; if (!response.responseEnvelope.ack.ToString().Trim().ToUpper().Equals(AckCode.FAILURE.ToString()) && !response.responseEnvelope.ack.ToString().Trim().ToUpper().Equals(AckCode.FAILUREWITHWARNING.ToString())) when i am using this code I am getting this error An exception of type 'PayPal.Exception.HttpException' occurred in PayPalCoreSDK.dll but was not handled in user code Additional information: The remote server returned an error: (404) Not Found. |
@KushTiwari that appears to be an Adaptive Payment SDK integration, can you please add your issue here: https://github.com/paypal/adaptivepayments-sdk-dotnet |
I very well may be doing something wrong here, but I have noticed that the credit card processing is working flawlessly when run from within the debugger (VS), but when I run the application locally (With all dependencies carried over to the program folder), the payment doesn't process...
I realize this isn't much to go on here, and I'm willing to do whatever I need to in order to get this working, but has anyone else seen an issue like this? I have no idea where the issue could lie if it works perfectly fine within the debugger... There shouldn't be any difference in code execution at all...
I appreciate any insight or help anyone can provide here. I've been trying to figure this out for some time...
Thanks,
The text was updated successfully, but these errors were encountered: