Stripe preview invoice without an active subscription - stripe-payments

Can we query Stripe with the subscription_items and a quantity to preview the incoming invoice without an active subscription with the Preview API https://api.stripe.com/v1/invoices/upcoming?
We tried to set subscription_items to preview an invoice without an active subscription. Its response contains a subscription and subscription_item. But when we query the subscription or subscription_item specifically, it threw an error Invalid subscription_item.
Eg, When calling /v1/invoices/upcoming with subscription_items
curl --location -g --request GET 'https://api.stripe.com/v1/invoices/upcoming?customer=cus_MIjwgFDqhg8uBf&subscription_items[0][price]=price_1LDx6JL3XoZTtiHnl5wAWtkg&subscription_items[0][quantity]=1' \
--header 'Authorization: Basic xxxxxx'
{
"object": "invoice",
"lines": {
"object": "list",
"data": [
{
"subscription": "sub_1LeoDVL3XoZTtiHn998jF9zp",
"subscription_item": "si_MNZM3MetxDd9Gu"
}
]
}
}
Then when we query the subscription or subscription_item with /v1/subscription_items/si_MNZM3MetxDd9Gu, it shows Invalid subscription_item:
{
"error": {
"message": "Invalid subscription_item id: si_MNZM3MetxDd9Gu",
"type": "invalid_request_error"
}
}

When you are viewing an upcoming invoice, you are simply viewing a preview – the invoice and subscription has not yet been created. So you cannot query the subscription or subscription item in the response from the upcoming invoice API.
https://stripe.com/docs/api/invoices/upcoming does not require an active Subscription. subscription is an optional parameter. The Stripe docs mention :
The identifier of the subscription for which you’d like to retrieve the upcoming invoice. If not provided, but a subscription_items is provided, you will preview creating a subscription with those items....
The below Node.js example code previews creating a subscription :
const invoice = await stripe.invoices.retrieveUpcoming({
customer: 'cus_...',
subscription_items: [
{
price : `price_...`,
quantity : 2
}
]
});

Related

How to retrive Stripe card ID added via Stripe customer portal?

How to retrive Stripe card ID added via Stripe customer portal?
It is not visible when I try to access it via:
test = stripe.Customer.list_sources(
'cus_Izw...',
object="card",
limit=3,
)
I see this in the response:
{
"data": [],
"has_more": false,
"object": "list",
"url": "/v1/customers/cus_Izw.../sources"
}
Cards that are added through the Customer Portal are PaymentMethods not Sources. In order to list them, you can use the /v1/payment_methods. In Python it would look something like:
stripe.PaymentMethod.list(
customer="cus_xxx",
type="card",
)

Is there an Instagram API/Graph API for finding the Instagram Profile Type (Business/Personal)?

I am using the Graph API to get details from business users. Since most of the Profile is Non-Business, would like to find-out, if there is an API to get the Profile Type?
During the trial, I keep getting the following message and also discovered sometime the API is misbehaving..
{
"error": {
"message": "Invalid user id",
"type": "OAuthException",
"code": 110,
"error_subcode": 2207013,
"is_transient": false,
"error_user_title": "Cannot find User",
"error_user_msg": "The user with username: rohit_xxx cannot be found.",
"fbtrace_id": "FkKgUvBdJWZ"
}
}
So, If I know the Profile Type in advance, We can handle the response in much better way..
Thanks in Advance..
The instagram Graph API is designed to work with creator/business accounts. This is specified in multiple places.
If a user doesn't have business/creator account, the instagram id would be empty in the response.
curl -i -X GET \
"https://graph.facebook.com/v3.2/{fb-page-id}?fields=instagram_business_account&access_token={access-token}"
Response:
{
"instagram_business_account": {
"id": "" // Connected IG User ID
},
"id": "134895793791914" // Facebook Page ID
}

Received unknown parameter: transfer_data

I'm trying to add an application percentage fee and a destination for the subscription charge. I'm following the docs (https://stripe.com/docs/connect/subscriptions)
This works fine without transfer_data.
sub = stripe.Subscription.create(
customer=_stripe_customer_id,
items=[
{
"plan": _plan_id,
},
],
transfer_data={
"destination": _destination_id,
},
application_fee_percent = mooch_application_fee_percent,
)
return sub
This is the error I'm getting 'Received unknown parameter: transfer_data'
I don't know what I should be doing.
I don't see transfer_data in the list of fields for subscription object.
Ref: https://stripe.com/docs/api/subscriptions/object#subscription_object-customer
You may use metadata to store custom data.
If the destination_id is a stripe account id, use stripe_account instead of transfer_data.

Modify Stripe subscription status

I have been trying to modify the subscription 'status' from 'trialing' to 'active' once the user buys our standard subscription but it doesn't recognize the parameter 'status'.
Post URL : https://api.stripe.com/v1/subscriptions/sub_DlwSiqrLvSArgV
Request body:
{
"Status": "active",
"items": {
"0": {
"id": "si_DlwSpUvFPN6Mje",
"deleted": "true"
},
"1": {
"plan": "plan_Dk4I92tnE0cmXS"
}
}
}
Response:
{
"error": {
"code": "parameter_unknown",
"doc_url": "https://stripe.com/docs/error-codes/parameter-unknown",
"message": "Received unknown parameter: Status",
"param": "Status",
"type": "invalid_request_error"
}
}
I'm not sure if I'm putting the status in wrong place or if i need to add some other additional parameter(s) to change the status.
The status property is calculated by Stripe and it's not something you can set yourself. It is not in the list of parameters for the Update Subscription API either.
If you want to move a subscription from 'trialing' to 'active' you have to explicitly end the trial period by passing trial_end: "now" as documented here. This will automatically charge the customer the expected amount and if the charge succeeds it will switch your subscription to active at the same time.

Figure out last completed payment via Accounts.payments: list in AdSense Management API v1.4

I am successfully using Google's AdSense API to retrieve payments. The AdSense account I am testing the app with does not have any completed payments.
I am using Accounts.payments:list to retrieve the payments and currently I am only getting one row with Id = "unpaid". This entry specifies the amount that is available for payment.
My question here is what are the other possible entries in the result? Specifically how can I find last completed payment?
Thank you for your help.
items[] description: "The list of Payments for the account. One or both of a) the account's most recent payment; and b) the account's upcoming payment".
As far I can see id can be "unpaid", or date of the last payment (probably the "payment issued" date):
{
"kind": "adsense#payments",
"items": [
{
"kind": "adsense#payment",
"id": "unpaid",
"paymentAmount": "***.**",
"paymentAmountCurrencyCode": "***"
},
{
"kind": "adsense#payment",
"id": "****-**-**",
"paymentDate": "****-**-**",
"paymentAmount": "***.**",
"paymentAmountCurrencyCode": "***"
}
]
}
how can I find last completed payment?
In my understanding, that is exactly what Accounts.payments:list is (or will be) returning:
your account current balance
last payment (if there was any)

Resources