braintree / braintree_dotnet Goto Github PK
View Code? Open in Web Editor NEWBraintree .NET library
Home Page: https://developer.paypal.com/braintree/docs/start/overview
License: MIT License
Braintree .NET library
Home Page: https://developer.paypal.com/braintree/docs/start/overview
License: MIT License
Following error occurred while updating Braintree .Net SDK from 2.64.0 to 3.4.0 for .Net framework version 4.5.1 (VS2015 CE edition)
I know that the latest version is available for .Net framework version 4.5.2 but I don't want to update my application framework version due to other dependencies.
Could not install package 'Braintree 3.4.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
Please help.
Thanks,
Dharmendra
The API provides a reasonable interface to Braintree.
However none of the classes for this are interfaced. This makes it hard to apply Dependancy Injection and to mock the classes. If they can't be mocked then unit testing is substantially hampered.
In order to unit test a series of calls to the Braintree API, I'd need to implement a Facade that is interfaced, just so we can mock the calls to the API. It ends up being a lot of plumbing being written due to an oversight.
For more complex scenarios, unit testing is a must. It's certainly a best practice for current software development practices.
When unit testing the service I have wrapped the Braintree SDK in, I am able to mock the ValidationErrors
object returned from the Result<Transaction>
interface but not the DeepAll()
method that I use to retrieve the list of errors for a transaction.
It would be useful to have virtual method so DeepAll()
can be mocked.
Build passes
Build fails with the following error (sorry for the screencap!)
Removing the "buildOptions": { "keyFile": "../../../braintreeSgKey.snk" },
in the project.json
file fixes the problem
Luckily, most of the library uses the same core call methods to abstract the http/xml parts away, but they'd need to be adapted. To start with, an async
/Task<XmlNode>
version of BraintreeService.GetXmlResponse
would have to be made with the following changes:
HttpWebRequest.GetRequestStreamAsync()
instead of HttpWebRequest.GetRequestStream()
Stream.WriteAsync()
instead of Stream.Write()
Stream
should be disposed instead of calling Stream.Close()
HttpWebRequest.GetResponseAsync()
instead of HttpWebRequest.GetResponseAsync()
HttpWebResponse.Close()
could also possibly be eliminated by disposing the response, but this isn't documented (it might take some investigation)I'm interested in submitting a pull request implementing this, but I'd like some feedback first to make sure the async
versions of each method are how you'd all like them to be, although I'd figure it'd be the normal: return value encapsulated in Task<>
, method marked async
, "Async" appended to method name.
It would be nice to be able to do
switch (notification.Kind) {
}
but WebhookKind is a custom defined "Enumeration" instead of a true Enum, so this cannot be done.
namespace Braintree
{
public abstract class Enumeration
{
protected string Name;
protected Enumeration(string name);
public override string ToString();
}
}
is it because you are trying to support ALL?
I'm using Braintree 2.40.0
and when I call this gateway.Transaction.Sale(transactionRequest)
method I got this error
The request was aborted: Could not create SSL/TLS secure channel
The example provided on the first page of this repo worked immediately with no issues but no payment_method_nonce required, so according to the support folks at Braintree, this method is not secure. Is there a method(s) in this api to securely transfer credit card information? Is there a method in the api that creates the payment_method_nonce?
As a DBA responsible for our Data Warehouse, I want to be able to pull Customer and Subscription objects by UpdatedAt date ranges so that I only pull modified/new records. Currently, our sync takes 10 hours - because we sync ALL the Subscription and Customer records since we don't know if any updates have occurred. I was told that this isn't necessary with Transactions - that they're never updated, only created. If that isn't true, then we'd need to be able to grab by UpdatedAt ranges, too.
PLEASE add this functionality.
Thanks!
PaymentMethodOptionsRequest in v2.65.0 does not have a VerificationAmount property as shown in the documentation.
We tried to transition to .NET Core 1.1 runtime
We keep getting issues with the:
/usr/share/dotnet/sdk/1.0.0-preview4-004233/NuGet.targets(70,5): error : Package Microsoft.AspNet.WebUtilities 1.0.0-rc1-final is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package Microsoft.AspNet.WebUtilities 1.0.0-rc1-final supports: [/var/www/wkd-dotnet/src/Wkd/Wkd.csproj]
/usr/share/dotnet/sdk/1.0.0-preview4-004233/NuGet.targets(70,5): error : - dotnet5.4 (.NETPlatform,Version=v5.4) [/var/www/wkd-dotnet/src/Wkd/Wkd.csproj]
/usr/share/dotnet/sdk/1.0.0-preview4-004233/NuGet.targets(70,5): error : - net451 (.NETFramework,Version=v4.5.1) [/var/www/wkd-dotnet/src/Wkd/Wkd.csproj]
/usr/share/dotnet/sdk/1.0.0-preview4-004233/NuGet.targets(70,5): error : One or more packages are incompatible with .NETCoreApp,Version=v1.1. [/var/www/wkd-dotnet/src/Wkd/Wkd.csproj]
It seems your dependency of Microsoft.AspNet.WebUtilities 1.0.0-rc1-final
is causing the issue.
Do you have plans of supporting 1.1 out of the box?
So far the dotnet restore
fails on our project but strangely it still builds successfully.
Hello,
I was trying to get your new dll to work with .NET 4.0. The only way to currently use your dlls is upgrade your project to .net 4.5.2 but some projects dont allow for that pleasure in production. I thus downloaded the source of braintree 3.5 to downgrade it to 4.0 and it didnt compile.
The source code below does not compile.
https://github.com/braintree/braintree_dotnet/archive/3.5.0.zip
It complains of 3 bugs with WebUtility.UrlDecode(). This function doesnt exist in WebUtility.
I got it to work once I resolved the 3 issues. However does WebUtility.HtmlDecode() solve what you needed it to?
By adding this property to the interface and implementing it in the inheriting classes, the type of the payment method can be determined without using reflection. This is important because all of the constructors are protected internal
for the models making it impossible to test code that consumes the returned models without using dynamic
and mocking new models. This technique makes it impossible to use reflection to determine what kind of payment method was created.
The property PaymentInstrumentType
should match what is on the Transaction
model and use the existing enumeration.
Is there a reason why the methods in ClientTokenGateway.cs are camelCased? This seems to go against the standard .NET naming convention and is inconsistent with other methods in this library.
Ran into this issue today when I was testing adding a customer (but seen this with other gateway methods as well): When the merchant ID and keys are missing and I call gateway.CreateCustomer() I get a null reference exception.
An exception here is fine, but it'd be nice if it wasn't a null reference exception but something that told me what actually wasn't set.
Scenario: The merchant ID info is set from configuration in my case and I forgot to set the config settings when I switched to a different setup. So when the exception hit I didn't know immediately where to look. I had to trace through each object to find the issue.
Just saying ;). This isn't even documented though.
The async operations still use blocking calls while their non-blocking equivalent is available for .NET 4.5.
#55 is an attempt to fix this along extra optimizations.
Here is the error I am getting:
Package Microsoft.AspNet.WebUtilities 1.0.0-rc1-final is not compatible with netstandard1.6 (.NETStandard,Version=v1.6). Package Microsoft.AspNet.WebUtilities 1.0.0-rc1-final supports:
- dotnet5.4 (.NETPlatform,Version=v5.4)
- net451 (.NETFramework,Version=v4.5.1)
One or more packages are incompatible with .NETStandard,Version=v1.6.
I have had nothing but struggles trying to integrate Braintree webhooks into my Web API. The .net documentation only focuses on MVC apps, but does not clarify subtle differences with a Web API. It took me days to figure out I need to strip out an additional character that is being added to the payload:
hook.bt_payload.Replace("\\n", "\n")
Would it not be better to support a json payload type with base64 encoding? x-www-form-encoded does not fit all needs and is error prone.
After copy/pasting the example from the README I ran into the following compilation error.
Cannot implicitly convert type 'Braintree.CreditCardRequest' to 'Braintree.TransactionCreditCardRequest'
Changing the type of the test credit card from CreditCardRequest to TransactionCreditCardRequest resolved the problem. I am happy to put a pull request together, but wanted to make sure it addresses the real problem. If I am reading the log correctly things diverged in e6179f5. Given that the commit is close to five years old I just wanted to make sure there is not something else going on here I don't understand.
I am attempting to retrieve the BinData (referenced in the documentation here: https://developers.braintreepayments.com/reference/response/payment-method-nonce/dotnet) from the PaymentMethodNonce.FindAsync() response but it doesn't seem to be a part of the strongly typed model (at least in version 3.9.0 of the nuget package). I see the data is actually being returned from the endpoint but it isn't being made available from the c# model.
Is this something that is planned for a future release or would you accept a pull request to add BinData to the PaymentMethodNonce model?
Seems that there is no support for TLS 1.2 with current implementation in Mono. At least not at the server side (ASPX).
Calling gateway.ClientToken.generate() generates:
Mono.Security.Protocol.Tls.TlsException
The authentication or decryption has failed.
Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): Mono.Security.
Exception stack trace:
at Mono.Security.Protocol.Tls.RecordProtocol.EndReceiveRecord (System.IAsyncResult asyncResult) [0x0003a] in /private/tmp/source-mono-4.8.0/bockbuild-mono-4.8.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/RecordProtocol.cs:430
at Mono.Security.Protocol.Tls.SslClientStream.SafeEndReceiveRecord (System.IAsyncResult ar, System.Boolean ignoreEmpty) [0x00000] in /private/tmp/source-mono-4.8.0/bockbuild-mono-4.8.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslClientStream.cs:256
at Mono.Security.Protocol.Tls.SslClientStream.NegotiateAsyncWorker (System.IAsyncResult result) [0x00071] in /private/tmp/source-mono-4.8.0/bockbuild-mono-4.8.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslClientStream.cs:418
Version Information: 4.8.0 (mono-4.8.0-branch/e4a3cf3 Fri Feb 17 15:57:45 EST 2017); ASP.NET Version: 4.0.30319.42000
The core version of library has dependency to Microsoft.AspNet.WebUtilities 1.0.0 rc1 final.
Shouldn't it be migrated to stable version Microsoft.AspNetCore.WebUtilities 1.1.1 ? or 1.1.0
There are many (about 27) Enumeration types in the Braintree .net client library. Each of them needs to write a custom serialization/deserialization logic.
e.g. Various Status(e.g. SubscriptionStatus, TransactionStatus)
I understand the reason is .net enum is serialized to integer and Braintree Api wants string.
But there are two ways to solve this enum-as-string problem:
Use NewtonSoft.json, the de facto .net standard for serialization, which has built-in StringEnumConverter to serialize enum as string.
Use plain string, e.g.:
public class TransactionStatus
{
public static readonly string AUTHORIZATION_EXPIRED ="authorization_expired";
public static readonly string AUTHORIZED = "authorized";
public static readonly string AUTHORIZING = "authorizing";
...}
Build and maintain 27 custom serialization/deserialization logic is a daunting task, and may not work in some scenarios.
gacutil.exe - "Failure adding assembly to the cache: Attempt to install an assembly without a strong name"
At present you can't rely on the Target property of the Result to always be populated. Ideally this property should always be populated and be consistent.
If this is a design decision that won't change then the documentation and samples should be updated to clearly note this behaviour.
I first need to test for Success or Failure and then depending on scenario treat the Result object differently.
As an example:
var brainTreeResponse = gateway.Transaction.Sale(btRequest);
// On success = Transaction Object | on failure = null.
var transactionTarget = brainTreeResponse.Target;
// On success = null | on failure = Transaction Object.
var transactionProperty = brainTreeResponse.Transaction;
ClientTokenRequest has 2 generate methods with same signature.
Using in VB.NET is causes error as its not case sensitive
error BC31429: 'Generate' is ambiguous because multiple kinds of members with this name exist in interface 'IClientTokenGateway'.
It seems there is an issue with the SDK or API when retrieving Subscription.StatusHistory
.
All history items contains the PlanId
of the last status PlanId
.
This follows on from #11, where you converted a number of the gateway classes to use interfaces. There is still a bit more work to make the library easily testable. This comes down to:
Transaction
- this has a reference to BraintreeGateway
when IBraintreeGateway
would suffice).Transaction
) so that they can be mocked. There are two obvious ways to achieve this:
ITransactionGateway.Sale
returns Result<ITransaction>
instead of Result<Transaction>
. I appreciate this is more complex due to your implementation of ResultImpl<>
At present, it is technically possible to mock the result of calling an operation on your gateway, but to do this we have to create an XmlNode containing the properties that your constructor expects (which we have to guess based on your code) and pass this into the protected constructor.
Support async/await model on all API operations.
Stack Trace:
Http WebRequest POST https://api.braintreegateway.com:443/merchants/XXXXXX/transactions
HttpWebRequest.GetResponse POST https://api.braintreegateway.com:443/merchants/XXXXXX/transactions
System.Net.WebException: The remote server returned an error: (422) Unprocessable Entity.
at System.Net.HttpWebRequest.GetResponse
at System.Net.HttpWebRequest.GetResponse
at Braintree.BraintreeService.GetXmlResponse
HttpWebRequest.ResponseReceived Response: Unprocessable Entity
braintree_dotnet
V 2.59.0
The above issue is not reproducible on our DEV/Staging but recorded in our production environment. Did any one encountered the same or help us why this is happening?
Thanks,
Ravi.
All asynchronous API methods should support cancellation token. There is no need to finish API request, when there is nobody to get result, so async should be able to be cancelled.
I'm updating from 2.52.0 to 3.4.0 to comply with latest TLS changes.
I have the Braintree library installed in class project. Nuget fails to add it because I need a reference to System.Web.
Looking at the source looks like System.Web is included but not used.
Can we remove this dependency?
My requirement is to pass all values from view to controller via jquery ajax call only. How to pass all values using jquery ajax calls and assign it to ur api in controller?? Before going to pass how should I encrypt these datas using your functions????
Please provide samples or links regarding my doubt
Of the 528 unit tests in the solution, 382 of the tests fail.
Most of them failing to connect 127.0.0.1:3000. Are these unit tests or functional/integration tests tests? They look to be a mix of the two.
If this is trying to connect to a development server on the, what is required to get the development server running on a desktop? This might just be a gap in documentation.
Version 3.9.0 of the Braintree .NET Client Library (installed via the NuGet Package Manager) seems to have a change that breaks it for VB.NET. Unlike C#, VB.NET is not case sensitive so does not permit two methods with the same name that differ only in upper/lower case letters. The ClientToken.Generate method now gives the following error preventing compilation:
'Generate' is ambiguous because multiple kinds of members with this name exist in interface 'IClientTokenGateway'.
The Braintree IClientTokenGateway interface appears to declare the following methods:
The two methods “Generate” and “generate” are treated as different by C#, but they are seen as the same in VB.NET - hence it is ambiguous as to which one is being referenced and therefore gives the error reported above.
I would much rather be using C# but legacy code makes that impractical!
Over the past few days, we have been receiving a lot of connection timeout errors (50+). Can the library automatically retry if a connection can't be established in a reasonable time period (i.e. 30 seconds) -- it's currently using the .NET default of 60 seconds, or allow the timeout to be configured so retry function can be added up the stack.
Stack Trace:
System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: 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 204.109.13.121:443
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at Braintree.BraintreeService.GetXmlResponse(String URL, String method, Request requestBody)
at Braintree.BraintreeService.Post(String URL, Request requestBody)
at Braintree.TransactionGateway.Sale(TransactionRequest request)
The dotnet SDK currently includes properties for all of the Dispute fields that are described in the documentation. There are several other properties that are included in the raw Transaction/Disputes API response, but there is no way to access these values.
I really only need access to updated-at and the status-history values, but might as well include everything.
Hi,
Is there a way to distinguish whether the user (iOS) selected his Paypal or his Credit Card payment method? I need this on my Server (.Net) when making the sale since right now I authorise OK for 3D Secure cards but fail when Paypal with the error "Cannot 3D Secure a non-credit card payment instrument".
Right now, since I can't distinguish between the 2, I always have the ThreeDSecure TransactionOptionsRequest Required property to true, and it causes it to fail when it's a Paypal nonce.
Hi, I need help using Braintree with Xamarin. I have no idea how to add credit card and get nonce (I 'm able to create CardBuilder, but when I try to do Card.Tokenize(braintreeFragment, cardBuilder), I have no idea how to get Nonce from Braintree). Please help me.
Thanks
Got a null pointer in 2.4 when calling cancel subscription against the sandbox (subscription is successfully cancelled on sandbox side):
Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object. at Braintree.CollectionUtil.Find(Object[] items, String name, Object defaultValue) at Braintree.StatusEvent..ctor(NodeWrapper node) at Braintree.Transaction..ctor(NodeWrapper node) at Braintree.Subscription..ctor(NodeWrapper node) at Braintree.Result`1.newInstanceFromResponse(NodeWrapper node) at Braintree.Result`1..ctor(NodeWrapper node) at Braintree.SubscriptionGateway.Cancel(String id)
Proxy server does not allow credentials to be specified.
Please expose IWebProxy property instead, allowing something along the lines of:
client.Configuration.WebProxy = new WebProxy("http://some.proxy.server:3128/", false, null, new NetworkCredential(user, password));
or in our case:
client.Configuration.WebProxy = DependencyInjector.Resolve<IProxyFactory>().GetProxy();
I'm looking at the Webhooks documentation here:
https://developers.braintreepayments.com/javascript+dotnet/guides/webhooks
and trying to implement a controller using this code. However, I can't seem to localte the reference to the Constants object - where does this type/namespace live? Searching the BrainTree assembly I also don't see this anyway.
I can't figure out where to get .Parse() to work from...
What am I missing?
Hi,
I'm just testing cancel subscription and response is inconsistent. I'm expecting to check IsSuccess() to see if error has occured as this is the approach for all other methods Transaction and subscription but I get the following error which I consider as inconsistent response behavior:
Result Message: Braintree.Exceptions.NotFoundException : Exception of type 'Braintree.Exceptions.NotFoundException' was thrown.
Result StackTrace:
at Braintree.BraintreeService.ThrowExceptionIfErrorStatusCode(HttpStatusCode httpStatusCode, String message)
at Braintree.BraintreeService.GetXmlResponse(String URL, String method, Request requestBody)
at Braintree.BraintreeService.Put(String URL, Request requestBody)
at Braintree.BraintreeService.Put(String URL)
at Braintree.SubscriptionGateway.Cancel(String id)
at
Do you plan to fix this and make it consistent or there are some other reasons to throw exception here ?
Regards
Hi
I have been busy integrating your payment system into my website, can I just make a few points about my experiences while integrating your components...
I am using the JavaScript/.NET combination and downloaded your Braintree-2.40.0.dll (and tried the Nuget version too). It isn't signed. I have signed all my dlls in my website as this provides a high level of protection against tampering. However, your dll isn't signed and will not run in my website. I did mange to use ILMerge (a Microsoft assembly integration tool) to sign it with my key however it did take most of an evening and would be beyond most developers.
Perhaps you can provide a signed version of the dll please. It is just one checkbox in the project properties along with a key which you can generate on the same page or buy one. Signed dlls can be used with unsigned dlls, just not the other way round
On the website the search feature doesn't find .Net API.
Additionally, it would be helpful to have a description of what the method does rather than having to guess, e.g. https://developers.braintreepayments.com/javascript+dotnet/reference/request/transaction/find
Intellisense on methods would also be helpful
(both of which can be automatically generated by doing /// on the line in front of each method (or ‘’’ for VB.NET) and using a help generation tool (of which there are many quality free ones)
Despite these small niggles, congratulations on providing an interface that “just works”.
Jonathan
we are working on integration of braintree marketplace in nopcommerce
I have to implement the merchant on-boarding functionality.
but we dont find the object MerchantAccountRequest & some properties in TransactionRequest in dot net sdk which are mention here.
https://developers.braintreepayments.com/guides/braintree-marketplace/onboarding/dotnet
https://developers.braintreepayments.com/guides/braintree-marketplace/create/dotnet
Please suggest what we are missing here Or for marketplaces you have any other .Net Sdk or Api
I'd like to aks if it would be possible to change dll name to not contain version number, to be standard with any other .NET DLL.
Hi,
I'm currently serializing a WebhookNotification to so I can add the message to my Azure Service Bus. However it appears that the kind property is not serialized correctly, it comes out as blank:
{ "Kind":{}, "Subscription" :null, ....... }
Is it possible to allow the Kind value to be serialized so that I can have a full copy of the notification stored?
I'm using Json.Net's JsonConvert.SerializeObject method to serialize the object.
And then subsequently can you allow the json string to be deserialized back to the WebhookNotification object?
Thanks
Reproduce by creating a new ASP.NET5 project.
Add Braintree nuget package.
Reference won't be added for .NET platform 5.4 but only for 4.5.1(.Net 4.6).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.