I'm creating my own cart and then using Paypal smart button for the payment in Angular.
For multiple items to handle, I'm uing items array in createOrder method at the backend in Express.
function arrayOfItems() {
art_details.forEach((item, index) => {
let sku = item.message;
let currency = priceDetails.collPriceL[index];
let tax = priceDetails.taxAmtL[index];
let quantity = item.quantity;
let items = [
{
name: "Collection",
sku: sku,
description: '' + item.collid,
unit_amount: { currency_code: "CAD", value: "" + currency },
tax: { currency_code: "CAD", value: "" + tax },
quantity: quantity,
},
];
return items;
});
}
I'm now using arrayOfItems() as items in createOrder:
const request = new checkoutNodeJssdk.orders.OrdersCreateRequest();
request.prefer("return=representation");
request.requestBody({
intent: "CAPTURE",
purchase_units: [
{
amount: {
currency_code: "CAD",
value: ...,
breakdown: {
...
},
},
soft_descriptor: orderkey,
items: arrayOfItems(),
shipping: {
...
},
},
],
});
Suppose I'm creating order for 2 items. art_details contains array of items I need to purchase. My order is creating successfully but the Paypal window doesn't show the items in right side. (it should appear as a dropdown of items).
What am I missing here?
Thanks
Related
Reading the prisma docs i find that is possible to create a connection where i make the plan have one item connected (as i did below). but i want to dinamic pass an array of strings (that items prop) that have ids of items to connect when creating my plan.
The code below works well, but i dont know how to pass that array n connect every item that match one of the ids on the array
const plan = await this.connection.create({
data: {
name,
description,
type,
picture,
productionPrice,
price,
items: {
connect: [
{
id: items,
},
],
},
},
include: {
items: true,
},
});
return plan;
I think, you have to provide an array like this:
const plan = await this.connection.create({
data: {
name,
description,
type,
picture,
productionPrice,
price,
items: {
connect: [
{
id: 1,
},
{
id: 2,
},
{
id: 3,
},
],
},
},
include: {
items: true,
},
});
If items contains a list of IDs, you can use:
...
items: {
connect: items.map(id => ({ id }),
},
...
I have the following code it suppose to send the data to pay pal to process the payment but it keepsgeting this TypeError: Cannot read property 'price' of undefined i have gone through the code but i think the error is occuring "storeItems.get(item.id).price" when i try to get the "items id" for some reson thwe value is nt being seen
this is my request body contains the following array
{"items":[
{"id":"1", "quantity":1},
{"id":"2", "quantity":2},
{"id":"3", "quantity":3},
{"id":"4", "quantity":4}
]}
app.post("/create-order", async (req, res) => {
const request = new paypal.orders.OrdersCreateRequest()
const total = req.body.items.reduce((sum, item) => {
return sum + storeItems.get(item.id).price * item.quantity
}, 0)
console.log(total);
request.prefer("return=representation")
request.requestBody({
intent: "CAPTURE",
purchase_units: [
{
amount: {
currency_code: "USD",
value: total,
breakdown: {
item_total: {
currency_code: "USD",
value: total,
},
},
},
items: req.body.items.map(item => {
const storeItem = storeItems.get(item.id)
return {
name: storeItem.name,
unit_amount: {
currency_code: "USD",
value: storeItem.price,
},
quantity: item.quantity,
}
}),
},
],
})
const order = await paypalClient.execute(request)
})
The error means that storeItems.get(item.id) in the total function is undefined.
From your comment, storeItems is defined like:
const storeItems = new Map([
[1, { price: 100, name: "Learn React Today" }],
[2, { price: 200, name: "Learn CSS Today" }],
])
So the issue must come from the item. Either it does not have an id property, or it is undefined, or its id property does not match any entry in your map.
I have a dynamoDB table that has an Item that includes a user and a List of plans. It looks like this:
Item:
{
user: 'abc123',
plans: [
{
id: 1,
name: 'movies',
category: 'category',
price: 200,
},
{
id: 2,
name: 'fishing',
category: 'category2',
price: 400,
}
]
}
Now, I want to update only id:2's object(name, category, price) in the List. So I wrote the handler below. And there is an error edit error ValidationException: The document path provided in the update expression is invalid for update in CloudWatch.
export const processAddPlan = async (event:APIGatewayEvent) => {
const data = JSON.parse(event.body)
const { store, id } = event.queryStringParameters
const params = {
TableName: usersTable,
Key: {
store: store,
id: id,
},
UpdateExpression: 'SET #pl[1] = :plans',
ExpressionAttributeNames: {
'#pl' : 'plans',
},
ExpressionAttributeValues: {
':plans': [
{
'name': data.planName,
'category': data.planCategory,
'price': data.planPrice,
},
],
},
ReturnValues: 'UPDATED_NEW',
}
log.info('params', params)
await dynamoDb.update(params).catch(e => log.info('edit error', e))
return success('edit plan succeeded')
}
I set query params and I tested(send) by postman like this.
{
"plans":[
{"planName":"ga2new",
"planCategory": "ttnew",
"planPrice": 5675
}
]
}
You need to use SET.
SET pl[1] = :plans
As the docs show here:
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.SET.AddingListElements
The docs for ADD say
The ADD action supports only number and set data types.
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.ADD
I have a callback_query when users hit on a purchase button. The callback_query is to send an invoice to the user, but it is throwing the above error.
bot.on('callback_query', (ctx) => {
let data = ctx.callbackQuery.data
if (data.includes('purchase') == true) {
return handlePurchase(ctx)
}
})
function handlePurchase(ctx) {
let data = ctx.callbackQuery.data
let itemId = data.split(':')[1]
let invoice = {
chat_id: ctx.callbackQuery.from.id,
title: "Title",
description: "Description",
payload: itemId.toString(),
provider_token: stripeToken,
start_parameter: itemId.toString(),
currency: "USD",
need_phone_number: true,
need_shipping_address: true,
photo_url: the_image_url,
prices: [{
label: "Item",
amount: 1000
}]
}
return ctx.replyWithInvoice(invoice)
}
I also attempted to use ctx.telegram.sendInvoice(invoice) instead but the bot did not send an invoice to the user, ie the bot did not respond at all.
I am trying to send a list of total paid and unpaid client with count along with data from my node API.
In mongoose method, I am stuck at thinking how to go further.
can anyone suggest the best way to achieve this?
router.get("/", ensureAuthenticated, (req, res) => {
Loan.aggregate([
{
$match: {
ePaidunpaid: "Unpaid"
}
}
]).then(function(data) {
console.log(data);
res.render("dashboard", { admin: req.user.eUserType, user: req.user,data:data });
});
});
Loan Model:
const Loan = new Schema({
sName: { type: String },
sPurpose: [String],
sBankName: String,
sBranchName: [String],
nTotalFees: { type: Number },
ePaidunpaid: { type: String ,default:'Unpaid'},
sCashOrCheque: { type: String },
});
Outcome:
Details of a user with a count of paid and unpaid clients
[
Paid:{
// Paid users
},
Unpaid:{
// Unpaid Users
},
]
Well in that case, try this -
Loan.aggregate([
{
$group: {
_id: "$ePaidunpaid",
data: { $push: "$$ROOT" },
count: { $sum: 1 }
}
}
]);
Output would be something like this -
{
"_id": "Paid",
"data": [
// All the documents having ePaidunpaid = Paid
{ _id: "asdasd123 1eqdsada", sName: "Some name", // Rest of the fields },
{ _id: "asdasd123 1eqdsada", sName: "Some name", // Rest of the fields }
],
count: 2
},
{
"_id": "Unpaid",
"data": [
// All the documents of having ePaidunpaid = Unpaid
{ _id: "asdasd123 1eqdsada", sName: "Some name", // Rest of the fields },
{ _id: "asdasd123 1eqdsada", sName: "Some name", // Rest of the fields }
],
count: 2
},
Explanation
First stage of the pipeline $group groups all the documents according to ePaidunpaidfield which only have two values Paid or Unpaid thus rendering only two documents respectively.
Next step is to accumulate original data (documents) being grouped together. This is achieved using $push accumulator on data field, pushing $$ROOT which effectively references the document currently being processed by pipeline stage.
Since you needed count of all paid and unpaid users hence a $sum accumulator to count all the items in each group.