mivita/app/Services/Payment/Payone/PayoneRequestBuilder.php
Kevin ccc6f85809 Payment Phase R: PAYONE-Integration entflechten (R1–R7 + Review)
Strangler-Refactoring der PAYONE-Zahlungslogik in eine testbare
Service-Schicht, ohne Verhalten in Checkout/Cron/IPN zu ändern.

Neue Services (app/Services/Payment/Payone):
- PayonePaymentService (+ PayonePaymentResult-DTO) für CC-/SEPA-Check
  und Abo-Abbuchung
- PayoneRequestBuilder, PaymentMethodResolver, PayoneMethodConfig
- PayoneTransactionRecorder: zentrale PaymentTransaction-Erstellung
  (API-Response, Invoice, Webhook) inkl. PCI-Redaction (cardpan/cardcvc2)
- PayoneWebhookHandler (+ PayoneWebhookResult): IPN/TSOK-Logik aus
  Api\PayoneController; response('TSOK') statt echo/exit
- PayoneTransportException + Handler-Mapping (403) statt abort() im Service

Hotfixes (R1): var_dump/exit & bare exit() entfernt, Log-Redaction.

Security (R-Review):
- PAYONE_KEY_HASH (MD5-Hash, kein Klartext) mit Boot-Hard-Fail; schließt
  zugleich die ''-Webhook-Bypass-Lücke. Artisan-Command payone:hash-key
  (verdeckte Eingabe, optional --write) zur Hash-Erzeugung.
- Webhook: txaction Pflichtfeld, mode-Fallback auf payment->mode.

Pay\PayoneController ist @deprecated-Fassade (614 → 328 Zeilen),
delegiert an Services via Container-Singleton.

Migration: fehlende Spalte shopping_payments.carddata nachgezogen.

Tests: 47 grün (PayonePaymentService, Recorder, Webhook, Resolver,
TransportException, hash-key). End-to-End im Test-System verifiziert
(siehe dev/2026-06-09-payments).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 13:42:45 +00:00

81 lines
2.9 KiB
PHP

<?php
namespace App\Services\Payment\Payone;
use App\Models\ShoppingUser;
class PayoneRequestBuilder
{
/**
* Builds the personal/billing data block for a PAYONE request.
*
* @return array<string, mixed>
*/
public static function buildPersonalData(ShoppingUser $shoppingUser): array
{
return [
'firstname' => $shoppingUser->billing_firstname,
'lastname' => $shoppingUser->billing_lastname,
'street' => $shoppingUser->billing_address,
'zip' => $shoppingUser->billing_zipcode,
'city' => $shoppingUser->billing_city,
'country' => $shoppingUser->billing_country?->code ?? 'DE',
'email' => $shoppingUser->billing_email,
'language' => 'DE',
];
}
/**
* Builds the shipping/delivery data block for a PAYONE request.
* When same_as_billing is true, billing address is used for shipping.
*
* @return array<string, mixed>
*/
public static function buildDeliveryData(ShoppingUser $shoppingUser): array
{
if ($shoppingUser->same_as_billing) {
return [
'shipping_firstname' => $shoppingUser->billing_firstname,
'shipping_lastname' => $shoppingUser->billing_lastname,
'shipping_zip' => $shoppingUser->billing_zipcode,
'shipping_city' => $shoppingUser->billing_city,
'shipping_country' => $shoppingUser->billing_country?->code ?? 'DE',
'shipping_street' => $shoppingUser->billing_address,
];
}
return [
'shipping_firstname' => $shoppingUser->shipping_firstname,
'shipping_lastname' => $shoppingUser->shipping_lastname,
'shipping_zip' => $shoppingUser->shipping_zipcode,
'shipping_city' => $shoppingUser->shipping_city,
'shipping_country' => $shoppingUser->shipping_country?->code ?? 'DE',
'shipping_street' => $shoppingUser->shipping_address,
];
}
/**
* Merges all PAYONE request segments into one flat array, in the correct
* precedence order (later segments override earlier ones on key collision).
*
* @param array<string, mixed> $defaults
* @param array<string, mixed> $personalData
* @param array<string, mixed> $deliveryData
* @param array<string, mixed> $methodParams
* @param array<string, mixed> $prepayment
* @param array<string, mixed> $aboInitPayment
* @param array<string, mixed> $urls
* @return array<string, mixed>
*/
public static function buildRequest(
array $defaults,
array $personalData,
array $deliveryData,
array $methodParams,
array $prepayment,
array $aboInitPayment = [],
array $urls = [],
): array {
return array_merge($defaults, $personalData, $deliveryData, $methodParams, $prepayment, $aboInitPayment, $urls);
}
}