Products - plug-and-pay/sdk-php Wiki

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;

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

$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();

Update product

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

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

try {
    $service->update(
        productId,
        fn(Product $product) => $product
            ->setStock((new Stock())
                ->setHidden(true)
                ->setEnabled(true)
                ->setValue(100)
            )
    );
} catch (DecodeResponseException $e) {
    // Do your exception handling
}

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);