#shammah-ach

1 messages · Page 1 of 1 (latest)

past cloak
past cloak
dense heathBOT
#

This thread has been archived. If you need help with anything else please ask in #dev-help or contact Stripe Support: https://support.stripe.com/contact

tired flicker
#

@paper hedge I've reopened this thread for you!

paper hedge
#

Thank you

#

I'm using a destination charge, so there was a transfer and a transfer reverals. I'm trying to figure out where the balance_transaction is for the actual bounced payment.

#

Refunds list on the original charge that failed is empty:

    refunds: {
      object: 'list',
      data: [],
      has_more: false,
      total_count: 0,
      ...
    }
#

It seems like the only way to do this is to get all the balance transactions, look at the sources, if it's a refund, look at the chargeId, make your own map and go from there. But this is not a great solution

tired flicker
#

Do you happen to have a failling ACH charge handy? I'm not the most familiar with the reversal in this situation, and looking at an example will help

paper hedge
#

Yes.

#

This is the API call I'm making:

    const transfer = await stripe.transfers.retrieve('tr_3JmgpcAN9UGzw70g0kwwAh0o', {
      expand: [
        'source_transaction',
        'source_transaction.balance_transaction',
        'reversals',
        'balance_transaction',
        'destination_payment',
        'destination_payment.balance_transaction',
        'destination_payment.refunds',
      ],
    });

And here's the balance_transaction for the failed charge: txn_1JmPHLAN9UGzw70g8aH6t4qT

I'm trying to find the balance_transaction on the subaccount associated with the transfer_reversal for the failed payment

#

destination charges have been nice, but ensuring money is returned on failed charges and refunds seems rather confusing

silk bison
#

@paper hedge so what's blocking you exactly?

#

Like when you retrieve that Transfer, you should see the reversals collection, and that has the trr_123 with destination_payment_refund in it with all the BTs you want

paper hedge
#

It shows the subaccount BTs, but not the platform account bts for the charge failure

silk bison
#
    expand: [
      'source_transaction',
      'source_transaction.balance_transaction',
      'reversals',
      'balance_transaction',
      'destination_payment',
      'destination_payment.balance_transaction',
      'destination_payment.refunds',
      // Expand the refund info on the connected account for the reversal
      'reversals.data.destination_payment_refund'.
    ],
  });```
#

and then transfer.reversals.data[0].destination_payment_refund.balance_transaction

paper hedge
#

Let me try it; I don't think that's the balance transaction on the platform account though. I was looking last night at that. Let me double check

silk bison
#

I'm sorry, there are 10+ objects involved here, they each have a balance transaction. What BT do you need? If you want the Transfer Reversal's BT (the trr_123) you want transfer.reversal.data[0].balance_transaction in that case

paper hedge
#

I'm trying to find: txn_1JmPHLAN9UGzw70g8aH6t4qT and map it to the corresponding balance_transaction on the subaccount. It looks like I need to go through destination_payment_refund on transfer reversal

silk bison
#

txn_1JmPHLAN9UGzw70g8aH6t4qT is the BT on the connected account already right?

paper hedge
#

No, it's the platform account

#

It looks like going through the destination_payment_refund gives txn_1JmPHMCTez1W7Fj0zrbVHukM as the subaccount balance transaction associated with txn_1JmPHLAN9UGzw70g8aH6t4qT But this still has the issue of this how can I be sure that txn_1JmPHLAN9UGzw70g8aH6t4qT (given that there are possibly multiple reversals) that it's the right one.

#

Does that make sense?

silk bison
#

It doesn't really make sense I'm sorry

paper hedge
#

1 second, let me post the code

silk bison
#

Like there are many objects, but every object is liunked to each other

#

you have to understand each object is like a box with a pointer to another object and some have points back

paper hedge
#
  assert(typeof transaction.source !== 'string');
  assert(transaction.source?.object === 'refund');
  assert(typeof transaction.source.charge !== 'string');
  assert(typeof transaction.source.charge?.transfer !== 'string');
  console.log(transaction.source.charge?.transfer);
  for (const reversal of transaction.source.charge?.transfer.reversals.data) {
    const refund = await stripe.transfers.retrieveReversal(reversal.transfer, reversal.id, {
      expand: ['destination_payment_refund'],
    });
    console.log(refund.balance_transaction);
  }
silk bison
#

Transfer Reversal trr_123 -> destination_payment_refund -> Refund pyr_123 -> source_transfer_reversal -> Transfer Reversal trr_123

paper hedge
#

That last refund.balance_transaction (in this case) is the one I want, but if there are multiple transferReversals how can I be sure?

silk bison
#

I don't know why you talk about a last one while retrieving the Transfer unfortunately

paper hedge
#
console.log(refund.balance_transaction);

In the code I posted

#

There's only one reversal in this case.

silk bison
#

Let's pause for a second and take a step back. What are you really trying to achieve? What is causing you to call https://stripe.com/docs/api/transfers/retrieve at that specific point? Why don't you track the BTs when you explicitly reverse things?

paper hedge
#

I didn't explicitly reverse this transaction afaik

#

It happened because it was a destination charge*

silk bison
paper hedge
#

I am not doing it in a webhook. I'm trying to find the stripe fees and metadata on the platform account that would be associated with the reversal on the subaccount. So I need the associated platform balance_transaction for the a subaccount txn of txn_1JmPHMCTez1W7Fj0zrbVHukM

silk bison
#

I'm trying to find the stripe fees and metadata on the platform account that would be associated with the reversal on the subaccoun
I don;t understand those words. What Stripe fees? what metadata?

paper hedge
#
  id: 'txn_1JmPHLAN9UGzw70g8aH6t4qT',
  object: 'balance_transaction',
  amount: -153500,
  available_on: 1634774400,
  created: 1634676683,
  currency: 'usd',
  description: 'REFUND FOR FAILED PAYMENT (Invoice 071E2135-0039)',
  exchange_rate: null,
  fee: -100,
  fee_details: [

This fee

#

txn_1JmPHMCTez1W7Fj0zrbVHukM has no fees associated with it.

#

But there seems to be no direct paper trail between txn_1JmPHMCTez1W7Fj0zrbVHukM and txn_1JmPHLAN9UGzw70g8aH6t4qT

silk bison
#

sorry it's so hard to follow with just small bits of info like this. Not your fault at all, there are just dozens of objects to keep track of and without seeing what you see it's hard

paper hedge
#

Maybe if I explain the use case?

silk bison
#

What I do, personally, is that I expand every single object in one call and I dump the entire formatted JSON and I cmd+F

paper hedge
#

Our particular use of stripe connect is a little unusual

silk bison
#

which you haven't seemed to have done

#

But I will just write you an example that will be easier

paper hedge
#

I did do that. My point is that the association is 1->M even though there is a unique refund on the subaccount

#

transaction.source.charge?.transfer.reversals is a list

silk bison
#

My point is that the association is 1->M even though there is a unique refund on the subaccount
as far as I know that is not the case at all

paper hedge
#

This is the balance_transaction associated with the transfer_reversal: txn_1JmPHMAN9UGzw70gLJiP9jt1 But there is also another balance transaction that goes back to the customer.

paper hedge
#

This balance_transaction is also not associated with a specific reversal:

{
  id: 'txn_1JmPHMAN9UGzw70gLJiP9jt1',
  object: 'balance_transaction',
  amount: 153500,
  available_on: 1634774400,
  created: 1634676684,
  currency: 'usd',
  description: 'REFUND FOR TRANSFER',
  exchange_rate: null,
  fee: 0,
  fee_details: [],
  net: 153500,
  reporting_category: 'transfer_reversal',
  source: 'tr_3JkrFgAN9UGzw70g2exPLyTp',
  status: 'available',
  type: 'transfer_refund'
}
#

Neither of the two platform balance_transactions have a linkage (as far as I can see) to the balance_transaction associated with the reversal on the subaccount (txn_1JmPHMCTez1W7Fj0zrbVHukM)

I'm asking if, and how to find that. I can't see a 1-1 link anywhere.

silk bison
#

give me a few minutes please, I'm write code because this is not working

#

it will take me a while but it should help

paper hedge
#

Okay, thank you

silk bison
#

@paper hedge ```const transfer = await stripe.transfers.retrieve(
'tr_123',
{
expand: [
// Transfer's BT
'balance_transaction',
// Original Charge's BT from what create the Transfer
'source_transaction.balance_transaction',
// Connected account's charge's BT (result of the Transfer)
'destination_payment.balance_transaction',
// Refund's BT associated with that specific transfer reversal
'reversals.data.source_refund.balance_transaction',
// Connected account's refund associated with that specific transfer reversal
'reversals.data.destination_payment_refund.balance_transaction',
],
}
);

