I am using stripe latest version in production.
When I try to fetch transactions:
Stripe::Transfer.all.first.transactions
I fount, there is no transactions method for latest Stripe::Transfer
undefined method `transactions' for #<Stripe::Transfer
Stripe API is upgrades:
2014-08-04
The transactions, summary, and other_transfers properties in automatic transfer responses have been removed in favor of the balance history endpoint (/v1/balance/history), which can be called with the transfer id (using the ?transfer= parameter) to filter transactions by transfer.
So How we fetch transactions from Stripe transfer ?
But its working fine with Stripe old version.
You have a couple of options depending on what you want. If you a certain level of detail for charges you can fetch all the charges associated with a transfer which will fetch only that:
var options = {};
stripe.transfers.listTransactions(id, options);
If, on the other hand, you would like something more akin to the old summary object then I would get the balances associated with the transfer:
var options = { transfer: id };
stripe.balance.listTransactions(options);
The balances returned will contain a variety of balance types - the first one refers to the actual transfer as a whole and can be ignored and the rest is a combo of charges, refunds, adjustments, etc including the fees for each.
In both the above cases id refers to the transfer ID. Note that you will need to loop through these to fetch all items - this can be done in a couple of ways as listed under Pagination. In the above cases, I check if the result contains the has_more: true field and, if so, loop through again using the starting_after: X addecd to the options object where X is the ID of the last charge/balance returned on previous call.
Related
In stripe, we have the option to expand some of the child object when the property has the expandable option. And the expandable property is not shown by default. For example in customer object, we have the sources list which is not shown by default. But we need to expand it when retrieving the customer by adding the expand parameter - "sources" as below.
var customer = this.stripeService.getCustomer(stripeCustomerId(), List.of("sources", "default_source.card"));
Now since sources is a list it by defaults shows only 10 cards. But I wanted to limit that to more number say 20. How can we do this on the expandable property?
I Still did not find a way to set the limit but we can fetch all the items without the default limit of 10 using the following code. The key is autoPagingIterable that brings all the data without paging
var customer = this.stripeService.getCustomer(stripeCustomerId(), List.of("sources", "default_source.card"));
if(customer.getSources().getHasMore()){
List<PaymentSource> paymentSources = new ArrayList<>();
customer.getSources().autoPagingIterable().forEach(paymentSource -> {
paymentSources.add(paymentSource);
});
customer.getSources().setData(paymentSources);
customer.getSources().setHasMore(false);
customer.getSources().setUrl(null);
}
Reference -> https://stackoverflow.com/a/64173387/12752873
The autoPagingIterable is the right approach but it's best to be used on the correct API endpoint.
From Stripe's docs:
The sources property on Customers is no longer included by default. You can expand the list but for performance reasons we recommended against doing so unless needed.
If you want to get a customer’s sources you should call the separate endpoint.
I am listening to Stripe's invoice.payment_failed webhook with my web app and I would like to get the default_payment_method from each invoice but for some reason it always returns nothing but an empty array!
When I query for a Stripe invoice on the command line and expand on the default_payment_method like this...
Stripe::Invoice.retrieve('in_3K6dIY2KgYRkshw2LAzya63P', :expand => "default_payment_method")
...I also get empty arrays. This surprises me because all my Stripe customers do have a default payment method associated with them.
What am I missing here?
Thanks for any help.
There are three independent places a default payment method can be set. From more specific to less specific they go :
invoice.default_payment_method (which you are looking at)
subscription.default_payment_method
customer.invoice_settings.default_payment_method
Stripe charges the most specific one if it's set. When reading from the API, those values don't inherit from the level above, they can all be set individually, if they are not set explicitly then they are null. So that's why you see it as null on the Invoice level.
Instead you likely want to look at the Subscription object or the Customer object(and can leverage the expand feature for that), depending on how you built your integration and which one it sets.
Overall though, you probably actually want the PaymentMethod used in the invoice payment though? That would be from the last_payment_error.
inv = Stripe::Invoice.retrieve({
id: 'in_1K8iiKJoUivz182DMzSkuBgp',
expand: ["customer.invoice_settings.default_payment_method",
"subscription.default_payment_method",
"payment_intent"]
}
)
print("invoice : #{inv.default_payment_method} \n")
print("subscription : #{inv.subscription.default_payment_method} \n")
print("customer : #{inv.customer.invoice_settings.default_payment_method} \n")
print("failed charge : #{inv.payment_intent.last_payment_error.payment_method} \n")
We are using the following API call to get orders created in SC as unshipped orders.
https://sellingpartnerapi-na.amazon.com/orders/v0/orders?MarketplaceIds=ATVPDKIKX0DER&CreatedAfter=2021-01-01&OrderStatuses=Unshipped
Above one returns correct order data if there are no partially shipped orders. But, if there are partially shipped orders, the API call above includes that one as well. This is causing a problem while syncing the orders between SC and SAP.
The same thing is happening if we call the API with below url -
https://sellingpartnerapi-na.amazon.com/orders/v0/orders?MarketplaceIds=ATVPDKIKX0DER&CreatedAfter=2021-01-01&OrderStatuses=Partiallyshipped
is there a way to restrict the API call to return only either Unshipped or Partiallyshipped orders when called for a single Order status?
Github link - https://github.com/amzn/selling-partner-api-docs/blob/main/references/orders-api/ordersV0.md#orderstatus
Thanks
Sugata
I created a POC with a customer/credit card in Stripe and I logged into my dashboard within Stripe and was able to see this customer has a default source (the test credit card I added) associated correctly. It shows this card is the default source.
When I run this .Net code:
var customerService = new CustomerService();
var stripeCustomer = await customerService.GetAsync(customerId);
To get that customer, it returns everything correctly except his source. All of the fields I had hoped I can find it from are empty! I want to know his default payment source so I can show it on the front end with a little icon to indicate it's default.
DefaultSource, DefaultSourceId, and Sources properties are all blank/null.
Is there a way to have Stripe return it, or do I need to do something else? I tried the 'expand' property for the GetAsync method but that threw an error saying the above properties are not expandable (i.e. I can't ask Stripe to expand/return Source).
Any ideas what I can do?
FYI I also tried this:
var paymentMethodService = new PaymentMethodService();
var cards = await paymentMethodService.ListAsync(new PaymentMethodListOptions { Customer = customerId, Type = "card"});
and there doesn't seem to be a property anywhere that says the card is default (although it does correctly return all cards). I believe Stripe documentation states the Customer is the holder of the default source, not the card object. What gives?
Thanks in advance!
It looks like you're using Payment Methods, since your payment method list call has the results you expect, which means the customer likely doesn't have any sources. You can try that again with the properly pluralized expand[]=sources if you do know your Customer has Sources attached.
For Payment Methods, there is no general default for the Customer. For one-time Payment Intents, you must always specify the payment_method from among those attached to the Customer for future payments.
For paying invoices (related to recurring subscriptions, eg), you can set the invoice_settings.default_payment_method for Customer. This only applies to invoices.
My app uses subscriptions with Stripe.
I want to create a standard "account" page, which will list the customer's current card information (like "MasterCard" and last 4 of card number), and give the customer the option of updating that information.
I'm stuck on the first piece--getting back the current card information. To do this, I need the current card_id. I have tried the "listSources" method, but this returns blank data where the card info is supposed to be. What do I need to do to get that card info?
Here is what I've tried:
(I'm using Node, and running this server side)
The closest method I have found is here:
var stripe = require('stripe')(STRIPE_TOKEN);
stripe.customers.listSources(
CUSTOMER_ID,
{object: 'bank_account', limit: 3},
function(err, cards) {
// asynchronously called
}
);
This returns information (there's no error), but the docs say this method should return a data array of the cards that includes the card id for each. In testing, the data array keeps coming back empty.
I am testing with a customer id that has a valid subscription and a card that I can see on my Stripe dashboard.
Why is the data array coming back empty?
Note: there's also a retrieve source method, which should give back card details, but this method requires you have the id of the card you want info on, and that's what I am not able to get right now.
Converting this to an answer...
Stripe has recently rolled out PaymentMethods, which replace (and are separate from) the older Tokens and Sources API.
OP's issue is that their integration creates PaymentMethod objects, which won't show up in the sources list, but can instead be accessed via stripe.paymentMethods.list.