Possible to query a Stripe managed account's balance? - stripe-payments

I've gone through the docs and haven't been able to spot a way to query balance info for Stripe managed accounts. Here's the use case: a 3rd party sets up a managed account through my Stripe Connect enabled platform; I create some charge objects on their account after a few customers buy goods/services (so their balance is now positive); now they want a payout BUT I want to query their balance before issuing the transfer to ensure they're not asking for more than is in their account.
Surely I'm missing something obvious. Thanks in advance.

So for Ruby, based on Ywain's answer, I figured that instead of doing what's documented:
Stripe.api_key = CONNECTED_STRIPE_ACCOUNT_SK
Stripe::Balance.retrieve
a better way, that is not documented, is to do:
Stripe::Balance.retrieve(stripe_account: CONNECTED_STRIPE_ACCOUNT_ID)
as long as the current api_key is your platform account with the managed accounts option enabled.

PHP
\Stripe\Balance::retrieve([
'stripe_account' => CONNECTED_STRIPE_ACCOUNT_ID
]);
Python
stripe.Balance.retrieve(
stripe_account=CONNECTED_STRIPE_ACCOUNT_ID
)
Ruby
Stripe::Balance.retrieve(
:stripe_account => CONNECTED_STRIPE_ACCOUNT_ID
)
Node
stripe.balance.retrieve({
stripe_account: CONNECTED_STRIPE_ACCOUNT_ID
}, function(err, charge) {});

You should be able to do this by simply issuing a balance retrieval call while authenticating as the connected account, e.g.:
curl https://api.stripe.com/v1/balance \
-H "Authorization: Bearer {PLATFORM_SECRET_KEY}" \
-H "Stripe-Account: {CONNECTED_STRIPE_ACCOUNT_ID}"

Related

Angular/node.js Stripe Checkout Integration (1 account to facilitate payments from third party payer to third party receiver)

Man, I have been at this for some days and can't find a good solution to this. I want to use my account (via public key and private key) to facilitate payments from one account to another (nothing will be going into my account). On the front-end I have:
checkout(amount) {
const strikeCheckout = (<any>window).StripeCheckout.configure({
key: environment.PRODUCTION==='true'?stripeLiveClientId:stripeTestClientId,
locale: 'auto',
token: (stripeToken: any) => {
if(stripeToken){
console.log(stripeToken)
this.createCharge(stripeToken,amount)
}
}
});
strikeCheckout.open({
name: 'Camel Stripe',
description: 'Stripe Checkout',
amount: amount
});
}
Just a small snipet, but essentially this just captures the credit card and email and ensures it is a valid credit card and then makes a stripe token. I then pass this token to the node backend and do:
stripe.paymentIntents.create({
amount: priceInPence,
currency: 'usd',
source: stripeTokenId,
capture: false, // note that capture: false
}).then(charge => {
return res.json({ success: true, message: 'Success', result: charge })
}).catch(error => {
res.status(400).json({ success: false, status: 400, message: error });
});
//})
};
No matter how I structure it, it always end's up getting the payment to my account, the account with the public/private key. Does anyone know a way I can use this token since it has the necessary information, and send the money to another account?
You can't accept payments and move the funds into a completely different Stripe account unless you're using Connect.
To piggy back on Paul's comment, after much research on Stripe Connect I wanted to share my findings. Please note this is specific to my use case and is using angular/express.
Connect offers multi-party payments, meaning you can receive funds from 1 user, then route them into another users account. You will need a stripe connect account. After that you connect an account, aka create account. They offer 3 account types all these account types need to be
Custom: basically is if you don't want the account you're routing to to see anything stripe related, meaning it is white labeled and the user has no dashboard or view of what is going on in the background.
Standard(the one I chose): this account will have a full stripe dashboard, it has all the functionality that an account would have that you make on your own. You will get a unique account id relevant to your specific connect account environment, on their end, they will have multiple account ids depending on how many other connects they are connected to, or if it is an already existing account. You will need to use this api to get the link to have them verify information before they are integrated into your connect environment account link api
Express: they will have a slimmed down version of a dashboard, it is similar to standard with less functionality
At this point you're ready to start routing payments. I did angular on the front-end, here is an example basically this simply creates a stripeToken, which is a verification that the card data is valid. You need to pass this to a backend to make use of it, this will not create any charges.
On the backend, I used express, you use the charge api You pass the stripeToken as the source attribute. One important step is to add the stripe account id you see in your connected accounts dashboard. It should look similar to:
stripe.charges.create({
amount: priceInPence,
currency: 'usd',
source: stripeTokenId,
capture: false, // note that capture: false
},{
stripeAccount:'{{acctId}}'
})
This should be sufficient to get your payments routing to the necessary account while leveraging a simple UI checkout.
One thing to note about the charges API, this is an older API and has less functionality. For my use case (US CA only with only card payments) it is sufficient. If you have a more complicated use case, or maybe your app is for heavy prod use to many users you should look into payment intents.

