The following is appearing after choosing paypal as the payment option and continuing. I am not a developer but have had a look at the code the best I can. When looking at line 698, 702 etc I think it is down to the missing $currency_code variable. I compared this to the wps module and replaced "($amount)" with ($amount, $currency_code), 2. This allowed the progression through to paypal with the caveat that if multiple products were purchased they all had the same name and when payment completed it then gave another host of errors relating to the currency_code. I read somewhere else that this had been patched in wps which is why I tried the fix above.

Can anyone help?

Warning: Missing argument 2 for commerce_currency_amount_to_decimal(), called in /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce_paypal_ec/commerce_paypal_ec.module on line 264 and defined in commerce_currency_amount_to_decimal() (line 698 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce/commerce.module).
Notice: Undefined variable: currency_code in commerce_currency_amount_to_decimal() (line 702 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce/commerce.module).
Notice: Undefined variable: currency_code in commerce_currency_amount_to_decimal() (line 704 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce/commerce.module).
Notice: Undefined variable: currency_code in commerce_currency_amount_to_decimal() (line 705 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce/commerce.module).
Notice: Undefined variable: currency_code in commerce_currency_amount_to_decimal() (line 708 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce/commerce.module).
Warning: Missing argument 2 for commerce_currency_amount_to_decimal(), called in /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce_paypal_ec/commerce_paypal_ec.module on line 266 and defined in commerce_currency_amount_to_decimal() (line 698 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce/commerce.module).
Notice: Undefined variable: currency_code in commerce_currency_amount_to_decimal() (line 702 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce/commerce.module).
Notice: Undefined variable: currency_code in commerce_currency_amount_to_decimal() (line 708 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce/commerce.module).
A problem was found connecting to Paypal. Please try again later.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

citlacom’s picture

Assigned: Unassigned » citlacom
Status: Active » Fixed

Hello Chris,

Thanks for your issue report, I did a fix for this and commited into the dev branch please take a look at http://drupalcode.org/project/commerce_paypal_ec.git/blobdiff/1c43d75a61...

Downloading the last dev version should fix your problem. Let me know if this works.

Chris Machnicki’s picture

I think I went a bit paste happy with $currency_code as I also tried it without the '),2' but couldn't get it to work. I have installed the alpha you have posted (I assume thats ok as i don't know how to use git) but when I entered the following details in the payment method -
all the sandbox details, Currency = GBP, Login Page = GB, Sale, Sole, Focus in the no paypal account form, Checked Autofill and send the shopping cart, "paypal" for the custom page, Sandbox and Log during IPN validation I just get the message -

Please wait while you are redirected to the payment server. If nothing happens within 10 seconds, please click on the button below.
"A problem was found connecting to Paypal. Please try again later."

and it keeps refreshing.
I checked the module urls and they seem to be ok

Thanks

citlacom’s picture

Hello Chris,

