Search code examples
balanced-payments

Obtaining list of Customers


Is there any way to query balanced and obtain a list of customers via code?

Consider my site has many users, only some of them require a balanced customer id. I could search my own DB and look for customers who have a balanced id assigned. For the purpose of error checking I would like to query balanced and get their list of customers.

I know I can do this manually through the marketplace UI, this is not practical so i need to do it programatically.


Solution

  • Here's an example: https://github.com/balanced/balanced-php/blob/master/tests/Balanced/SuiteTest.php#L259

    $marketplaces = Marketplace::query()->all();

    Balanced's PHP client uses https://github.com/bninja/restful underneath the hood, so every resource has a static query method. Look @ https://github.com/bninja/restful/blob/master/src/RESTful/Query.php#L120 to see that this exposes a all() member method as well.

    So, for any Balanced resource, in PHP, you can query it by saying ${RESOURCE_NAME}::query(). In your case, if you want to get ALL the customers, then you can do:

    Balanced\Customer::query()->all();

    Hope this helps.