Q: PayPal collecting the amount from the basket - paypal

I want the amount from the basket to be downloaded when I click the PayPal button and instead of the total entered. I can not seem to get it to work.
I use this.
Anyone have any pointers?

You need to update below total with the total of your basket - it's not going to happen automatically.
{
amount: { total: '0.01', currency: 'USD' }
}

Related

How to remove shipping from the PayPal subscribe button and default other values?

I'm creating a subscription button using the JavaScript SDK from PayPal. Here's the basic code snippet I'm following:
paypal.Buttons({
createSubscription: function(data, actions) {
return actions.subscription.create({
'plan_id': 'P-2UF78835G6983425GLSM44MA'
});
},
onApprove: function(data, actions) {
alert('You have successfully created subscription ' + data.subscriptionID);
}
}).render('#paypal-button-container');
When a user selects Credit Card (non PayPal account option),the next PayPal popup Window has a long form, collecting Credit Card, Billing Address, Shipping Address, Phone Number, and Email. For my needs, I don't need a shipping address and I'd like to be able to default things like Billing Address, Phone, and Email.
The PayPal SDK documentation is large but somehow lacking critical details around this library. My questions are:
How can I exclude shipping address collection from this form?
How can I default the other info I have already collected from the user (phone, email, etc)?
Thanks to Preston PHX, I was able to get the collection of shipping info removed from the mile long form, but for some reason, my subscriber information is not be pre-filled into the PayPal popup window.
Here's my update code section:
createSubscription: function (data, actions) {
return actions.subscription.create({
/* Creates the subscription */
plan_id: 'P-2UF78835G6983425GLSM44MA',
subscriber: {
name: {
given_name: "FirstName",
surname: "LastName",
},
email_address: "test#example.com",
phone: {
phone_type: "MOBILE",
phone_number: {
national_number: "2145551212",
}
},
address: {
address_line_1: "123 Main Street",
address_line_2: "Suite 101",
admin_area_1: "Addison",
admin_area_2: "TX",
postal_code: "75001",
country_code: "US"
}
},
application_context: {
shipping_preference: "NO_SHIPPING"
}
});
},
However, when the popup is rendered, here's what I see:
Note, the shipping elements are no longer rendering, but the form is not getting prefilled.
It would seem that I'm close to doing this right because if I put an phone number in that is not a well-formed phone number, the API spits out errors about the number not being valid.
All available parameters are the same as the create subscription API operation.
Set application_context.shipping_preference to NO_SHIPPING
Phone, email, and other information can be set in the subscriber object.

Sales tax not updated when shipping option is changed if buyer pays with Credit/Debit rather than PayPal?

