use constants for subscriptions

This commit is contained in:
Daniel Seifert 2025-01-03 09:33:08 +01:00
bovenliggende 395d6c3b2e
commit cc3814bbcd
3 gewijzigde bestanden met toevoegingen van 35 en 25 verwijderingen

Bestand weergeven

@ -15,33 +15,34 @@
namespace D3\KlicktippPhpClient\Entities; namespace D3\KlicktippPhpClient\Entities;
use D3\KlicktippPhpClient\Resources\SubscriptionProcess;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
class Subscription extends ArrayCollection class Subscription extends ArrayCollection
{ {
public function getListId(): string public function getListId(): string
{ {
return $this->get('listid') ?? ''; return $this->get(SubscriptionProcess::LISTID) ?? '';
} }
public function getName(): string public function getName(): string
{ {
return $this->get('name') ?? ''; return $this->get(SubscriptionProcess::NAME) ?? '';
} }
public function getPendingUrl(): string public function getPendingUrl(): string
{ {
return $this->get('pendingurl') ?? ''; return $this->get(SubscriptionProcess::PENDINGURL) ?? '';
} }
public function getThankyouUrl(): string public function getThankyouUrl(): string
{ {
return $this->get('thankyouurl') ?? ''; return $this->get(SubscriptionProcess::THANKYOUURL) ?? '';
} }
public function useSingleOptin(): bool public function useSingleOptin(): bool
{ {
return $this->get('usesingleoptin'); return $this->get(SubscriptionProcess::USE_SINGLE_OPTIN);
} }
public function useDoubleOptin(): bool public function useDoubleOptin(): bool
@ -51,11 +52,11 @@ class Subscription extends ArrayCollection
public function resendConfirmationEmail(): bool public function resendConfirmationEmail(): bool
{ {
return $this->get('resendconfirmationemail'); return $this->get(SubscriptionProcess::RESEND_CONFIRMATION_EMAIL);
} }
public function useChangeEmail(): bool public function useChangeEmail(): bool
{ {
return $this->get('usechangeemail'); return $this->get(SubscriptionProcess::USE_CHANGE_EMAIL);
} }
} }

Bestand weergeven

@ -22,6 +22,15 @@ use GuzzleHttp\RequestOptions;
class SubscriptionProcess extends Model class SubscriptionProcess extends Model
{ {
public const LISTID = 'listid';
public const NAME = 'name';
public const PENDINGURL = 'pendingurl';
public const THANKYOUURL = 'thankyouurl';
public const USE_SINGLE_OPTIN = 'usesingleoptin';
public const RESEND_CONFIRMATION_EMAIL = 'resendconfirmationemail';
public const USE_CHANGE_EMAIL = 'usechangeemail';
public const PARAM_EMAIL = 'email';
/** /**
* @throws BaseException * @throws BaseException
*/ */
@ -58,7 +67,7 @@ class SubscriptionProcess extends Model
'list.json', 'list.json',
[ [
RequestOptions::FORM_PARAMS => array_filter([ RequestOptions::FORM_PARAMS => array_filter([
'name' => trim($name ?? ''), self::NAME => trim($name ?? ''),
]), ]),
] ]
); );
@ -77,7 +86,7 @@ class SubscriptionProcess extends Model
'list/'.urlencode(trim($listId)).'.json', 'list/'.urlencode(trim($listId)).'.json',
[ [
RequestOptions::FORM_PARAMS => array_filter([ RequestOptions::FORM_PARAMS => array_filter([
'name' => trim($name ?? ''), self::NAME => trim($name ?? ''),
]), ]),
] ]
) )
@ -95,8 +104,8 @@ class SubscriptionProcess extends Model
'list/redirect.json', 'list/redirect.json',
[ [
RequestOptions::FORM_PARAMS => [ RequestOptions::FORM_PARAMS => [
'listid' => trim($listId), self::LISTID => trim($listId),
'email' => trim($email), self::PARAM_EMAIL => trim($email),
], ],
] ]
) )

Bestand weergeven

@ -93,21 +93,21 @@ class SubscriptionProcessTest extends IntegrationTestCase
public static function getDataProvider(): Generator public static function getDataProvider(): Generator
{ {
yield 'success' => [new Response(200, [], '{ yield 'success' => [new Response(200, [], '{
"listid": "470370", "'.SubscriptionProcess::LISTID.'": "470370",
"name": "name 1", "'.SubscriptionProcess::NAME.'": "name 1",
"pendingurl": "", "'.SubscriptionProcess::PENDINGURL.'": "",
"thankyouurl": "", "'.SubscriptionProcess::THANKYOUURL.'": "",
"usesingleoptin": false, "'.SubscriptionProcess::USE_SINGLE_OPTIN.'": false,
"resendconfirmationemail": false, "'.SubscriptionProcess::RESEND_CONFIRMATION_EMAIL.'": false,
"usechangeemail": false "'.SubscriptionProcess::USE_CHANGE_EMAIL.'": false
}'), new Subscription([ }'), new Subscription([
"listid" => "470370", SubscriptionProcess::LISTID => "470370",
"name" => "name 1", SubscriptionProcess::NAME => "name 1",
"pendingurl" => "", SubscriptionProcess::PENDINGURL => "",
"thankyouurl" => "", SubscriptionProcess::THANKYOUURL => "",
"usesingleoptin" => false, SubscriptionProcess::USE_SINGLE_OPTIN => false,
"resendconfirmationemail" => false, SubscriptionProcess::RESEND_CONFIRMATION_EMAIL => false,
"usechangeemail" => false, SubscriptionProcess::USE_CHANGE_EMAIL => false,
])]; ])];
yield 'unknown id' => [new Response(404, [], '["Kein Opt-In-Prozess mit dieser ID."]'), null, true]; yield 'unknown id' => [new Response(404, [], '["Kein Opt-In-Prozess mit dieser ID."]'), null, true];
yield 'access denied' => [new Response(403, [], '["API Zugriff verweigert"]'), null, true]; yield 'access denied' => [new Response(403, [], '["API Zugriff verweigert"]'), null, true];