Workarounds to using this in Vue - javascript

I am attempting to create a PayPal checkout order on my Vue site. I am currently passing two props to the component as well as two data objects
props: {
price: Number,
shipping: Number,
},
data() {
return {quantity: 1, switches: 'red'}
},
I am referencing these four variables in my code as this.price, this.shipping etc. I have confirmed these are all valid
I am attempting to access these inside a method but this is being over-ridden and all four of these are undefined.
I still don't quite understand this, but I was under the impression that using an arrow function as I have done should stop this from changing. Is this not the case?
Code
await paypal.Buttons({
style: {
layout: 'vertical',
color: 'black',
shape: 'pill',
},
createOrder: (data, actions) => {
return actions.order.create({
purchase_units: [{
amount: {
currency_code: "USD",
value: ((this.price + this.shipping) * this.quantity).toString(),
breakdown: {
item_total: { /* Required when including the `items` array */
currency_code: "USD",
value: this.price.toString()
},
shipping: {
currency_code: "USD",
value: this.shipping.toString()
}
}
},
items: [
{
name: "First Product Name", /* Shows within upper-right dropdown during payment approval */
description: "Optional descriptive text..", /* Item details will also be in the completed paypal.com transaction view */
unit_amount: {
currency_code: "USD",
value: this.price.toString()
},
quantity: this.quantity.toString
},
]
}]
});
},
}).render('#paypal-button-container')

Related

MongoDB group $ROOT (collection) document items as key value pairs in the new field

consider the following array of documents returned from the aggregation:
[
{
id: '#abcdefg123',
title: 'Doc 1'
...
},
{
id: '#abcdefg124',
title: 'Doc 2'
...
},
{
id: '#abcdefg125',
title: 'Doc 3'
...
}
]
Each document contains like 20 fields...
I would like to get the following output:
{
edges: [
{
node: {
id: '#abcdefg123',
title: 'Doc 1',
...
}
cursor: '#abcdefg123'
},
{
node: {
id: '#abcdefg124',
title: 'Doc 2',
...
}
cursor: '#abcdefg124'
},
{
node: {
id: '#abcdefg125',
title: 'Doc 3',
...
}
cursor: '#abcdefg125'
}
]
}
I've tried to $group a new field edges with $push as k, v pair of '$ROOT' but with no such desired result.
And I've tried to use $map on something like '$$ROOT' as input and trying to return object
{
node: '$item',
cursor: '$item._id'
}
Of course with not luck either.
I don't want to iterate over the results and populate the right object shape of data after the aggregation. Considering the performance would drop.
I would prefer to achieve the desired result inside of aggregation pipeline.
Thanks in advance.
db.collection.aggregate([
{
$project: {
"node": "$$ROOT",
"cursor": "$id"
}
},
{
$group: {
"_id": null,
"edges": {
$push: "$$ROOT"
}
}
}
]);
Mongo Playground

How to change the value of a field in an array mongodb nodejs

There are many array levels, that's why I can't choose the right field, I guess.
This is the Schema of the model:
{
season: 1,
finished: 0,
Games: [{
Game: [{
game: 1,
Players: [{
Id: 0,
name: "Peter",
jails: 3, //I want to change this value
pays: 1000,
gets: 2000,
points: 3
}]
}]
}]
}
I tried this query but it's not working:
Seasons.update({
season: 1,
game: 2,
Id: 0
}, {
jails: 4
},
(err, data) => {
if (err) {
console.log(err)
} else {
console.log(data)
}
}
)
I have used the $set propery but it didn't work as I want. It make changes all jails field of all players to same value in the same season. I mean, the query is selecting the most parent record, so it is the season record. But I want to change value of child element.

Delimited List from Nested JavaScript Array

I have a simple JavaScript object that contains nested arrays.
All I'm looking for here us to return a comma delimited list of the "productID' values that are present at "digitalData.transaction.item.productInfo[i].productID[j]"
I appreciate the help.
Here's an example of the JS (sorry for the length, but better dafe than sorry I guess):
window.digitalData = {
transaction: {
purchaseID: "30010819", //Typically the same as transactionID
transactionID: "30010819", //Unique Identifier for this transaction
item: [{ //Array of items in this transaction
productInfo: {
productID: "63493",
color: "Fuscia", //color if this product has colors
size: "M (8-10)", //size if this product has sizes
sku: "63493-12456", //sku
inventoryStatus: "In Stock", // Mirror the on-site messaging
skuAttr: [{ // extensible array of sku attributes and values
typeLabel: "Color",
valueCode: "FSA",
valueLabel: "Fuscia"
}, {
typeLabel: "Size",
valueLabel: "M (8-10)"
}]
},
price: {
currency: "USD"
},
quantity: 1
}, {
productInfo: {
productID: "55027",
color: "", //color if this product has colors
size: "", //size if this product has sizes
sku: "55027", //sku if known. otherwise use productID
inventoryStatus: "Low Stock", // Mirror the on-site messaging
skuAttr: [] //Empty array if no sku attributes exist
},
price: {
currency: "USD"
},
quantity: 2
}]
}]
}
You can do it that way:
digitalData.transaction.item.map(x => x.productInfo.productID).join(',')