This looks more like a fail in the API call when try to get a transaction token, the reasons for this are multiple for example a wrong authentication credentials, problems with the CURL connection, bad parameter value (I don't supose this is reason because all values have default configurations that works). So the best way to figure what is happening is to see the watchdog messages where in caise of fail the module save a debug message of the problem. Please go to to the relative path admin/reports/dblog in your drupal installation then filter the messages for type = commerce_paypal_ec and look if you see some error message there.

Important to note that you should have the dblog module enabled so if don't then enable try a paypal transaction then go to the reports log and check if there is a message. If you found something please copy and paste here so I could help you better.

Regards.

Chris Machnicki’s picture

Sorry i took my time I tried a few things in the module code but the small bits I am picking up are not enough for this. There was lots of duplicate messages due to the multiple tries. I have done some research and found the same problem on another site and it refers to the total price being sent to Paypal not matching the actual order price due to rounding. My initial thought was to investigate the removal of rounding but soon discovered that this is a requirement of Paypal. All my products are full prices i.e. £2.50 and I can't see the total order amount being different to that being sent unless it is related to the field names used below

The Paypal EC API call failed. Array ( [TIMESTAMP] => 2012-05-26T00:59:54Z [CORRELATIONID] => 1bb318cd328e5 [ACK] => Failure [VERSION] => 88.0 [BUILD] => 2975009 [L_ERRORCODE0] => 10413 [L_SHORTMESSAGE0] => Transaction refused because of an invalid argument. See additional error messages for details. [L_LONGMESSAGE0] => The totals of the cart item amounts do not match order amounts. [L_SEVERITYCODE0] => Error )

From reviewing the fields reports I can see few different prices being used -
commerce_order_total (Locked) Price (module: Price) Order
commerce_price (Locked) Price (module: Price) Product
commerce_total (Locked) Price (module: Price) Product, Shipping
commerce_unit_price (Locked) Price (module: Price) Product, Shipping
field_old_price Price (module: Price) Product

citlacom’s picture

After analyse all this info you provided we know that the problem is related to some difference between the sum of total for every cart item and the total amount of the order. What I get in mind is a probably bug related to some shipping / tax rule that is not correctly calculated when initialize payment request.

Do you have some shipping or taxes configured?

You can debug a bit and compare the value of:

'PAYMENTREQUEST_0_AMT' => round(commerce_currency_amount_to_decimal($amount, $currency_code)),

and

'L_PAYMENTREQUEST_0_AMT' . $item_no => commerce_currency_amount_to_decimal($item_price['amount'], $item_price['currency_code']),

This last parameter is an iteration of all the cart items and based on the error message looks like the sum of all the amounts for items doesn't match with the global total. You can check easily if at line 365 of commerce_paypal.module you do a print_r($request_params); so you can see all the values of that parameter and make the calculations for the amounts to compare.

Let me know what you find.

Regards.

Chris Machnicki’s picture

I haven't done the testing recommended just yet but have taken account of the possibility that shipping may be the issue. I use the flat rate module for shipping so that I can calculate shipping by weight and do not have tax enabled.
I will detail below what tests I have completed -

1. Flat rate module disabled and checked out with a £2 product successfully to Paypal EC
2. Flat rate module disabled and checked out with a £15 product successfully to Paypal EC

3. Flat rate module enabled and a basic £0 shipping method successfully checked out with a £2 product
4. Flat rate module enabled and a basic £0 shipping method successfully checked out with a £15 product

5. Flat rate module enabled and a basic £2 shipping method successfully checked out with a £2 product
6. Flat rate module enabled and a basic £2 shipping method successfully checked out with a £15 product

7. Flat rate module enabled and a basic £0 shipping method successfully checked out with 2x £2 products
8. Flat rate module enabled and a basic £0 shipping method successfully checked out with 2x £15 products

9. Flat rate module enabled and a basic £2 shipping method successfully checked out with 2x £2 products
10. Flat rate module enabled and a basic £2 shipping method successfully checked out with 2x £15 products

11. Flat rate module disabled and with 1x £2 & 1x £2.25 product failed to checkout
12. Flat rate module disabled and with 1x £15 & 1x £16 product successfully checked out

13. Flat rate module enabled and a basic £0 shipping method failed checkout with 1x £2 & 1x £2.25 product
14. Flat rate module enabled and a basic £0 shipping method successfully checked out with 1x £15 & 1x £16 product

15. Flat rate module enabled and a basic £2 shipping method failed checkout with 1x £2 & 1x £2.25 product
16. Flat rate module enabled and a basic £2 shipping method successfully checked out with 1x £15 & 1x £16 product

There is nothing conclusive here other than that it fails with or without shipping enabled and all three fails were with a £2 & £2.25 product in the basket. I can rule out the £2 product being the problem as this worked above on a single test. If I run a single product free delivery test on the £2.25 product it fails which now leads me to believe the problem lies with items that are decimal values rather than whole numbers, I ran another test on £2.30 which also failed.
I doubt this is related but may be easier to fix whilst looking at this rather than afterwards. I have included an image which shows what is being passed to paypal this is what prompted the above tests. As you can see it is duplicating the item name in place of the shipping name.
I read somewhere about Round requiring a precision which I couldn't see? Not sure if this is the problem that it rounding to 0 decimal places.
If I can help in anyway let me know.
Thanks

Chris Machnicki’s picture

FileSize
8.01 KB

I've made a few changes to the module file attached adding 2 decimal places to the $amount, $currency_code
This now checks out if the total price is a decimal but I haven't tested intensively. It still presents the product name instead of the shipping name and I have no ideas where to start with that.

Chris Machnicki’s picture

Testing went well until I processed the payment on Paypals EC page just after selecting the continue as a guest option. I got the following errors. I'm going to see what I can do from this end but if these are to be looked at would you prefer them in there own issues thread?

Notice: Undefined index: payer_id in commerce_paypal_ec_redirect_form_submit() (line 395 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce_paypal_ec/commerce_paypal_ec.module).
Notice: Undefined index: PAYMENTINFO_0_RECEIPTID in commerce_paypal_ec_response_to_ipn() (line 456 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce_paypal_ec/commerce_paypal_ec.module).
Notice: Undefined index: PAYMENTINFO_0_TRANSACTIONID in commerce_paypal_ec_response_to_ipn() (line 457 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce_paypal_ec/commerce_paypal_ec.module).
Notice: Undefined index: PAYMENTINFO_0_TRANSACTIONTYPE in commerce_paypal_ec_response_to_ipn() (line 458 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce_paypal_ec/commerce_paypal_ec.module).
Notice: Undefined index: transaction_id in commerce_paypal_ec_response_to_ipn() (line 461 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce_paypal_ec/commerce_paypal_ec.module).
Notice: Undefined index: PAYMENTINFO_0_AMT in commerce_paypal_ec_response_to_ipn() (line 462 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce_paypal_ec/commerce_paypal_ec.module).
Notice: Undefined index: PAYMENTINFO_0_CURRENCYCODE in commerce_paypal_ec_response_to_ipn() (line 463 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce_paypal_ec/commerce_paypal_ec.module).
Notice: Undefined index: PAYMENTINFO_0_PAYMENTSTATUS in commerce_paypal_ec_response_to_ipn() (line 465 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce_paypal_ec/commerce_paypal_ec.module).
Notice: Undefined index: PAYMENTINFO_0_PAYMENTTYPE in commerce_paypal_ec_response_to_ipn() (line 466 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce_paypal_ec/commerce_paypal_ec.module).
Notice: Undefined index: PAYMENTINFO_0_PENDINGREASON in commerce_paypal_ec_response_to_ipn() (line 467 of /homepages/27/d373782473/htdocs/Orion2/sites/all/modules/commerce_paypal_ec/commerce_paypal_ec.module).
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect decimal value: '' for column 'mc_gross' at row 1: INSERT INTO {commerce_paypal_ipn} (txn_id, txn_type, order_id, transaction_id, mc_gross, mc_currency, mc_fee, payment_status, payment_type, created, changed) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10); Array ( [:db_insert_placeholder_0] => [:db_insert_placeholder_1] => [:db_insert_placeholder_2] => 31 [:db_insert_placeholder_3] => 0 [:db_insert_placeholder_4] => [:db_insert_placeholder_5] => [:db_insert_placeholder_6] => 0 [:db_insert_placeholder_7] => [:db_insert_placeholder_8] => [:db_insert_placeholder_9] => 1338314264 [:db_insert_placeholder_10] => 1338314264 ) in drupal_write_record() (line 6975 of /homepages/27/d373782473/htdocs/Orion2/includes/common.inc).

