Stripe API - Get all Skus for a Product - stripe-payments

Using the Stripe API to build a simple e-comm site. I initially was requesting all SKUs but realized what I really wanted was to display all Products.
For example, instead of listing all the variations (SKUs) of Product A, Product B, and Product C, I want to list the main Product A, Product B, and Product C. When the user view the details of Product A, then they see all related SKUs (sizes, colors, etc).
The Stripe API has an endpoint for retrieving all products, and an endpoint for retrieving a single product, but I don't see a property on the product object with the associated SKUs for that product?
How do you retrieve all SKUs for a specific Product using the Stripe API?

You can do it with the SKUs API. One of the endpoints there will list the SKUs. You can filter these SKUs based on the product. i.e.
curl https://api.stripe.com/v1/skus?limit=3 \
-u sk_test_9GavlLpfiKewqeCBXvRvmVgd: \
-d product=PRODUCT_ID
-G
Where PRODUCT_ID is a good typed product, not a service.

Related

Stripe Embeddable pricing table - show active subscription plan

Is there any way to show active subscription plan on stripe's embeddable table, like passing customer, subscription or price id?
https://stripe.com/docs/payments/checkout/pricing-table
How on client side, where stripe pricing table is used, can be prevented for user/customer to select another (or same) plan and do any sort of action except updating current plan with upgrade or downgrade?
The pricing table product is built for first time purchases and it allows you to easily drop an iframe on your webpage that shows the different price options that you offer to your new customers. Once you have a Customer that has already made a purchase, the pricing table product is not what should be used.
Instead, separately, you can let your existing customers manage their subscriptions with the Customer Portal here which has a full Stripe redirect page. You can pass the list of Price ids when creating the portal configuration so your customers are able to upgrade or downgrade to different prices.

Microservice aggragate design?

I develop an eCommerce app with DDD as a microservice.
I have product service, category service, price service.
First question:
I don't store any info about category or price in product service because they are in their own service.
Should I store default value or etc in the product model?
second question:
When CreateProductRequest comes to product service. It includes category and price data in the request model. After creating a product. I fire productCreatedEvent. It stores created product id, category, price info.
Other services consume that event and save its own database related data. For example, pricing service saves price with product id, price. Category service saves product id and category id.
Should I send all data in one event like productCreatedEvent? Or send separated commands like createProductCategory to category service and createProductPrice to price service via rabbitMQ or grpc call.
First of all, you should think if it makes sense to separate product service from price and category services. I dont know what are the responsibilities of each one, but only makes sense to split them if each one has functionality on its own.
I mean, if it is impossible to have a price or a category without its product, the three would be part of the same microservice. There will be a product service wich contains products each of one with its price and category.
In case that this division makes sense because the price and category service have its own functionality and responsibilities independent from the product, these are the answers in my opinion
The first question should be to create categories and prices in first place and when you need to create a product you will reference the price id and category id and pass it to the producto service.
regarding the second question, You should not send price and category info to the product because these are not info that product service have to know, so the proper way to do, as I said before, is first create the price and category calling its own services and then send the createProduct command with the reference.
But once more, I think the best approach is to merge these three services into one because they seem very related

How to get price for Stripe subscription product with volume pricing?

How do I get the price for a subscription product in Stripe where there is volume pricing? The Pricing API docs are here.
For example, in the Stripe dashboard I create a single subscription product priced at $10/month for the first 5 units, $5 thereafter. So if the user enters 5 into a numeric input on a webpage then I want to display $50. If the user enters 6, I want to display $30. I want the value from Stripe, not try and calculate it in the browser.
The Stripe docs on subscriptions don't seem to cover anything other than multiple tiered products, each with a fixed price.
When I create the subscription I can set the quantity, but I want to display the price before the user commits to buying.
Note: this question specifically relates to using the Stripe API and is not about getting the price by using a vendor product.
You can use the Upcoming Invoice API for this. In particular, you'd want to provide pricing & quantity with the subscription_items parameter to simulate a new subscription:
curl https://api.stripe.com/v1/invoices/upcoming \
-u sk_test_123: \
-d customer=cus_456 \
-d 'subscription_items[0][price]=price_789' \
-d 'subscription_items[0][quantity]=10'
If this is for a new customer, you'll need to create a Customer to use with the API, as the customer parameter is required. You can create a customer with just a description -- it's not necessary to collect personal details up front.

Check is item sold in Amazon Product Advertising using API

In my website i have items from amazon, every items has referral link. How can i determine is item sold by refferal link using api ?

How to check if customer is subscribed using curl and Stripe

In Stripe, to get the list of customers who are subscribed using the curl API offered by the online payment system Stripe, one only needs to call:
curl https://api.stripe.com/v1/customers -u sk_test_key:
This returns a list of customers in JSON format. You can run the code yourself as it uses the test data from Stripe.
What if I only want to check if a given customer is subscribed? for example customer ID cus_5uR2Kp7ukpBSBc
First, it's probably not a great idea to put your test keys on SE. It can't be escalated to full control over your account, but anybody could come by and delete all your test customers for giggles (for example). You should probably roll your test keys at this point.
To your actual question, to find any active subscriptions on that customer, you can look at the subscriptions property on the customer response (https://stripe.com/docs/api#customer_object). If you're only interested in the subscriptions, and not the rest of the customer, you can use the list subscriptions endpoint (https://stripe.com/docs/api#list_subscriptions).
Either of these will list all subscriptions on the account, so if you're looking for a subscription to a particular plan, you'll need to iterate through and search for that plan id.

Resources