#devonthedo88-balance

1 messages ยท Page 1 of 1 (latest)

humble tree
#

@south lichen Retrieving the balance is something you can only do server-side with your Secret API key. Never do it in a mobile app

south lichen
#

I am lol

#

do i need to narrow it down server side?

humble tree
#

not sure what you mean, you mentioned React Native which is almost always client-side in a mobile app

south lichen
#

im using amplify lamda for stripe

#

server side

#

server side code


// event
// {
//   "typeName": "Query" | "Mutation", /* Filled dynamically based on @function usage location */
//   "fieldName": "createPaymentMethod", /* Filled dynamically based on @function usage location */
//   "arguments": { amount  /* GraphQL field arguments via $ctx.arguments */ },
//   "identity": { /* AppSync identity object via $ctx.identity */ },
//   "source": { /* The object returned by the parent resolver. E.G. if resolving field 'Post.comments', the source is the Post object. */ },
//   "request": { /* AppSync request object. Contains things like headers. */ },
//   "prev": { /* If using the built-in pipeline resolver support, this contains the object returned by the previous function. */ },
// }
exports.handler = async (event) => {
    const { typeName, arguments } = event;

   

    // create payment intent
    const balance = await stripe.balance.retrieve({
        stripeAccount: 'acct_1JSu3Q2XrkSfqCJb',
    });

    return {
        driverpayBal: balance,

    }
};
#

I want to be able to just get available bal, and pending

humble tree
#

I've ~never heard of amplify lambda. You seem to return the entire balance client-side which is not something I'd do/recommend. I'd parse the information server-side (in that lambda) and return what I want the mobile app to access in the format I expect

south lichen
#

yea i need help parsing.

humble tree
#

What have you tried?

#

like you can do balance.available[0].amount and balance.available[0].currency to get the first balance.

humble tree
#

depending on your country you could have more than one currency

south lichen
#

US

humble tree
#

sure, but you ask questions regularly here, I'm just tring to nudge you to try things first

#

like it's a simple array/object

#

if you move away from lambda for a sec and run this in node.js locally on your laptop you can quickly debug code like this directly

south lichen
humble tree
#

yep that's why I'm nudging you to try things for yourself first locally (separate from the lambda call). Way easier to make sense of it all

south lichen
#

u know docs to run it on node.js

#

never done that

#

that would help me alot cuz to change stuff on aws i got wait for it to upload.

humble tree
#

I'd start by googling how to install node locally and then it's mostly running it on the command line

#

depends on your laptop/OS and such

#

and then you can install stripe-node and run it

#

way easier than debugging on the mobile app with calls to AWS that's for sure

#

you likely can even build your mobile app to talk to a Node.js server that runs on your laptop to make debugging way faster, but I've never built a React Native mobile app myself

south lichen
#

im on windows

#

ill take a look cuz i need something easier then doing it all though the app to see if it works.

#

but

#

CheckBalance:
driverpayBal: "900"

#

what u gave me works

humble tree
#

it's similar though I'm less familiar with Windows dev, haven't done this in 10 years

#

and yay

#

one thing that you need to understand: our library already creates objects in memory

south lichen
#

I havent grasped objects yet

humble tree
#

so you can mostly change . and [xxx]`

#

do you can do balance.object => that's the string balance

#

balance.available => it's the array you saw in your output [{amount=900, currency=usd, source_types={card=900}}]

#

and so balance.available[0] is the first element in your output => {amount=900, currency=usd, source_types={card=900}}

#

and so balance.available[0].amoun is the amount property here so 900.

#

etc. etc.

south lichen
#

Oh okay gotcha so on these balances which are important to a end user?

humble tree
#

What I do when I'm lost is that I basically log every layer, until I see what I get/what errors. You can use console.log(JSON.stringify(balance.available)); for example and read the logs

#

Well it really depends, I don't know what you are building and why your mobile app would show anyone's balance

#

are you integrating Connect?

south lichen
#

like my app is like a uber

humble tree
#

ah yeah

south lichen
#

yup connect

humble tree
#

If so you want to show the amount/currency in available as that's what they can pay themselves (assuming you leave them on manual payouts)

south lichen
humble tree
#

and also the amount/currency in pending which is funds that will be available later

south lichen
#

okay good better understanding of the balances.

humble tree
#

And yeah I commend you. I have been coding for 20 years. I think I'm good overall, but I can not imagine learning all of this at once. I still barely grasp React Native myself and you''re doing that + server-side Node.j + HTTP + parsing objects + Stripe.
I know it's a lot, just go one step at a time, and try to always try something first

south lichen
humble tree
#

yep I hear the struggle, but you'll get there

#

the speed at which you just added my code and then confirmed it works is a good sign ๐Ÿ™‚

south lichen
#

My code might not be the nicest looking but its working with the help of the react native on discord.

humble tree
#

that's awesome ๐Ÿ™‚

south lichen
#

thanks! yea aws has it where i can test the functions on the web for output

#

balance.pending[0].amount so to get to the pending would that be what i use

humble tree
#

correct

south lichen
#

okay dokie thanks