paloma/shop-client

Paloma Shop client library

v3.5.1 2023-11-02 13:25 UTC

README

PHP client library for the Paloma Shop. Facilitates the access to the following APIs (see https://docs.paloma.one/ for details and code examples):

  • Catalog
  • Checkout
  • Customers

Note: This is v3 of the Paloma Shop PHP Client. It is not backwards-compatible with v2 and is intended to be used together with the Paloma Shop Bundle for Symfony.

Usage

// Create Paloma client
$factory = new Paloma\Shop\PalomaClientFactory($options);

$client = $factory->create([
    'base_url' => 'https://demo.paloma.one/api/', 
    'api_key' => 'yourAPIKey',
    'channel' => 'yourChannel',
    'locale' => 'yourLocale',
]);

// Create security service
$security = new MyPalomaSecurity(); // implements \Paloma\Shop\Security\PalomaSecurityInterface

// Create Paloma catalog
$catalog = new \Paloma\Shop\Catalog\Catalog($client, new \Paloma\Shop\Common\PricingContextProvider($security));

// Call API, e.g. fetch catalog categories
$categories = $catalog->getCategories();

// Create Symfony validator
$validator = new Validator(); // implements Symfony\Component\Validator\Validator\ValidatorInterface

// Create Paloma checkout
$checkout = new \Paloma\Shop\Checkout\Checkout($client, $security, $validator);

// Add cart item
$checkout->addCartItem('100-200', 1);

Examples

Hint: Find more examples at https://docs.paloma.one/.

Get product for a category, sorted by price:

$page = $catalog->search(new SearchRequest(...));

Get cart (e.g. to render shopping cart view):

$order = $checkout->getCart();

Add product to cart:

$order = $checkout->addCartItem('12345', 1);

Update cart item quantity:

$checkout->updateCartItem('123' /* order item id */, 2 /* quantity */);

Remove a cart item:

$checkout->removeCartItem('123');

Get cart items count:

// Number of order items
$checkout->getCart()->itemsCount();

// Number of items times quantities
$checkout->getCart()->unitsCount();

Set order addresses:

$billingAddress = new Address(...);
$shippingAddress = new Address(...);
$checkout->setAddresses($billingAddress, $shippingAddress);

Initialize payment:

$payment = $checkout->initializePayment(new PaymentInitParameters(...));

Use $payment->getProviderParams() to create payment URL or to render payment form.

Place the order:

$orderPurchase = $checkout->purchase();
echo 'Purchased order ' . $orderPurchase->getOrderNumber() . '!';