paypal payment api doesn't work with property "payee"

I already took a look into the question that people keep saying this question is duplicated to, but I couldn't figure out how to deal with it with my code. I need an explanation. Thank you
I'm new to paypal APIs so I'm kind of confused right now. creating transaction only works when I don't specify payee property, but how would paypal know who to send the money when there's no payee specified?
Here's the code
$(function() {
paypal.Button.render({
env: 'sandbox', // Or 'sandbox'
client: {
sandbox: 'xxxxxx',
production: 'xxxxxx'
},
commit: false, // Show a 'Pay Now' button
payment: function(data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: '5.00', currency: 'USD' },
description: "TEST",
payee: { email: "seller-inventory#gmail.com" }
}
]
}
});
},
onAuthorize: function(data, actions) {
return actions.payment.execute().then(function(payment) {
console.log("payment", payment)
});
}
}, '#paypal');
})
Error code:
In the transaction object you need to have the items list with the items you are trying to sell. The mail also needs to exist.
If you don't specify the mail paypal send the money to whom has generated the client id key.
Also the items sum and currenct needs to match with the amount sum and currency
Try this (change sandbox id and the payee email need to exist in paypal):
$(function() {
paypal.Button.render({
env: 'sandbox', // Or 'sandbox'
client: {
sandbox: 'yourclientid',
production: 'xxxxxx'
},
commit: false, // Show a 'Pay Now' button
payment: function(data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: '5.00', currency: 'USD' },
payee: { email: "seller-inventory#gmail.com" },
item_list: {
items: [
{
name: "hat",
sku: "1",
price: "5.00",
currency: "USD",
quantity: "1",
description: "Brown hat."
}]}
}
]
}
});
},
onAuthorize: function(data, actions) {
return actions.payment.execute().then(function(payment) {
console.log("payment", payment)
});
}
}, '#paypal');
})

Angular JS replace values ng grid

I am newbie in angular JS and I think that I need help.
This is my issue :
I have a ng-grid which is linked with a table. Within there are values and a ID (which is a foreignkey from a another table). I don't want to show the ID but another field in this foreign table.
CompanyFactory.getCompanies().success(function (data) { $scope.objs = data })
$scope.gridOptions = {
data: 'objs',
showGroupPanel: true,
jqueryUIDraggable: true,
columnDefs: [
{ field: 'COMP_NAME', displayName: 'comp_name'},
{ field: 'COUNTRY', displayName: 'country' },
{ field: 'LU_SECTOR_ID', displayName: 'sector', },
]
};
I want show the sector_name field instead of the sector_ID field. How can I make the relation between these two tables ?
$scope.countries = [
{ COMP_NAME: 'KOLI', COUNTRY: 'KOLI_COUNTRY', LU_SECTOR_ID: '1'},
{ COMP_NAME: 'ZOLI', COUNTRY: 'ZOLI_COUNTRY', LU_SECTOR_ID: '2'},
{ COMP_NAME: 'TULI', COUNTRY: 'TULI_COUNTRY', LU_SECTOR_ID: '3'},
];
$scope.sector= [
{ LU_SECTOR_ID: '1', LU_SECTOR_NAME: 'SECTOR_1'},
{ LU_SECTOR_ID: '2', LU_SECTOR_NAME: 'SECTOR_2'},
{ LU_SECTOR_ID: '3', LU_SECTOR_NAME: 'SECTOR_3'},
];
I would like to show in the ng-grid the SECTOR NAME instead of the SECTOR_ID.
It is difficult to answer the question without the information of the data object.
However, suppose that your data object returned by your CompanyFactory is something like:
[
{
"COMP_NAME": "Tomms",
"COUNTRY": "France",
"LU_SECTOR_ID": "9":,
"SECTOR": { "SECTOR_NAME": "IT" }
}
]
You just need to bind the correct field:
$scope.gridOptions = {
data: 'objs',
showGroupPanel: true,
jqueryUIDraggable: true,
columnDefs: [
{ field: 'COMP_NAME', displayName: 'comp_name'},
{ field: 'COUNTRY', displayName: 'country' },
// Here
{ field: 'SECTOR.SECTOR_NAME', displayName: 'sector', },
]
};
But, if you returning both objects separated you will need to link it manually. My suggestion is to perform that in the server side and return the object like I used as an example.
the problem is here
{ field: 'LU_SECTOR_ID', displayName: 'sector', }
Specifically
LU_SECTOR_ID
you need to change the name of this variable to be the name on the objs and not the id

Categories

Resources