Rounding tax amount for Paypal - paypal

In a US e-commerce webshop I am looking for input on how to solve an issue with Paypal Orders API
Example
The price per lamp excluding tax is $1547
A customer adds 2 of these lamps to his shopping basket
A third party service will calculate the tax amount for the two lamps to be $274.59
The total price for 2 lamps including tax is
2*1547 + 274.59 = $3368.59
When paying using Paypal we need to send the different amounts to Paypal Orders API.
This is where the issue occur with the tax amount.
Paypal want's it "pr unit", meaning 274.59 / 2 = $137.295
But Paypal will only accept 2 digits :-(
Below is how the order should be sent if 3 digits was allowed:
"purchase_units": [{
"amount": {
"currency_code": "USD",
"value": "3368.59",
"breakdown": {
"item_total": {
"currency_code": "USD",
"value": "3094"
},
"tax_total": {
"currency_code": "USD",
"value": "274.59"
}
}
},
"items": [{
"name": "Oval lamp",
"tax": {
"currency_code": "USD",
"value": "137.295"
},
"unit_amount": {
"currency_code": "USD",
"value": "1547"
},
"quantity": "2"
}
]]
This will give me an error:
"details": [
{
"field": "/purchase_units/0item/0/tax/value",
"value": "137.295",
"issue": "DECIMAL_PRECISION",
"description": "If the currency supports decimals, only two decimal place precision is supported."
}
]
If I then round the tax from $137.295 to $137.30 I get this error:
"details": [
{
"field": "/purchase_units/0/amount/breakdown/tax_total/value",
"value": "274.59",
"issue": "TAX_TOTAL_MISMATCH",
"description": "Should equal sum of (tax * quantity) across all items for a given purchase_unit"
}
]
If I update the total tax amount from 274.59 to 274.6 I get this error:
"details": [
{
"field": "/purchase_units/0/amount/value",
"value": "3368.59",
"issue": "AMOUNT_MISMATCH",
"description": "Should equal item_total + tax_total + shipping + handling + insurance - shipping_discount - discount."
}
]
My only option now is to change the total amount from $3368.59 to $3368.6, but that is not correct!
Any input is appreciated

Not much to say here--your question has the solution. Calculate the tax per item, round up or down as appropriate, and you'll have a different tax total. Use that.
If you want to adjust the order total to some different calculation, you'll need to add another line item with the positive or negative amount.

Related

Paypal API/ agreement page / hide shipping address block

I have a digital product and therefore want to hide the shipping block.
I use Paypal API CURL Create agreement
My CURL post data:
{
"name": "user#user.com Agreement",
"description": "Essential 1 Plan - 19$ trial 7 days - 1$",
"start_date": "2021-11-11T00:52:01Z",
"payer": {
"payment_method": "paypal"
},
"plan": {
"id": "P-XXXXXXXXXXXXXXXXXXXXXXXX"
},
"override_merchant_preferences": {
"setup_fee": {
"value": 0,
"currency": "USD"
},
"return_url": "http://domain.local/membership/checkout/success",
"cancel_url": "http://domain.local/membership/checkout/cancel",
"auto_bill_amount": "YES",
"initial_fail_amount_action": "CONTINUE",
"max_fail_attempts": 2
}
}
I read that I need to set the
no_shipping => 1
parameter, but I don't know where.
Please help find a solution.

PayPal APIs - Set multiple curriences in a single order

I'm trying to set more than one currency code within a single order.
I sent this json to the PayPal API Create order with two currency codes, EUR and USD, distributed at random.
{
"intent": "CAPTURE",
"brand_name": "Miller-Miller",
"cancel_url": "https://adkins-knight.biz/login/",
"landing_page": "LOGIN",
"return_url": "https://kennedy.net/",
"shipping_preference": "NO_SHIPPING",
"user_action": "PAY_NOW",
"payer_email_address": "lindaholland#gmail.com",
"payer_address_line_1": "98169 Tina Ramp Apt. 548",
"payer_address_line_2": "Unions",
"payer_admin_area_1": "United States Virgin Islands",
"payer_admin_area_2": "South Veronicaborough",
"payer_country_code": "BE",
"payer_postal_code": "16858",
"payer_full_name": "Jeremy Martin Jr.",
"payer_given_name": "Sarah",
"payer_middle_name": "Richard",
"payer_prefix": "Dr.",
"payer_suffix": "DDS",
"payer_surname": "Donovan",
"user": null,
"purchase_units": [
{
"custom_id": "3cef9acd-acfd-4b57-9426-fe25b993b51f",
"description": "Process would successful not stage girl.\nEat economy air stuff wind box city. Suffer scene deal much. Rise or friend provide.",
"invoice_id": "0f2ac8bf-c763-48a2-8207-6c15a422cf44",
"reference_id": "0ea30992-6cc2-4e3f-9f9f-bb2a1ff9458d",
"soft_descriptor": "break",
"amount_currency_code": "EUR",
"amount_value": 9998008.45,
"breakdown_discount_currency_code": "EUR",
"breakdown_discount_value": 9999889.5,
"breakdown_handling_currency_code": "USD",
"breakdown_handling_value": 9999884.8,
"breakdown_insurance_currency_code": "EUR",
"breakdown_insurance_value": 9997223.61,
"breakdown_item_total_currency_code": "USD",
"breakdown_item_total_value": 9994971.56,
"breakdown_shipping_currency_code": "USD",
"breakdown_shipping_value": 9991250.62,
"breakdown_shipping_discount_currency_code": "USD",
"breakdown_shipping_discount_value": 9997344.57,
"breakdown_tax_total_currency_code": "USD",
"breakdown_tax_total_value": 9999229.59,
"shipping_type": "SHIPPING",
"shipping_address_line_1": "2359 Greene Path Suite 645",
"shipping_address_line_2": "Springs",
"shipping_admin_area_1": "Hong Kong",
"shipping_admin_area_2": "South Debra",
"shipping_country_code": "CU",
"shipping_postal_code": "95591",
"shipping_full_name": "Ashley Stone",
"items": [
{
"category": "PHYSICAL_GOODS",
"description": "Despite should allow. Military determine up she goal.",
"name": "Mary Harper",
"quantity": 4405,
"sku": "total",
"tax_currency_code": "USD",
"tax_value": 9997113.36,
"unit_amount_currency_code": "USD",
"unit_amount_value": 9998795.33
},
{
"category": "PHYSICAL_GOODS",
"description": "Hospital cover job rest new. Only citizen I generation raise present. Majority president stuff west.",
"name": "Lucas Parker",
"quantity": 1759,
"sku": "little",
"tax_currency_code": "USD",
"tax_value": 9996456.8,
"unit_amount_currency_code": "USD",
"unit_amount_value": 9999554.88
}
]
}
]
}
I got this response:
{
"name": "UNPROCESSABLE_ENTITY",
"details": [
{
"issue": "MULTI_CURRENCY_ORDER",
"description": "Multiple differing values of currency_code are not supported. Entire Order request must have the same currency_code."
}
],
"message": "The requested action could not be performed, semantically incorrect, or failed business validation.",
"debug_id": "527aca32094a2",
"links": [
{
"href": "https://developer.paypal.com/docs/api/orders/v2/#error-MULTI_CURRENCY_ORDER",
"rel": "information_link",
"method": "GET"
}
]
}
I have searched through the PayPal documentation and on Google, but it is not clear if it is possible to set up two or more currencies in a single order.
The inserted curriences (EUR & USD) are both approved in my PayPal settings following these steps from PayPal FAQ:
EDIT:
If I need to set multiple products with two curriences in a single transaction, I cannot do it? Have I do separate the order in two order, apply a single currency code for each of them?
Multiple differing values of currency_code are not supported. Entire Order request must have the same currency_code.

initial_fail_amount_action not working as expected

I'm trying to create a recurring payment plan which allow me to get the user first payment immediately, for doing this I've used the option setup_fee setted as 14.99 but for some reason I can't get this working. Infact, the sandbox user that I used for this doesn't have any funds, and the subscription shouldn't be approved just as it happens. These are the payment details:
{
"name": "Monthly Plan",
"description": "Monthly plan based subscription",
"status": "ACTIVE",
"usage_type": "LICENSED",
"product_id": "PROD-32M79039A8219464Y",
"billing_cycles": [
{
"frequency": {
"interval_unit": "MONTH",
"interval_count": 1
},
"tenure_type": "TRIAL",
"sequence": 1,
"total_cycles": 1,
"pricing_scheme": {
"fixed_price": {
"value": "0",
"currency_code": "EUR"
}
}
},
{
"frequency": {
"interval_unit": "MONTH",
"interval_count": 1
},
"tenure_type": "REGULAR",
"sequence": 2,
"total_cycles": 0,
"pricing_scheme": {
"fixed_price": {
"value": "14.99",
"currency_code": "EUR"
}
}
}
],
"payment_preferences": {
"auto_bill_outstanding": true,
"setup_fee": {
"value": "14.99",
"currency_code": "EUR"
},
"setup_fee_failure_action": "CANCEL",
"payment_failure_threshold": 0
},
"taxes": {
"percentage": "0",
"inclusive": false
},
"merchant_preferences": {
"initial_fail_amount_action": "CANCEL",
"max_fail_attempts": 0
}
}
I've specified merchant_preferences, that must cancel the subscription process in the PayPal smart buttons process. But this doesn't do anything. The expected behavior:
User approve a subscription using the PayPal smart buttons
The user has no funds so PayPal should stop the process as merchant_preference configuration
If the user has found, then the subscription must be created and the funds must be sent to merchant account in order to activate the subscription in my server
What country is the sandbox user, and what funding sources are on the account? Most sandbox users have infinite funds from a default bank account funding source, or a credit card. It does not matter that their PayPal balance is zero.
In general it is not possible to create a PayPal subscription with only a PayPal balance -- a backup funding source is required.

How to create a Subscription payment using Paypal client-side rest api?

The Client-side REST integration documentaion describes about creating a express checkout for one or more items.
How can i use the same for creating a subscription or Recurring payment? How should the following be modified?
payment: function(data, actions) {
return actions.payment.create({
transactions: [
{
amount: { total: '1.00', currency: 'USD' }
}
]
});
},
I found a similar Rest api for Node. Not sure how it would be on JS.
First you need to create a billing plan:
billing_plan_attributes = {
"name": PLAN_NAME_HERE,
"description": PLAN_DESCRIPTION,
"merchant_preferences": {
"auto_bill_amount": "yes", # yes if you want auto bill
"cancel_url": "http://www.cancel.com", # redirect uri if user cancels payment
"initial_fail_amount_action": "continue",
"max_fail_attempts": "1",
"return_url": RETURN_URL,
"setup_fee": {
"currency": CURRENCY,
"value": VALUE # how much do you want to charge
}
},
"payment_definitions": [
{
"amount": {
"currency": request.form['currency'],
"value": request.form['amount']
},
"cycles": CYCLES, # how much time this subscription will charge user
"frequency": FREQ, # month, day
"frequency_interval": INTERVAL, # per month or per three month or so on
"name": NAME,
"type": TYPE
}
],
"type": TYPE
}
billing_plan = BillingPlan(billing_plan_attributes)
if billing_plan.create():
print("success")
The attributes used have literal meaning here. Now since you have created a billing plan you need to give users some interface so that they can subscribe with it. Below is a sample code for this:
billing_agreement = BillingAgreement({
"name": "Organization plan name",
"description": "Agreement for " + request.args.get('name', ''),
"start_date": (datetime.now() + timedelta(hours=1)).strftime('%Y-%m-%dT%H:%M:%SZ'),
"plan": {
"id": request.args.get('id', '')
},
"payer": {
"payment_method": "paypal"
},
"shipping_address": {
"line1": "StayBr111idge Suites",
"line2": "Cro12ok Street",
"city": "San Jose",
"state": "CA",
"postal_code": "95112",
"country_code": "US"
}
})
if billing_agreement.create():
for link in billing_agreement.links:
if link.rel == "approval_url":
approval_url = link.href
In the last line you get the approval link which can be given to user.
Next you have to setup an endpoint which will be the callback url if user approves the payment.
billing_agreement_response = BillingAgreement.execute(payment_token)
payment_token is sent by paypal to your callback url.

PayPal hide order total

I am using PayPal's REST API to implement paying via PayPal into my website. When I send an approval request to PayPal it always shows the order total. I really don't want to show this. At the point in which we are asking for approval the user won't even know what their total order amount will be. Is there anyway to hide the order total on the PayPal page?
Are you sending line items in your API request? For example:
"item_list": {
"items": [{
"name": "Test",
"sku": "18",
"price": "7.47",
"currency": "USD",
"quantity": "1"
}
]
}
If you send the items array, the price will be displayed in PayPal's payment page.
However, you can just send a total amount, and it won't appear during buyer approval, for example:
{
"intent": "sale",
"redirect_urls": {
"return_url": "http://URL.com/restapi_test/_payments_execute-an-approved-paypal-payment.html",
"cancel_url": "http://URL.com/restapi_test/_payments_create-a-payment-paypal.html"
},
"payer": {
"payment_method": "paypal"
},
"transactions": [{
"amount": {
"total": "7.47",
"currency": "USD"
},
"description": "This is the payment transaction description."
}]
}