#incaelum
1 messages · Page 1 of 1 (latest)
Hi, let me help you with this.
You can use a "deferred PaymentIntent" flow, to create the PaymentIntent after the customer provides the payment details. This way you will be able to run your logic to check the available stock before creating and confirming the PaymentIntent on the backend: https://stripe.com/docs/payments/accept-a-payment-deferred
do you have any video in youtube explaing this the documentatios is a littel confusing to me
This is a new flow so there's no videos about it yet. What's exactly confusing, I can try to clarify.
xd i am tryiong to understand de documentation i guess in my frontend this confirmhandler is related to my needs:
import { useStripe } from '@stripe/stripe-react-native';
export default function CheckoutScreen() {
const { initPaymentSheet, presentPaymentSheet } = useStripe();
const initializePaymentSheet = async () => {
const { error } = await initPaymentSheet({
merchantDisplayName: "Example, Inc.",
intentConfiguration: {
mode: {
currencyCode: 'USD',
},
confirmHandler: handleConfirmation
}
});
if (error) {
// handle error
}
};
const confirmHandler = async (paymentMethod, shouldSavePaymentMethod, intentCreationCallback) => {
// explained later
}
}
buy i dont really understand what need to do in my backend
Are you looking at the React Native tab? https://stripe.com/docs/payments/accept-a-payment-deferred?platform=react-native
yes i am in react native tab
So what's the question exactly?
i just trying to understand how my backend needs to handle all this, let me go into the documentation I will try to do it by myself
The main difference is that your backend doesn't do anything until the very end: https://stripe.com/docs/payments/accept-a-payment-deferred?platform=react-native&type=payment&integration=paymentsheet#ios-submit-payment
curently in my backend i have this view, if works fine:
class PaymentSheet(APIView):
def post(self,request):
user = get_user_from_token(request)
offer_id = request.data.get('offer_id')
if not offer_id:
return Response({'details':'No offer provided'},status.HTTP_400_BAD_REQUEST)
offer = OfferSpot.objects.filter(id=offer_id).last()
if not offer:
return Response({'details':'Not offer found'},status.HTTP_404_NOT_FOUND)
owner = offer.owner
print(offer.price)
stripe.api_key = settings.PRIVATE_TEST_STRIPE_KEY
customer = None
if user.profile.customer_stripe_id:
customer = user.profile.customer_stripe_id
else:
customer_raw = stripe.Customer.create()
customer = customer_raw.id
user.profile.customer_stripe_id = customer
user.profile.save()
ephemeralKey = stripe.EphemeralKey.create(
customer=customer,
stripe_version='2023-10-16',
)
paymentIntent = stripe.PaymentIntent.create(
amount=int(offer.price*100),
currency='eur',
customer=customer,
# In the latest version of the API, specifying the `automatic_payment_methods` parameter is optional because Stripe enables its functionality by default.
automatic_payment_methods={
'enabled': True,
},
application_fee_amount=int(offer.price*100*10/100), # app collect
transfer_data={
'destination': owner.profile.vendor_stripe_id,# target destination
},
)
return Response({
'paymentIntent': paymentIntent.client_secret,
'ephemeralKey': ephemeralKey.secret,
'customer': customer,
'publishableKey': settings.PUBLIC_TEST_STRIPE_KEY
},status.HTTP_201_CREATED)
the point is that this is returned to the user and then the user can click checkout.
I am looking for a function to call after user inputs their card data and before transaction is submited, in order to confirm product is avaliable or not
Have you look at docs section about the backend call?