Saqib Ashraf
Saqib Ashraf

Reputation: 94

Stripe for crowdfunding

I am using stripe for crowdfunding website. Its simple to pledge card using stripe api. When campaign meets its goal all the cards must be charged.I am using cronjobs to check if any campaigns meets its funding goal if yes then charge pledged cards.As the cards are in bulk the stripe api takes more time and php execution time limit ends. So I choose nodejs for this purpose that sends charging requests asynchronously (that works).

I have another option to create onetime subscription of funded amount on the deadline of campaign when pledging card.

And if campaign isn't successful all the subscriptions will be deleted from stripe through cron job. My question is whats the best approach using charging request to charge all cards if campaign succeeds or creating subscriptions when card is pledged and deleting all subscriptions in case the campaign doesn't meets its goal.

Upvotes: 0

Views: 737

Answers (1)

Patrick Moore
Patrick Moore

Reputation: 13344

If it were me, I would:

  1. Create a customer object on each pledge via Stripe API.

  2. Create a card object on each pledge, attach to a customer, also via Stripe API.

  3. Store in your local DB a record identifying the customer and card object in Stripe, and relating it to the campaign. Add a column "has_been_charged" (BOOL) = 0 (false). Add column "has_been_deleted" (BOOL) = 0 (false).

Then, on campaign completion, a manual or automatic job would verify campaign success.

If successful campaign:

  1. Loop through each DB record WHERE has_been_charged = 0 AND campaign_id = the campaign. Do this in blocks of 100 or 500 or 1000 depenending on DB connectivity and time it takes to loop through.

  2. During loop, retrieve card/customer object via Stripe API, create charge via Stripe API, update database column has_been_charged = 1.

  3. Repeat loop until all charges are completed.

If unsuccessful campaign:

  1. Loop through each DB record WHERE has_been_deleted = 0 AND campaign_id = the campaign Again, do this in blocks.

  2. During loop, remove card object via Stripe API (and perhaps also customer object), also update database column has_been_deleted = 1.

  3. Repeat loop until all cards have been removed.

Upvotes: 1

Related Questions