Skip to content
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

"Transaction failed. Please select a different payment method." error not translated #406

Closed
davidetan opened this issue May 31, 2018 · 3 comments

Comments

@davidetan
Copy link

General information

  • SDK/Library version: 1.10.0
  • Environment: Sandbox
  • Browser and OS 66.0.3359.181 (64-bit) on Ubuntu 18.04

I have a very basic setup. My server exposes two enpoints:

  • /client_token: to get the token for the dropin-ui initialization
  • /checkout: to perform the transaction once obtained a nonce

These following code snippets show my setup:

SERVER

server.get('/client_token', async () => {
   const token = await gateway.clientToken.generate({
    customerId: CUSTOMER_ID,
    options: {
      failOnDuplicatePaymentMethod: true,
    }
  })
    .then(({ clientToken }) => {
      if (clientToken) {
        return clientToken
      }
      return gateway.clientToken.generate({
        options: {
          failOnDuplicatePaymentMethod: true,
        }
      })
        .then(({ clientToken }) => clientToken)
    })
  return token
})

server.post('/checkout', async ({ body }, res) => {
 // ...
})

CLIENT

<html>
<head>
  <meta charset="utf-8">
  <script src="fetch.js"></script>
  <script src="https://js.braintreegateway.com/web/dropin/1.10.0/js/dropin.min.js"></script>
</head>
<body>
<div id="dropin-container"></div>
<button id="submit-button">Paga</button>
</body>
/<html>
var button = document.querySelector('#submit-button')
fetch('/client_token')
    .then(res => res.text())
    .then((clientToken) => {
      braintree.dropin.create({
        authorization: clientToken,
        container: '#dropin-container',
        paypal: {
          flow: 'vault',
        },
        locale: 'it_IT',
      }, function (createErr, instance) {
        button.addEventListener('click', function () {
          instance.requestPaymentMethod(function (requestPaymentMethodErr, payload) {

            if (requestPaymentMethodErr) {
              console.log(requestPaymentMethodErr)
              return
            }

            fetch('/checkout', {
              method: 'POST',
              headers: {
                'Content-Type': 'application/json'
              },
              body: JSON.stringify({
                nonce: payload.nonce,
              })
            })

These are my requirements:

  • Dropin-ui completely localized in italian
  • No card duplication is allowed (failOnDuplicatePaymentMethod set true during token generation)

Everything works fine, but my first requirement is not met since the error Transaction failed. Please select a different payment method. is shown whenever a card already present in the vault is inserted.

In the translation file I did not find this error, so I was not able to give to the dropin-ui my own translation for this error.

Is it possible to add this error to the translation file?

@crookedneighbor
Copy link
Contributor

Can you tell me where you are getting Transaction failed. Please select a different payment method.? That doesn't look like part of Drop-in's code, as it has no knowledge of the state of a Transaction.

When I use the code you provided, I get this screen as expected:

screen shot 2018-05-31 at 9 19 01 am

Here's the Italian version:

screen shot 2018-05-31 at 9 22 16 am

Can you share a github repo that can reproduce this error?

And, finally, just a few notes about your server code:

  1. The failOnDuplicatePaymentMethod option requires a customer id, so this will always fail with an error that states A customer id is required for the following options: failOnDuplicatePaymentMethod (at least in version 2 of the Node SDK).
return gateway.clientToken.generate({
   options: {
     failOnDuplicatePaymentMethod: true,
  }
})
  1. Just to clarify, the failOnDuplicatePaymentMethod option is vault wide. So if you have 2 customers in the same family using the same credit card, it'll fail when the second customer tries to add the same card. You may already know this, but many people using the option don't realize that.

Also, Drop-in will automatically filter out duplicate cards (showing the one with the most recent expiration date) when showing saved payment methods to the customer. So you may not even need to pass that option.

@davidetan
Copy link
Author

davidetan commented Jun 1, 2018

First of all, thanks crookedneighbor for your quick answer.

I am aware of point 2, thanks anyway for the clarification.

Regarding point 1, I actually gave you a restricted version of the code I am using. In the actual version, prior to token creation, the customer is searched in the vault. If it does not exists, a customer is created.

I need to avoid the possibility to insert the same card for multiple users since in my use case there is a 10€ discount on the first order. So generally the same customer creates more users and insert the same cart. So, this is a way to prevent this abuse.

Anyway, for the problem I have, I set up the following repo.

In the readme I explain how to reproduce the problem.

@Epreuve
Copy link
Contributor

Epreuve commented Jun 1, 2018

Thanks for setting up that demo for us. We took another look and confirmed the hostedFieldsTokenizationFailOnDuplicateError was added in v1.11.0.

Upgrading to this version should render this newer more accurate message in this scenario.

I'm going to close this, but feel free to leave a comment if this doesn't work for you.

@Epreuve Epreuve closed this as completed Jun 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants