Stripe subscription schedule update - disable prorations - javascript

While I try to update subscription, invoice is unnecessary complicated.
await stripe.subscriptionSchedules.update(
subscriptionSchedule.id,
{
end_behavior: 'release',
phases: [
{
start_date: stripeSub.current_period_start,
end_date: stripeSub.current_period_end,
proration_behavior: 'none',
items: [
{
price: stripeSub.plan.id,
plan: stripeSub.plan.id,
quantity: stripeSub.quantity
},
],
},
{
start_date: stripeSub.current_period_end,
proration_behavior: 'none',
items: [
{
price: priceId,
quantity: quantity
},
],
},
],
}
);
I'm updating subscription at the end of current subscription phase.
In stripe subscription change log proration was created for 6.99 and then -6.99.
stripe log
I tried almost everything from stripe docs docs
Can I avoid this to have only one position on invoice with scheduled subscription cost (new subsctiprion is $60) when invoice will be finalized of current phase end?
Current invoice is
6.99
-6.99
60
I want to only be 60

Related

Google Analytics Data API (GA4) How to use runRealtimeReport function?

I do a call to
await analyticsDataClient.runRealtimeReport({
entity: {
propertyId: propertyId,
},
dateRanges: [
{
startDate: '2020-03-31',
endDate: 'today',
},
],
dimensions: [
{
name: 'city',
},
],
metrics: [
{
name: 'activeUsers',
},
],
});
but this return the following error:
A property in the form 'properties/1234' where '1234' is a GA4 property Id is required
I think it is because my object inside my runRealtimeReport function is wrong but I don't know how to put in.
To create a realtime report, you need to update the request to be similar to
const propertyId = 'YOUR-GA4-PROPERTY-ID';
const [response] = await client.runRealtimeReport({
property: 'properties/' + propertyId,
dimensions: [{ name: 'city', },],
metrics: [{ name: 'activeUsers', },],
});
Please replace the 'YOUR-GA4-PROPERTY-ID' with your numeric property ID. This page describes where to find your GA4 property ID.
Realtime reports do not need dateRanges. Realtime reports are always for the last 30 minutes for your App or Website. There is more information about creating realtime reports on this page.

How to create "products filter" efficiently in Node.js and Angular?

I'm creating an angular application (computer online store) with a node/express backened. I have a products page to display all the products in my DB. A product has this model (typescript):
interface Product {
name: string
properties: {name: string, value: string | number}[]
}
I have a section within the page where you can filter products by properties. for instance a user can filter all the CPUs that have 4 cores or 8 cores. right now this is implemented like this:
In the angular application i query ALL THE PRODUCTS of the requested category,
loop through all of them, collect their properties and all the possible values and filter like this...
const products = [
{
name: 'intel cpu 1',
properties: [
{name: 'cores', value: 8},
{name: 'clock speed', value: 2.6}
]
},
{
name: 'intel cpu 2',
properties: [
{name: 'cores', value: 4},
{name: 'clock speed', value: 1.2}
]
}
]
collectPropertiesFromProducts(products)
// RESULT:
[
{property: 'cores', possibleValues: [4,8]},
{property: 'clock speed', possibleValues: [1.2,2.6]}
]
For now it works great, i can filter products easily by the result and it is all dynamic (i can just add a property to a product and thats it).
The problem is that it scales VERY BADLY, because:
I have to query all of the products to know their properties
The more products/properties = more CPU time = blocks main thread
My question is how can i do better? i have a node server so moving all the logic to there its pretty useless, i could also just move the "property collecting" function to a worker thread but again, ill have to query all the products...
Instead of dealing with this in the client or in the service itself, you can let mongodb do the calculations for you. E.g. you could write the following aggregation:
db.getCollection('products').aggregate([{
$unwind: "$properties"
},
{
$project: {
name: "$properties.name",
total: {
$add: ["$properties.value", ]
}
}
}, {
$group: {
_id: "$name",
possibleValues: {
$addToSet: "$total"
}
}
}
])
You could then expose this query through a custom endpoint (e.g. GET /product-properties) on your node-server and consume the response on the client.
You should consider doing multiple requests to the backend:
First:
getQueryParams, a new endpoint which returns your RESULT
Second:
A none filtered request to receive the initial set of products
Third:
When select a filter (based on first request) you do a new request with the selected filter

