Skip to content
Joey de Haas edited this page Aug 5, 2024 · 1 revision

Introduction

For how to handle the exceptions correctly, see Exceptions.

Index

The RuleService->get() method extracts all Rule models.

use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\RuleService;

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

$rules = $service->get();

Show

The RuleService->find() method extracts one Rule model.

use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\RuleService;

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

$rule = $service->find($id);

Store

The RuleService->create() method creates a new Rule model.

use PlugAndPay\Sdk\Model\Rule;
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\RuleService;

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

$rule = (new Rule())
    ->setActionType('call_webhook')
    ->setActionData(['url' => 'https://example.com/webhook'])
    ->setTriggerType('order_paid')
    ->setConditionData(['product_id' => [1]])
    ->setName('Plug&Pay Example Rule')
    ->setDriver('webhook')

$rule = $service->create($rule);

Update

The RuleService->update() method updates a Rule model.

use PlugAndPay\Sdk\Model\Rule;
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\RuleService;

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

$id = 1;
$rule = $service->find($id);

$rule->setName('New Name');

$rule = $service->update($rule);

Delete

The RuleService->delete() method deletes a Rule model.

use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\RuleService;
  
$client = new Client($token);
$service = new RuleService($client);

$id = 1;
$service->delete($id);
Clone this wiki locally