The documentation in README.md and example code in /examples looks to be old, wrong, and may just return 400 Bad Request errors from Xero, if it gets as far as making the request. Let's fix that.

  • Fix the Ubercart example
  • Provide an equivalent Commerce example
  • Provide accurate documentation and working code in README.md

Comments

John Pitcairn created an issue. See original summary.

mradcliffe’s picture

StatusFileSize
new7.78 KB

I have a small test module that I keep around locally to test get/post and dump out the results. Could be helpful for expanding the README to make any corrections. Though the post/form is using xero.form_builder (i.e. typed_widget before typed widget which I need to make stable at some point).

The ubercart example was probably written in 2014 and basically from the Drupal 7 example. It's a bit harder to do a Commerce example since it's a bit more complex. Maybe an example about how to structure data coming from commerce and what entities you may need to populate data (commerce_payment, commerce_order, profile)?

johnpitcairn’s picture

I'll be able to supply simple commerce example code that does approximately the same thing as the ubercart code from a commerce_order and profile.

Pascal-’s picture

Priority: Major » Critical

Outdated documentation and examples make this module unusable for me.
I cannot figure out how to get it to run after several hours.

None of the documented or example code works.

The example provided above here does work, but is not enough to continue using the module.
I need at least an example on how to generate new data to post back to xero.

johnpitcairn’s picture

I got pulled off this for a few months, but the project is still on my client's integration radar so I do hope to get back to it.

@Pascal if it's Commerce 2 example code you need message me and I can provide what I have, which from memory was very basic proof of concept code to post contact/invoice data to Xero via a route and controller. Not at all production-ready or security checked so you would need to flesh it out.

mradcliffe’s picture

Hi @Pascal-,

It may help me to understand what type of data you're trying to send to Xero. The basic idea is to create the Typed Data data types, the ones this module provides, from TypedDataManager, and then use XeroQuery to post that data. Could you provide any more details about some of the code you tried and what your expectation was? Thank you.

There two things that help me when I'm trying to figure out if I messed up the data that I posted to Xero:

1. The error from Xero should be in the watchdog details.
2. Using a debugger, I can put a breakpoint at (XeroQuery.php line 506).

I haven't been able to work on Commerce Xero in a few months, but I did have that in a fairly good state for posting invoice or bank transaction data back to Xero. However it is still fairly brittle.

Pascal-’s picture

I was trying to create a new xero_invoice from scratch.

Here's how far I got:

$list_definition = $this->typedDataManager->createListDataDefinition('xero_invoice');
$newInvoice = $this->typedDataManager->create($list_definition, 'xero_invoice');

is returning:

InvalidArgumentException: Cannot set a list with a non-array value.

I then followed this issue: https://www.drupal.org/project/xero/issues/2913401
With led to the next error:

$definition = $this->typedDataManager->createListDataDefinition('xero_invoice');
$newInvoice = $typedDataManager->create($definition, [], 'xero_invoice');

/** @var \Drupal\xero\XeroQuery $query */
    $this->query
      ->setType('xero_invoice')
      ->setData($newInvoice)
      ->setMethod('post');
Argument 1 passed to Drupal\xero\XeroQuery::setData() must implement interface Drupal\Core\TypedData\ListInterface, array given

I no longer have the exact code, but the above should demonstrate my issues.
I also tried several other options, but to no success.

I just have no clue how to start building a typedDataManager object that has all the info the xero_invoice type requires, since I've never worked with typedDataManager before.

A simple working example would be sufficient.

mradcliffe’s picture

I think you're using 8.x-1.1, which, although the stable release, is out-of-date based on Xero changes.

I've been testing and working with 8.x-1.2-alpha6 or greater with success for invoices, @_Pascal. I've been waiting for some feedback on commerce xero and making that stable before I release 1.2 as stable.

$newInvoice = $typedDataManager->create($definition, [], 'xero_invoice');

Small fix here, the "name" parameter is used when creating a child data type on a parent. It's not the plugin ID of the data type.

The following works given a newer release. This is what I am doing in Commerce Xero in #3023730: Implement invoice data type plugin, payment processor plugin.

    $list_definition = $this->typedDataManager->createListDataDefinition('xero_invoice');
    $invoices = $this->typedDataManager->create($list_definition, []);

    $values = [
      'Contact' => [
        'Name' => 'Blah',
        'EmailAddress' => 'blah@example.com',
      ],
      'Type' => 'ACCREC',
      'Date' => date('Y-m-d'),
      'DueDate' => date('Y-m-d', time() + 1296000),
      'LineAmountTypes' => 'NoTax',
      'Status' => 'SUBMITTED',
      'Reference' => 'ORDER-23456',
      'LineItems' => [
        [
          'Description' => 'Some line item',
          'LineAmount' => 10.00,
          'AccountCode' => 400,
        ],
      ],
    ];

    $invoices->appendItem($values);

    $result = $this->query
      ->setType('xero_invoice')
      ->setMethod('post')
      ->setData($invoices)
      ->execute();
Pascal-’s picture

Thanks, will definitely test that later, currently working on something else.
But we will need to implement this in the future.

mradcliffe’s picture

Status: Active » Needs review
StatusFileSize
new28.25 KB

Swaps out the uc_xero_example module for xero_example module dependent on examples module. I wonder if I should require-dev drupal/examples?

I updated the README with a bit more as well, and then fixed some bugs in data types while I was at it. Also, wow, I started the drupal 8 port so long ago that hook_permissions was still in there. No wonder I added my own permission in commerce_xero :-)

  • mradcliffe committed f522fc6 on 8.x-1.x
    Issue #2993692 by mradcliffe: Fixes and moves broken uc_xero_example to...
mradcliffe’s picture

Status: Needs review » Fixed

Reclosing for now.

Status: Fixed » Closed (fixed)

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