Skip to content

Support collection of shipping address details #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thorsten-stripe opened this issue Aug 5, 2020 · 13 comments · Fixed by #170
Closed

Support collection of shipping address details #26

thorsten-stripe opened this issue Aug 5, 2020 · 13 comments · Fixed by #170
Labels
enhancement New feature or request

Comments

@thorsten-stripe
Copy link
Contributor

Feature request

  • Extension name: firestore-stripe-subscriptions

Is your feature request related to a problem? Please describe.

Some subscription business models ship physical goods. We should support collection of shipping address details for those.

Describe the solution you'd like

Support https://site-admin.stripe.com/docs/payments/checkout/customization#shipping-address-collection

We need to figure out whether to

  1. Set allowed_countries via the client side (not ideal as it could be modified by customer via browser dev console)
  2. Set allowed_countries as metadata on the product? (need to figure out if the 500 character limit would be a problem)
  3. Read allowed_countries from a location in Firestore?
@thorsten-stripe thorsten-stripe added the enhancement New feature or request label Aug 5, 2020
@Ess-Bidali
Copy link

Hi, I have the same issue where, my invoices do not contain all the details I need to display to my clients.

I am looking for the following:

  1. Name
  2. Address
  3. Phone number
  4. Custom fields

It's possible for me to put this information manually when I generate the link as per the following screenshot:
https://ibb.co/dLdf2Qv

Is there some way that I can update the invoice object so that this information is captured?

@thorsten-stripe
Copy link
Contributor Author

@Ess-Bidali sorry for the delay. I'm discussing this one with the team. As it stands today, Checkout does not propagate the billing address to the customer object. I have a PR open that copies the billing address collected from Checkout to the customer object, you can follow along there: #96

To note that this only collects the name and billing address, it does not collect phone number nor custom fields. These would have to be collected outside of the checkout and added to the customer object via a separate Cloud Function for example.

@jellelimpens
Copy link

Hello, I am using this system for my project in the Netherlands. All of the functions work perfectly but I have one problem. The only accepted payment method is creditcard. But in the Netherlands this is not that common. Most of the people use their bank account for online payments so I would like to implement SEPA.

Is there any way to do this implementation, but keep the features from firebase with all of the stuff.

@thorsten-stripe
Copy link
Contributor Author

@jellelimpens Stripe Checkout does not yet support SEPA Direct Debit for subscription creation, you would have to follow this tutorial to build your own checkout form and start subscriptions with your own Cloud Function: https://stripe.com/docs/billing/subscriptions/sepa-debit

The extension would still work for the webhook handling to sync subscription statuses and the creation of the portal link etc.

@thorsten-stripe
Copy link
Contributor Author

Quick note that the billing address is now being transcribed to the customer object since v0.1.8: https://github.com/stripe/stripe-firebase-extensions/blob/next/firestore-stripe-subscriptions/CHANGELOG.md#version-018---2020-11-19

@ghost
Copy link

ghost commented Apr 3, 2021

Absolutely. I collect shipping addresses in JavaScript checkout, this would stop me from using a middleman like SuperPortal.

@thorsten-stripe
Copy link
Contributor Author

Shipping address collection is supported as of version 0.1.12: https://github.com/stripe/stripe-firebase-extensions/blob/next/firestore-stripe-subscriptions/CHANGELOG.md#version-0112---2021-04-29

You can update the extension in your Firebase console to enable this.

@reavpC6K
Copy link

reavpC6K commented May 2, 2021

Should country codes be individual array strings?
I understand collect_shipping_address: true would go in app.js:182?
I didn't add one-time payments. Not sure what I'm missing.

@thorsten-stripe
Copy link
Contributor Author

Should country codes be individual array strings?

Only one array:
image

I understand collect_shipping_address: true would go in app.js:182?

Correct, see: https://github.com/stripe-samples/firebase-subscription-payments/blob/master/public/javascript/app.js#L177 you can test it out here: https://stripe-subs-ext.web.app/

I didn't add one-time payments. Not sure what I'm missing.

This works both for one-time payment and for subscription mode

@reavpC6K
Copy link

reavpC6K commented May 5, 2021

Thanks. My array was poorly formatted.

@MatkoMilic
Copy link

If anybody struggles like me to use Stripe firebase extension for fetching billing address details, just use my code, u need to change handleWebhookEvents cloud function that the extension gave u, and u only need this part that will update the billing address inside payment:

const insertPaymentRecord = async (
  payment: Stripe.PaymentIntent,
  checkoutSession?: Stripe.Checkout.Session
) => {
    let paymentMethod: any;
     if(payment?.payment_method) {
        try {
     paymentMethod = await stripe.paymentMethods.retrieve(`${payment?.payment_method}`);
      logger.log("00000000000000", JSON.stringify(paymentMethod, null, 2));
        }
        catch (error) {
            logger.log("error:", error);
        }
}
  logger.log("MMMMMMMMMMMMMMMMMMMMMMMMMM", JSON.stringify(paymentMethod, null, 2));

    
  // Get customer's UID from Firestore
  const customersSnap = await admin
    .firestore()
    .collection(config.customersCollectionPath)
    .where('stripeId', '==', payment.customer)
    .get();
  if (customersSnap.size !== 1) {
    throw new Error('User not found!');
  }
  if (checkoutSession) {
    const lineItems = await stripe.checkout.sessions.listLineItems(
      checkoutSession.id
    );
    const prices = [];
    for (const item of lineItems.data) {
      prices.push(
        admin
          .firestore()
          .collection(config.productsCollectionPath)
          .doc(item.price.product as string)
          .collection('prices')
          .doc(item.price.id)
      );
    }
    payment['prices'] = prices;
    payment['items'] = lineItems.data;
  }

  if (paymentMethod?.billing_details) {
      payment['billing_details'] = paymentMethod?.billing_details;
    }

  // Write to invoice to a subcollection on the customer doc.
  await customersSnap.docs[0].ref
    .collection('payments')
    .doc(payment.id)
    .set(payment, { merge: true });
  logs.firestoreDocCreated('payments', payment.id);
};

@m00tt
Copy link

m00tt commented Nov 29, 2024

I also had the same problem.
I had followed step by step what is stated within the extension description:

  • inserting the collect_shipping_address field: true
  • creation of the document shipping_countries with inside it the field allowed_countries containing the list of country codes (inside the Stripe products collection).

But in this case it did not work.

Investigating the ext-firestore-stripe-payments-createCheckoutSession function, I noticed the following code:

const shippingCountries:Stripe.Checkout.SessionCreateParams.ShippingAddressCollection.AllowedCountry[] =
          collect_shipping_address
            ? (
                await admin
                  .firestore()
                  .collection(
                    config.stripeConfigCollectionPath ||
                      config.productsCollectionPath
                  )
                  .doc('shipping_countries')
                  .get()
              ).data() ??['allowed_countries'] ?? []
            : [];

I modified the function by adding logs to check the variables.
An empty array was always returned.

I modified the function by commenting config.stripeConfigCollectionPath || so that the collection called was only the one inherent to Stripe products.

const shippingCountries:Stripe.Checkout.SessionCreateParams.ShippingAddressCollection.AllowedCountry[] =
          collect_shipping_address
            ? (
                await admin
                  .firestore()
                  .collection(
                    //config.stripeConfigCollectionPath ||
                      config.productsCollectionPath
                  )
                  .doc('shipping_countries')
                  .get()
              ).data() ??['allowed_countries'] ?? []
            : [];

This correctly retrieves the country codes and prompts for the shipping address at checkout.

@reavpC6K
Copy link

My shipping shows up fine since 2021.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants