Stripe charged total amount - stripe-payments

The Stripe home dashboard (not payments, transfers, or customers but when you first login...) shows "gross volume" total which is calculated by totaling all of the successful charges together within the given time period. With the current limiting of a maximum of 100 records, this proves to be difficult when querying for several days worth of data. Meanwhile their internal dashboard endpoint does this fairly effortlessly:
https://dashboard.stripe.com/v1/charts/gross_volume?start_time=1487635200&end_time=1488239999
{
"currency": "usd",
"data": [...],
"estimated": false,
"total": 123456, //gross volume total
"unit": "day"
}
NOTE: The above endpoint is not offered in the Stripe API documents as far as I can tell. I'm looking for an alternative solution.
Is there a better / best practice to retrieve the data that's provided at this endpoint using one of the resources in the given documents?

You can use the Balance Transaction API with auto-pagination to get at all of the information.
By expanding data.source, data.source.customer and data.source.balance_transaction you will have access to all of the information that makes up that Transfer Summary Dashboard page.

Related

What is the most efficient way of frequently getting the last tweets from 1000+ accounts using Twitter API?

I have a list of approximately 1.500 twitter accounts (that may or may not have tweeted) for which I want to retrieve the last (max 100 tweets) every ~20 minutes. Considering the rate limits of Twitter API v.2, what is the most efficient way of doing this without hitting the rate limits (https://developer.twitter.com/en/docs/twitter-api/rate-limits)?
As far as I understand, there is no way of getting tweets from multiple users at the same time using https://api.twitter.com/2/users/<twitter id>/tweets and iterating through the 1.500 accounts to get the last tweets will make you hit the rate limit of ~900 requests per 15 minutes.
Is there a bulk request that can do this? Is adding them all to a Twitter list and get the latest tweets from there the only real option here?
I am needing this for a Node.js application but the issue is more about how to solve it at a Twitter API level.
The Twitter search API is publicly available at /2/tweets/search/all. You can also use /2/tweets/search/recent.
Using this, you can search from tweets from multiple accounts at once using their OR operator:
(from:twitter OR from:elonmusk)
Returns:
{
"data": [
{
"id": "1540059169771978754",
"text": "we would know"
},
{
"id": "1540058653155278849",
"text": "ratios build character"
},
{
"id": "1539759270501023744",
"text": "RT #NASA: The landmark law #TitleIX opened up a universe of possibility for women, including Janet Petro, the 1st woman director of #NASAKe…"
},
// ...
Note, this has a more strict rate limit, and you will have a limit of how many characters you can use in your search (probably 512).
You can add extra fields like author_id from tweet.fields, if you need them.
If you cannot get by with this, then you may be able to combine API endpoints, since rate limits are applied per-endpoint. For example, search half via the searching endpoint, and the other half via the individual user endpoints.
If this still doesn't work, you're right (from everything that I've found), you will need to either:
Increase your cache time from 20 minutes to something more 30-45 minutes
Create a list

How to recoup Stripes $2 per month active fee from small transfer amounts to custom Connect accounts

I'm using separate charges and transfers with Stripe Connect accounts.
So, if I create a transfer of $1.00 to a Connect account, Stripe is going to charge my platform(me) $2.00/month + % fees + $0.25/payout for that active account according to their Connect pricing page
Question - Is there any way to charge the Connect account or pass that $2.00/month active fee onto the Connect account, so my platform doesn't have to pay it? ex. Direct charge, negative balance, invoice, debit custom account, etc. Or is there a way to see the total pending balance that will be sent out to the Connect bank account and "take back" some of it before it gets delivered?
Concern and/or Challenge - When I issue a transfer, I won't have any problems recouping funds (my 5% fees, Stripe's Connect fees 0.25%) from my customers Connect accounts. I won't go into the math explicitly, unless you ask, but I will remove all fees from the transfer before it's sent, then check via "TransferGroup" to look and see if any transfers have been made to the Connect account for that pay period (1/month) and if no transfers have been created yet, I will deduct on another $0.25/payout to be withheld. BUT now I have to do something similar to collect/recoup the Stripe $2.00/month flat rate per active account and this is where my problem arrises. My transfers might all be for $1.00 each! Ex. $1.00x100. So I can't simply deduct $2.00 from a $1.00 transfer to collect this fee.
My idea - The transfers for Stripe are coming from a tipping mechanism I've implemented between students and instructors on my site/app. The students can tip $1,2,3,4,...N tips. I can do a check to see if any tips have been sent for the month and if it's the first tip, force a minimum tip amount of $3.00, for each additional tip a student wants to send, it will only be $1.00. So the first student to send a tip gets forced into a min. $3.00 tip.
Another idea - Check each transfer amount to see if it's >= $3.00, if true, I can take all fees including the $2.00 account fee and still be in the Net positive to transfer, but if this transfer group doesn't receive any $3.00+ transfers in a month, I would then track the amount owed/not collected ($2.00) and try and collect it next month. This might work but seems like a sub par solution. Maybe there's a better way?
Another idea - Allow the Connect account to go into a negative balance , if I had to take $2.00 + $0.25 + %fees out of the first $1.00 transfer. I don't know if this is a good idea or how it would work exactly.
Another idea - I was looking to see if Stripe has a way to look at the total pending balance that will be transferred out to the bank account before the end of the pay period and somehow deduct the $2.00 from the total? I see there is a way to debit accounts, but there are lots of restrictions so I don't think it will work for my scenario (lots of international accounts).
Another idea - Debit custom accounts seems reasonable but it has too many restrictions ex. doesn't work for international accounts.
Another idea - I was looking at Direct Charges where it looks like I can charge a Connect account, but looking at this code, it only creates a "Request". How does it get me the money? Is it automatically sent from the Connect account to me(platform)? What happens if I only transfer $1.00 to a Connect account for a payout, but then send a "Request" for $2.00, does the Connect account go into some negative balance?
var service = new PaymentIntentService();
var createOptions = new PaymentIntentCreateOptions
{
PaymentMethodTypes = new List<string>
{
"card",
},
Amount = 2000,
Currency = "usd",
};
var requestOptions = new RequestOptions();
requestOptions.StripeAccount = "{{CONNECTED_STRIPE_ACCOUNT_ID}}";
service.Create(createOptions, requestOptions);
Stripe only charges the $2.00 fee on active Connect accounts - i.e. ones that you either transfer money to or customers do direct charges to. As such, there is always a monetary transaction before the Stripe Connect charges are accumulated.
In your case (and mine, actually) you are using separate charges and transfers - so withhold an amount equal to the $2.00 charge the first time you transfer to an account each month (a little bit of database/bookkeeping), as well as a "guess" at the payout charges as well (a "guess" because you know when you transferred money, but don't necessarily know how they will be combined into payouts).
2022-01-20
Pseudo-code:
//if using multiple charges to a single vendor
=> collect charges filtered by transfer_group, summing available, pending, fees, then net as AVAILABLE
=> collect existing transfers by transfer_group, summing amounts as ALREADY_TRANSFERED, and gathering transfer Id's
=> we'll use AVAILABLE_TO_TRANSFER = AVAILABLE - ALREADY_TRANSFERED
=> check Connect Account receipt records (your database) for previous transfers in this calendar month (I did mention bookkeeping)
=> if there are no other receipts, then what we'll set BASE = CONNECTED_ACTIVE (currently $2)
=> the amount we will transfer is the AVAILABLE_TO_TRANSFER less reserved fees
=> We know the potential Payout fees will be based on the amount actually transferred (might be less if transfers are collected into a single payout - remember I said pessimistic)
=> The Payout Fee (which we will save as RESERVE) will be based on the actual transfer, FEE = BASE + PER_PAYOUT + PAYOUT_RATE*PAYOUT, with the pessimistic assumption PAYOUT = TRANSFER. PER_PAYOUT is currently $0.25 and PAYOUT_RATE is currently 0.25%.
PLEASE PLEASE PLEASE put the actual values in a database somewhere and use variables to pass into the formula - that way you can easily maintain your code.
=> So now we know AVAILABLE_TO_TRANSFER, and we know that TRANSFER = AVAILABLE_TO_TRANSFER - RESERVE, and we know that RESERVE = BASE + PER_PAYOUT + PAYOUT_RATE*TRANSFER
=> a half-page of algebra, and we can get
RESERVE = (AVAILABLE_TO_TRANSFER*PAYOUT_RATE + (BASE + PER_PAYOUT))/(1 + PAYOUT_RATE)
and
TRANSFER = AVAILABLE_TO_TRANSFER - RESERVE
As mentioned, you do need to keep receipts in your database to know if the Active Connected Account fee needs to be collected. Keep the reserves in your platform account until the monthly Connected Account & Payout fees are charged, reconcile the # of actual payouts against the pessimistic guesses above, and you can the withdraw (payout) any excess from your platform account.
2022-01-20a
you can be even more pessimistic (by a small amount) and just use
RESERVE = BASE + PER_PAYOUT + PAYOUT_RATE*AVAILABLE_TO_TRANSFER
You'll just reserve a tiny amount more than you have to - which we are kinda already doing anyway...
BIG NOTE
This is NOT official advice from Stripe - I do not work for them. This is my approach.
You can specify an application_fee_amount to collect a fee for a Direct Charge.
With Direct Charge, the connected account will pay the Stripe fee, and you as the platform will get the application fee that you specified in the Payment Intent creation.

Stripe Payouts API, how to get the transactions?

With the Stripe Payout API you can list your payouts, for example to your bank account:
https://stripe.com/docs/api/payouts/retrieve
The returning object don't includes the individual transactions, just the total amount of all transactions and some other data.
I want to find out which transactions a certain payout includes, to mark them as "paid_to_bank" in my database.
What ist the best practice in such a case?
I'm working with PHP.
I solved this issue, as #karllekko recommended with the balanceTransactions API, but this way:
$a = $stripe->balanceTransactions->all(
[
'limit' => 10,
'payout' => 'po_xxxxxx'
]
);
var_dump($a->data); // contains all transactions in po_xxxxxx

How to get cost for new g suite licenses?

I am a G Suite Reseller and I need to create a website where my clients can enter the number of g suite users/licenses they want to add and it will calculate the price for them based on the number of licenses and the remaining period.
I have already searched the reseller API page but didn't find any useful resources.
I don't think you need the re-seller API for that, you can check the G Suite licenses price at gsuite.google.com you can just create your own page and calculate it based on those prices,the re-seller API works just to manage the subscription of your clients but nothing related to billing all the reference about the reseller API can be found here https://developers.google.com/admin-sdk/reseller/v1/reference/.
Now if you want to retrieve the expiration date for the plan then you can use the Rseller API,Reseller API > Subscriptions you will find the JSON with the plan start and end time, I would say you can use them to .
"plan": {
"planName": string,
"isCommitmentPlan": boolean,
"commitmentInterval": {
"startTime": long,
"endTime": long
}
I don't have a reseller account but I would say that the best option is to use the Subscriptions > Get to retreive the start and endtime from the plan. The methods I found are
Plan 'startTime plan.commitmentInterval.startTime', an annual commitment plan's interval's startTime in milliseconds using UNIX Epoch format
Plan 'endtTime plan.commitmentInterval.endTime', an annual commitment plan's interval's endTime in milliseconds using the UNIX Epoch format.(for more information about the UNIX Epoch format check the subscription overview property names)
What I am not sure since I dont have how to test is if these two are linked to an annual plan or can be used to any other plan. I hope this information can be of help, greetings.

Stripe Connect - How to charge multiple users to 1 customer

I use Stripe Connect to charge users credit card and transfer to a customer with a commission. I'd like to implement a 'Ride-sharing' functionality type on my app. The idea is to split the amount charged among a number of N people and still transfer to one customer, i.e. a many-to-one transaction.
What is the best way to implement that ? I didn't find any tutorial or docs for many-to-one transactions (only the other way around)
One way is to create as many transfers as charges but it is not ideal for the customer because it can split the payout for one business transaction
The other way, it seems, is to use 'Creating Separate Charges and Transfers' with several charges and one transfer thanks to a transfer_group.
But when I tried :
$charge1 = \Stripe\Charge::create(array(
"amount" => 500, "currency" => "eur", "customer" => "cus_1",
"transfer_group" => "mytransfergroup_1"
));
$charge2 = \Stripe\Charge::create(array(
"amount" => 500, "currency" => "eur", "customer" => "cus_2",
"transfer_group" => "mytransfergroup_1"
));
$transfer = \Stripe\Transfer::create(array(
"amount" => 800, "currency" => "eur", "destination" => "{CONNECTED_STRIPE_ACCOUNT_ID}",
"transfer_group" => "mytransfergroup_1",
));
I got the message
"Insufficient funds in Stripe account. In test mode, you can add funds to your available balance (bypassing your pending balance) by creating a charge with 4000 0000 0000 0077 as the card number."
Ok I am on test mode but in live, should I run a cron job every day to launch the transfer of my untransfered charges, so way after the time of the transaction ?
And even if the balance is enough, I am going to transfer money from older transactions for a more recent one. The problem is when the payout is due for the older transactions, I will not have enough on my balance to payout the right amount for my old transactions.
Hope I am clear.
Thanks for your help.
According to what you've said, it sounds like using separate charges & transfers is the best choice. As explained in the documentation, with this flow your platform "can only transfer up to the platform’s available account balance". In other words, this flow is most suited for platforms that process enough transactions so that their available balance can cover the transfers they need to create. If necessary, you can pre-fund your account's balance to get started.
That said, as this is less of a technical question and more of a payment flow one, I'd recommend reaching out to Stripe's support at https://support.stripe.com/email to ask about this. They will be able to advise you on which flow would be most appropriate for your business.

Resources