How to send email receipt from Stripe in Power Pages payments

Andrew GrischenkoPower Apps1 month ago23 Views

Microsoft Power Pages added Stripe payments integration last year, and I wrote a post about the anatomy of this integration and suggested improvements. Since then, the Power Pages team have implemented many good changes, including handling security keys, and the solution now looks solid.

One question remained unanswered: How do you send an email receipt from Stripe to the customer using Power Pages Stripe?

Stripe documentation explains how to send email receipts automatically when payments are completed. However, we have no control over creating the PaymentIntent object as it’s done by the Power Pages Stripe solution on the “server” side. On the Power Pages Studio side, there is no way to specify an email address value for Stripe (like there is for the payment amount) or another configuration to specify the email to initiate sending a receipt.

The good news is that there is a way to update the PaymentIntent already created and specify the receipt_email property. Once set, this is used to send the receipt when payment is complete. Moreover, updating this value would trigger a new email event after payment completion!

This is great, you may say, but how do we access the PaymentIntent created by Power Pages? And where to get the required identifier of it to make such an API call?

This is where the Payment table comes in handy with the column “Payment Identifier” (pp_paymentidentifier). When a user navigates to the payment step where the Stripe form is displayed, the following happens:

  1. The PaymentIntent object is created in Stripe
  2. A record in the Payment table in Dataverse is created.
  3. The Payment Identifier column is populated with the Stripe PaymentIntent ID. This is what we need!

So, we need a simple Power Automate Cloud Flow triggered by a new Payment record and calling Stripe API to update the PaymentIntent with the required email address. Once the payment is successful, the email receipt will be sent by Stripe to the specified email upon successful payment.

Two complications, though.

Firstly, where do I get the required email in that flow? The Payment table has no email column. Well, it has the “Regarding” column value. While it may not be well documented (is it?), this column points to the record on which Multistep Form you added the Payment form. Depending on your case, this table or tables related to it will eventually give you the email value – you’ll need just to navigate to get it.

The other complication is that Stripe sends email receipts only in “live” (production) mode keys, according to the Stripe documentation on Email receipts and paid invoices. So, technically, you cannot test this solution end to end with an emailed receipt sent without an actual payment.

Regarding the secret key, don’t forget that the updated Power Pages integration requires you to store the live key in an Azure Key Vault. So you need to set one up first. After that, in the cloud flow actions, you can access it via a secure environment variable backed by the Azure Key Vault. See here on how to set up such a variable: https://learn.microsoft.com/en-us/power-apps/maker/data-platform/environmentvariables-azure-key-vault-secrets

With all the above, let’s implement this into a working solution now.

Assumptions for the steps below that you have:

  • enabled and configured Stripe integration on Power pages;
  • set up a multistep form for your tables with a payment step;
  • created Azure Key Vault (for production/live) and stored a live Stripe secret there;
  • set up environment variables to determine if the environment is production or not; storing test Stripe secret key (regular, text); storing live secret key (backed by Azure Key Vault).

The rest should be straightforward.

1. Create a new automated cloud flow with the Dataverse trigger “When a new record is created”:

    2. Use the value of the Regarding column to get the record of the table for which the payment is for, assuming that one contains the email address to send the receipt to:

    3. The next block extracts the secret value from the Azure Key Vault. It’s needed in production only for the live key. See more on how to extract secrets from Azure Key Vault here. Note:

    • The variable used in the condition is set to indicate the environment’s production or not.
    • The “tec_PORTALStripeSecret” is the environment variable connected to Azure Key Vault.
    • The “Retrieve Stripe Secret” is a “Perform an unbound action” action.
    • In the settings of the “Retrieve Stripe Secret” use “Secure outputs” option to prevent writing secret in the logs and flow run history!

    4. And now we’re ready to call the Stripe API to update Payment intent. Note:

    • Payment Identifier in URI is the column from the Payment record trigger.
    • Email is the email extracted from the associated record (or further associated records – depending on your data model).
    • The condition in the Username field chooses the secret from the unsecured environment variable for the dev/test environment or from the action extracting the secret value for production. Below is an expression using the variable names from my project. You’d have your own names, but the gist should be clear.
    • There is no Password, so you may just need to enter a space there.
    if(parameters('PORTAL Is Production (tec_PORTALIsProduction)'), outputs('Retrieve_Stripe_Secret')?['body/EnvironmentVariableSecretValue'], parameters('PORTAL Stripe Test Key (tec_PORTALStripeTestKey)'))

    5. Now, in your Power Pages portal, complete your multistep form with a payment. You will receive the Stripe email receipt if you are in live mode with the production live secret; otherwise, the flow should succeed anyway.

    This is it, folks! I hope this helps and let me know if you have questions or improvements to this solution. All the best!

    Original Post https://cloudminded.blog/2025/01/18/how-to-send-email-receipt-from-stripe-in-power-pages-payments/

    0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

    Leave a reply

    Follow
    Sign In/Sign Up Sidebar Search
    Popular Now
    Loading

    Signing-in 3 seconds...

    Signing-up 3 seconds...