#devonthedo88-balance
1 messages ยท Page 1 of 1 (latest)
@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
not sure what you mean, you mentioned React Native which is almost always client-side in a mobile app
Like what language do you use server-side? What is blocking you from the documentation https://stripe.com/docs/api/balance/balance_retrieve ?
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
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
yea i need help parsing.
What have you tried?
like you can do balance.available[0].amount and balance.available[0].currency to get the first balance.
aws amplify lambda
depending on your country you could have more than one currency
Yea see thats what i needed.
US
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
Yea i know im new to coding but sorta know lol
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
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.
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
https://nodejs.org/en/download/ likely is a good first step, though if you're on Mac OS you can use brew install node if you use Homebrew
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
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
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
I havent grasped objects yet
so you can mostly change . and [xxx]`
so balance is an object, it has properties documented on https://stripe.com/docs/api/balance/balance_object or what you see in the raw json
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.
Oh okay gotcha so on these balances which are important to a end user?
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?
like my app is like a uber
ah yeah
yup connect
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)
i just dont know how to parse objects yet im working on that
and also the amount/currency in pending which is funds that will be available later
okay good better understanding of the balances.
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
yup lol thanks!! youtube videos i usually mess with websites and html and php is my go to. lots of info on it on the web.
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 ๐
My code might not be the nicest looking but its working with the help of the react native on discord.
that's awesome ๐
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
correct
okay dokie thanks