Result.Credit_Card_Verification Is Returning Nil Even on Error in Braintree

result.credit_card_verification is returning nil even on error in braintree

I work at Braintree. If you'd like more help than you can get here on Stack Overflow, please reach out to our support team.

Handling Braintree result objects is progressive.

If result.success? is false, then you check for result.errors, which represent validation errors.

If result.errors is nil, then the request was valid. In this case, you will have a transaction or verification object just as if result.success? was true.

You can then look at the result.verification's status, processor_response_code, gateway_rejection_reason, etc.

The linked documentation provides more details on handling error results.

credit card verification not working with braintree and rails

Braintree will only run the verification if the passed parameters are valid, and only return the verification if it failed.

In your first example (now edited out of your post), the creation failed because you didn't pass valid parameters.

In your second example, the verification succeeded so it isn't returned.

You can simulate these different conditions in the Sandbox by using an invalid card number or one of the Sandbox credit card numbers or unsuccessful verification numbers.

Example:

result = Braintree::Customer.create(  
:credit_card => {
:number => "4000111111111115",
:expiration_month => "10",
:expiration_year => "2014",
:cvv => "200",
:options => {:verify_card => true}
}
)

if result.success?
# handle success
elsif result.credit_card_verification
p verification.processor_response_code
p verification.processor_response_text
else
# use result.errors to see what part of the request was invalid

How to change normal form which is linked with active merchant to Braintree dropin-ui?

Disclaimer: I work at Braintree.

Short answer: you can't. The Drop-in is meant as a secure replacement for a credit card form you host. To use the Drop-in, you should take out the entire credit card section of your form and account model, and—instead of expecting to handle and store credit card data—receive a payment method nonce returned by the Drop-in and use it via the Braintree transaction or payment method API.

Long answer: the Drop-in is a pre-built form hosted by Braintree that we'll insert via an iframe into a form on your page. When the form is submitted, the credit card (or PayPal, etc) information from the Drop-in is sent to Braintree, and a payment method nonce is returned to your page (either via a JavaScript callback or inserted into a hidden field in your form.) The nonce is a randomly-generated string that stands in for the payment info, and can be passed through your application without security risks. Check out the Braintree developer docs for more details and sample code.

The primary reason for all this is security. It's against industry regulations (called the PCI security standards) to store credit card information in a non-secure environment, and it is against PCI regulations to ever store the CVV/security code of a credit card. Even having credit card data passing through your site can put it at risk. The Drop-in (or our Hosted Fields integration) makes it much easier to meet PCI standards and reduces the burden on you of securing your site.

To sum up: you should remove the integration of customer credit cards from ActiveMerchant and not include them in your schema at all. Instead, include a blank div in your form for the Drop-in to be inserted into, and use the payment method nonce the Drop-in returns in your model/controller. How you integrate the nonce, server-side Braintree API calls, and their results into your rails model is up to you. We have a full example rails app that uses the Drop-in: feel free to take a look at the braintree_rails_example repo on the Braintree github page for ideas.

How to implement a payment app with Braintree in iOS

Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.

You can access the payment method nonce via the result object within showDropIn(). This is also where you may call postNonceToServer().

func showDropIn(clientTokenOrTokenizationKey: String) {
let request = BTDropInRequest()
request.amount = "\(total)"
request.currencyCode = "MXN"
let dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
{ (controller, result, error) in
if (error != nil) {
print("ERROR")
} else if (result?.isCancelled == true) {
print("CANCELLED")
} else if let result = result {
let selectedPaymentMethod = result.paymentMethod! // retrieve the payment method.
self.postNonceToServer(paymentMethodNonce: selectedPaymentMethod.nonce) // call postNonceToServer() with the nonce from the selected payment method.
}
controller.dismiss(animated: true, completion: nil)
}
self.present(dropIn!, animated: true, completion: nil)
}

After you successfully call postNonceToServer() you can receive the payment method nonce and create a transaction on your server.



Related Topics



Leave a reply



Submit