Create Custom Stripe Connect Accounts

I have built a platform with buyers and sellers and now I would like to integrate payments.
I came across Stripe, it is quite easy and straight forward to use.
However, I found the documentation to be lacking since I want to implementation whereby the seller doesn't have to create a stripe account in order to get paid by the buyer.
What Stripe offers is a solution they call; stripe connect.
Stripe connect has three options; Standard, Express and Custom.
The solution that makes sense for my specific use case is the custom option.
From the documentation, they have this code snippet;
Stripe.api_key = 'STRIPE_SECRET_KEY'
account = Stripe::Account.create({
country: 'US',
type: 'custom',
requested_capabilities: ['card_payments', 'transfers'],
})
The above, they write, is used to create a custom account. Quite frankly, there isn't much to work with.
Has anyone developed something that I am trying to implement. Assistance in this regard would really be helpful.
I have implemented Express Stripe connect. This is an helper that I have written;
module ApplicationHelper
# Express Stripe url
def stripe_url
"https://dashboard.stripe.com/express/oauth/authorize?response_type=code&client_id=#{ENV["STRIPE_CONNECT_CLIENT_ID"]}&scope=read_write"
end
# Express Stripe Implementation
def stripe_connect_button
link_to stripe_url, class: "stripe-connect" do
content_tag :span, "Connect With Stripe"
end
end
end
I write <%= stripe_connect_button %> in the .erb file and it rendered properly. I am able to go through the entire process.
I would like to have a somewhat similar approach but for Custom Stripe Connect because with the above implementation, I had to create a stripe account as a seller.
I was able to test the custom stripe account creation using curl based on this
With curl it is like so;
curl https://api.stripe.com/v1/accounts \
-u STRIPE_SECRET_KEY: \
-d country=US \
-d type=custom \
-d "requested_capabilities[]"=card_payments \
-d "requested_capabilities[]"=transfers
The above returns json and I copy the id which an account_id. I use this id in another curl request;
curl https://api.stripe.com/v1/account_links \
-u STRIPE_SECRET_KEY: \
-d account= #{id} \
-d refresh_url="https://example.com/reauth" \
-d return_url="https://example.com/return" \
-d type=account_onboarding
This returns json that looks like so;
{
"object": "account_link",
"created": 1594988541,
"expires_at": 1594988841,
"url": "https://connect.stripe.com/setup/c/AUyum7LCw4cV"
}
Then I visit the url: https://connect.stripe.com/setup/c/AUyum7LCw4cV to do the on-boarding. I have successfully been able to create a stripe connect custom account.
However, I want to translate this flow to RubyOnRails.
So, my question is, how do I cause the below code snippet to initiate account creation when a Seller clicks a button (Connect To Stripe) ?
Stripe.api_key = STRIPE_SECRET_KEY
account = Stripe::Account.create({
country: 'US',
type: 'custom',
requested_capabilities: ['card_payments', 'transfers'],
})
In the Express Stripe Connect implementation, I had a url that I was passing to the button. With the above, I have no url to work with.
The code you share would create a Custom account on behalf of the seller in the API. This is only the first step before you can accept payments on their behalf and send funds to their bank account.
There are a lot of regulations around the flow of funds and the information you need to collect from the seller and you can't simply send $100 to a bank account in the US without completing those steps. Stripe covers in details all the information that needs to be collected depending on the type of business you are building and the countries you are going to operate in. You can read more about this here: https://stripe.com/docs/connect/required-verification-information
Collecting this information reliably can be fairly tricky early on for a project like yours. Similarly, rules and regulations evolve regularly, requiring you to collect more details for new users, backfill some missing information and do extra reporting.
This is why Stripe built their Connect Onboarding hosted page so that you can defer the collection of all information to them. You can read more about this here: https://stripe.com/connect/onboarding
Using Connect Onboarding is likely to be the best solution for your business as you can easily enable your sellers to provide the relevant information without having to own a Stripe account directly while you focus on the core parts of your own business.

