Adding custom card information to Payment Request - javascript

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.

Related

Dynamo DB: How to update specific object inside an array in aws dynamodb?

Inside my companies table there is a company collection I have an array of users.
I need to change one of the users name ('David' to 'Solomon').
I don't mind changing to insert a new user object instead David.
But I don't mind to keep the same id and just change the name field from 'David' to 'Solomon'
company: {
id: cde9e41d-8d16-4054-907f-cc92a69d68e0
name: 'Gold Crowns Ltd',
users: [
{
id: abc9e41d-8d16-4054-907f-cc92a69d68e0
name: 'David' // <-------- I want to change 'David' to 'Solomon'
},
{
id: fgh9e41d-8d16-4054-907f-cc92a69d68e0
name: 'Saul'
},
],
}
Which option will work best and what should be the query in DynamoDB

How to search products ,Categorys and brand by using Names in mong.db?

How to search products,Category and brand by using Names
in mong.db , in nodejs,
am getting all items, but how sort and get the searching products,?
here is my search container,
user-header.hbs
<div class="search-container">
<form class="form-inline" action="/products/search/:key" method="get">
<input class=" search-input" type="search" name="searchTerm" class="form-control" placeholder="Search..."
aria-label="Search" />
</form>
</div>
product.js
here get router
router.get("/search/:key",(req, res)=> {
// var searchTerm = req.body.searchTerm
// console.log('regex',regex)
userHelpers.getAllSearchProducts(req.params.seraechresult
).then((product)=>{
console.log('result>>>>>>>',product)
res.render('user/search', {product});
})
})
user-helpers.js
through user helpers am geting the all prosucts but how to get the searching products ?
getAllSearchProducts:(seraechresult)=>{
return new Promise(async(resolve,reject)=>{
let SearchItems=await db.get().collection(collection.CART_COLLECTION)
.findOne(
{
"$or":[
{'Name':{'$regex':seraechresult}}
]
}
)
resolve(SearchItems)
})
},
here is my collection, products,
products [
{
_id: new ObjectId("62873c15c7becd09b1377fd8"),
Name: 'pixel 6',
Category: 'smart Phone',
Price: '60000',
Description: 'Note that to perform a smart search, DataTables uses regular expressions, so if enable regular expressions using the second parameter to this method, you will likely want to disable smart searching as the two regular expressions might otherwise conflict and cause unexpected results.',
Brand: 'Google'
},
{
_id: new ObjectId("628795e6a55d421aaca788cb"),
Name: 'iphone 11 pro ',
Category: 'smartphone',
Price: '100000',
Brand: 'apple',
Description: 'Super-strong materials and water resistance make iPhone incredibly durable. And automatic iOS updates deliver new features and security enhancements that keep your iPhone running beautifully and help it hold its value longer than other smartphones.'
},
{
_id: new ObjectId("6294f13458c9d3947bd2db5f"),
Name: 'samsung fold 2',
Category: 'smartphone',
Price: '1000000',
Brand: 'samsung',
Description: 'something going '
},
{
_id: new ObjectId("6295c129ff104b9c3d1eef9b"),
Name: 'lgg8x',
Category: 'smartphone',
Price: '280000',
Brand: 'LG',
Description: 'something'
}
]
I am not able to search the product by using mongodb how to solve this?

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

Redux: local state id's and/or api uuid's

I'm using Redux with a REST api that uses UUID's. The usual pattern for storing state is using id's as a key for objects:
entities: {
articles: {
1: {
id: 1,
title: 'Some Article',
author: 1
},
2: {
id: 2,
title: 'Other Article',
author: 1
}
},
users: {
1: {
id: 1,
name: 'Dan'
}
}
}
How would I use the UUID's from the api in this? I'd like to be able to create a new entity without having to request the UUID from the server first (for offline capabilities).
Should I:
Use local id's, keep the UUID in a _id property of the entity, and only use it when making an API request? This seems the easiest way, although it feels redundant and I will probably have to search through entities for a certain _id in some cases.
entities: {
articles: {
1: {
_id: 'UUID',
title: 'Some Article',
author: 1
},
2: {
id: 'UUID',
title: 'Other Article',
author: 1
}
},
users: {
1: {
_id: 'UUID',
name: 'Dan'
}
}
}
Use only UUID's from the API, and when creating a new item use a sort if temporary id until the API call is resolved? This seems the best way, although I'm not sure how I would go about changing the id's, which also feels wrong (as they're id's).
entities: {
articles: {
'UUID': {
_id: 'UUID',
title: 'Some Article',
author: 'UUID'
},
'UUID': {
_id: 'UUID',
title: 'Other Article',
author: 'creating'
}
},
users: {
'UUID': {
_id: 'UUID',
name: 'Dan'
},
'creating': {
name: 'Stan'
}
}
}
Do it some other way?
I wouldn't add it to the Redux store until the API returns a response.
In Vue, in my data for a given component I usually have two (sometimes more) root keys, one of which points to the part of my Redux store that handles the data, and the other that is usually form or something of that sort, and the Vue data changes due to binding.
After the user initiates the action to add the resource (POST /resources), and the server returns a successful response, I dispatch an action addedResource. And prior to that I'd dispatch something like addingResource, etc.
Is there any reason this wouldn't work? There shouldn't be a difference using an auto incremented, integer id field vs. a UUID. Your data normalization should still work the same way.

Categories

Resources