citlacom’s picture

Hello Chris,

After do some testing for an orders with totals with decimals I found that the round function over totals give us this problem. I removed the roundings so we could have the totals calculated with the correct decimal positions and it works for me. Please download the last dev version and test it. Look the commit with the changes: http://drupalcode.org/project/commerce_paypal_ec.git/commit/075b65a

About the shipping name this is a problem because I think I don't have yet integrated this description into the module. Can you export your shipping and taxes rules from your environment in a feature or in php code so I can replicate that to try doing the integration? I'm not sure why there is a duplication of product description.

Related with the last issue report with purchases with anonymous users I did some testing in my dev environment and I could finish correctly a anonymous purchase. I couldn't reproduce the error you report. The error you copied looks a problem in the function function commerce_paypal_ec_redirect_form_submit($order, $payment_method) {

Try to debug a bit after the line: $do_response = commerce_paypal_ec_api_call("DoExpressCheckoutPayment", $request_params, $settings);

Looks like the response from the API is returning empty, tomorrow I will implement some conditions that check the response before process the ipn_save so we could add missing responses in to dblog and avoid fatal errors but is something that you need to help me to figure what is happening in your environment that I cannot reproduce.

Regards.

Chris Machnicki’s picture

FileSize
14.85 KB

I'm still going with the testing and am currently doing a print_r on the various stages to try and track the problem down. I started to read the paypal dev guide and have tried a few steps but are there any tools you would recommend to narrow the problem? I am now scratching my head trying to find new ways.

