#Devonthedo88-PaymentIntent
1 messages · Page 1 of 1 (latest)
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,
}
};
Yes you have the Charge object inside the PaymentIntent object, in the response: https://stripe.com/docs/api/payment_intents/object#payment_intent_object-charges
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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);
}
};```
Securely accept payments online.
Sorry I am a bit confused. At this line
const paymentIntent = await stripe.paymentIntents.create
you have the paymentIntent object, right?
this is creating the payment intent.
yes, and the result is a PaymentIntent object itself
paymentIntent.charges.data, inside that you have the id
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
Securely accept payments online.
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'],
});
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
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
no i dont get that
let me show you we get intent then open payment paymentsheet
ill get you the whole return.
sure
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
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
"charges": {
"object": "list",
"data": [
{
"id": "ch_3JXceyFXkUN0aehr0bGMZPbD",
"object": "charge",
"amount": 188,
"amount_captured": 188,```
Yes after capture, that's the charge ID
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.
I just wonder, why don't you know the account to transfer on intent? How do you determine it later?
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.
I see, that makes sense. Let me look around for a bit
okay thanks
i was using transfer later but running into the account not having available funds.
Transfer later is the transfer_group here? https://stripe.com/docs/connect/charges-transfers
With Connect, you can make charges on your platform account on behalf of connected accounts, perform transfers separately, and retain funds in the process.
yea i was trying that but running into the issue of funds being available. i got error insignificant funds.
I think transfer_group is the correct approach. You would need to resolve the insufficient fund error. How is it telling you?
i dont know it was eariler and i already chnaged code to that they told me
@twin mesa @sly spruce you got any input?
Can you share the code you were using to create the Transfer Group?
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
@bold gate to clarify, have you tried the above code and does it work now?
no im not able to get a charge id from payment intent
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
Yes, the time you capture = the time you have the charge id = the time you are going to create the Transfer
but i need to do it all in one function..
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
thats where the issue lies.
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
is there a way just to take the payment without capturing.. then transfer later without a balence.
Instead of using Separate charge and transfer, you can use destination charges
With Connect, you can create charges on your platform account, take fees, and then transfer remaining funds to your connected accounts.
This is charge/transfer in one API call which you can use manual capture mode
but that might not fit your business cases
thats the thing im not sure where the funds are going till after intent.
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
Okay ill do then when driver accepts the order ill capture.. then when they end the order ill transfer right?
correct, as long as you've captured the charge, you can start the transfer