PHP-Xero icon indicating copy to clipboard operation
PHP-Xero copied to clipboard

Problem with $xero->Payments

Open swordfox opened this issue 14 years ago • 6 comments

All methods seem to work fine except $xero->Payments

The screen just goes blank after calling the following method with print_r. I've PHP error values set to show all & it's still blank.

$payment_result = $xero->Payments( $new_payment ); print_r($payment_result);

Any ideas?

swordfox avatar Jan 06 '11 00:01 swordfox

Hi I've just starting using this and I get a Segmentation fault (i'm test using the command line) when adding a new payment but both adding a new Contact and Invoice and listing my Accounts all work fine. I've also emailed xero to see if its anything at there end Note the xero status for these are 400 but i can't see anything wrong. It crash's here $xero_response = curl_exec($ch) (line 309 approx) I've also copy my code to my laptop which is a ubuntu 10.10 php 5.3.3 and it crash's on there as well.

Nick

nickteagle avatar Jan 07 '11 13:01 nickteagle

I seem to be having the same issue, what I have noticed is that on my development machine which runs windows 7 it works fine, but on our production machine which runs Debian it is having issues when it reaches that line $xero_response = curl_exec($ch).

relaxomatic avatar Jan 13 '11 22:01 relaxomatic

I've got mine to work by using fsocket for the put message if you email me I can send you my xero.php. nickteagle (at) gmail.com. I'm also tried installing the latest version of php and curl and I still have the error so i'm going to raise a bug on curl and see if that helps. Nick

nickteagle avatar Jan 14 '11 08:01 nickteagle

I've commited Nick's fix for this here: https://github.com/dmytton/PHP-Xero/commit/054c45906aa1d9d0b70d49ed133081464810436a

davidmytton avatar Feb 14 '11 15:02 davidmytton

What's happening is that the memory-mapped file is closed before curl has a chance to read it - it's a problem with the xero library, not curl. Here's a patch:

diff --git a/xero.php b/xero.php
index 3afa43d..1215780 100644
--- a/xero.php
+++ b/xero.php
@@ -303,10 +303,13 @@ class Xero {
                                curl_setopt($ch, CURLOPT_INFILE, $fh);
                                curl_setopt($ch, CURLOPT_INFILESIZE, strlen($xml));
                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-                               fclose($fh);
                        }
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                        $xero_response = curl_exec($ch);
+                       if (isset($fh))
+                       {
+                               fclose($fh);
+                       }
                        $xero_xml = simplexml_load_string( $xero_response );
                        if (!$xero_xml) {
                                return $xero_response;

I've opened a new pull request (#13) with this change as well.

eugeneius avatar Oct 21 '11 10:10 eugeneius

Thanks for posting this fix. Much obliged.

calvinfroedge avatar Jun 16 '12 17:06 calvinfroedge