I need help with finding a way to get the seller_receivable_breakdown values (gross_amount, paypal_fee, net_amount) from Paypal v2 Api in the sandbox
Here is my code:
onApprove: function (data, actions) {
return actions.order.capture().then(function (details) {
alert('paypal fees: ' + details.purchase_units[0].payments.captures[0].seller_receivable_breakdown.paypal_fee.value);
});
},
I followed the documentation:
https://developer.paypal.com/docs/api/payments/v2#captures_get
And I managed to get other fields such as:
details.purchase_units[0].payments.captures[0].status
details.purchase_units[0].payments.captures[0].id
but I couldn't get the seller_receivable_breakdown values. any tips would be greatly appreciated
From the shared log:
purchase_units: Array(1) 0: amount: {value: "100.99", currency_code: "SEK"} payee: {email_address: "blablabla#gmail.com", merchant_id: "D8AOYHUX2L75G"} payments: captures: Array(1) 0: amount: {value: "100.99", currency_code: "SEK"} create_time: "2020-11-24T08:56:04Z" final_capture: true id: "1VE71745JL288960Y" links: (3) [{…}, {…}, {…}] seller_protection: {status: "NOT_ELIGIBLE"} status: "COMPLETED" update_time: "2020-11-24T08:56:04Z"
Note payee: {email_address: "blablabla#gmail.com"
There is no breakdown because no PayPal transaction exists yet, this order is completed but was sent to a payee email with no account, and so the payment has not (yet) been accepted.
If the payment is not accepted within 30 days, it will be returned to the sender.
Related
I'm trying to use Braintree with the PayPal Checkout SDK (sandbox environment) however everytime I try and add in line items, I get a 'create_order_error' 'PayPal error undefined: could not initialise paypal flow'. This is only when I add in the lineItems option:
...
return paypalCheckoutInstance.createPayment({
flow: 'checkout',
amount: '100',
currency: 'USD',
intent: 'capture',
displayName: 'Display Test',
landingPageType: 'login',
lineItems: [
{
quantity: '1',
unitAmount: '50.00',
name: 'Test Name',
kind: 'debit'
},
{
quanity: '1',
unitAmount: '50.00',
name: 'Test Name 2',
kind: 'debit'
}
],
enableShippingAddress: true,
...
If I remove the lineItems property or set
...
lineItems: []
...
I get no error, so presumably its the way I'm formatting the items.
Can anyone assist?
Thank you!
Misspelt 'quantity' in line item 2 as pointed out by #Reynadan in comments. Silly mistake, don't know how I didn't spot it! Many thanks to all.
new to Javascript. Attempting to pull data from a weather API for a project but have run into an issue that I'm sure is simple to solve. Here is the data I've fetched already:
{coord: {…}, weather: Array(1), base: "stations", main: {…}, visibility: 9656, …}
coord: {lon: -76.13, lat: 43.04}
weather: Array(1)
0: {id: 500, main: "Rain", description: "light rain", icon: "10d"}
length: 1
__proto__: Array(0)
base: "stations"
main: {temp: 281.12, feels_like: 274.24, temp_min: 280.37, temp_max: 282.04, pressure: 1004, …}
visibility: 9656
wind: {speed: 8.2, deg: 310}
rain: {1h: 0.25}
clouds: {all: 90}
dt: 1587324361
sys: {type: 1, id: 5965, country: "US", sunrise: 1587291309, sunset: 1587340289}
timezone: -14400
id: 0
name: "Syracuse"
cod: 200
__proto__: Object
What I need to do is select "Rain" under the weather class. However, since it is inside of an array I do not know how to get it. For example, if I do
data.visibility
I will of course be returned with 9656. Yet if I do
data.weather.0 or even data.weather.["0"]
I will be met with the following error: Uncaught SyntaxError: Unexpected number. And even if I were to not get this error, how would I go about accessing the specific element "Rain" in the Array?
Sorry if this is an easy fix, just having trouble finding an answer due to the very specific wording whenever I search.
If you need only the first element of an array, you can simply use an index to get the value data.weather[0].main.
Or you can map an array via the Array method data.weather.map(item => item.main). You will get a customized array ["Rain"]
You access it like this:
data.weather[0].main
where 0 is an integer describing the index of the element of the array.
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 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!'
}
});