up2date / flow-php-sdk
Requires
- ext-curl: *
- ext-mbstring: *
- ext-openssl: *
README
The Flow PHP library provides convenient access to the Flow API from applications written in the PHP language. It includes a pre-defined set of classes for API resources that initialize themselves dynamically from API responses which makes it compatible with a wide range of versions of the Flow API.
Requirements
PHP 8.0 and later.
Composer
You can install the sdk via Composer. Run the following command:
composer require up2date/flow-php-sdk
To use the bindings, use Composer's autoload:
require_once 'vendor/autoload.php';
Dependencies
The bindings require the following extensions in order to work properly:
If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.
Getting Started
Create a Flow client with configuration:
Flow::setApiKey('10|x1lf89YRu4YVQEP7rHcnWA6YdHlGgl3nj7fAykGL'); Flow::setApiBase('https://flow.up2date.ro/api'); $flow = new \Up2date\FlowPhpSdk\FlowClient();
Customers
Create a customer
try { $customer = $flow->customers->create([ 'email' => 'john.doe@example.com', 'firstName' => 'John', 'lastName' => 'Doe', 'countryCode' => 40, 'phone' => '723534609' ]); echo $customer; } catch (Up2date\FlowPhpSdk\Exception\ApiErrorException $exception) { echo $exception->getMessage(); }
Find a customer by email address
try { $customer = $flow->customers->findOne([ 'email' => 'john.doe@example.com' ]); echo $customer; } catch (Up2date\FlowPhpSdk\Exception\ApiErrorException $exception) { echo $exception->getMessage(); }
Find a customer by phone number
try { $customer = $flow->customers->findOne([ 'phone' => '723512322' ]); echo $customer; } catch (Up2date\FlowPhpSdk\Exception\ApiErrorException $exception) { echo $exception->getMessage(); }
Loyalty
Get the loyalty rules
try { $loyaltyRules = $flow->loyalty->getRules(); echo $loyaltyRules; } catch (Up2date\FlowPhpSdk\Exception\ApiErrorException $exception) { echo $exception->getMessage()."\n"; }
Add loyalty points from amount
try { $loyaltyParams = [ 'total' => 100, // Amount in the default currency 'details' => 'Bonus points' ]; $customer = $customer->addLoyaltyFromAmount($loyaltyParams); } catch (Up2date\FlowPhpSdk\Exception\ApiErrorException $exception) { echo $exception->getMessage()."\n"; }
Remove loyalty points from amount
try { $loyaltyParams = [ 'total' => 100, 'points' => 20, 'details' => 'Spend points' ]; $customer = $customer->removeLoyaltyFromAmount($loyaltyParams); } catch (Up2date\FlowPhpSdk\Exception\ApiErrorException $exception) { echo $exception->getMessage()."\n"; }
Calculate loyalty points from amount
try { $params = [ 'total' => 100 ]; $points = $flow->loyalty->calculate($params); echo $points->data; } catch (Up2date\FlowPhpSdk\Exception\ApiErrorException $exception) { echo $exception->getMessage()."\n"; }