In the PayPal JavaScript SDK when the order is created the client passes the shipping cost options. If the purchaser changes the shipping option from within the PayPal window, the sales tax must be recalculated because sales tax applies to shipping for this product. The sales tax is not passed in the order creation but the onShippingChange event is fired/invoked after the address is first applied in PayPal; and then the new values, including sales tax, are passed through return actions.order.patch().
If the purchaser pays through clicking the PayPal button, all works fine because the onShippingChange event is fired/invoked when the shipping option is changed. However, when the purchaser uses the Credit/Debit button to pay, the onShippingChange event is fired/invoked only once and not again when the shipping option is changed. If the user changes the shipping option, the cost appears to be taken from the data passed in the order creation and since the onShippingEvent is not run again, the sales tax remains based upon the initial shipping option.
The only difference in these two scenarios is which button the purchaser uses to pay: either PayPal for an account, or Credit/Debit to pay as a guest. All the JS code is the same.
Am I doing something wrong that is causing the onShippingChange event code to not be invoked? Thank you.
A couple things I've noticed while working on this. One is that the messages of "contacting merchant" and "processing" vary, such that when the shipping option is changed when paying with credit/debit, the message is only "processing". When paying with PayPal the message is "contacting merchant." Another is that even after the values are updated, with the sales tax inaccurate, the total cost shown in the top right corner of the PayPal window differs from the total in larger font in the message by difference in shipping options. The one in large font never changes when the shipping option is changed.
In the image below, the shipping option was changed from $9.25 priority to $4.00 standard. The initial total was $28.83. When shipping was changed to standard, the cost changed as $(28.83-9.25+4.00) = $23.58. Sales tax was not adjusted; and it should be $23.27.
I asked a similar question a day or so ago, but thought the values were correct in both payment scenarios but now see they are not.
Update:
After messing around with various options it occurred to me that I don't need to provide shipping options in the PayPal window. If the buyer wants to change the option, he'll have to cancel and change the order in the web page. That eliminates the issue of onShippingChange not firing. Not ideal; but good enough for our little case, especially since few buyers will be changing their shipping option in PayPal, for they see all that cost info. before clicking a payment button.
paypal.Buttons({
// Sets up the transaction when a payment button is clicked
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
reference_id: "HardCopy_0001",
amount: {
value: order.discSub.toFixed(2)
},
shipping: {
options: [
{
id: "STD",
label: "USPS Standard",
type: "SHIPPING",
selected: order.el_shipOptsInp[0].checked,
amount: {
value: order.shipStdVal.toFixed(2),
currency_code: "USD"
}
},
{
id: "PRI",
label: "USPS Priority",
type: "SHIPPING",
selected: order.el_shipOptsInp[1].checked,
amount: {
value: order.shipPriVal.toFixed(2),
currency_code: "USD"
}
}
]
}
}],
});
},
// Finalize the transaction after payer approval
onApprove: function(data, actions) {
return actions.order.capture().then(function(orderData) {
/* ... */
});
},
onShippingChange: function (data, actions) {
try {
// Reject non-US addresses
if (data.shipping_address.country_code !== 'US') {
return actions.reject();
}
const taxRate = data.shipping_address.state === 'PA' ? order.taxRate : 0,
shippingAmount = parseFloat(data.selected_shipping_option.amount.value),
tax_total = taxRate === 0 ? 0 : Math.round( (order.discSub + shippingAmount) * order.taxRate * 100)/100,
oTotal = order.discSub + shippingAmount + tax_total;
if ( data.selected_shipping_option.id === "STD" ) {
if ( !order.el_shipOptsInp[0].checked ) {
order.el_shipOptsInp[0].checked = true;
order.change();
}
} else if ( !order.el_shipOptsInp[1].checked ) {
order.el_shipOptsInp[1].checked = true;
order.change();
}
return actions.order.patch([{
op: "replace",
//path: "/purchase_units/#reference_id==\'default\'/amount",
path: "/purchase_units/#reference_id=='HardCopy_0001'/amount",
value: {
value: oTotal.toFixed(2),
currency_code: "USD",
breakdown: {
item_total: {
currency_code: "USD",
value: order.discSub.toFixed(2)
},
shipping: {
currency_code: "USD",
value: shippingAmount.toFixed(2)
},
tax_total: {
currency_code: "USD",
value: tax_total.toFixed(2)
}
}
}
}
]);
} catch (err) {
console.log("We apologize. There was an error in the onShippingChange event. Reason is provided below.");
console.log(err);
order.error();
return actions.reject();
}
},
onError: function(err) {
console.log(err);
// For example, redirect to a specific error page
//window.location.href = "/your-error-page-here";
order.error();
}
}).render('#paypal-button-container');

PayPal IPN message not sending invoice, even though it was definitely included in button code

