Add PayPal support for add-on and gift voucher checkout
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Api\Tenant;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CheckoutSession;
|
||||
use App\Services\Addons\EventAddonCatalog;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
@@ -12,9 +13,25 @@ class EventAddonCatalogController extends Controller
|
||||
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$provider = config('package-addons.provider')
|
||||
?? config('checkout.default_provider', CheckoutSession::PROVIDER_PAYPAL);
|
||||
|
||||
$addons = collect($this->catalog->all())
|
||||
->filter(fn (array $addon) => ! empty($addon['variant_id']))
|
||||
->map(fn (array $addon, string $key) => array_merge($addon, ['key' => $key]))
|
||||
->map(function (array $addon, string $key) use ($provider): array {
|
||||
$priceId = $provider === CheckoutSession::PROVIDER_PAYPAL
|
||||
? ($addon['price'] ?? null ? 'paypal' : null)
|
||||
: ($addon['variant_id'] ?? null);
|
||||
|
||||
return [
|
||||
'key' => $key,
|
||||
'label' => $addon['label'] ?? null,
|
||||
'price_id' => $priceId,
|
||||
'increments' => $addon['increments'] ?? [],
|
||||
'price' => $addon['price'] ?? null,
|
||||
'currency' => $addon['currency'] ?? 'EUR',
|
||||
];
|
||||
})
|
||||
->filter(fn (array $addon) => ! empty($addon['price_id']))
|
||||
->values()
|
||||
->all();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user