Stripe modelling prices that are a % of revenue of customer - stripe-payments

I have a case where customers that use the product generate revenue with it and a small percentage should be paid to my company in return.
I wonder how to model that in stripe. If all customers would make their revenue in the same currency I could setup a usage based price in EUR that reflects the percentage and for each customer generated revenue could create a UsageRecord with an amount that represents the revenue e.g. EUR-Cent like with below code.
However I have customers with multiple currencies and thus their revenue comes in multiple currencies too. And then I cannot use the approach as the UsageRecord just states an amount but not currency. And the amount*pricePerAmount in Currency is specified in the UsagePrice. Thus I would report amounts in a different currency which with this approach would be considered to be in EUR - i.e. that wouldn't work.
const record: Stripe.UsageRecord = await this.stripe.subscriptionItems.createUsageRecord(subscription.stripeUsageSubscriptionItem,
{
quantity: order.customerPrice * 100,
timestamp: Math.trunc(order.createdDate.getTime() / 1000),
action: 'increment',
},
{
idempotencyKey: idempotencyKey
}
);
Also I dont want to create a price item for each currency and apply the UsageRecord to that price since I would need to create lots of such prices(one per currency).
Or should I jsut for each customer order create a paymentintent with the right amount sort of manually?
Weird thing to me is that Stripe itself charges the same way i.e. percent of revenue we make over it - so they somehow can do it right?
Thanks
Tom

Related

Retrieve all products prices with multiple currency options

I have two products A and B with two prices each (1 monthly and 3 months cycle).
Every price has two currency options (USD and EUR).
I'm able to list all the prices using :
const prices = await stripe.prices.list({});
But it doesn't return the currency options for each product prices. I only get the price in the default currency (USD).
How can retrieve prices with all the currencies ?
I tried this :
const businessOwnerProduct = await stripe.prices.retrieve(
'price_xxxxxxxxxxxxxx',
{expand: ['currency_options']}
);
But it returns the price per product. Thus i need multiple requests (4).
Is there a way to retrieve a list of products + prices (in multiple currencies) ?
The currency_options property is not returned by default. This is what Stripe calls an "includable" property. The idea is that it's costly to render as you could have many currencies and so you have to explicitly ask for it when you retrieve it using their Expand feature.
This is what your second example does where you expand it when calling the Retrieve Price API.
The Expand feature also works during a list call as documented here. So your code should look like this:
const prices = await stripe.prices.list({
expand: ['data.currency_options'],
});
Note the data. prefix as the API return a List which has the data array with 10 Prices by default

Joining multiple Table using sequelize

I have 4 table t1,t2,t3,t4 in a POSTGRESQL database. Each of the table contains 3 common field, "currency" eg INR DOLLAR etc, "debt" eg 12006 , "credit" eg 1000. Credit and debt are integers.
Each table contains multiple entries of every currency possible
I want the sum of debt and credit of each currency across all the 4 tables
currency
debt
credit
INR
12006
1000
DOLLAR
50002
3012
yen
1234
12546
I'm using sequelize, there's no realtion between any 4 tables, I'm only able to add credit and debt of 1 table at a time using this
var a = await asset.findAll({
attributes: ['currency',[sequelize.fn('SUM', sequelize.col('credit')),
'credit'],
[sequelize.fn('SUM', sequelize.col('debt')), 'debt']
],
group: ['currency'],
});
can someone please guide me how can I make a complete outer join using sequelize preferably else raw query would also work

Calculate median of aggregated values for a category using pivot table