I have a paypal checkout button on my website along with funding icons. This is part of the code for it:
style: {
label: 'checkout',
fundingicons: true, // optional
size: 'responsive', // small | medium | large | responsive
shape: 'rect', // pill | rect
color: 'gold' // gold | blue | silver | black
},
payment: function (data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: {
total: amount,
currency: currency
},
invoice_number: '{$invoice}',
custom: '{$invoice}'
}
],
"redirect_urls": {
"return_url": , // these are both filled correctly
"cancel_url":
}
}
});
As you can see, the invoice field is explicitly defined, however, when getting sent back IPN messages, my ipn.php file is failing due to the lack of an invoice number being sent to it.
What makes this even weirder is that whenever the txn_type is express_checkout the invoice is there, but when it's web_accept, which is most of the time, neither the invoice nor the custom field are getting passed (I added the custom field when the IPN messages started failing).
The api we use for the button is https://www.paypalobjects.com/api/checkout.js
Is there something I'm missing or is it just that the api is deprecated and this is another sign to switch over?
EDIT:
After testing this out on other browsers it seems that adblock is blocking part of the checkout.js dependencies from loading:
Firefox: Cross-Origin Request Blocked
Opera: Failed to load resource: net::ERR_BLOCKED_BY_ADBLOCKER
Edge: POST https://www.paypal.com/xoplatform/logger/api/logger net::ERR_BLOCKED_BY_CLIENT
No error message from chrome.
EDIT 2:
sample IPN of type web_accept
mc_gross=300.00&protection_eligibility=Ineligible&payer_id=SOMEREALID&
payment_date=11:32:11 Sep 27, 2021 PDT&payment_status=Completed&charset=windows-1252&
first_name=&mc_fee=9.00&notify_version=3.9&custom=&payer_status=unverified&
business=our_business_email&quantity=1&
verify_sign=sign_in_alpha_numeric&
payer_email=random_alpha_numeric#dcc2.paypal.com&txn_id=1KM93595HU1361254&payment_type=instant&
last_name=NotProvided&receiver_email=same_as_business_email&payment_fee=&
shipping_discount=0.00&receiver_id=more_alpha_numeric&insurance_amount=0.00&
txn_type=web_accept&item_name=&discount=0.00&mc_currency=CAD&item_number=&
residence_country=OUR_COUNTRY_CODE&receipt_id=1111-1111-1111-1111&shipping_method=Default&
transaction_subject=&payment_gross=
In the example IPN given:
mc_gross=300.00&protection_eligibility=Ineligible&payer_id=SOMEREALID&
payment_date=11:32:11 Sep 27, 2021 PDT&payment_status=Completed&charset=windows-1252&
first_name=&mc_fee=9.00&notify_version=3.9&custom=&payer_status=unverified&
business=our_business_email&quantity=1&
verify_sign=sign_in_alpha_numeric&
payer_email=random_alpha_numeric#dcc2.paypal.com&txn_id=1KM93595HU1361254&payment_type=instant&
last_name=NotProvided&receiver_email=same_as_business_email&payment_fee=&
shipping_discount=0.00&receiver_id=more_alpha_numeric&insurance_amount=0.00&
txn_type=web_accept&item_name=&discount=0.00&mc_currency=CAD&item_number=&
residence_country=OUR_COUNTRY_CODE&receipt_id=1111-1111-1111-1111&shipping_method=Default&
transaction_subject=&payment_gross=
Note: #dcc2.paypal.com
This is from a direct credit card integration, perhaps using the classic NVP DoDirectPayment API, or Virtual Terminal [or Payflow with PayPal as the processor, as it happens]
So, not related to the button code in the question -- rather a separate integration to this PayPal account.

How do I remove a "Ship to" section from Checkout Popup?

Is there any option, when creating a payment with Paypal API, that allows to remove a "Ship to" section from Checkout popup? I mean just not to displayit in popup.
I do not use a shipping_address option anywhere in payment_json object when creating a configuration for a payment. But the section still persists.
I'm adding this answer since I came here while searching for disabling the shipping to information by using PayPal Smart Payment Button. This answer may help them.
You have to add the below line to remove Ship to address.
application_context: { shipping_preference: 'NO_SHIPPING' }
Eg:
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{ amount: { value: 1.00 } }],
application_context: { shipping_preference: 'NO_SHIPPING' }
});
}
}).render("#paypal-button-container");
You need to use Payment Experience API.
Create new web_profile, and set presentation with
"no_shipping": 1,
"address_override": 0

Facebook Ads - value means

In the standard tracking for ads I want to implemet the "Purchased" as the name of the event. I need to implement it on my site. this could be the possible for it:
fbq('track', 'Purchase', {currency: 'USD', value: 0.50});
I don't know if that is the right code for it.
I would like to ask if what is the meaning of this :
value: 0.50
The value parameter should be the total value of the purchase, in the specified currency.
For example, if this Purchase event was for a subscription that cost $20, your event would be:
fbq('track', 'Purchase', {
currency: 'USD',
value: 20.00
})
You can read more about event parameters here: https://developers.facebook.com/docs/marketing-api/facebook-pixel/v2.6#parameters