Closed (fixed)
Project:
Commerce PayPal
Version:
7.x-1.x-dev
Component:
PayPal WPS
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
28 May 2011 at 23:27 UTC
Updated:
19 Nov 2014 at 14:54 UTC
Jump to comment: Most recent
Comments
Comment #1
bc24102 commentedI have the same issue as well. I have noticed when I go the payment page (the page that redirects you to pay with Paypal) my shopping cart goes back to 0 on items and price. Have you noticed this?
Comment #2
bc24102 commentedCode above is commerce_paypal_wps.module line 290
I have been doing some testing of this issue and from what I can tell it seems to be stemming from amount_1 value. It converts it into a decimal like paypal wants but maybe its in the wrong format. I tested with using just $amount in the line and I was able to complete payment. I sent $25.06 and it came out to $2,506.40. So I can only assume the decimal format is the culprit.
Here are the qualifications from the Paypal website incase anybody working on this needed quick reference.
Value must be a positive number. No currency symbol. Must have two decimal places, decimal separator must be a period (.), and the optional thousands separator must be a comma (,)
I am going to do some more investigating on commerce_currency_amount_to_decimal. Any help would be greatly appreciated. Hopefully either myself or someone else can resolve this soon.
Comment #3
bc24102 commentedI think I may have resolved the problem. PayPal needs a number with only two decimal places. I checked the source of the page with the "Proceed to PayPal" button and the value that was actually being sent had more than two decimal places. It was 25.064. I rounded the number to two decimal places and now I am able to complete payment with the correct pricing.
Here is the change I made.
Code below is on commerce.module line 493
Please test this out and let me know if this is working properly and doesn't cause any other problems
Comment #4
gagoo commentedSubscribe
Comment #5
gagoo commentedIs there a way to solve the issue without patching the commerce.module file ?
Is there a planed next release for Commerce Paypal module ?
Thanks
Comment #6
gagoo commentedOK,
As patching the Drupal Commerce commerce_currency_amount_to_decimal function in the commerce.module file can affect some calculations because of the amount rounding, I think it's better to only patch the Commerce Paypal module.
So I only replaced the line that define the amount sent to Paypal in commerce_paypal_wps.module.
The only needed change is to replace line 292 :
'amount_1' => commerce_currency_amount_to_decimal($amount, $currency_code),
by
'amount_1' => round(commerce_currency_amount_to_decimal($amount, $currency_code),2),
Can testers give a feedback please ?
What the maintainer think about it ?
Thanks :)
Comment #7
bc24102 commentedJust tested this out. It worked for me. I agree that this is better to fix it in commerce_paypal_wps.module.
Comment #8
rszrama commentedYeah, I just committed a fix to round it in our module instead of editing Commerce.
Comment #9
gagoo commentedNice :)
Thx
Comment #11
nocean commentedApologies for re-opening this issue -- but did this change get dropped in later versions? Looking in commerce_paypal_wps.module in the latest dev release, on ln 427, the round() function is missing. I re-added the round() function and it works as expected.
Comment #12
rszrama commentedActually, this does appear to have come back to haunt us; currently it's getting visibility in #1800896-8: Product's price get bloated with float decimals, and we'll need to ensure all payment gateway modules get the memo.
Comment #13
nellngun commented#2 working perfectly! For Drupal 7 is line 462:
// Define a single item in the cart representing the whole order
'amount_1' => round(commerce_paypal_price_amount(commerce_currency_convert($amount, $order_currency_code, $currency_code), $currency_code),0),
'item_name_1' => t('Order @order_number at @store', array('@order_number' => $order->order_number, '@store' => variable_get('site_name', url('', array('absolute' => TRUE))))),
'on0_1' => t('Product count'),
'os0_1' => commerce_line_items_quantity($wrapper->commerce_line_items, commerce_product_line_item_types()),
);
instead of
// Define a single item in the cart representing the whole order
'amount_1' => commerce_paypal_price_amount(commerce_currency_convert($amount, $order_currency_code, $currency_code), $currency_code),
'item_name_1' => t('Order @order_number at @store', array('@order_number' => $order->order_number, '@store' => variable_get('site_name', url('', array('absolute' => TRUE))))),
'on0_1' => t('Product count'),
'os0_1' => commerce_line_items_quantity($wrapper->commerce_line_items, commerce_product_line_item_types()),
);
* 2 for 2 decimals (for me 0 for no decimals)