opened
h2non
username_0
I'm creating a payout and with only one destinatary and the amount is sent three times and I don't know why. This is so estrange.

I'm just using the same code as in the examples:
```js
var params = {
  "sender_batch_header": {
    "sender_batch_id": "4f4ezsemi",
    "email_subject": "New payment from Guidecentral"
  },
  "items": [
    {
      "recipient_type": "EMAIL",
      "receiver": "test@email.com",
      "note": "Thank you for",
      "sender_item_id": "Test title",
      "amount": {
        "value": 0.1,
        "currency": "EUR"
      }
    }
  ]
}
```

And then I call:
```js
paypal.payout.create(params, 'true', callback)
```

This is generating duplicated payments. I can confirm that the payment was recieved multiple times by the destinatary. This is happening in production `live` mode
Payouts is sending duplicated payments
issue
created
avidas
username_1
Hey @username_0 , do you have the [debug_id](https://github.com/paypal/PayPal-node-SDK#debugging) for a case where the payment was received multiple times? Would really help us to get to root cause.
comment
created
h2non
username_0
I got two `debug-id` when running the script:
```
paypal-debug-id: 3b682f067c319
paypal-debug-id: 7af7a818b7277
```

As I said, it happen when running as `live` mode
comment
created
avidas
username_1
Hey from the logs it looks like there is logic from your app that are retrying failed payouts. These payouts have failed due to insufficient funds on the merchant account and the recipients should not have received  any money. If you have reasons to believe that what we are seeing is incorrect, please reach out to https://ppmts.custhelp.com for accounts related issues.
comment
created
h2non
username_0
Despite the last debug, it was due to missing funds. 
Now I tried it again with funds, and the transaction was success, but the amount was sent 4 times.

Curiously, it generates only two `debug ids`:
```
paypal-debug-id: 4ba5be5ced36a
paypal-debug-id: de7f22efee0d3
```
comment
created
avidas
username_1
We are seeing four individual calls for payouts from our end and these are the debug ids for each are 7876c5ba58346, 55da39d1e0d65, c072fa30e002f, de7f22efee0d3. Are you just running the script separately or inside your app? Are you able to reproduce the issue with just individual CURL request to create a payout?
comment
created
h2non
username_0
I'm running it in a dead simple one-file script, based on your payouts example, like:
```
node pay.js
```

To be more specific, here's the script I'm actually running:
```js
var paypal = require('paypal-rest-sdk')

paypal.configure({
  'mode': 'live',
  'client_id': 'super-client-id',
  'client_secret': 'super-client-s3cret!' 
})

var payout = function (items, callback) {
  var batchId = Math.random().toString(36).substring(9)

  var items = items.map(function (item) {
    var amount = +(+item.amount || 0).toFixed(2)

    return {
      'recipient_type': 'EMAIL',
      'receiver': item.email,
      'note': 'Test note.',
      'sender_item_id': 'Test sender',
      'amount': {
        'value': amount,
        'currency': 'EUR'
      }
    }
  })
  .filter(function (payment) {
    return payment != null
  })

  var payoutParams = {
    'sender_batch_header': {
      'sender_batch_id': batchId,
      'email_subject': 'New test payment'
    },
    items: items
  }

  paypal.payout.create(payoutParams, 'true', callback)
}

// test it!
payout([{
  email: 'me@mail.com',
  amount: 0.05
}], function (err, res) {
  console.log(JSON.stringify(res, null, 2))
})
```
comment
created
h2non
username_0
I've just noticed the error with my script. The `items` variable is reused.
comment
created
h2non
username_0
The problem persist. It continues sending duplicated payments. Here're the new debug ids:
```
paypal-debug-id: f185bc5ee3c1b
paypal-debug-id: 3706cc464bedd
```

The `items` array has only length 1, so I don't understand why this happen. The **payment the made 4 times** as well
comment
created
avidas
username_1
Sorry to be asking for more tests, but this is different from the behavior you notice with curl requests? https://developer.paypal.com/docs/api/#create-a-batch-or-single-payout
comment
created
h2non
username_0
I made some debugging in the library, and there're only two outgoing requests: the first one for the oauth2 autorization, and the second one is a `POST` request to `/v1/payments/payouts`.

So the problem is not (probably) on the client side, which is thing that concerns me. 
Could you scale this issue to dig into it in more detail? I can provide specific identifiers about the payments done.
comment
created
h2non
username_0
Any news about this?
comment
created
avidas
username_1
We thought it was likely that the issue was client side, perhaps some sort of retry logic. The logic could be getting invoked if the response from paypal is delayed, and since it gets resend with a different batch id, (its generated by using random so it would be different with each retry), on the server side it seems like separate payout requests are being made and hence multiple payouts are getting made. This is one possible scenerio of course, but seems to be a likely one as an issue like this server side would be felt by many more clients.
comment
created
h2non
username_0
Thanks for the reply. That sounds a bit estrange. I don't have a clear idea about the retry logic, just because the status code is 400, instead of 500-600, so there isn't needed any kind of retry.

So... what's the solution? Any specific idea to dig into it in detail?
comment
created
avidas
username_1
Unfortunately, this is the best we can offer in debugging this, since multiple debug ids are getting received, there are likely multiple requests being made somehow, likely via retries.
comment
closed
avidas
username_1
issue