Skip to content

Quickstart

Reindert edited this page Oct 14, 2022 · 7 revisions

Introduction

Creating a token

We need a token to be able to connect to the Plug&Pay dashboard. To create a token navigate to the admin dashboard of Plug&Pay.

  1. Click on "Settings" in the sidebar
  2. Click on "Developers" In the tab "Integrations"
  3. Sign the "Developer Agreement"
  4. Click on "Add new API key"
  5. Enter a name for your API key

Plug&Pay Dashboard Connection

For more information about the client go to: Home.

use PlugAndPay\Sdk\Service\Client;

$client = new Client('your_access_token');

Products

Get all products

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

$client = new Client('your_access_token');
$productService = new ProductService($client);

$products = $productService->get();

Get one product

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

$client         = new Client('your_access_token');
$productService = new ProductService($client);

$productId = 1;
$product   = $productService->find($productId);

Store product

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

$client         = new Client('your_access_token');
$productService = new ProductService($client);

$product = (new Product())
    ->setTitle('Product Title')
    ->setPhysical(false);

$product = $productService->create($product);

$productId = $product->id();

Update product

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

$client         = new Client('your_access_token');
$productService = new ProductService($client);

$productId = 1;
$productService->update(
    $productId,
    fn(Product $product) => $product->setTitle('Updated Product Title')
);

Delete product

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

$client         = new Client('your_access_token');
$productService = new ProductService($client);

$productId = 1;
$productService->delete($productId);

Orders

Get all orders

use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;

$client       = new Client('your_access_token');
$orderService = new OrderService($client);

$orders = $orderService->get();

Get one order

use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;

$client       = new Client('your_access_token');
$orderService = new OrderService($client);

$orderId = 1;
$orders  = $orderService->find($orderId);

Store order

use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;
use PlugAndPay\Sdk\Service\TaxRateService;
use PlugAndPay\Sdk\Entity\Order;
use PlugAndPay\Sdk\Entity\OrderBilling;
use PlugAndPay\Sdk\Entity\Contact;
use PlugAndPay\Sdk\Entity\Address;
use PlugAndPay\Sdk\Entity\Payment;
use PlugAndPay\Sdk\Entity\Item;
use PlugAndPay\Sdk\Enum\CountryCode;
use PlugAndPay\Sdk\Enum\PaymentType;
use PlugAndPay\Sdk\Filters\TaxRateFilter;

$client       = new Client('your_access_token');
$orderService = new OrderService($client);
$taxService   = new TaxRateService($client);

$taxFilter = (new TaxRateFilter())->country(CountryCode::NL);
$taxRates = $taxService->get($taxFilter);

$item = (new Item)
    ->setAmount(10.50)
    ->setLabel('Label')
    ->setTaxByRateId($taxRates[0]->id());

$payment = (new Payment)
    ->setType(PaymentType::MANUAL);

$address = (new Address())
    ->setCountry(CountryCode::NL);

$contact = (new Contact())
    ->setFirstName('First')
    ->setLastName('Last')
    ->setEmail('[email protected]');

$billing = (new OrderBilling())
    ->setContact($contact)
    ->setAddress($address);

$order = (new Order())
    ->setBilling($billing)
    ->setPayment($payment)
    ->setItems([$item]);

$order   = $orderService->create($order);
$orderId = $order->id();

Update order

use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;
use PlugAndPay\Sdk\Entity\Order;

$client       = new Client('your_access_token');
$orderService = new OrderService($client);

$orderId = 1;
$orderService->update(
    $orderId,
    fn(Order $order) => $order->setAmount(100)
);

Delete order

use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;

$client       = new Client('your_access_token');
$orderService = new OrderService($client);

$orderId = 1;
$orderService->delete($orderId);

Subscriptions

Get all subscriptions

use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\SubscriptionService;

$client              = new Client('your_access_token');
$subscriptionService = new SubscriptionService($client);

$subscriptions = $subscriptionService->get();

Get one subscription

use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\SubscriptionService;

$client              = new Client('your_access_token');
$subscriptionService = new SubscriptionService($client);

$subscriptionId = 1;
$subscription   = $subscriptionService->find($subscriptionId);

Store subscription

use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\SubscriptionService;
use PlugAndPay\Sdk\Entity\Subscription;
use PlugAndPay\Sdk\Entity\SubscriptionBilling;
use PlugAndPay\Sdk\Entity\Contact;
use PlugAndPay\Sdk\Entity\Address;
use PlugAndPay\Sdk\Entity\SubscriptionPaymentOptions;
use PlugAndPay\Sdk\Entity\SubscriptionBillingSchedule;
use PlugAndPay\Sdk\Entity\SubscriptionPricing;
use PlugAndPay\Sdk\Entity\Tax;
use PlugAndPay\Sdk\Enum\Interval;
use PlugAndPay\Sdk\Enum\CountryCode;
use PlugAndPay\Sdk\Enum\PaymentType;

$client              = new Client('your_access_token');
$subscriptionService = new SubscriptionService($client);

$tax = (new Tax())
    ->setAmount(10.00);

$pricing = (new SubscriptionPricing())
    ->setQuantity(10)
    ->setTax($tax);

$billingSchedule = (new SubscriptionBillingSchedule())
    ->setInterval(Interval::MONTHLY)
    ->setNextAt(new \DateTimeImmutable());

$paymentOptions = (new SubscriptionPaymentOptions())
    ->setType(PaymentType::MANUAL);

$address = (new Address())
    ->setCountry(CountryCode::NL);

$contact = (new Contact())
    ->setFirstName('Last')
    ->setLastName('Last')
    ->setEmail('[email protected]');

$billing = (new SubscriptionBilling())
    ->setContact($contact)
    ->setAddress($address)
    ->setPaymentOptions($paymentOptions)
    ->setSchedule($billingSchedule);

$subscription = (new Subscription())
    ->setBilling($billing)
    ->setPricing($pricing)
    ->setProductId(7);

$subscription   = $subscriptionService->create($subscription);
$subscriptionId = $subscription->id();

Update subscription

use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\SubscriptionService;
use PlugAndPay\Sdk\Entity\Subscription;
use PlugAndPay\Sdk\Enum\Mode;

$client              = new Client('your_access_token');
$subscriptionService = new SubscriptionService($client);

$subscriptionId = 1;
$subscriptionService->update(
    $subscriptionId,
    fn(Subscription $subscription) => $subscription->setMode(Mode::TEST)
);

Delete subscription

use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\SubscriptionService;
use PlugAndPay\Sdk\Entity\Subscription;

$client              = new Client('your_access_token');
$subscriptionService = new SubscriptionService($client);

$subscriptionId = 1;
$subscriptionService->delete($subscriptionId);