braintree / braintree_dotnet

Braintree .NET library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
136 stars 73 forks source link

Test Nonces for Processor Rejected coming back with "result.IsSuccess() // true" #72

Closed franklintarter closed 6 years ago

franklintarter commented 6 years ago

General information

Issue description

I am writing integration tests for an online store. Currently, I am testing the non-happy path using the Processor_Rejected Nonces here but when I build a workflow it comes back with a successful result.

Note: I have other statuses being tested with the Valid, Gateway_Rejected, and Validation_Failure nonces, and those seem to be behaving correctly. It is only the nonces listed under Processor_Declined that are behaving unexpectedly for me.

As a side note, I wouldn't mind being able to test the TransactionStatus.FAILED with another nonce that triggers that type of failure, but perhaps there is a better way to spoof that than a nonce? If so I don't see a super obvious way to trigger that type of failure in the docs.

My code is something like this (it's currently split up into quite a few files via NUnit and test runners, but this is essentially the flow):

  var _btGateway = new BraintreeGateway(
    "sandbox", // env
    "my_id", // merchantId
    "my_public_key", // publicKey
    "my_private_key" //
  );

  // Do stuff to create order and transaction request

  var request = new TransactionRequest{
    PaymentMethodNonce = nonce, // This nonce I am injecting with my test harness, when I debug the values they are getting set correctly here i.e. "fake-processor-declined-visa-nonce"
    // other properties omitted for brevity
  };

  var res = await _btGateway.SaleAsync(request);

  if (result.IsSuccess()) {
    // do stuff
    // The "processor-declined" nonce requests are getting into this if block when I expect them not to
  }
  else
  {
    // do stuff
    // this is where I expect the Processor_Declined none requests to get
  }

Thank you so much in advance. So far everything in this SDK and the documentation is very top notch!

crookedneighbor commented 6 years ago

Those nonces are for card verifications, not transactions:

https://developers.braintreepayments.com/reference/request/payment-method/create/dotnet#card-verification

PaymentMethodRequest request = new PaymentMethodRequest
{
    CustomerId = "the_customer_id",
    PaymentMethodNonce = nonceFromTheClient,
    Options = new PaymentMethodOptionsRequest
    {
        VerifyCard = true
    }
};

Result<PaymentMethod> result = gateway.PaymentMethod.Create(request);

I'll pass along your feedback to our docs team to make that clearer. I can see how it is confusing.

franklintarter commented 6 years ago

Thank you for clearing that up, @crookedneighbor ! As a suggestion could there be the possibility of creating nonces to simulate processor response codes for Transactions? Or is using transaction amounts the only feasible way to test those response types with Transactions?

I can certainly get by and do adequate testing using transaction amounts. I would consider it a "nice to have" option to use nonces for some use cases. For example: a large integration test (almost end to end) that covers both internal order logic (where the price is set by products/discounts/taxes) and charging Braintree transactions.

Thank you for your time.

crookedneighbor commented 6 years ago

I'll pass your feedback on about the additional nonces, but that's not on our roadmap at this time.