-
Notifications
You must be signed in to change notification settings - Fork 4
Rules
Joey de Haas edited this page Aug 5, 2024
·
1 revision
For how to handle the exceptions correctly, see Exceptions.
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();
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);
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);
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);
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);