console.log('Transfer id: ', transfer.id, ' - BT id: ', transfer.balance_transaction.id);
console.log('Original charge id (source_transaction): ', transfer.source_transaction.id, ' - BT id: ', transfer.source_transaction.balance_transaction.id);
console.log('Connected account's charge id (destination_payment): ', transfer.destination_payment.id, ' - BT id: ', transfer.destination_payment.balance_transaction.id);

var reversals = transfer.reversals.data;
console.log('Now looking at all reversals: ', reversals.length, ' total');

for(i = 0; i < reversals.length; i++){
console.log('Transfer Reversal id: ', reversals[i].id, ' - BT id: ', reversals[i].balance_transaction.id);
console.log(' * Original Refund id (source): ', reversals[i].source_refund.id, ' - BT id: ', reversals[i].source_refund.balance_transaction.id);
console.log(' * Connected account's refund id (destination_payment_refund): ', reversals[i].destination_payment_refund.id, ' - BT id: ', reversals[i].destination_payment_refund.balance_transaction.id);
}```

#

can you try this ^ ?

paper hedge
#

Yes, let me look

paper hedge
#

There is no source_refund on the transfer reversal

#

This is for an NSF. There's no refund to the customer, but there is a balance_transaction for removing the funds from our account.

silk bison
#

Ah, okay, so that seems to be the misunderstanding in that case. You basically have the transfer reversed with no link to the refund. So now, what is missing in the list of things I printed?

#

Can you share the whole output of my script as a gist or something? That way I can load it and we keep the real ids out of discord and later you can delete

paper hedge
#

Yes, give me a bit.

#
Transfer Reversal id:  trr_1JmPHMAN9UGzw70gK7idn25y  - BT id:  txn_1JmPHMAN9UGzw70gLJiP9jt1
  * Original Refund id (source):  null  - BT id:
  * Connected account's refund id (destination_payment_refund):  pyr_1JmPHMCTez1W7Fj06OhsbCg5  - BT id:  txn_1JmPHMCTez1W7Fj0zrbVHukM
#

This definitely links txn_1JmPHMCTez1W7Fj0zrbVHukM to txn_1JmPHMAN9UGzw70gLJiP9jt1 which is helpful, but I need to have a way to find this balance_transaction on the platform account: txn_1JmPHLAN9UGzw70g8aH6t4qT

#

It's related to charge py_3JkrFgAN9UGzw70g2dZij8pW which has no refunds. There are transfer reverals, which is essentially the above information. But again, the reversals is a list with no way to tell which one would be associated with txn_1JmPHLAN9UGzw70g8aH6t4qT aside from the amounts.

silk bison
#

I see, yeah it's because of that API version I mentioned, unfortunately in that specific case, it is impossible to link them beyond using the created 😦