#Devonthedo88-PaymentIntent

1 messages · Page 1 of 1 (latest)

minor eagle
#

Do you mean to take Charge ID from a PaymentIntent?

bold gate
#

yes

#

// 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;

    if (typeName !== 'Mutation') {
        throw new Error('Request is not a mutation');
    }

    if (!arguments?.amount) {
        throw new Error('Amount argument is required');
    }

    // create payment intent
    const paymentIntent = await stripe.paymentIntents.create({
        amount: arguments.amount,
        currency: 'usd',
        capture_method: 'manual',
        setup_future_usage: "off_session",
        payment_method_types: ['card'],
    });

    return {
        clientSecret: paymentIntent.client_secret,
        paymentIntent: paymentIntent.id,
        chargeid: paymentIntent.charges.data[0].id,
    }
};
minor eagle
bold gate
#

chargeid: "{object=list, data=[], has_more=false, total_count=0, url=/v1/charges?payment_intent=pi_3JXc86FXkUN0aehr0pGY1Abi}"

#

im not getting that

#

how do i get response back after payment had autherized.

#

would it be here?

    if (!clientSecret) {
      return;
    }
    const {error} = await initPaymentSheet({
      paymentIntentClientSecret: clientSecret,
    });
    console.log('YAY!');
    if (error) {
      Alert.alert(error);
    }
  };```
minor eagle
#

Sorry I am a bit confused. At this line

 const paymentIntent = await stripe.paymentIntents.create

you have the paymentIntent object, right?

bold gate
#

this is creating the payment intent.

minor eagle
#

yes, and the result is a PaymentIntent object itself

bold gate
#

yes

#

but where do i get charge ID from?

minor eagle
#

paymentIntent.charges.data, inside that you have the id

bold gate
#

but im not getting that back

#
    if (!clientSecret) {
      return;
    }
    const {error} = await presentPaymentSheet({clientSecret});

    if (error) {
      Alert.alert(`Error code: ${error.code}`, error.message);
    } else {
      Alert.alert('Success', 'Your order is confirmed!');
      await AddData();
      TrackDriver();
    }
  };```
#

im using the react native setup

minor eagle
#

That's the PaymentSheet opening logic. How was the PaymentIntent creating logic here:

   // create payment intent
    const paymentIntent = await stripe.paymentIntents.create({
        amount: arguments.amount,
        currency: 'usd',
        capture_method: 'manual',
        setup_future_usage: "off_session",
        payment_method_types: ['card'],
    });
bold gate
#

thats what I read to put there

#

but when user puts in CC info I dont get a return from that

#

all i get is payment intent return

minor eagle
#

Let me clarify. After the code above, you should have a response (inside that paymentIntent object), and you should have a Charge object with an ID inside already. After that you send that PaymentIntent Id to client, your client call openPaymentSheet, and your customer input their CC. But the Id of the Charge and the Id of the PaymentIntent remains the same

bold gate
#

no i dont get that

#

let me show you we get intent then open payment paymentsheet

#

ill get you the whole return.

minor eagle
#

sure

bold gate
#

no charge ID

#

charges={object=list, data=[], has_more=false, total_count=0, url=/v1/charges?payment_intent=pi_3JXcutFXkUN0aehr0EHHiopX},

#

after capture i think i get a charge ID

minor eagle
#

let me see

#

Ah, I see, sorry.

#

So in the first time create a PaymentIntent, we haven't charged the customer yet, so it's normal to not have a Charge data inside. Please forget what I say above

bold gate
#
    "charges": {
      "object": "list",
      "data": [
        {
          "id": "ch_3JXceyFXkUN0aehr0bGMZPbD",
          "object": "charge",
          "amount": 188,
          "amount_captured": 188,```
minor eagle
#

Yes after capture, that's the charge ID

bold gate
#

so how do i transfer funds during a capture.

#

i cant do it on intent since i dont know the account it going too.

#

transfer to a connected account.

minor eagle
#

I just wonder, why don't you know the account to transfer on intent? How do you determine it later?

bold gate
#

im building a uber type app

#

so intent happens before a driver accepts.

#

thus im not sure where the money is going till a driver accepts the order.

minor eagle
#

I see, that makes sense. Let me look around for a bit

bold gate
#

okay thanks

#

i was using transfer later but running into the account not having available funds.

minor eagle
bold gate
#

yea i was trying that but running into the issue of funds being available. i got error insignificant funds.

minor eagle
#

I think transfer_group is the correct approach. You would need to resolve the insufficient fund error. How is it telling you?

bold gate
#

i dont know it was eariler and i already chnaged code to that they told me

#

@twin mesa @sly spruce you got any input?

minor eagle
#

Can you share the code you were using to create the Transfer Group?

bold gate
#
        amount: arguments.driverpay,
        currency: 'usd',
        destination: arguments.driverPayAcct,
        source_transaction: arguments.chargeid,
    });


    return {
        transfer: transfer,
    }
};```
#

is is after they told me to change it

#

with getting a charge id

twin mesa
#

@bold gate to clarify, have you tried the above code and does it work now?

bold gate
#

only after capturing charge

#

just thinking about it.. the same time i capture charge is the same time i need to transfer to connected account

minor eagle
#

Yes, the time you capture = the time you have the charge id = the time you are going to create the Transfer

bold gate
#

but i need to do it all in one function..

sly spruce
#

you cannot

#

you will need to capture first before you can transfer

#

capture a charge will create a balance transaction under the hood

#

Transfer requires a balance Transaction to be there before the transfer could happen

#

having a balance transaction meaning Stripe is sure that we have the fund

bold gate
sly spruce
#

That is just how the API works unfortunately, without the capture, Stripe will have no money to initiate the money movement.
Capture the charge is to ensure the system has the money to move between accounts

bold gate
sly spruce
#

Instead of using Separate charge and transfer, you can use destination charges

#

This is charge/transfer in one API call which you can use manual capture mode

#

but that might not fit your business cases

bold gate
sly spruce
#

yup, then the only way is Separate charge and transfer. and you cannot use capture:manual

#

if you want to use capture:manual, you cannot use source_transaction

#

you will just need to make sure your platform has sufficient balance for you to transfer; you can topup your balance or accumulate enough balance for your business

bold gate
#

Okay ill do then when driver accepts the order ill capture.. then when they end the order ill transfer right?

sly spruce
#

correct, as long as you've captured the charge, you can start the transfer

bold gate
#

Okay thanks ill mess with it in the am.. ill let yall know

#

Thanks