How to retrive Stripe card ID added via Stripe customer portal? - stripe-payments

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",
)

Related

Stripe preview invoice without an active subscription

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
}
]
});

API Integration across multiple accounts within same organization

I have had my API Integration promoted to my Production environment for a few weeks now and all is well but I ran into a new issue that I need help understanding. The process is setting up impersonation. The hierarchy of the organization is relatively simple:
My Integration was built under Company A and so far 100% of Company A accounts are able to be impersonated as expected. The issue came up when Company B was added to the Organization and one of the existing accounts was included in the list to be impersonated. The following message is what I am getting back from my API call.
I have Organization Admin permissions as well as Admin permissions on all of the Company Accounts too and this message appears even for me. My feeling is this is a simple administrative function to grant the User in Company A the permissions to access either a User in Company B or all of Company B. I am just not seeing where this gets setup. I hope anyone can point me in the right direction on this one.
=== 07/06/2022 - Adding additional details ===
/oauth/userinfo respose...
{
"sub": "xxxxx-xx-xx-xx-xxxxx",
"name": "Greg Miller",
"given_name": "Greg",
"family_name": "Miller",
"created": "2017-11-10T18:26:23.583",
"email": "greg.miller#companyA.com",
"accounts": [
{
"account_id": "xxxxx-xx-xx-xx-xxxxx",
"is_default": true,
"account_name": "CompanyA",
"base_uri": "https://###.docusign.net",
"organization": {
"organization_id": "xxxxx-xx-xx-xx-xxxxx",
"links": [
{
"rel": "self",
"href": "https://account.docusign.com/organizations/xxxxx-xx-xx-xx-xxxxx"
}
]
}
},
{
"account_id": "zzzzz-zz-zz-zz-zzzzz",
"is_default": false,
"account_name": "CompanyB",
"base_uri": "https://###.docusign.net",
"organization": {
"organization_id": "zzzzz-zz-zz-zz-zzzzz",
"links": [
{
"rel": "self",
"href": "https://account.docusign.com/organizations/zzzzz-zz-zz-zz-zzzzz"
}
]
}
}
]
}
Additional Info Added 07/07/22
Both Company A and Company B base_uri designation is the same "https://na2.docusign.net"
This is the /oauth/userinfo data returned using the JWT created for the Company B user account I am trying to impersonate.
{
"sub": "xxxxx-xx-xx-xx-xxxxx",
"name": "Company B",
"given_name": "CompanyB",
"family_name": "XYZ TEAM",
"created": "2021-03-31T18:20:05.23",
"email": "xyzteam#companyb.com",
"accounts": [
{
"account_id": "xxxxx-xx-xx-xx-xxxxx",
"is_default": true,
"account_name": "Compan B",
"base_uri": "https://na2.docusign.net",
"organization": {
"organization_id": "xxxxx-xx-xx-xx-xxxxx",
"links": [
{
"rel": "self",
"href": "https://account.docusign.com/organizations/xxxxx-xx-xx-xx-xxxxx"
}
]
}
}
]
}
The steps I take are basically the same as you outline:
Generate JWT Access Token
I am manually storing the required userinfo data userID(sub) and base_uri in a local db table.
I am using CURL to make my API calls " $base_uri.'/restapi/v2.1/accounts/'.$AccountID.'/views/console'"
You have two choices for accessing data in Company B (Account B):
Add the user in Company A (Account A) to also be a user in Account B. (Users can have memberships in more than one account.)
To access the data in Account B (Company B), impersonate a (different) user who is in account B. This is done via the eSign Admin app or via the Org Admin app.
By design, a user who is not in Account B cannot access any data in Account B. (This is the error message you're receiving.)
Note: you do not need to make any changes to your app's integration key (client ID)--all client IDs in production can be used with any user, with any account the user has access to.
To see which accounts the current user has access to, use the /oauth/userinfo API method.
Added
When you get the message User does not have a valid membership in this account check:
What account is the request using? (What is the URL of the request?)
Was the request sent to the right base url for the account?
What result does the current access token provide when calling the /oauth/userinfo API method.
Your test API calls should be:
Get an access token
Call /oauth/userinfo
Call the eSign API (eg list envelopes or somesuch) for each of the accounts listed in /oauth/userinfo

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.

Retrieving the senders name and email from an envelope?

I have a service account that is using DocuSign's polling to retrieve a list of envelopes that had a status change. These envelopes were sent by various internal users. When I go to retrieve the envelopes, I'd like to retrieve who the sender of the envelope is (sender's name and email).
I initially excepted this information to be part of the Envelope object, but it's not:
Envelope envInfo = envelopesApi.GetEnvelope(AccountId, envelopeId);
I've tried various other API calls and reviewed documentation, but none of them seem to provide a way to get the sender's name and email.
Can this information be retrieved?
There actually is a way that you can get Sender Name and Email for an Envelope via the API. First, issue a Get Envelope Audit Events request to identify the UserId of the Sender. Then, use that UserId to issue a Get User request to obtain the sender's name and email address. Here are the steps, with sample requests/responses (irrelevant info omitted, for brevity):
1) Get Envelope Audit Events
Request:
GET /accounts/{accountId}/envelopes/{envelopeId}/audit_events
Response:
{
"auditEvents": [
{
"eventFields": [
...
{
"name": "UserName",
"value": "John Doe"
},
{
"name": "UserId",
"value": "af465e97-83a6-472c-a25b-ebad10e4cc6a"
},
{
"name": "Action",
"value": "Registered"
},
{
"name": "Message",
"value": "The envelope was created by John Doe"
},
{
"name": "EnvelopeStatus",
"value": "created"
},
...
]
},
...
]
}
2) Get User (specifying the UserId from the previous response)
Request:
GET /accounts/{accountId}/users/af465e97-83a6-472c-a25b-ebad10e4cc6a
Response:
{
"userName": "John Doe",
"userId": "af465e97-83a6-472c-a25b-ebad10e4cc6a",
"email": "john.doe#test.com",
"firstName": "John",
"lastName": "Doe",
...
}
Another option (if you're creating the Envelopes with the API to begin with) would be to always specify "Custom Envelope Fields" for each Envelope at creation-time that contain the sender's name and email address. Doing it this way would let you retrieve this info with the same request you're already issuing to retrieve the envelope info (provided that you include the extra querystring parameter (include=custom_fields):
GET accounts/{accountId}/envelopes/{envelopeId}?include=custom_fields
DocuSign does not work in this way, as envelopes are linked to a user and its user's documents so no one can access the document until and unless user shares the envelopes with anyone. So there are no APIs which will inform you the sender email/name by querying DS on envelopeId. You have two ways to achieve this requirement:
Use DS Connect (recommended way), configure Connect in your DS
Account and DocuSign will push the connect messages with the sender
details in that XML message when a subscribed trigger event occurs
Another way is you need to get OAUTH access token of all your users and
then call DS APIs to know the envelopes for each user
Connect message will look like below:
<UserName>Sender Name</UserName>
<Email>SenderEmail#email.com</Email>

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