#solbass

1 messages · Page 1 of 1 (latest)

proven craterBOT
alpine yacht
#

When you say "link the payment to the product" can you elaborate? What does this look like for you?

hollow flax
#
  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)

proven craterBOT
alpine yacht
#

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.

hollow flax
#

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.

wooden hatch
#

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.

hollow flax
#

So should I create an invoice on the BE first and then update the invoice after the payment is succesful?

wooden hatch
#

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

hollow flax
#

Are invoices the same as receipts? For example, if a customer's payment goes through, auto emailing them a receipt would be nice

wooden hatch
hollow flax
#

After reading the docs, I think in my scenario it makes best sense to just store it in metadata.

wooden hatch
#

yes that sounds like a good path for you