Load all data from local database

I am using react-native-gifted-chat(https://github.com/FaridSafi/react-native-gifted-chat) to create a chat interface on my app, I want to load messages from my database.
I am using realm, and I am able to load the data but my code below loads only the first row of the data. I want to be able to load all the data from the database.
let chatData = realmDatabase.objects(DatabaseTableNames.chatTable);
let data=[];
for (let message of chatData ){
data = [{
_id: message.chatUniqueID,
text: message.msgBody,
createdAt: (new Date()).getTime(),
user: {
_id: message.chatUniqueID,
name: message.senderName
}
} ]
}
console.log(data)
I want to be able to load all the data from the database not only the first row, like the sample below.
[
{
_id: Math.round(Math.random() * 1000000),
text:
"It uses the same design as React, letting you compose a rich mobile UI from declarative components https://facebook.github.io/react-native/",
createdAt: new Date(Date.UTC(2016, 7, 31, 17, 20, 0)),
user: {
_id: 1,
name: "Developer"
},
},
{
_id: Math.round(Math.random() * 1000000),
text: "React Native lets you build mobile apps using only JavaScript",
createdAt: new Date(Date.UTC(2016, 7, 30, 17, 20, 0)),
sent: true,
received: true,
user: {
_id: 2,
name: "Developer"
},
}
];
Doing data = [{...}] in the for loop, will assign the last value of message to data. To get all the values, you need to push the items in the data array. You can do it like this:
let chatData = realmDatabase.objects(DatabaseTableNames.chatTable);
let data=[];
for (let message of chatData ){
data.push({
_id: message.chatUniqueID,
text: message.msgBody,
createdAt: (new Date()).getTime(),
user: {
_id: message.chatUniqueID,
name: message.senderName
}
});
}
console.log(data)

Adding custom card information to Payment Request

I want to implement payment request api to my website.
Payment request popup lists users saved cards associated with mobile phone and Google&Apple accounts.
I also want to put custom credit cards into that popup because we have already implemented save credit cards feature and it is been working for a while. I couldn't find any support for it reading documentations. Is it possible?
Expected to have a support like
var supportedInstruments = [{
supportedMethods: 'basic-card',
data: {
supportedNetworks: ['visa', 'mastercard'],
supportedTypes: ['credit', 'debit']
},
customCards: [{ //Custom credit cards
number: '000000000000000',
owner: 'John Doe'
}]
}];
var details = {
total: {label: 'Donation', amount: {currency: 'USD', value: '65.00'}},
displayItems: [
{
label: 'Original donation amount',
amount: {currency: 'USD', value: '65.00'}
}
],
shippingOptions: [
{
id: 'standard',
label: 'Standard shipping',
amount: {currency: 'USD', value: '0.00'},
selected: true
}
]
};
var request = new PaymentRequest(supportedInstruments, details);
There's no such feature nor proposal as far as I know, though I have heard similar requests in the past.
One work around would be to implement a merchant specific payment method using the Payment Handler API. This API allows you to provide your own payment method. You can consume it by yourself and allow third parties to do so.

how get data within particular period using dates in angular2?

Hi I have certain amount data related to a customer. I need to get period of transactions of a customer and show to angular2 app.
I have one page with drop down list and output area. In dropdown items are like "Last one month transactions", "Last Three months transactions" and etc.
When I select a one of the item in dropdown I need show the all transactions in output area.
I am unable filter data using the pipes in angular2. Please send your thoughts about it. Thanks in advance.
[{
productNo:1,
productName: 'Toys',
quantity: 2,
purchaseDate: '2016/17/08'
},
{
productNo:1,
productName: 'Shoes',
quantity: 4,
purchaseDate: '2016/30/07'
},
{
productNo:1,
productName: 'Books',
quantity: 10,
purchaseDate: '2016/07/06'
},
{
productNo:1,
productName: 'Mobile',
quantity: 1,
purchaseDate: '2016/21/06'
}]

Categories

Resources