I have to implement Paypal into my application. Here I have added some products into the cart. If I click the cart, I have to pay the amount using Paypal.
When clicking the Paypal button, I am getting the following error:
The amounts specified for item price,tax,and shipping do not add up to the total amount.
Why am getting this error?
I am using the following code:
$.paypalWindow.addEventListener('open', function(){
var Paypal = require('ti.paypal');
var u = Ti.Android != undefined ? 'dp' : 0;
var status = Ti.UI.createLabel({ top: 20 + u, height: 50 + u, color: '#333', text: 'Loading, please wait...' });
$.paypalWindow.add(status); var price = totalamount;
var invoiceitemslist = JSON.stringify(data);
var button; function addButtonToWindow() {
if (button) { $.paypalWindow.remove(button); button = null; }
button = Paypal.createPaypalButton({ width: 194 + u, height: 37 + u, buttonStyle: Paypal.BUTTON_194x37, top: 20 + u,
language: 'en_US',
appID: 'APP-80W284485P519543T',
paypalEnvironment: Paypal.PAYPAL_ENV_SANDBOX,
feePaidByReceiver: false,
enableShipping: false,
payment: {
paymentType: Paypal.PAYMENT_TYPE_BUSINESS,
subtotal: price,
tax: 0.00,
shipping: 0.00,
currency: 'USD',
recipient: 'thaibusiness#gmail.com',
customID: 'anythingYouWant',
invoiceItems:
[{"name":"Bajaj 200 mm Ultima PT01 Personal Fan","totalPrice":2997,"itemPrice":999,"itemCount":3},
],
ipnUrl: 'http://www.appcelerator.com/',
merchantName: 'EYMOBINS Insurance',
memo: 'For the insurance with EYMOBINS!'
}
});
button.addEventListener('paymentCancelled', function (e) {
alert('Payment cancelled. Please try again!');
addButtonToWindow();
});
button.addEventListener('paymentSuccess', function (e) {
alert('Payment successfull. Please get your Policy No.!'+" "+e.transactionID);
$.paypalWindow.remove(button);
//addButtonToWindow();
});
button.addEventListener('paymentError', function (e) {
alert('Payment Error. Please try again!');
addButtonToWindow();
});
button.addEventListener('buttonDisplayed', function () {
$.paypalWindow.remove(status);
//alert('Please pay '+Ti.App.totalcost+'$ with Paypal!')
});
button.addEventListener('buttonError', function () {
});
$.paypalWindow.add(button);
}
addButtonToWindow();
});
$.paypalWindow.open();
Please check the code and give me an idea to resolve the above issue.
EDIT:
Here I am facing one issue:
[{"name":"Bajaj 200 mm Ultima PT01 Personal Fan","totalPrice":999,"itemPrice":999,"itemCount":1},{"name":"Average2Excellent CBSE KG EVS MATHS ENG Educational CD ROMS","totalPrice":547,"itemPrice":547,"itemCount":1}]
Here the totalamount is 1546. Here I have printed the invoiceitems in the console, and I am getting the data like above.
So that I have given like:
invoiceItems:invoiceitems,
Like means am getting the issue (the amounts specified for item price, tax, and shipping do not add up to the total amount).
Same thing I have written the code like:
invoiceItems:[{"name":"Bajaj 200 mm Ultima PT01 Personal Fan","totalPrice":999,"itemPrice":999,"itemCount":1},{"name":"Average2Excellent CBSE KG EVS MATHS ENG Educational CD ROMS","totalPrice":547,"itemPrice":547,"itemCount":1}]
it's working perfectly.
It is not working dynamically when assigned the value. Can you please check the code and help?
EDIT:
If i have tried to run this code on android device, as am clicking the paypal button nothing happends. Why the login form is not open in the android device.
Why are you escaping the quotes in this code?
[{"name":"Bajaj 200 mm Ultima PT01 Personal Fan","totalPrice":2997,"itemPrice":999,"itemCount":3}
This is not valid JSON (or Javascript for that matter). Is this required by Paypal? I think it should look like this:
[{"name":"Bajaj 200 mm Ultima PT01 Personal Fan","totalPrice":2997,"itemPrice":999,"itemCount":3}
Edit:
I've had a closer look at your code sample. Can you confirm where totatamount is coming from? As the code sample stands it will be undefined, which would be consistent with the error message you have described. Can you confirm it is definitely the correct value IMMEDIATELY before you submit this data?
The ti.paypal spec has a nice code sample in the README file, which gives a good example of how to setup createPaypalButton. I would recommend looking at this if you haven't already.
button = Paypal.createPaypalButton({
// NOTE: height/width only determine the size of the view that the button is embedded in - the actual button size
// is determined by the buttonStyle property!
width: 194 + u, height: 37 + u,
buttonStyle: Paypal.BUTTON_194x37, // The style & size of the button
bottom: 50 + u,
language: 'en_US',
textStyle: Paypal.PAYPAL_TEXT_DONATE, // Causes the button's text to change from "Pay" to "Donate"
appID: '<<<YOUR APP ID HERE>>>', // The appID issued by Paypal for your application; for testing, feel free to delete this property entirely.
paypalEnvironment: Paypal.PAYPAL_ENV_SANDBOX, // Sandbox, None or Live
feePaidByReceiver: false, // This will only be applied when the transaction type is Personal
enableShipping: false, // Whether or not to select/send shipping information
advancedPayment: { // The payment itself
payments: [
{
isPrimary: true, // Mark this as the primary vendor; this marks this as a chain payment.
merchantName: 'Primary Vendor',
paymentType: Paypal.PAYMENT_TYPE_SERVICE, // The type of payment
paymentSubtype: Paypal.PAYMENT_SUBTYPE_DONATIONS, // The subtype of the payment; you must be authorized for this by Paypal!
subtotal: 13, // The total cost of the order, excluding tax and shipping
tax: 0,
shipping: 0,
recipient: '<<<YOUR RECIPIENT HERE>>>',
customID: 'anythingYouWant',
invoiceItems: [
{ name: 'Shoes', totalPrice: 8, itemPrice: 2, itemCount: 4 },
{ name: 'Hats', totalPrice: 2, itemPrice: 0.5, itemCount: 4 },
{ name: 'Coats', totalPrice: 3, itemPrice: 1, itemCount: 3 }
]
},
{
merchantName: 'Vendor 1',
paymentType: Paypal.PAYMENT_TYPE_SERVICE, // The type of payment
paymentSubtype: Paypal.PAYMENT_SUBTYPE_DONATIONS, // The subtype of the payment; you must be authorized for this by Paypal!
subtotal: 10, // The total cost of the order, excluding tax and shipping
tax: 0,
shipping: 0,
recipient: '<<<YOUR RECIPIENT HERE>>>',
customID: 'anythingYouWant',
invoiceItems: [
{ name: 'Shoes', totalPrice: 8, itemPrice: 2, itemCount: 4 },
{ name: 'Hats', totalPrice: 2, itemPrice: 0.5, itemCount: 4 }
]
},
{
merchantName: 'Vendor 2',
paymentType: Paypal.PAYMENT_TYPE_SERVICE, // The type of payment
paymentSubtype: Paypal.PAYMENT_SUBTYPE_DONATIONS, // The subtype of the payment; you must be authorized for this by Paypal!
subtotal: 3, // The total cost of the order, excluding tax and shipping
tax: 0,
shipping: 0,
recipient: '<<<YOUR RECIPIENT HERE>>>',
customID: 'anythingYouWant',
invoiceItems: [
{ name: 'Coats', totalPrice: 3, itemPrice: 1, itemCount: 3 }
]
}
],
ipnUrl: 'http://www.appcelerator.com/',
currency: 'USD',
memo: 'For the orphans and widows in the world!'
}
});
Related
Hi to every one reading this. I am struggling with a PDF.js problem. I am using this library: https://github.com/edisonneza/jspdf-invoice-template to render a PDF with data that I am getting from an internal axios route that returns orders. This orders are listed with a checkbox, for the orders checked I generate a new array with the objects of the different orders checked.
Up to this I was doing fine, but the next thing I need is to generate this PDFs. I got it to work rendering one single pdf with the data order, but i would like to generete a PDF with (N) numbers of pages, using the checked orders to print with a button.
Below are the blocks of the code that i wrote.
printAllbtn.addEventListener('click',function(){
try {
if(ordersSelectedToPrint.length \> 1){
console.log(ordersSelectedToPrint);
for (let orderPrint of ordersSelectedToPrint) {
let pdfObject = jsPDFInvoiceTemplate.default(props);
console.log( 'object created' + pdfObject + orderPrint)
var props = {
outputType: jsPDFInvoiceTemplate.OutputType.Save,
returnJsPDFDocObject: true,
fileName: "remito",
orientationLandscape: false,
compress: true,
business: {
name: "Isidorito",
address: "San Pedro, Buenos",
phone: "(3329) 069 11 11 111",
email: "contacto#isidorito.com",
website: "www.isidorito.com.ar/nosotros",
},
contact: {
label: "Remito dirigito a:",
name: `${orderPrint.cliente.dueño}`,
address:`${orderPrint.cliente.direccion}`,
phone: `${orderPrint.cliente.telefono1}`,
email: `${orderPrint.cliente.correo}`,
},
invoice: {
label: "Pedido #",
num: 19,
invDate: `${orderPrint.createdAt}`,
invGenDate: `28/10/2022`,
headerBorder: false,
tableBodyBorder: false,
header: [
{
title: "#",
style: {
width: 10
}
},
{
title: "Productos descripción",
style: {
width: 70
}
},
{
title: "Cantidad ",
style: {
width:20
}
},
{ title: "Por Unidad",
style:{width:30}},
// { title: "Cantidad"},
{ title: "Por tot",
style:{
width:30
}},
{ title: "Total",
style:{
width:30
}}
],
table: Array.from(orderPrint.productosPedidosNombre).forEach(function(productoIm, index){[
index + 1,
`${productoIm.nombre} - ${productoIm.marca} - ${productoIm.presentacion}`,
`${productoIm.cantidad}`,
`${productoIm.cantidad}`,
`${productoIm.cantidad}`,
`${productoIm.cantidad}`,
]}),
invDescLabel: "Cliente:",
invDesc: `${orderPrint.cliente.nombreLocal}`,
},
footer: {
text: "Este remito generado digitalmente es valido para el pedido realizado",
},
pageEnable: true,
pageLabel: "Page ",
};
} } } catch (error) { console.log(error); }
});
The first note is that "orderPrint.productosPedidosNombre" is an array of products of the order. In the example from the documentation its represented in this way.
table: Array.from(Array(10), (item, index)=>([
index + 1,
"There are many variations ",
"Lorem Ipsum is simply dummy text dummy text ",
200.5,
4.5,
"m2",
400.5
])),
And the way I generate the PDF is:
let pdfObject = jsPDFInvoiceTemplate.default(props);
First I would like to know if it is possible the loops and iteration to generate this type of single file with N number of order pages, and each page with different data. It's possible with this library.
Thanks you. It's my second question I've asked in StackOverflow, so I welcome the feedback on the how to ask in stack overflow.
So I'm adding a feature to my discord bot to collect the users most recent gameclip, at the moment I'm able to collect all the information in my console log but struggling to understand how to send it in a message. I'm pretty new to this stuff.
This is a snippet of my code right now:
const userXuid = await XboxLiveAPI.getPlayerXUID(gamertag, authInfo).catch(err => message.reply('That gamertag could not be found. Make sure spaces are replaced with \'_\''));
const scores = await XboxLiveAPI.getPlayerScreenshotsFromMediaHub(userXuid, authInfo, num);
console.log(scores);
And this is what gets returned to the console:
{
continuationToken: 'YWJjZGVfdnd4eXoxMDA1',
values: [
{
captureDate: '2016-09-13T19:11:11Z',
contentId: 'e61118b6-c940-4hc9-a32a-49dd53ab4192',
contentLocators: [Array],
CreationType: 'Edited',
localId: '501bf44b-c1b2-4519-b78e-a1f88097f8d1',
ownerXuid: 25332749247888726,
resolutionHeight: 720,
resolutionWidth: 1280,
sandboxId: 'RETAIL',
sharedTo: [],
titleId: 1129121809,
titleName: 'OF: Dragon Rising',
dateUploaded: '2016-09-13T19:12:34.6226406Z',
uploadLanguage: 'en-GB',
uploadRegion: 'GB',
uploadTitleId: 201477059,
uploadDeviceType: 'XboxOne',
commentCount: 0,
likeCount: 0,
shareCount: 0,
viewCount: 2,
contentState: 'Published',
enforcementState: 'None',
safetyThreshold: 'None',
sessions: [],
tournaments: []
}
]
}
Conclusion
So how would I, for example, get captureDate to send in:
message.channel.send(???)
Any help would be appreciated, cheers!
If you're simply talking about accessing captureDate, you'll use scores.values[0].captureDate.
I'm trying to set up a facebook purchase event in GTM and i'm almost there but i son't understand why I can only see the first product from the transactiuon array in facebook business manager? I can see that a transaction been made and I can see the value but only one product SKU!
This is the datalayer after a specifik purchase, with two different kind of tickets:
{
transactionId: "31000226",
transactionTotal: 243,
transactionProducts: [
{
name: "Adult",
sku: "Adult",
price: 135,
quantity: 1,
category: "tickets"
},
{
name: "Pensioner",
sku: "Pensioner",
price: 108,
quantity: 1,
category: "tickets"
}
],
And this is my GTM-tag for the facebook purchase event:
<script>
fbq('track', 'Purchase',{
products: '[{{DLV - Ecommerce - Product}}]',
value: '{{DLV - Ecommerce - TransactionTotal}}',
currency: 'SEK'
});
</script>
The datalayer variable {{DLV - Ecommerce - Product}} is set up like this in GTM:
transactionProducts.0.sku
This is what I can see in facebook business manager:
Parametrar: (3)
value: 243
currency: SEK
products: [Adult]
Does anyone see the problem? Why can't I in this exampel see the second ticket that says "Pensioner"?
You could write a custom variable “sku variable” for the sku to be the below:
function () {
{{DLV - Ecommerce - Product}}.forEach {
return sku
};
}
Change the {{DLV - Ecommerce - Product}} to just transactionProducts
This question already has answers here:
MongoDB: How to update multiple documents with a single command?
(13 answers)
Closed 3 years ago.
I looked at other questions and I feel mine was different enough to ask.
I am sending a (potentially) large amount of information back to my backend, here is an example data set:
[ { orders: [Array],
_id: '5c919285bde87b1fc32b7553',
name: 'Test',
date: '2019-03-19',
customerName: 'Amego',
customerPhone: '9991112222',
customerStreet: 'Lost Ave',
customerCity: 'WestZone',
driver: 'CoolCat',
driverReq: false, // this is always false when it is ready to print
isPrinted: false, // < this is important
deliveryCost: '3',
total: '38.48',
taxTotal: '5.00',
finalTotal: '43.48',
__v: 0 },
{ orders: [Array],
_id: '5c919233bde87b1fc32b7552',
name: 'Test',
date: '2019-03-19',
customerName: 'Foo',
customerPhone: '9991112222',
customerStreet: 'Found Ave',
customerCity: 'EastZone',
driver: 'ChillDog',
driverReq: false,// this is always false when it is ready to print
isPrinted: false, // < this is important
deliveryCost: '3',
total: '9.99',
taxTotal: '1.30',
finalTotal: '11.29',
__v: 0 },
{ orders: [Array],
_id: '5c91903b6e0b7f1f4afc5c43',
name: 'Test',
date: '2019-03-19',
customerName: 'Boobert',
customerPhone: '9991112222',
customerStreet: 'Narnia',
customerCity: 'SouthSzone',
driver: 'SadSeal',
driverReq: false,// this is always false when it is ready to print
isPrinted: false, // < this is important
deliveryCost: '3',
total: '41.78',
taxTotal: '5.43',
finalTotal: '47.21',
__v: 0 } ] }
My front end can find all the orders that include isPrinted:false, I then allow the end user to 'print' all the orders that are prepared, in which, I need to change isPrinted into true, that way when I pull up a next batch I won't have reprints.
I was looking at db.test.updateMany({foo: "bar"}, {$set: {isPrinted: true}}), and I currently allow each order to set a new driver, which I update by:
Order.update({
_id: mongoose.Types.ObjectId(req.body.id)
},
{
$set: {
driver:req.body.driver, driverReq:false
}
which is pretty straight forward, as only 1 order comes back at a time.
I have considered my front end doing a foreach and posting each order individually, then updating the isPrinted individually but that seems quite inefficient. Is there a elegant solutions within mongo for this?
I'm not sure how I would user updateMany considering each _id is unique, unless I grab all the order's who are both driverReq:false and isPrinted:false (because that is the case where they are ready to print.
I found a solution, that was in fact using UpdateMany.
Order.updateMany({
isPrinted: false, driverReq:false
},
{
$set: {
isPrinted: true
}
consider there this special case where both are false when it needs to be changed too true. But I do wonder if there is a way to iterate over multiple document id's with ease.
I'm trying to calculate the value of the shopping cart based on data contained in my websites datalayer.
{
event: 'checkout',
ecommerce: {
checkout: {
actionField: {step: 1},
products: [
{
name: 'Nude Fur Collar Quilted Puffer Jacket',
id: 'Nude-JKT-6824',
price: 39.99,
quantity: 1,
category: ['Clothing', 'Clothing/Jackets & Coats'],
variant: [false, false]
},
{
name: 'Black Side Stripe Knee Cut Jeans',
id: 'JN-004',
price: 19.99,
quantity: 1,
category: ['Clothing', 'Clothing/Jeans'],
variant: [false, false]
}
]
}
},
gtm.uniqueEventId: 12
}
I have created a custom javascript variable with the following script, that i got from a previous question on stack overflow here
Dinesh's script works, but the output returns this number
59.980000000000004
I would like it to return this
59.98
Here is Dinesh's code
function(){
var productList={{ecommerce}}.checkout.products;
var totalAmount=0;
for(var i=0;i<productList.length;i++)
{
totalAmount+=(productList[i].quantity)*(parseFloat(productList[i].price));
}
return totalAmount;
}
How can i modify this to output the result in the correct format, with two decimal places. Thanks.
try using toFixed() method when returning the totalAmount. This method is useful in keeping a specified number of decimal.so using toFixed(2) would return only 2 decimal places.
function(){
var productList={{ecommerce}}.checkout.products;
var totalAmount=0;
for(var i=0;i<productList.length;i++)
{
totalAmount+=(productList[i].quantity)*(parseFloat(productList[i].price));
}
return totalAmount.toFixed(2);
}