Skip to content

Products

Joey de Haas edited this page Sep 21, 2022 · 18 revisions

Introduction

For how to handle the exceptions correctly, see Exceptions.

Show

To load more information see Extra Information.

$client = new Client(self::KEY, self::URL);
$service = new ProductService($client);
$product = (new Product())
    ->setCreatedAt(new DateTimeImmutable())
    ->setDeletedAt(new DateTimeImmutable())
    ->setDescription('natoque penatibus et magnis dis parturient montes')
    ->setPhysical(true)
    ->setLedger(8001)
    ->setPricing((new Pricing)
        ->setTaxIncluded(true)
        ->setShipping((new Shipping)
            ->setAmount(100.00)
        )
        ->setTax((new PricingTax)
            ->setRate((new TaxRate)
                ->setId(1)
                ->setPercentage(21)
            )
            ->setProfile((new TaxProfile)
                ->setRates([12, 21, 36])
            )
        )
    )
    ->setPublicTitle('Penatibus')
    ->setSku('70291520')
    ->setSlug('natoque-penatibus')
    ->setStock((new Stock())
        ->setEnabled(true)
        ->setHidden(false)
        ->setValue(10)
    )
    ->setTitle('Lorem Ipsum')
    ->setType(ProductType::ONE_OFF)
    ->setUpdatedAt(new DateTimeImmutable());

$product = $service->create($product);
$productId = $product->id();

Index

To load more information see Extra Information.

use \PlugAndPay\Sdk\Enum\ProductIncludes;
use \PlugAndPay\Sdk\Service\Client;
use \PlugAndPay\Sdk\Service\ProductService;

$client  = new Client($token);
$service = new ProductService($client);

$products = $service->include(ProductIncludes::PRICING, ProductIncludes::SHIPPING)->get();

Filter

use \PlugAndPay\Sdk\Service\Client;
use \PlugAndPay\Sdk\Service\ProductService;
use \PlugAndPay\Sdk\Filters\ProductFilter;

$client  = new Client($token);
$service = new ProductService($client);

$products = $service->get(function(ProductFilter $filter) {
    $filter
      ->direction(\PlugAndPay\Sdk\Enum\Direction::ASC)
      ->hasLimitedStock(1)
      ->isDeleted(1)
      ->limit(10)
      ->page(1)
      ->q('Lorem')
      ->sort(\PlugAndPay\Sdk\Enum\ProductSortType::ACTIVE_SUBSCRIPTIONS)
      ->tag(['blauw', 'boek'])
      ->type(\PlugAndPay\Sdk\Enum\ProductSortType::SUBSCRIPTION);
});

Create Product

When creating an product, to load more information see Extra Information.

use \PlugAndPay\Sdk\Entity\Product;
use \PlugAndPay\Sdk\Service\Client;
use \PlugAndPay\Sdk\Service\ProductService;

$product = (new Product())
    ->setDescription('natoque penatibus et magnis dis parturient montes')
    ->setPhysical(true)
    ->setLedger(8001)
    ->setPublicTitle('Penatibus')
    ->setSku('70291520')
    ->setSlug('natoque-penatibus')
    ->setStock((new Stock())
        ->setEnabled(true)
        ->setHidden(false)
        ->setValue(10)
    )
    ->setTitle('Lorem Ipsum')
    ->setType(ProductType::ONE_OFF)
    ->setPricing((new Pricing())
        ->setShipping((new Shipping())
            ->setAmount(10.50)
        )
        ->setTax((new PricingTax())
            ->setRate((new TaxRate())
                ->setId(1)
            )
        )
    );

$product = $service->create($product);
$productId = $product->id();

Destroy product

use \PlugAndPay\Sdk\Service\Client;
use \PlugAndPay\Sdk\Service\ProductService;

$client  = new Client($token);
$service = new ProductService($client);

$productId = 12;

$service->delete($productId);

Extra Information

By using the include method you can get more information. It is important that you only request the information you need.

use \PlugAndPay\Sdk\Enum\ProductIncludes;
use \PlugAndPay\Sdk\Service\Client;
use \PlugAndPay\Sdk\Service\ProductService;

$client  = new Client($token);
$service = new ProductService($client);

$service
    ->include(
        ProductIncludes::PRICING,
        ProductIncludes::SHIPPING,
    )
    ->find(1);
Clone this wiki locally