This is the guide for setting up shipping by weight -
Install Commerce Physical (attached one is pre-patched with a Total Weight), Commerce Shipping, Physical Fields & Flat Rate
Go to Home » Administration » Store » Configuration » Shipping » Shipping Services

Click - Add a flat rate service

Create a unique title that describes the shipping service i.e. "1st Class Royal Mail 0>100"
Add the Display Title i.e. "1st Class Royal Mail" **Needs to match the other shipping methods of the same kind

Add the base rate price for this method
Save

Click configure Component
Add Condition
Commerce Physical - Orders Total Weight is under a chosen limit
Choose 'commerce-order' for the data selector
Enter the max weight that would apply
Save

To add a charge which only applies above a weight
Add a Shipping service as above

Click configure Component
Add Condition
Commerce Physical - Orders Total Weight is under a chosen limit
Choose 'commerce-order' for the data selector
Enter the max weight that would apply
Save
Click 'Add and'
Check negate to reverse the rule i.e. weight above
Add a condition to the NOT AND
Choose
Commerce Physical - Orders Total Weight is under a chosen limit
Choose 'commerce-order' for the data selector
Enter the Min weight that would apply
Save

citlacom’s picture

Hello Chris,

Today I configured commerce_shipping and commerce_flat_rate it was a bit complex due some incompatibility problem that caused me lost time. Problem was that the beta version of commerce_shipping doesn't work well with flat rate and I needed to update to commerce_shipping-7.x-2.x-dev. Now I have this setup and will start digging a bit tomorrow into the PayPal integration.

FYI we need to integrate this parameters in the SetExpressCheckout call:

  • L_SHIPPINGOPTIONNAMEn - (Required) Is the internal/system name of a shipping option, such as Air, Ground, or Expedited. These parameters must be ordered sequentially beginning with 0 (for example, L_SHIPPINGOPTIONNAME0, L_SHIPPINGOPTIONNAME1).
  • L_SHIPPINGOPTIONLABELn - (Required) The label for the shipping option as displayed to the buyer. Examples: Air: Next Day, Expedited: 3-5 days, Ground: 5-7 days. These labels can be localized based on the buyer’s locale, which is a part of the callback request. These parameters must be ordered sequentially beginning with 0 (for example, L_SHIPPINGALABEL0, L_SHIPPINGLABEL1).
  • L_SHIPPINGOPTIONAMOUNTn- (Required) Is the amount for this shipping option. These parameters must be ordered sequentially beginning with 0 (for example, L_SHIPPINGAMOUNT0, L_SHIPPINGAMOUNT1).
  • L_SHIPPINGOPTIONISDEFAULT - (Required) The option that is selected by default for the buyer and is also reflected in the “default” total.
