Add PayPal support for add-on and gift voucher checkout

This commit is contained in:
Codex Agent
2026-02-04 14:54:40 +01:00
parent 7025418d9e
commit 17025df47b
24 changed files with 1599 additions and 34 deletions

View File

@@ -72,6 +72,61 @@ class PayPalOrderService
return $this->client->post('/v2/checkout/orders', $payload, $headers);
}
/**
* @param array{
* custom_id?: string|null,
* return_url?: string|null,
* cancel_url?: string|null,
* locale?: string|null,
* request_id?: string|null
* } $options
* @return array<string, mixed>
*/
public function createSimpleOrder(
string $referenceId,
string $description,
float $amount,
string $currency,
array $options = [],
): array {
$formattedAmount = $this->formatAmount($amount);
$currency = strtoupper($currency);
$purchaseUnit = array_filter([
'reference_id' => Str::limit($referenceId, 127, ''),
'description' => Str::limit($description, 127, ''),
'custom_id' => $options['custom_id'] ?? null,
'amount' => [
'currency_code' => $currency,
'value' => $formattedAmount,
],
], static fn ($value) => $value !== null && $value !== '');
$applicationContext = array_filter([
'brand_name' => config('app.name', 'Fotospiel'),
'landing_page' => 'NO_PREFERENCE',
'user_action' => 'PAY_NOW',
'shipping_preference' => 'NO_SHIPPING',
'locale' => $this->resolveLocale($options['locale'] ?? null),
'return_url' => $options['return_url'] ?? null,
'cancel_url' => $options['cancel_url'] ?? null,
], static fn ($value) => $value !== null && $value !== '');
$payload = [
'intent' => 'CAPTURE',
'purchase_units' => [$purchaseUnit],
'application_context' => $applicationContext,
];
$headers = [];
$requestId = $options['request_id'] ?? null;
if (is_string($requestId) && $requestId !== '') {
$headers['PayPal-Request-Id'] = $requestId;
}
return $this->client->post('/v2/checkout/orders', $payload, $headers);
}
/**
* @param array{request_id?: string|null} $options
* @return array<string, mixed>