How to retrieve Instagram username from User ID?

How can one retrieve an Instagram username from it's ID using Instagram's API or website? I have gotten a database table which contains Instagram User IDs and I need to know their usernames.
One can use https://i.instagram.com/api/v1/users/USERID/info (replace USERID by the user id). It returns a JSON in which the field user.username is that user's username.
With curl and jq installed, this shell oneliner will directly return the username:
curl -s https://i.instagram.com/api/v1/users/USERID/info/ | jq -r .user.username
However, keep in mind that this isn't an official API endpoint.
before continuing I would like to inform you that due to recent experiences, this "solution" is no longer available due to the latest updates in instagram api, but I hope it will contribute to something for you!
You could access the user data that you have the userId through the instagram api through the endpoint: https://api.instagram.com/v1/users/{user-id}/?access_token=ACCESS-TOKEN
However this requires [public_content], a permission that needs to be accepted by instagram so you can explore all the "public users" of instagram, this permission is no longer being waited for by instagram.
You can learn more about the instagram endpoints here: https://www.instagram.com/developer/endpoints/users/#get_users
Instagram Graph API
In 2019-08-13 Instagram had introduced Business Discovery API where it allows you to get data about other Instagram Business or Creator IG Users.
For that you need following permissions:
instagram_basic
instagram_manage_insights
pages_read_engagement or pages_show_list
First of all you need to fetch your Instagram Business Id using this query
https://graph.facebook.com/v7.0/{your_instagram_id}?fields=instagram_business_account&access_token={your_access_token}
then you will get Instagram Business Id
{
"instagram_business_account": {
"id": "17841430463493290"
},
"id": "101345731473817"
}
Using Instagram Business Id and your access token you can fetch anyone's user id from username
Example:
https://graph.facebook.com/v7.0/17841430463493290?fields=business_discovery.username(zimba_birbal){id,username,followers_count,media_count}&access_token={your_access_token}
Response:
{
"business_discovery": {
"id": "17841401828704017",
"username": "zimba_birbal",
"followers_count": 166,
"media_count": 36
},
"id": "17841430463493290"
}
Need modify the user agent (instagram app's agent), and use some browser web, otherwise use wget.
wget --user-agent="Instagram 85.0.0.21.100 Android (23/6.0.1; 538dpi; 1440x2560; LGE; LG-E425f; vee3e; en_US" https://i.instagram.com/api/v1/users/*SOME_ID_INSTAGRAM*/info/
find your desidered username in file "index.html" saved
Note: to find the user ID, you can add ?__a=1 to a profile URL, for example: https://www.instagram.com/*SOME_USERNAME*/?__a=1
Data 365 Instagram API that I am currently working for seems to be a suitable tool that may help you.
Birbal Zimba has already described a number of restrictions on the official API in his answer. Instagram API from data365.co doesn't have such limits.
To get the username, you should send requests including the profile_id (the same as the user_id), namely:
POST request to download profile data:
https://api.data365.co/v1.1/instagram/profile/{profile_id}/update?access_token=YOUR ACCESS TOKEN
GET request to receive profile data:
https://api.data365.co/v1.1/instagram/profile/{profile_id}?access_token=YOUR ACCESS TOKEN
You will receive a response not only a username but also a full name, biography, profile photo, business category, user gender and age, number of followers, followings, posts, and much more.
You can see a response example in JSON here.

Are the Azure usage and rate card APIs supported for US GOV EA subscriptions?

I have a client with a Azure subscription sitting in a US GOV data center. This subscription is under an EA (not pay-as-you-go).
Attempting to use the standard billing APIs (ratecard and usage) fails with a 'Subscription not found' error. I.e. running the following:
https://management.azure.com/subscriptions/[subscription id here]/providers/Microsoft.Commerce/RateCard?api-version=2015-06-01-preview&$filter=OfferDurableId eq 'MS-AZR-USGOV-0017P' and Currency eq 'USD' and Locale eq 'en-US' and RegionInfo eq 'US'
fails with:
{
"error": {
"code": "SubscriptionNotFound",
"message": "The subscription '[subscription id here]' could not be found."
}
}
I've found very little information on the rate card and usage APIs with EA accounts and even less information on these APIs for accounts running in a US GOV Azure region. Does anyone know if this is supposed to work?
I don't have any experience with the Gov environment, but otherwise my experience is that Resource Usage API also works for EA, whereas the RateCard does not.
I would suggest you to start out with the powershell cmdlets for an easy start
* Get-AzureRmUsage
https://learn.microsoft.com/en-us/powershell/resourcemanager/azurerm.insights/v2.3.0/get-azurermusage
Be sure that you have powershell running correctly towards the Government environment first.
If you want to roll your own client remember to use the correct endpoints as described in "Azure Government developer guide"
https://learn.microsoft.com/en-us/azure/azure-government-developer-guide
Brgds Brian
For EA offer IDs, you need to use the following API:
https://consumption.azure.com/v2/enrollments/(enrollment_id)/pricesheet
You will need to provide EA API Key (different than bearer token from other APIs):
curl -X GET https://consumption.azure.com/v2/enrollments/(enrollment_id)/pricesheet -H 'authorization: Bearer (api_key)'
Note that the API bearer token needs to be created in the EA Portal under the User Account. More detail can be found here: https://learn.microsoft.com/en-us/azure/billing/billing-enterprise-api
Also note that the user must have appropriate privileges otherwise the API will reject your request.

Stripe API error when passing application_fee

I am trying to collect an application fee using the Stripe API. I am sure I am missing something in the request.
Stripe complaints that it needs either of these: OAuth key, the Stripe-Account header, or the destination parameter.
I am passing in the Stripe-Account header.
Here is my curl request:
curl https://api.stripe.com/v1/charges \
-u sk_test_<key>: \
-H "Stripe-Account: acct_<key>" \
-d amount=2000 -d currency=usd -d capture=true \
-d card=tok_<key> -d description="curl" -d application_fee=48
Here is the response I get:
{
"error": {
"type": "invalid_request_error",
"message": "Can only apply an application_fee when the request is made on behalf of another account (using an OAuth key, the Stripe-Account header, or the destination parameter).",
"param": "application_fee"
}
}
What can I try next?
To add my experience of this issue to the comments above – when you include an application fee in the request, Stripe expects that you will be charging a customer on behalf of a connected account. The application fee is the amount that should go to your platform account, as your fee for the service you provide.
Stripe throws this error if it believes that the account being paid is the platform account, and therefore it makes no sense to process a separate application fee to the same account. Ways this can happen include passing in your platform account number instead of a connected account number in the request, or a destination parameter that is set to null.
The solution is to double check the account you are making payment to is not your platform account, or not include the application fee if the charge is going to your platform. I would add a link to the relevant part of the documentation, but I'm not aware of this being covered anywhere.
This happened to me when I accidentally had a nil value for the recipient's stripe account number.
The solution was to make sure destination was a valid stripe account code: e.g. "acct_1HtSHv7fgYVxT5fZ"
Stripe.api_key = 'sk_test_4eC39kjhkhgkhlhj1zdp7dc'
payment_intent = Stripe::PaymentIntent.create({
payment_method_types: ['card'],
amount: #amount_minor_unit,
currency: #currency,
application_fee_amount: 123,
transfer_data: {
destination: #stripe_account,
},
})
Stripe::InvalidRequestError (Can only apply an application_fee_amount when the
PaymentIntent is attempting a direct payment (using an OAuth key or Stripe-Account header)
or destination payment (using `transfer_data[destination]`).)
Once I had the correct value for #stripe_account (instead of nil), the above code worked

Resources