#solbass
1 messages · Page 1 of 1 (latest)
When you say "link the payment to the product" can you elaborate? What does this look like for you?
useStripe,
ApplePay,
confirmPlatformPayPayment,
PlatformPay
} from '@stripe/stripe-react-native';
import { useState, useEffect } from 'react';
import { Alert, Button } from 'react-native';
import BottomTabScreenContainer from '../../../components/BottomTab/BottomTabScreenContainer/BottomTabScreenContainer';
import { useQueryPaymentSheet } from '../../api/queries/useQueryPaymentSheet';
export default function CheckoutScreen() {
// const [loading, setLoading] = useState(false);
const { data } = useQueryPaymentSheet({ amount: 999 });
const initializePaymentSheet = async ({ data }: { data: any }) => {
const { customer, ephemeralKey, paymentIntent } = data;
const { paymentIntent: paymentIntentResult, error } =
await confirmPlatformPayPayment(paymentIntent, {
applePay: {
cartItems: [
{
label: 'Direct Messages(3)',
amount: '9.99',
paymentType: PlatformPay.PaymentType.Immediate
}
],
merchantCountryCode: 'US',
currencyCode: 'USD',
// requiredShippingAddressFields: [PlatformPay.ContactField.PostalAddress],
requiredBillingContactFields: [
PlatformPay.ContactField.PhoneNumber,
PlatformPay.ContactField.EmailAddress
]
}
});
if (error) {
// handle error
} else {
Alert.alert('Success', 'Check the logs for payment intent details.');
console.log(JSON.stringify(paymentIntentResult, null, 2));
}
};
if (!data) return <></>;
return (
<BottomTabScreenContainer>
<Button
variant="primary"
// disabled={!loading}
title="Checkout"
onPress={() => initializePaymentSheet({ data })}
/>
</BottomTabScreenContainer>
);
}
I am manually filling in the cart information, but I want to like the payment Intent to the product I created (through the stripe dashboard) with a price of $9.99 (which is also created on the dashboard)
Can you just use metadata on the Payment Intent for that? That will ensure that your product information is retrievable on the Payment Intent object: https://stripe.com/docs/api/payment_intents/create#create_payment_intent-metadata
Not sure if that's what you mean by "link" in this context though.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Sorry for lack of clarity, by "link" I mean connecting a payment intent to a product and price id. Just off the top of my head, it would make most sense to me if I click a payment in my stripe dashboard, I can see the associated plan and product id. Right now I have no information what the payment is for, i just see the amount.
As @alpine yacht shoes described, you can use metadata for storing that kind of custom information. Payment Intents, by thsemselves, are not associated with any prices or products. This kind of "link" might be created for example when using Invoices or Checkout Sessions (which internally create payment intents), but when using Payment Intents directly you need to track this in your integration.
Okay the docs here don't mention anything about checkout sessions or invoices -- https://stripe.com/docs/apple-pay?platform=react-native
So should I create an invoice on the BE first and then update the invoice after the payment is succesful?
Only if you want to create invoices, I was mentioning that as an example
If you just want to associate your own product IDs with payments, you can store that in metadata
Are invoices the same as receipts? For example, if a customer's payment goes through, auto emailing them a receipt would be nice
No, those are different things. You can send email receipts automatically, yes.
https://stripe.com/docs/receipts?payment-ui=direct-api#automatically-send-receipts
After reading the docs, I think in my scenario it makes best sense to just store it in metadata.
yes that sounds like a good path for you