-
Notifications
You must be signed in to change notification settings - Fork 3
refactor: enhance type safety and improve request flexibility #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 12 commits
a82ea2b
a6743f2
77d607d
b7faafb
178d416
5c3ffe5
bf53a3e
cc8f2ad
d93151b
98df9ba
806ec90
47f6a47
634efef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Devscast\Flexpay\Data; | ||
|
|
||
| enum Type: int | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,44 +9,62 @@ | |
| use Webmozart\Assert\Assert; | ||
|
|
||
| /** | ||
| * Class Request. | ||
| * | ||
| * @author bernard-ng <bernard@devscast.tech> | ||
| * Class Request | ||
| * * Classe de base abstraite pour toutes les requêtes de l'API Flexpay. | ||
| * Elle centralise les informations communes à chaque transaction. | ||
| * * @author bernard-ng <bernard@devscast.tech> | ||
| */ | ||
| abstract class Request | ||
| { | ||
| /** | ||
| * ID du marchand fourni par Flexpay | ||
| */ | ||
| public ?string $merchant = null; | ||
|
|
||
| /** | ||
| * Jeton d'autorisation (Token) | ||
| */ | ||
| public ?string $authorization = null; | ||
|
|
||
| /** | ||
| * Constructeur de base. | ||
| * * @param float $amount Montant de la transaction (doit être > 0) | ||
| * @param string $reference Référence unique de la transaction | ||
| * @param Currency $currency Devise (CDF ou USD) | ||
| * @param string $callbackUrl URL de notification (Webhook) | ||
| * @param string $description Description optionnelle | ||
| * @param string $approveUrl URL de retour après succès | ||
| * @param string $cancelUrl URL de retour après annulation | ||
| * @param string $declineUrl URL de retour après échec | ||
| */ | ||
| public function __construct( | ||
| public readonly float $amount, | ||
| public readonly string $reference, | ||
| public readonly Currency $currency, | ||
| public readonly string $callbackUrl, | ||
| public readonly ?string $approveUrl = null, | ||
| public readonly ?string $description = null, | ||
| public readonly ?string $cancelUrl = null, | ||
| public readonly ?string $declineUrl = null, | ||
| public readonly string $description = '', | ||
| public readonly string $approveUrl = '', | ||
| public readonly string $cancelUrl = '', | ||
| public readonly string $declineUrl = '', | ||
|
Comment on lines
+45
to
+48
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be a breaking change. Why should we accept empty strings where |
||
| ) { | ||
| // Validations de base communes à tous les flux | ||
| Assert::greaterThan($this->amount, 0, 'The transaction amount should be greater than 0'); | ||
| Assert::notEmpty($this->reference, 'The transaction reference is mandatory'); | ||
| Assert::oneOf($this->currency, Currency::cases(), 'Unsupported currency'); | ||
| Assert::notEmpty($this->callbackUrl, 'The callback (webhook) url must be provided'); | ||
| } | ||
|
|
||
| /** | ||
| * @internal | ||
| * | ||
| * Cette méthode est utilisée pour définir les informations d'authentification. | ||
| * Elle est définie ici pour éviter de passer par le constructeur | ||
| * et rajouter de la complexité pour le développeur final | ||
| * Définit les informations d'authentification de manière centralisée. | ||
| * * @internal Cette méthode est utilisée par le Provider pour injecter les credentials. | ||
| */ | ||
| public function setCredential(Credential $credential): void | ||
| { | ||
| $this->merchant = $credential->merchant; | ||
| $this->authorization = $credential->token; | ||
| } | ||
|
|
||
| /** | ||
| * Chaque type de requête doit implémenter sa propre logique de génération de payload. | ||
| */ | ||
| abstract public function getPayload(): array; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another breaking change here. Last time I checked the Flexpay API, those URLs were mandatory and they still are.
If the user does not have corresponding handlers in their app, they should provide the app’s default URL on the calling side.