I have hourly data about sales $ of certain categories (Fruits, snacks etc). I'd like to display the median of daily sales values over a month or an year using the hourly data in the table. So, for each category it needs to sum the hourly values and create a daily value first and then calculate the median
regular pivot does not provide median function. I am familiar with Power pivots but have not used Measures. i tried to create a measure using medianX function, but could not make it work
First, you will need to add a Calendar table to your data model:
Calendar Table Explained
The Calendar table must have fields you want to group your sales by, such as "Year-Month" and "Year-Quarter".
Then, connect the Calendar table to your Sales table via date fields, to get a structure like this:
With this data model in place, create 2 measures ( I will assume your sales table is called "Sales", and calendar table is called "Date"):
Measure 1:
Total Sale = SUM(Sales[Amount])
It will simply calculate sum of sale amounts.
Measure 2:
Median Monthly Sale = MEDIANX( VALUES(Date[Year-Month]), [Total Sale])
This measure will first sum up sales by Year-Month, and then calculate the median of the sums.
To get median sales by a different period, just replace Year-Month with the desired grouping level, for example:
Median Yearly Sale = MEDIANX( VALUES(Date[Year]), [Total Sale])
Ali,
When you create your measure you will want to use the MEDIAN funciton not MEDIANX
The MedianX would be if you were trying to calculate the median value for a column in your table that did not already exist.
For Example, lets say we have Table1 which has two columns Net Revenue and Net Expense. And the following 3 data points exist for each row in the column.
Net Revenue:
Jan-2019 100
Feb-2019 300
Mar-2019 300
Net Expense:
Jan-2019 50
Feb-2019 100
Mar-2019 50
Since we do not have a Net Profit column in the table we could use MEDIANX to specify the table we would like to use then write our expression for the column that doensn't exist. In the example above it would go =MEDIANX(Table1, [Net Revenue] - [Net Expense]. This would create a median measure for NetProfit even though the column itself doesn't exist in our table.
In your case, since you are aggregating a column that already exists you can just stick with =MEDIAN.
If you need more clarification let me know!
Best,
Brett

Level of Detail on the primary data sources in tableau

I have one excel that contains the demand for each part by city:
e.g: the demand for part a for New york is 100 and 1+7=8 for Atlanta
I have another excel containing the inventory level for two warehouses: rural and urban:
e.g: Warehouse "Rural" stocks 50 for part a and warehouse "Urban" stocks zero for part c.
First I joined these two excels with the demand excel being the primary:
I googled about LOD (level of detail) in order to find out the inventory fulfillment for each warehouse by City
-- count the number of unique parts by each city for the demand:
calculated field [a] = { fixed [City]: countd([Part Number demand]) }
-- count the number of parts that are in stock (inventory level>0) by each warehouse:
calculated field [b] = { fixed [City],[Warehouse Location],[Part Number volume]: countd (if [Inventory Level] > 0 then [Part Number demand] end )}
-- calculate the inventory fulfillment %:
calculated field [c] = calculated field [a] / calculated [b]
and I got the following table and I think it is showing the correct fulfillment % by warehouse for each city: e.g: Warehouse "Rural" stocks 33% of unique parts needed by Atlanta.
Question 1: as I include more part numbers into the excel, I only want to consider the top 10 parts by volume needed for each city. I was trying to do the same thing with LOD to first find the total quantity needed per part per city:
{fixed [City], [Part Number demand]: sum([Part Number volume]) }
But it counts the quantity from both excels and I am just wondering if it is possible to only count the quantity from the primary excel (demand not the inventory),
Question 2: once I could count the total quantity needed, how do I transfer it into a filter so that I could only select top 10 parts by demand.
Apologize if these questions are dumb and appreciate for any advice!!

Count Index based on Multiple Conditions - Excel

I have a table with order records for each Product Type. The columns contain information like Order Number, Customer Name, Product Category, Product, and Order Receipt Date.
My goal is to find the quantity of orders that fall into the below conditions:
New Customers Ordering any Product Category for the First Time
Existing Customers Ordering from any Product Category for the First Time
Reorders from any Product Category
What would be the best way to go about this?
Think I figured it out:
I created two columns for records: "First Product Type Order?" and "First Order?"
"First_Product_Type_Order": IF(AND(Order2=Order1,Product_Type2=Product_Type1),First_Product_Type_Order1,IF(SUMPRODUCT(($Customer$2:$Customer2=D2)*($Product_Type$2:$Product_Type2=Product_Type2))>1,"Reorder","First Time Order"))
"First_Order":
IF(Order2=Order1,First_Order1,IF(SUMPRODUCT(($Customer$2:$Customer2=Customer2)*1)>1,"Existing Customer","New Customer"))

Resources