Stripe for crowdfunding - php

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.

If it were me, I would:
Create a customer object on each pledge via Stripe API.
Create a card object on each pledge, attach to a customer, also via Stripe API.
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:
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.
During loop, retrieve card/customer object via Stripe API, create charge via Stripe API, update database column has_been_charged = 1.
Repeat loop until all charges are completed.
If unsuccessful campaign:
Loop through each DB record WHERE has_been_deleted = 0 AND campaign_id = the campaign Again, do this in blocks.
During loop, remove card object via Stripe API (and perhaps also customer object), also update database column has_been_deleted = 1.
Repeat loop until all cards have been removed.

Related

Xero Api , How create "Multiple Item" in a single bank transaction

If a user creates one overpayment with the UI inside an invoice, automatically Xero creates, in Bank Transaction, a transaction called "Payment:multiple items". Inside the transaction, Xero UI shows "Transaction: View Transaction" with two areas, one for the Invoice Payments and the other for the Overpayments and Prepayments.
Is possible , with the XERO API, create a bank transaction with Multiple Items?. How it is done?
I tried with the API create an Overpayment through Bank Transaction and a Payment , both with the same Contact, but the UI Bank Transaction menu shows two different Bank Transaction.
Support answered me:
Unfortunately it is not possible to achieve the same thing via API.
In the web interface, you can essentially create overpayment in two
ways, via the bank account screen and also by creating payment that
are larger than the amount owed in an invoice.
With API, the overpayment is created via BankTransactions endpoint, so
essentially the same as the first method in the web UI. However, it is
not possible to post payment amount that are larger than the amount
owed via API.

Store Stripe payment history

I have integrated stripe in to my application.
Now i want to store the payment history in to my database.
Using stripe APIs, i can create new subscription as well as update that subscription.
Now say i have one subscription for one month for $20 and after few days i am updating to sixmonth for $60. So as per stripe logs it will deduct $40 while updating plan.
I want to store all these payment process along with subscription periods in to my database.
How can i do that. Is that any API for it?
You can use webhooks to get notification from Stripe whenever any event happen.
So you need to create a webhook for charge.succeeded. So that you can get notification for all the successful charges happen. You can get amount, customer data inside the event data which you can store to your DB. I assume you are already storing subscription along with customer, so that you can map subscription from customer data from event data.

Can I charge a variable amount to Stripe as a subscription?

I want to use the Stripe API to bill users every month for an amount they specify. It appears that Stripe does not allow websites to create a subscription without first setting up a plan for it manually, restricting what people can bill themselves for to predesignated amounts.
What is the best way to do this?
You can! Before we talk more about how this works in practice, make sure you understand when an invoice is open for modification.
Subscribing your customer to a new plan, or updating your customer's existing subscription
If you are subscribing your customer to a plan via the API, you won't be able to add any custom fees after the initial invoice is created since it will be immediately closed. This means you'll need to setup any custom amounts before the initial invoice is created. You can do this in one of two ways:
Set the account_balance when creating a customer or updating a customer's subscription.
Create any invoice items before your customer is subscribed to the plan, and then create the subscription via an update customer subscription call.
In either case, we'll pull the account balance or any outstanding invoice items into the initial invoice, so your customer will still be charged for the setup fees. These are essentially one-time charges that you are combining with the subscription's recurring charges. Since these are being added to the invoice total, only a single charge is being created.
Subscription renewals
The account balance and invoice items are simply one-time adjustments to your customer's account, so they won't be automatically applied each month. If your service uses metered billing or needs to add custom amounts for taxes or other dynamic costs, then you will need to create invoice items every month.
To get started, just use webhooks to listen for the invoice.created event. Whenever an invoice is open for modification, your webhook endpoint can create an invoice item that references the existing invoice's ID. We'll automatically pull this amount into the invoice total before charging your customer, approximately an hour after the invoice's creation.
Link:
https://support.stripe.com/questions/metered-subscription-billing

PHP - Best way of taking percentage of transaction

I'm building a website in PHP where users place bids on items. Once bidding has ended, a payment needs to be paid from the winning bidder to the listing owner. But, as the website owner, I also want to take a small percentage - say 5%.
So the process would be the winning bidder pays £100 to the listing owner, and I take 5% as that transaction takes place.
What's the best way of doing this?
I've read about PayPal MassPay, but I'm not sure whether it's what I need or not.
I'm in the UK too, not US - if that effects anything.
You can use Stripe Connect to do this if you're in the UK. You would ask your users to connect their Stripe account to your Connect Application first. You would get some data back, especially a publishable_key and an access_token which you would store on your end.
The you would use those this way:
On the front-end along with Stripe.js or Stripe Checkout you need to use the publishable_key you got from the connected user when going through the Connect flow. You should not use your API key.
Once you get a card token you send it to your server where you will create a charge. There, you should not set your API key but you should pass the access_token of the connected user as a second parameter to the Create Charge API. You can see some example code in the documentation showing how to collect fees.
This would automatically deposit the funds in the connected user's Stripe account minus the Stripe fee and the application_fee you chose. The fee would need to be a specific amount and not a percentage but you can calculate this on your end when creating the charge.
Based on your question, the solution would be as following:
Seller adds a listing on your website.
Bidding starts.
Buyer bids and win. E.g. for $10
Buyer pays using PayPal to your website, where money goes to your account (website owner).
You cut 5% of it, ($0.50) and do a Payout to seller's PayPal account of $9.50.
Optionally/Generally, website owners hold the money till the end of the month, and pay the seller the final amount, (if he is selling more than one thing, or he is a big merchant.)
However, the flow should help you setup a website based on your preferences. Many websites like eBay, Free lancing, apply the similar flow.
As a PayPal Employee, I would recommend using PayPal PHP SDK for developing. All the instructions are provided here and here

Paypal DoDirectPayment without user present (e.g. with cron job)

Is it possible to make Paypal payments using stored user's data (credit card info, name, address etc.) within cron job or other script execution without actual user present?
I want to implement autopayments on my service but I can not to use standard Paypal autocharge functionality because of its complexity.
What you're looking for is called Reference Transactions. You can use the DoReferenceTransaction API to accomplish your goal.
Using this API you simply pass in the transaction ID of a previous Authorization or Sale transaction along with a new amount you'd like to process. It will lookup the billing info saved on PayPal's system using that previous transaction ID, and then process the same source for the new transaction.
This works with both Payments Pro and Express Checkout.
I noticed you posted this with the adaptive payments tag, too. That would be the Preapproval API and the Pay API, but would not involve DoDirectPayment.

Categories