PHP POS API

Comments

38 comments

  • Avatar
    Tynan Fox

    It's awesome that you guys are working on this and will be very useful for developing custom integrations, so thanks in advance. The below comments "ideal" workflow is the reflection of my own company. Our business is a small retail store with 1 single location and just 6 staff members (two of which are the company owners). Some might refer to us as a "microbusiness".

    Products are sold both from the retail counter OR online at our shop website. The POS has one database and the website has a separate database. Not sure how companies with a similar setup do it, but for us, we consider the POS to be the "Official, legal company record" and the website database contains only just enough information to be able to display products and keep inventory levels current. Therefore, when clients order products online from us, all information from the customer record and the sales order must be entered into the POS. This is necessary to streamline our book-keeping processes (reports and sales history only need to be run from 1 system) and also minimizes our workload burden when it comes to filing taxes and preparing audit-records for the state/fed. 

    In a perfect world, here's what an ideal workflow would look like for my company:
    1)Customer places order on our website
    2a)My website pings the counter to notify of a pending web-order (we currently use an integration with Slack to accomplish this)
    2b)Simultaneously, the website pushes the order into PHPpos as a suspended sale.

    • This is because there will still be manual work to be done. If it is pushed through as a completed sale, then I would need to give all clerks the "edit completed sale" permission which is a security risk I'd rather not expose us to.
    • The website would also push the attached customer record to PHPpos. If it already exists, then the record would be updated if necessary and attached to the order. If it does not, it would be created as new.
    • The website processes its' payments via its own gateway so integrated payment processing is not necessary. The payment information sent to POS, which I would want to see updated on the suspended sale, include the payment methods (credit card, gift card, multiple others) and amount of payment, and hopefully, to include support for split payments (like $30 sale, paid for by a $25 gift card plus a $5 cc payment, etc. etc.)

    3)When the clerk gets pinged for the order, they check the suspended sale list (which I would probably name "Web Orders" or "Pending Web" or something similar) for new orders and pull it up. The clerk picks the products from the shelves or storage, packs the order, and prints a shipping label. The clerk does all this through our shipping software (right now we use Stamps.com). The clerk would then add the shipping/delivery information to the sales receipt(this is required under law in our jurisdiction - we are required to list the date of shipment, shipping address, and the tracking number from the shipping provider on sales receipts for all delivered sales). Once done, the clerk would "save" the web-sale in POS to take it off the suspended sales list.

    4)The POS would post-back the shipping information to the website - particularly the tracking number. When an order is updated with tracking info on my website, it automatically kicks out an e-mail with that info to the client. Alternatively, I can pull this information from Stamps.com as we do now. 

    5)Since the POS is considered the "master" record of current inventory levels, I would like the website to be updated with the current inventory levels in the POS's database a few times per day. This could be done by the website grabbing the data, or the POS could be the one to push the data it doesn't matter.

    So to accomplish an "ideal" workflow like this, I would want to add to your list:

    1. Add, update, delete, read Sales(or minimally, just add suspended sale, and read completed sales)
    2. Add, update, delete, read Deliveries (or minimally, the delivery information attached to a specific sale)

    Other "wishlist" api features which would be great to have but I could live without:

    1. Add, update, delete, read Gift Cards (this would allow clients to use company Gift Cards either in person OR online)
    2. Add, update, delete, read Rewards Points (no matter where you shop, earn and redeem rewards on every sale)
    3. Add, update, delete, read Price Rules (coupon barcodes/coupon codes could be redeemed whether you shop in-store or online)

    Items on your api list that I probably won't use:

    1. Add,update,delete,read suppliers (this data is not necessary to list inventory and make sales on our website). 
    2. Add,update,delete,read employees (adding employee access to the website administrative interface creates security implications - blindly importing employees and permissions for them is not advisable. Provisioning employee access should be done carefully and intentionally, only granting the minimal permissions necessary to complete job duties. Ideally, website integration is an automated process complete enough that employee access to the website administration is entirely unnecessary)
    3. Read locations (as a small business with only 1 location...it's not needed. I'm sure my compatriots who own multiple business locations might use this though)

     

    I hope this is helpful to you - looking forward to seeing what you come up with.

    1
    Comment actions Permalink
  • Avatar
    Chris Muench

    Thanks for feedback; we will take this into consideration as we develop API

    0
    Comment actions Permalink
  • Avatar
    Chris Muench

    We are making progress with API. You can view the current API layout at:

     

    https://app.swaggerhub.com/apis/PHP-Point-Of-Sale/PHP-Point-Of-Sale/1.0

     

    We will keep trying to meet your uses cases. We still have to do develop the delivery part.

    0
    Comment actions Permalink
  • Avatar
    Chris Muench

    I believe our API will meet all your needs. We are pretty much feature complete

     

    You can view the current API layout at: 

    https://phppointofsalestaging.com/api/

     

    I would really like feedback

    0
    Comment actions Permalink
  • Avatar
    Michael

    Thanks Chris, I'm attempting to call the URL manually from my browser using http://localhost/index.php/api/v1/

    but all I get is a 404 Page not found error. This is a local windows installation of PHPPos 16.1

    Is there something i'm missing?

    0
    Comment actions Permalink
  • Avatar
    Chris Muench

    The url would be

    http://locahost/application/controllers/api/v1/

     

    That url is just going to give you a open api file and not do much on its own. You need to generate keys and make API request with x-api-key header. See

     

    https://phppointofsale.com/api/

     

    0
    Comment actions Permalink
  • Avatar
    Michael

    Ok, I resolved my own dumb question by adding an API call to the end of the URI like /sales/1 etc
    Was just testing RAW access.

    0
    Comment actions Permalink
  • Avatar
    Michael

    Also, just saw your reply, thanks Chris

    0
    Comment actions Permalink
  • Avatar
    Tynan Fox

    Hi Chris,

    Thanks for your hard work on this. I've been out of the office for a couple of weeks and I'm playing catch up - but you can bet I will be reviewing this ASAP! It's very exciting.

    0
    Comment actions Permalink
  • Avatar
    Tynan Fox

    As I'm combing through the API specs, is there any kind of PDF format of the models/examples? 

    0
    Comment actions Permalink
  • Avatar
    Chris Muench

    Each api endpoint has curl requests. We will have client libraries for multiple languages once swagger code gen project has a release thar supports oas 3. Which api request do you want an example of and I can make a php example for you.

    0
    Comment actions Permalink
  • Avatar
    Chris Muench

    Make sure you get latest hotfix at https://phppointofsale.com/downloads.php

     

    Here is an example of getting customers

    <?php
    //////////////////////////////////////////////////////////
    $api_base_url = 'https://demo.phppointofsale.com/index.php/api/v1/';
    $api_key = 'API_KEY';
    ///////////////////////////////////////////////////////////


    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $api_base_url.'customers');
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'x-api-key:'.$api_key,
    'accept: application/json',
    ));
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    $result = json_decode(curl_exec($curl));
    var_dump($result);

    0
    Comment actions Permalink
  • Avatar
    Tynan Fox

    Wonderful. That's a huge help!

    Currently attempting to query the API using a 3rd party module - my site is a PHP site and I use Drupal with Drupal Commerce for our online store. There's a couple of modules out there I'm playing with. I'll let you know what happens

    0
    Comment actions Permalink
  • Avatar
    Tynan Fox

    Okay so I'm setting up some test transactions and I keep getting an error response. I haven't tried from my website yet - I'm still attempting some test transactions via the Swagger UI. 

    In Swagger, it is able to connect to my remotely-installed POS and authorize properly using the API key so I know that connectivity is good. 

    However when trying to push forward a test sale transaction, no matter what I do, this is the response I get:

    Header:

     cache-control: no-store, no-cache, must-revalidate  content-type: application/json; charset=utf-8  expires: Thu, 19 Nov 1981 08:52:00 GMT  pragma: no-cache 

    Body:

    {
      "sale_id": -1,
      "sale_time": "12/31/1969",
      "location_id": null,
      "employee_id": null,
      "register_id": null,
      "mode": "sale",
      "customer_id": null,
      "show_comment_on_receipt": false,
      "selected_tier_id": null,
      "sold_by_employee_id": null,
      "discount_reason": null,
      "excluded_taxes": [],
      "has_delivery": false,
      "delivery": {
        "delivery_person_info": null,
        "delivery_info": null,
        "delivery_tax_group_id": null
      },
      "paid_store_account_ids": [],
      "suspended": null,
      "subtotal": "0.00",
      "tax": "0.00",
      "total": "0.00",
      "profit": "0.00",
      "payments": [],
      "cart_items": []
    }
    0
    Comment actions Permalink
  • Avatar
    Chris Muench

    I also need request body

    You will need to perform debugging steps to figure out the exact error.
    Open up index.php in the phppos root folder:

    FIND:
    define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'production’);

    REPLACE:
    define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : ‘development’);

    open application/config/database.php

    FIND:
    $db['default']['db_debug'] = FALSE;

    REPLACE:
    $db['default']['db_debug'] = TRUE;

    Then see the errors.

    Do NOT forgot to undo these changes afterwords.

    0
    Comment actions Permalink
  • Avatar
    Tynan Fox

    Okay with Debugging Enabled

    Response Code: 200

    Response Header:

    cache-control: no-store, no-cache, must-revalidate  
    content-type: text/html; charset=UTF-8

    expires: Thu, 19 Nov 1981 08:52:00 GMT

    pragma: no-cache

    Response Body:

    Download
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
    
    <h4>A PHP Error was encountered</h4>
    
    <p>Severity: Notice</p>
    <p>Message:  date_default_timezone_set(): Timezone ID '' is invalid</p>
    <p>Filename: v1/Sales.php</p>
    <p>Line Number: 69</p>
    
    
    	<p>Backtrace:</p>
    	
    		
    	
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 69<br />
    			Function: date_default_timezone_set			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 304<br />
    			Function: _sale_id_to_array			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/libraries/REST_Controller.php<br />
    			Line: 793<br />
    			Function: index_post			</p>
    
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/index.php<br />
    			Line: 417<br />
    			Function: require_once			</p>
    
    		
    	
    
    </div>
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
    
    <h4>A PHP Error was encountered</h4>
    
    <p>Severity: Notice</p>
    <p>Message:  Trying to get property of non-object</p>
    <p>Filename: models/Sale.php</p>
    <p>Line Number: 2382</p>
    
    
    	<p>Backtrace:</p>
    	
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/Sale.php<br />
    			Line: 2382<br />
    			Function: _error_handler			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/cart/PHPPOSCartSale.php<br />
    			Line: 260<br />
    			Function: get_customer			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 72<br />
    			Function: get_instance_from_sale_id			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 304<br />
    			Function: _sale_id_to_array			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/libraries/REST_Controller.php<br />
    			Line: 793<br />
    			Function: index_post			</p>
    
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/index.php<br />
    			Line: 417<br />
    			Function: require_once			</p>
    
    		
    	
    
    </div>
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
    
    <h4>A PHP Error was encountered</h4>
    
    <p>Severity: Notice</p>
    <p>Message:  Trying to get property of non-object</p>
    <p>Filename: models/Sale.php</p>
    <p>Line Number: 3035</p>
    
    
    	<p>Backtrace:</p>
    	
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/Sale.php<br />
    			Line: 3035<br />
    			Function: _error_handler			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/cart/PHPPOSCartSale.php<br />
    			Line: 265<br />
    			Function: get_exchange_details			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 72<br />
    			Function: get_instance_from_sale_id			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 304<br />
    			Function: _sale_id_to_array			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/libraries/REST_Controller.php<br />
    			Line: 793<br />
    			Function: index_post			</p>
    
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/index.php<br />
    			Line: 417<br />
    			Function: require_once			</p>
    
    		
    	
    
    </div>
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
    
    <h4>A PHP Error was encountered</h4>
    
    <p>Severity: Notice</p>
    <p>Message:  Trying to get property of non-object</p>
    <p>Filename: models/Sale.php</p>
    <p>Line Number: 3035</p>
    
    
    	<p>Backtrace:</p>
    	
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/Sale.php<br />
    			Line: 3035<br />
    			Function: _error_handler			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/cart/PHPPOSCartSale.php<br />
    			Line: 265<br />
    			Function: get_exchange_details			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 72<br />
    			Function: get_instance_from_sale_id			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 304<br />
    			Function: _sale_id_to_array			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/libraries/REST_Controller.php<br />
    			Line: 793<br />
    			Function: index_post			</p>
    
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/index.php<br />
    			Line: 417<br />
    			Function: require_once			</p>
    
    		
    	
    
    </div>
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
    
    <h4>A PHP Error was encountered</h4>
    
    <p>Severity: Notice</p>
    <p>Message:  Trying to get property of non-object</p>
    <p>Filename: models/Sale.php</p>
    <p>Line Number: 3035</p>
    
    
    	<p>Backtrace:</p>
    	
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/Sale.php<br />
    			Line: 3035<br />
    			Function: _error_handler			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/cart/PHPPOSCartSale.php<br />
    			Line: 265<br />
    			Function: get_exchange_details			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 72<br />
    			Function: get_instance_from_sale_id			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 304<br />
    			Function: _sale_id_to_array			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/libraries/REST_Controller.php<br />
    			Line: 793<br />
    			Function: index_post			</p>
    
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/index.php<br />
    			Line: 417<br />
    			Function: require_once			</p>
    
    		
    	
    
    </div>
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
    
    <h4>A PHP Error was encountered</h4>
    
    <p>Severity: Notice</p>
    <p>Message:  Trying to get property of non-object</p>
    <p>Filename: models/Sale.php</p>
    <p>Line Number: 3035</p>
    
    
    	<p>Backtrace:</p>
    	
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/Sale.php<br />
    			Line: 3035<br />
    			Function: _error_handler			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/cart/PHPPOSCartSale.php<br />
    			Line: 265<br />
    			Function: get_exchange_details			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 72<br />
    			Function: get_instance_from_sale_id			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 304<br />
    			Function: _sale_id_to_array			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/libraries/REST_Controller.php<br />
    			Line: 793<br />
    			Function: index_post			</p>
    
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/index.php<br />
    			Line: 417<br />
    			Function: require_once			</p>
    
    		
    	
    
    </div>
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
    
    <h4>A PHP Error was encountered</h4>
    
    <p>Severity: Notice</p>
    <p>Message:  Trying to get property of non-object</p>
    <p>Filename: models/Sale.php</p>
    <p>Line Number: 3035</p>
    
    
    	<p>Backtrace:</p>
    	
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/Sale.php<br />
    			Line: 3035<br />
    			Function: _error_handler			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/cart/PHPPOSCartSale.php<br />
    			Line: 265<br />
    			Function: get_exchange_details			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 72<br />
    			Function: get_instance_from_sale_id			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 304<br />
    			Function: _sale_id_to_array			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/libraries/REST_Controller.php<br />
    			Line: 793<br />
    			Function: index_post			</p>
    
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/index.php<br />
    			Line: 417<br />
    			Function: require_once			</p>
    
    		
    	
    
    </div>
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
    
    <h4>A PHP Error was encountered</h4>
    
    <p>Severity: Notice</p>
    <p>Message:  Trying to get property of non-object</p>
    <p>Filename: models/Sale.php</p>
    <p>Line Number: 3035</p>
    
    
    	<p>Backtrace:</p>
    	
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/Sale.php<br />
    			Line: 3035<br />
    			Function: _error_handler			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/cart/PHPPOSCartSale.php<br />
    			Line: 265<br />
    			Function: get_exchange_details			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 72<br />
    			Function: get_instance_from_sale_id			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 304<br />
    			Function: _sale_id_to_array			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/libraries/REST_Controller.php<br />
    			Line: 793<br />
    			Function: index_post			</p>
    
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/index.php<br />
    			Line: 417<br />
    			Function: require_once			</p>
    
    		
    	
    
    </div>
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
    
    <h4>A PHP Error was encountered</h4>
    
    <p>Severity: Notice</p>
    <p>Message:  Trying to get property of non-object</p>
    <p>Filename: models/Sale.php</p>
    <p>Line Number: 3035</p>
    
    
    	<p>Backtrace:</p>
    	
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/Sale.php<br />
    			Line: 3035<br />
    			Function: _error_handler			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/cart/PHPPOSCartSale.php<br />
    			Line: 265<br />
    			Function: get_exchange_details			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 72<br />
    			Function: get_instance_from_sale_id			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 304<br />
    			Function: _sale_id_to_array			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/libraries/REST_Controller.php<br />
    			Line: 793<br />
    			Function: index_post			</p>
    
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/index.php<br />
    			Line: 417<br />
    			Function: require_once			</p>
    
    		
    	
    
    </div>
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
    
    <h4>A PHP Error was encountered</h4>
    
    <p>Severity: Notice</p>
    <p>Message:  Trying to get property of non-object</p>
    <p>Filename: models/Sale.php</p>
    <p>Line Number: 2586</p>
    
    
    	<p>Backtrace:</p>
    	
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/Sale.php<br />
    			Line: 2586<br />
    			Function: _error_handler			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/models/cart/PHPPOSCartSale.php<br />
    			Line: 275<br />
    			Function: get_deleted_taxes			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 72<br />
    			Function: get_instance_from_sale_id			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 304<br />
    			Function: _sale_id_to_array			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/libraries/REST_Controller.php<br />
    			Line: 793<br />
    			Function: index_post			</p>
    
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/index.php<br />
    			Line: 417<br />
    			Function: require_once			</p>
    
    		
    	
    
    </div>
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
    
    <h4>A PHP Error was encountered</h4>
    
    <p>Severity: Warning</p>
    <p>Message:  Cannot modify header information - headers already sent by (output started at /home/tynanfox/pos/system/core/Exceptions.php:271)</p>
    <p>Filename: core/Common.php</p>
    <p>Line Number: 564</p>
    
    
    	<p>Backtrace:</p>
    	
    		
    	
    		
    	
    		
    	
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/libraries/REST_Controller.php<br />
    			Line: 871<br />
    			Function: set_status_header			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/controllers/api/v1/Sales.php<br />
    			Line: 305<br />
    			Function: response			</p>
    
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/application/libraries/REST_Controller.php<br />
    			Line: 793<br />
    			Function: index_post			</p>
    
    		
    	
    		
    	
    		
    			<p style="margin-left:10px">
    			File: /home/tynanfox/pos/index.php<br />
    			Line: 417<br />
    			Function: require_once			</p>
    
    		
    	
    
    </div>{"sale_id":-1,"sale_time":"12\/31\/1969","location_id":null,"employee_id":null,"register_id":null,"mode":"sale","customer_id":null,"show_comment_on_receipt":false,"selected_tier_id":null,"sold_by_employee_id":null,"discount_reason":null,"excluded_taxes":[],"has_delivery":false,"delivery":{"delivery_person_info":null,"delivery_info":null,"delivery_tax_group_id":null},"paid_store_account_ids":[],"suspended":null,"subtotal":"0.00","tax":"0.00","total":"0.00","profit":"0.00","payments":[],"cart_items":[]}




    0
    Comment actions Permalink
  • Avatar
    Chris Muench

    I need request body also not just the response. You will also want to put the request body validated 

     

    https://jsonlint.com

     

    0
    Comment actions Permalink
  • Avatar
    Chris Muench

    Here is an example valid sale create request

     

    {
    "mode": "sale",
    "has_delivery": true,
    "delivery": {
    "delivery_person_info": {
    "first_name": "John",
    "last_name": "Doe",
    "email": "john@example.com",
    "phone_number": "555-555-5555",
    "address_1": "123 Nowhere Street",
    "address_2": "Apartment 123",
    "city": "Rochester",
    "state": "New York",
    "zip": "14445",
    "country": "United States",
    "comments": "A great customer"
    },
    "delivery_info": {
    "status": "completed",
    "is_pickup": true,
    "comment": "Needs to be fast",
    "tracking_number": "12345",
    "estimated_shipping_date": "2018-04-12T18:31:41.073Z",
    "estimated_delivery_or_pickup_date": "2018-04-12T18:31:41.073Z",
    "actual_delivery_or_pickup_date": "2018-04-12T18:31:41.073Z",
    "actual_shipping_date": "2018-04-12T18:31:41.073Z",
    "delivery_employee_person_id": 1
    },
    "delivery_tax_group_id": 1
    },
    "cart_items": [
    {
    "quantity": 4,
    "unit_price": 4.25,
    "discount": 10,
    "description": "Great Item",
    "serialnumber": "1234393849384",
    "size": "large",
    "item_id": 1,
    "cost_price": 4.25
    }
    ],
    "location_id": 1,
    "employee_id": 1,
    "register_id": 1,
    "suspended": 0,
    "payments": [
    {
    "payment_type": "Cash",
    "payment_amount": 3,
    "payment_date": "2017-07-21T17:32:28Z"
    }
    ]
    }
    0
    Comment actions Permalink
  • Avatar
    Tynan Fox

    Here is the request body I used. It's validated as valid JSON.

    (And all this data is made up and no sensitive customer data revealed).

    {
      "mode": "sale",
      "customer_id": 3,
      "show_comment_on_receipt": true,
      "selected_tier_id": 1,
      "sold_by_employee_id": 2,
      "discount_reason": "Loyal customer",
      "has_delivery": false,
      "cart_items": [
        {
          "quantity": 4,
          "unit_price": 12.00,
          "discount": 0,
          "description": "Great Item",
          "item_id": 2,
          "cost_price": 5.00
        }
      ],
    "location_id": 1,
    "employee_id": 2,
    "register_id": 1,
    "comment": "comment here",
    "suspended": 5,
    "payments": [
      {
        "payment_type": "Credit Card",
        "payment_amount": 48.00,
        "payment_date": "2018-04-26T12:00:00Z"
      }
    ]
    }

    0
    Comment actions Permalink
  • Avatar
    Chris Muench

    I was able to do this. Can you send your database backup to chris@phppos.com with the exact request so I can debug? It is odd that your location doesn't have a timezone (the first error).

    0
    Comment actions Permalink
  • Avatar
    Tynan Fox

    Shall I assume that skipping/removing elements from the request is not acceptable? I just assumed in generating a request that I can simply omit data that won't be transferred.

    0
    Comment actions Permalink
  • Avatar
    Chris Muench

    You can selected_tier_id of 1. There are no tiers; omit or put null

    0
    Comment actions Permalink
  • Avatar
    Tynan Fox

    YES That did the trick. I removed "selected_tier_id" from the request and it worked. Currently looking at the suspended sale in my POS

    0
    Comment actions Permalink
  • Avatar
    Tynan Fox

    So...I attempted to create a new Sale with some test data all in one single API request and it's not working but I think this is by design. Can you just confirm quick? The errors are all "trying to get property of non-object" so I get a sense that I'm missing some steps. 

    Attempting to create a "complete" sale which includes a customer record and shipping info in 1 request but it would seem to be attempting to locate a nonexistant customer record and create a delivery for a nonexistant sale. So is a proper workflow supposed to look more like

    Request 1) Create customer record
    Request 2) Create sale
    Request 3) Create delivery

    ....or am I missing something?

    0
    Comment actions Permalink
  • Avatar
    Chris Muench

    The process is to create a customer in one request and the sale in delivery in the 2nd request

    0
    Comment actions Permalink
  • Avatar
    Tynan Fox

    Perfect thanks

    0
    Comment actions Permalink
  • Avatar
    Tynan Fox

    Roadblock: The front-facing "Person ID" as listed in the POS customer listing is not the same as the internal "Customer ID" as listed in the customers table of the database. Querying the API by Person ID or using the search function returns all the customer data - EXCEPT the "Customer ID". Creating a new customer returns the Person ID as well. 

    Creating a Sale requires the "Customer ID" - which appears to be entirely inaccessible, unless I've missed something. 

    Just to keep things consistent could the Sale portion of the api be changed to accept the Person ID instead?

    0
    Comment actions Permalink
  • Avatar
    Chris Muench

    It only accepts person_id. It is called customer id in Api as the end user would never actually see customer id anywhere in the interface

    0
    Comment actions Permalink
  • Avatar
    Chris Muench

    anywhere you reference people it always uses person id even though field is called customer_id

    0
    Comment actions Permalink
  • Avatar
    Tynan Fox

    AH yes I was having a different problem sorry

    0
    Comment actions Permalink

Please sign in to leave a comment.