Chris Machnicki’s picture

Hi,
I'm going to be on and off for the next couple of weeks due to my shifts and working noons. I need to get a test environment up and running at some point as I fear I will have to go live with my shop using WPP until we have ironed out EC. The current template I am using is quite demanding and my old test environment with WAMP wasn't configured the way the template required. I shall try and answer any questions and do work where I can but just a heads up that I'm not being ignorant if I don't reply straight away.

Thanks

Chris

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

BrianLP’s picture

Status: Closed (fixed) » Active

I get the same errors. None of the above has worked for me.

Notice: Undefined index: PAYMENTINFO_0_RECEIPTID in commerce_paypal_ec_response_to_ipn() ...

Is there any progress on this?

EDIT:
After using the dev version of the module, the errors reduced to only one. It appears on the page after redirected back from paypal.

Notice: Undefined variable: transactions in commerce_paypal_ec_paypal_ipn_process() (Line 664 of .../sites/all/modules/commerce_paypal_ec/commerce_paypal_ec.module).

bporter2387’s picture

papalapapp, I got the same error. I've done *some* scripting and programming, so I'm by no means an expert. I looked at the module and it appears that the $transactions variable is inside the scope of the 'if' statement in line 660

line 660:
if (in_array($ipn['payment_status'], array('Voided', 'Completed')) && !empty($ipn['auth_id'])) {
    $transactions = commerce_payment_transaction_load_multiple(array(), array('remote_id' => $ipn['auth_id']));
  }

So when the next 'if' statement is called, the $transactions variable doesn't exist anymore since it's not outside the 'if' statement prior to the creation of it above.

line 664 (where the error is)
if ($transactions) {  
    // get the transaction to update
    $transaction = reset($transactions);
  }

So what I did was I added a '$transactions = NULL;' and then added the isset function to the 2nd if statement like so

$transactions = NULL;   // <--line 660
  if (in_array($ipn['payment_status'], array('Voided', 'Completed')) && !empty($ipn['auth_id'])) {
    $transactions = commerce_payment_transaction_load_multiple(array(), array('remote_id' => $ipn['auth_id']));
  }

  if (isset($transactions)) {  // <-- was line 664, now line 665
    // get the transaction to update
    $transaction = reset($transactions);
  }

I didn't get any errors with this. It might not be the correct way, but I'm just trying to help any way I can.

Brett

citlacom’s picture

Status: Active » Closed (fixed)

We don't go to integrate the parameters:

  • L_SHIPPINGOPTIONNAMEn - (Required) Is the internal/system name of a shipping option, such as Air, Ground, or Expedited. These parameters must be ordered sequentially beginning with 0 (for example, L_SHIPPINGOPTIONNAME0, L_SHIPPINGOPTIONNAME1).
  • L_SHIPPINGOPTIONLABELn - (Required) The label for the shipping option as displayed to the buyer. Examples: Air: Next Day, Expedited: 3-5 days, Ground: 5-7 days. These labels can be localized based on the buyer’s locale, which is a part of the callback request. These parameters must be ordered sequentially beginning with 0 (for example, L_SHIPPINGALABEL0, L_SHIPPINGLABEL1).
  • L_SHIPPINGOPTIONAMOUNTn- (Required) Is the amount for this shipping option. These parameters must be ordered sequentially beginning with 0 (for example, L_SHIPPINGAMOUNT0, L_SHIPPINGAMOUNT1).
  • L_SHIPPINGOPTIONISDEFAULT - (Required) The option that is selected by default for the buyer and is also reflected in the “default” total.

This allow to summarize the shipping details for every item in the order but normally in Drupal Commerce you select a global shipping option so is not really valuable to display in detail when simply we could show the total amount of shipping for all the order as is currently implemented with PAYMENTREQUEST_0_SHIPPINGAMT. For this reasons don't merit the effort because the most common use of shipping at Drupal Commerce will be flat rate based on number of items or in the total weight of the items.

Closing this ticket because all the other issues are resolved.