Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
/ round-up Public archive

A demo to show how you can implement a round-up and donate feature

Notifications You must be signed in to change notification settings

adreyfus-stripe/round-up

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[wip] Round up and donate

A round up and donate program allows your customers to round their order total to the nearest dollar and donate the difference to an organization.

Examples programs can be found at Lyft and in some grocery stores. A round-up program should:

  • Have a way to onboard organizations who want to accept donations
  • Offer the customer the ability to opt-in to the round up program
  • Transfer the donation either instantly using Stripe Connect or with a check / bank transfer on a regular (i.e monthly) cadence
  • [optionally] For recurring customers, track how much each customer has donated and send a summary at the end of the month

This demo uses Connect Express to onboard organizations and uses the Payment Intents API to process payments. You can see an example of using the Charges API in the charges-solution branch.

Image of a fake checkout flow with a the round-up program

Requirements

Running the demo

  • git clone https://github.com/adreyfus-stripe/round-up
  • cd round-up
  • Copy the .env.example to .env with your Stripe test API keys
  • Run npm install to download dependencies
  • Run npm start

Overview

1. Onboard organizations using Connect.

Connect Express is the fastest way to get an organization on to Stripe so you can transfer donations directly to them as they come in. The organization can add their bank account information to their Stripe accounts to pay out the funds.

2. Create a PaymentIntent on the server for the initial order amount when a customer lands on your payment page.

const paymentIntent = await stripe.paymentIntents.create({
    amount: amount,
    currency: currency
});

3. Update the PaymentIntent amount when a customer chooses to round up their order.

When a customer chooses to round up their order and donate the extra amount, you should update the PaymentIntent with a new order amount rounded up to the nearest dollar (eg; 6000 for a 5909 order). You can use the metadata field to store information about the intended donation.

stripe.paymentIntents.update(id, {
    amount: newAmount,
    transfer_group: `group_${id}`,
    metadata: {
        isDonating: true,
        donationOrg: selectedAccount,
        donationAmount: 91 // Hardcoded for demo but this would change depending on the order
    }
});

4. Transfer the donation amount to that selected organization when the payment succeeds.

You can associate this donation with the original payment by using the same transfer_group id.

Using the Transfers API requires onboarding the organization using Stripe's Connect product and only in situations where both the platform and the connected account are in the same region (i.e both in Europe or both in US). If you do not want to use Connect to directly transfer the donations, you can create your own cron job to read the recent sucessful payments and calculate the amount to send to the organization from the metadata.

// In a webhoook listening for the payment_intent.succeeded event

const { transfer } = await stripe.transfers.create({
    amount: data.object.metadata.donationAmount,
    currency: "usd",
    destination: data.object.metadata.donationOrg,
    transfer_group: data.object.transfer_group
});

About

A demo to show how you can implement a round-up and donate feature

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published