From d162ccfd989aa9cae8e9efcf04c46e2f00a4839e Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 20 Nov 2024 20:05:18 +0100 Subject: [PATCH] Enhance LineItems providers --- config/services/providers.yaml | 150 +-------------- .../checkout/create_params_providers.yaml | 174 ++++++++++++++++++ .../checkout/retrieve_params_providers.yaml | 34 ++++ .../refund/create_params_providers.yaml | 32 ++++ .../web_elements/create_params_providers.yaml | 44 +++++ .../Checkout/Create/AfterUrlProvider.php | 10 +- .../Checkout/Create/CustomerEmailProvider.php | 10 +- .../LineItem/OrderItemLineItemProvider.php | 37 ++-- .../LineItem/OrderItemPriceDataProvider.php | 49 +++++ .../LineItem/PriceData/CurrencyProvider.php | 49 +++++ .../OrderItemProductDataProvider.php | 48 +++++ .../ProductData/ProductImagesProvider.php} | 27 ++- .../ProductData/ProductNameProvider.php} | 30 +-- .../ProductData/ShipmentNameProvider.php} | 24 +-- .../PriceData/ShipmentProductDataProvider.php | 47 +++++ .../LineItem/PriceData/UnitAmountProvider.php | 49 +++++ .../Create/LineItem/QuantityProvider.php | 36 ++++ .../LineItem/ShipmentLineItemProvider.php | 41 ++--- .../LineItem/ShipmentPriceDataProvider.php | 48 +++++ .../Checkout/Create/LineItemsProvider.php | 24 +-- .../Checkout/Create/ModePaymentProvider.php | 10 +- .../OrderItemLineItemProviderInterface.php | 12 +- .../Create/PaymentIntentDataProvider.php | 18 +- .../ShipmentLineItemProviderInterface.php | 12 +- .../CompositeMetadataParamsProvider.php | 34 ++++ src/Provider/CompositeParamsProvider.php | 14 +- src/Provider/DetailsProviderInterface.php | 19 -- src/Provider/ExpandProvider.php | 37 ++++ src/Provider/InnerParamsProviderInterface.php | 19 ++ src/Provider/ParamsProviderInterface.php | 4 +- ...ymentIntentCaptureMethodManualProvider.php | 8 +- src/Provider/PaymentMethodTypesProvider.php | 10 +- src/Provider/Refund/Create/AmountProvider.php | 10 +- .../Metadata/RefundTokenHashProvider.php | 21 +++ .../Refund/Create/PaymentIntentProvider.php | 10 +- .../RefundTokenHashMetadataProvider.php | 25 --- src/Provider/TokenHashMetadataProvider.php | 12 +- .../WebElements/Create/AmountProvider.php | 10 +- .../WebElements/Create/CurrencyProvider.php | 10 +- 39 files changed, 886 insertions(+), 372 deletions(-) create mode 100644 config/services/providers/checkout/create_params_providers.yaml create mode 100644 config/services/providers/checkout/retrieve_params_providers.yaml create mode 100644 config/services/providers/refund/create_params_providers.yaml create mode 100644 config/services/providers/web_elements/create_params_providers.yaml create mode 100644 src/Provider/Checkout/Create/LineItem/OrderItemPriceDataProvider.php create mode 100644 src/Provider/Checkout/Create/LineItem/PriceData/CurrencyProvider.php create mode 100644 src/Provider/Checkout/Create/LineItem/PriceData/OrderItemProductDataProvider.php rename src/Provider/Checkout/Create/LineItem/{OrderItemProductDataImagesProvider.php => PriceData/ProductData/ProductImagesProvider.php} (83%) rename src/Provider/Checkout/Create/LineItem/{OrderItemProductDataNameProvider.php => PriceData/ProductData/ProductNameProvider.php} (71%) rename src/Provider/Checkout/Create/LineItem/{ShipmentProductDataNameProvider.php => PriceData/ProductData/ShipmentNameProvider.php} (52%) create mode 100644 src/Provider/Checkout/Create/LineItem/PriceData/ShipmentProductDataProvider.php create mode 100644 src/Provider/Checkout/Create/LineItem/PriceData/UnitAmountProvider.php create mode 100644 src/Provider/Checkout/Create/LineItem/QuantityProvider.php create mode 100644 src/Provider/Checkout/Create/LineItem/ShipmentPriceDataProvider.php create mode 100644 src/Provider/CompositeMetadataParamsProvider.php delete mode 100644 src/Provider/DetailsProviderInterface.php create mode 100644 src/Provider/ExpandProvider.php create mode 100644 src/Provider/InnerParamsProviderInterface.php create mode 100644 src/Provider/Refund/Create/Metadata/RefundTokenHashProvider.php delete mode 100644 src/Provider/Refund/Create/RefundTokenHashMetadataProvider.php diff --git a/config/services/providers.yaml b/config/services/providers.yaml index fd9f4d8..b956330 100644 --- a/config/services/providers.yaml +++ b/config/services/providers.yaml @@ -1,135 +1,12 @@ +imports: + - { resource: 'providers/**/*.yaml' } + parameters: flux_se.sylius_stripe.factories: - stripe_checkout - stripe_web_elements - flux_se.sylius_stripe.checkout.after_urls: - !php/const FluxSE\SyliusStripePlugin\Provider\AfterUrlProviderInterface::CANCEL_URL: ~ - !php/const FluxSE\SyliusStripePlugin\Provider\AfterUrlProviderInterface::SUCCESS_URL: ~ services: - # WEB ELEMENTS - flux_se.sylius_stripe.provider.web_elements.create.payment_intent_params: - class: FluxSE\SyliusStripePlugin\Provider\CompositeParamsProvider - arguments: - - !tagged_iterator flux_se.sylius_stripe.provider.web_elements.details - - flux_se.sylius_stripe.provider.web_elements.amount: - class: FluxSE\SyliusStripePlugin\Provider\WebElements\Create\AmountProvider - tags: - - name: flux_se.sylius_stripe.provider.web_elements.details - - flux_se.sylius_stripe.provider.web_elements.currency: - class: FluxSE\SyliusStripePlugin\Provider\WebElements\Create\CurrencyProvider - tags: - - name: flux_se.sylius_stripe.provider.web_elements.details - - flux_se.sylius_stripe.provider.web_elements.payment_method_types: - class: FluxSE\SyliusStripePlugin\Provider\PaymentMethodTypesProvider - tags: - - name: flux_se.sylius_stripe.provider.web_elements.details - - flux_se.sylius_stripe.provider.web_elements.token_hash_metadata: - class: FluxSE\SyliusStripePlugin\Provider\TokenHashMetadataProvider - tags: - - name: flux_se.sylius_stripe.provider.web_elements.details - - flux_se.sylius_stripe.provider.web_elements.capture_method.manual: - class: FluxSE\SyliusStripePlugin\Provider\PaymentIntentCaptureMethodManualProvider - tags: - - name: flux_se.sylius_stripe.provider.web_elements.details - - # CHECKOUT - - flux_se.sylius_stripe.provider.checkout.after_url.default: - class: FluxSE\SyliusStripePlugin\Provider\DefaultAfterUrlProvider - arguments: - - '%flux_se.sylius_stripe.checkout.after_urls%' - - flux_se.sylius_stripe.provider.checkout.create.checkout_session_params: - class: FluxSE\SyliusStripePlugin\Provider\CompositeParamsProvider - arguments: - - !tagged_iterator flux_se.sylius_stripe.provider.checkout.details - - flux_se.sylius_stripe.provider.checkout.after_url: - class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\AfterUrlProvider - arguments: - - '@flux_se.sylius_stripe.provider.checkout.after_url.default' - tags: - - name: flux_se.sylius_stripe.provider.checkout.details - - flux_se.sylius_stripe.provider.checkout.payment_mode: - class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\ModePaymentProvider - tags: - - name: flux_se.sylius_stripe.provider.checkout.details - - flux_se.sylius_stripe.provider.checkout.customer_email: - class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\CustomerEmailProvider - tags: - - name: flux_se.sylius_stripe.provider.checkout.details - - flux_se.sylius_stripe.provider.checkout.payment_method_types: - class: FluxSE\SyliusStripePlugin\Provider\PaymentMethodTypesProvider - tags: - - name: flux_se.sylius_stripe.provider.checkout.details - - flux_se.sylius_stripe.provider.checkout.token_hash_metadata: - class: FluxSE\SyliusStripePlugin\Provider\TokenHashMetadataProvider - tags: - - name: flux_se.sylius_stripe.provider.checkout.details - - flux_se.sylius_stripe.provider.checkout.payment_intent_data: - class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\PaymentIntentDataProvider - arguments: - - !tagged_iterator flux_se.sylius_stripe.provider.checkout.payment_intent_data - tags: - - name: flux_se.sylius_stripe.provider.checkout.details - - flux_se.sylius_stripe.provider.checkout.payment_intent_data.capture_method.manual: - class: FluxSE\SyliusStripePlugin\Provider\PaymentIntentCaptureMethodManualProvider - tags: - - name: flux_se.sylius_stripe.provider.checkout.payment_intent_data - - flux_se.sylius_stripe.provider.checkout.line_items: - class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItemsProvider - arguments: - - !tagged_iterator flux_se.sylius_stripe.provider.checkout.line_item.order_item - - !tagged_iterator flux_se.sylius_stripe.provider.checkout.line_item.shipment - tags: - - name: flux_se.sylius_stripe.provider.checkout.details - - flux_se.sylius_stripe.provider.checkout.line_item.order_item: - class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\OrderItemLineItemProvider - arguments: - - !tagged_iterator flux_se.sylius_stripe.provider.checkout.line_item.order_item.inner - tags: - - name: flux_se.sylius_stripe.provider.checkout.line_item.order_item - - flux_se.sylius_stripe.provider.checkout.line_item.order_item.product_data.images: - class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\OrderItemProductDataImagesProvider - arguments: - - '@liip_imagine.cache.manager' - - '%flux_se.sylius_stripe.line_item_image.imagine_filter%' - - '%flux_se.sylius_stripe.line_item_image.fallback_image%' - - '%flux_se.sylius_stripe.line_item_image.localhost_pattern%' - tags: - - name: flux_se.sylius_stripe.provider.checkout.line_item.order_item.inner - - flux_se.sylius_stripe.provider.checkout.line_item.order_item.product_data.name: - class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\OrderItemProductDataNameProvider - tags: - - name: flux_se.sylius_stripe.provider.checkout.line_item.order_item.inner - - flux_se.sylius_stripe.provider.checkout.line_item.shipment: - class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\ShipmentLineItemProvider - arguments: - - !tagged_iterator flux_se.sylius_stripe.provider.checkout.line_item.shipment.inner - tags: - - name: flux_se.sylius_stripe.provider.checkout.line_item.shipment - - flux_se.sylius_stripe.provider.checkout.line_item.shipment.product_data.name: - class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\ShipmentProductDataNameProvider - tags: - - name: flux_se.sylius_stripe.provider.checkout.line_item.shipment.inner FluxSE\SyliusStripePlugin\Provider\StripeNotifyPaymentProvider: arguments: @@ -138,24 +15,3 @@ services: - '@flux_se.sylius_stripe.stripe.resolver.event_resolver' tags: - name: sylius.payment_request.payment_notify_provider - - # REFUND - flux_se.sylius_stripe.provider.refund.create: - class: FluxSE\SyliusStripePlugin\Provider\CompositeParamsProvider - arguments: - - !tagged_iterator flux_se.sylius_stripe.provider.refund.details - - flux_se.sylius_stripe.provider.refund.metadata.amount: - class: FluxSE\SyliusStripePlugin\Provider\Refund\Create\AmountProvider - tags: - - name: flux_se.sylius_stripe.provider.refund.details - - flux_se.sylius_stripe.provider.refund.metadata.payment_intent: - class: FluxSE\SyliusStripePlugin\Provider\Refund\Create\PaymentIntentProvider - tags: - - name: flux_se.sylius_stripe.provider.refund.details - - flux_se.sylius_stripe.provider.refund.metadata.refund_token_hash: - class: FluxSE\SyliusStripePlugin\Provider\Refund\Create\RefundTokenHashMetadataProvider - tags: - - name: flux_se.sylius_stripe.provider.refund.details diff --git a/config/services/providers/checkout/create_params_providers.yaml b/config/services/providers/checkout/create_params_providers.yaml new file mode 100644 index 0000000..db01a9f --- /dev/null +++ b/config/services/providers/checkout/create_params_providers.yaml @@ -0,0 +1,174 @@ +parameters: + flux_se.sylius_stripe.checkout.after_urls: + !php/const FluxSE\SyliusStripePlugin\Provider\AfterUrlProviderInterface::CANCEL_URL: ~ + !php/const FluxSE\SyliusStripePlugin\Provider\AfterUrlProviderInterface::SUCCESS_URL: ~ + +services: + + flux_se.sylius_stripe.provider.checkout.after_url.default: + class: FluxSE\SyliusStripePlugin\Provider\DefaultAfterUrlProvider + arguments: + - '%flux_se.sylius_stripe.checkout.after_urls%' + + flux_se.sylius_stripe.provider.checkout.create.params: + class: FluxSE\SyliusStripePlugin\Provider\CompositeParamsProvider + arguments: + - !tagged_iterator flux_se.sylius_stripe.provider.checkout.create.inner_params + + flux_se.sylius_stripe.provider.checkout.create.after_url: + class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\AfterUrlProvider + arguments: + - '@flux_se.sylius_stripe.provider.checkout.after_url.default' + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.inner_params + priority: -100 + + flux_se.sylius_stripe.provider.checkout.create.mode.payment: + class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\ModePaymentProvider + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.inner_params + priority: -200 + + flux_se.sylius_stripe.provider.checkout.create.customer_email: + class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\CustomerEmailProvider + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.inner_params + priority: -300 + + flux_se.sylius_stripe.provider.checkout.create.payment_method_types: + class: FluxSE\SyliusStripePlugin\Provider\PaymentMethodTypesProvider + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.inner_params + priority: -400 + + flux_se.sylius_stripe.provider.checkout.create.payment_intent_data: + class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\PaymentIntentDataProvider + arguments: + - !tagged_iterator flux_se.sylius_stripe.provider.checkout.create.payment_intent_data + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.inner_params + priority: -500 + + flux_se.sylius_stripe.provider.checkout.create.payment_intent_data.capture_method.manual: + class: FluxSE\SyliusStripePlugin\Provider\PaymentIntentCaptureMethodManualProvider + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.payment_intent_data + priority: -100 + + flux_se.sylius_stripe.provider.checkout.create.line_items: + class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItemsProvider + arguments: + - !tagged_iterator flux_se.sylius_stripe.provider.checkout.create.line_item.order_item + - !tagged_iterator flux_se.sylius_stripe.provider.checkout.create.line_item.shipment + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.inner_params + priority: -600 + + flux_se.sylius_stripe.provider.checkout.create.line_item.order_item: + class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\OrderItemLineItemProvider + arguments: + - !tagged_iterator flux_se.sylius_stripe.provider.checkout.create.line_item.order_item.inner + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.line_item.order_item + priority: -100 + + flux_se.sylius_stripe.provider.checkout.create.line_item.order_item.quantity: + class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\QuantityProvider + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.line_item.order_item.inner + priority: -100 + - name: flux_se.sylius_stripe.provider.checkout.create.line_item.shipment.inner + priority: -100 + + flux_se.sylius_stripe.provider.checkout.create.line_item.order_item.price_data: + class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\OrderItemPriceDataProvider + arguments: + - !tagged_iterator flux_se.sylius_stripe.provider.checkout.create.line_item.order_item.price_data + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.line_item.order_item.inner + priority: -200 + + flux_se.sylius_stripe.provider.checkout.create.line_item.order_item.price_data.product_data: + class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\PriceData\OrderItemProductDataProvider + arguments: + - !tagged_iterator flux_se.sylius_stripe.provider.checkout.create.line_item.order_item.price_data.product_data + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.line_item.order_item.price_data + priority: -100 + + flux_se.sylius_stripe.provider.checkout.create.line_item.price_data.uni_amount: + class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\PriceData\UnitAmountProvider + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.line_item.order_item.price_data + priority: -200 + - name: flux_se.sylius_stripe.provider.checkout.create.line_item.shipment.price_data + priority: -200 + + flux_se.sylius_stripe.provider.checkout.create.line_item.price_data.currency: + class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\PriceData\CurrencyProvider + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.line_item.order_item.price_data + priority: -300 + - name: flux_se.sylius_stripe.provider.checkout.create.line_item.shipment.price_data + priority: -300 + + flux_se.sylius_stripe.provider.checkout.create.line_item.order_item.price_data.product_data.images: + class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\PriceData\ProductData\ProductImagesProvider + arguments: + - '@liip_imagine.cache.manager' + - '%flux_se.sylius_stripe.line_item_image.imagine_filter%' + - '%flux_se.sylius_stripe.line_item_image.fallback_image%' + - '%flux_se.sylius_stripe.line_item_image.localhost_pattern%' + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.line_item.order_item.price_data.product_data + priority: -100 + + flux_se.sylius_stripe.provider.checkout.create.line_item.order_item.price_data.product_data.name: + class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\PriceData\ProductData\ProductNameProvider + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.line_item.order_item.price_data.product_data + priority: -200 + + flux_se.sylius_stripe.provider.checkout.create.line_item.shipment: + class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\ShipmentLineItemProvider + arguments: + - !tagged_iterator flux_se.sylius_stripe.provider.checkout.create.line_item.shipment.inner + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.line_item.shipment + priority: -100 + + flux_se.sylius_stripe.provider.checkout.create.line_item.shipment.price_data: + class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\ShipmentPriceDataProvider + arguments: + - !tagged_iterator flux_se.sylius_stripe.provider.checkout.create.line_item.shipment.price_data + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.line_item.shipment.inner + priority: -200 + + flux_se.sylius_stripe.provider.checkout.create.line_item.shipment.price_data.product_data: + class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\PriceData\ShipmentProductDataProvider + arguments: + - !tagged_iterator flux_se.sylius_stripe.provider.checkout.create.line_item.shipment.price_data.product_data + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.line_item.shipment.price_data + priority: -100 + + flux_se.sylius_stripe.provider.checkout.create.line_item.shipment.price_data.product_data.name: + class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\PriceData\ProductData\ShipmentNameProvider + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.line_item.shipment.price_data.product_data + priority: -100 + + flux_se.sylius_stripe.provider.checkout.create.metadata: + class: FluxSE\SyliusStripePlugin\Provider\CompositeMetadataParamsProvider + arguments: + - !tagged_iterator flux_se.sylius_stripe.provider.checkout.create.metadata + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.inner_params + priority: -700 + + flux_se.sylius_stripe.provider.checkout.create.metadata.token_hash: + class: FluxSE\SyliusStripePlugin\Provider\TokenHashMetadataProvider + tags: + - name: flux_se.sylius_stripe.provider.checkout.create.metadata + priority: -100 diff --git a/config/services/providers/checkout/retrieve_params_providers.yaml b/config/services/providers/checkout/retrieve_params_providers.yaml new file mode 100644 index 0000000..aac97a5 --- /dev/null +++ b/config/services/providers/checkout/retrieve_params_providers.yaml @@ -0,0 +1,34 @@ +parameters: + flux_se.sylius_stripe.checkout.retrieve.expand_fields: + - 'customer' + - 'line_items' + - 'payment_intent' + - 'payment_intent.latest_charge' + - 'payment_intent.payment_method' + - 'invoice' + - 'invoice.charge' + - 'invoice.payment_intent' + - 'invoice.default_payment_method' + - 'invoice.discounts' + - 'setup_intent' + - 'setup_intent.payment_method' + - 'subscription' + - 'subscription.default_payment_method' + - 'subscription.latest_invoice' + - 'subscription.default_source' + - 'subscription.discounts' + +services: + + flux_se.sylius_stripe.provider.checkout.retrieve.params: + class: FluxSE\SyliusStripePlugin\Provider\CompositeParamsProvider + arguments: + - !tagged_iterator flux_se.sylius_stripe.provider.checkout.retrieve.inner_params + + flux_se.sylius_stripe.provider.checkout.retrieve.expand: + class: FluxSE\SyliusStripePlugin\Provider\ExpandProvider + arguments: + - '%flux_se.sylius_stripe.checkout.retrieve.expand_fields%' + tags: + - name: flux_se.sylius_stripe.provider.checkout.retrieve.inner_params + priority: -100 diff --git a/config/services/providers/refund/create_params_providers.yaml b/config/services/providers/refund/create_params_providers.yaml new file mode 100644 index 0000000..423c89d --- /dev/null +++ b/config/services/providers/refund/create_params_providers.yaml @@ -0,0 +1,32 @@ +services: + + flux_se.sylius_stripe.provider.refund.create.params: + class: FluxSE\SyliusStripePlugin\Provider\CompositeParamsProvider + arguments: + - !tagged_iterator flux_se.sylius_stripe.provider.refund.create.inner_params + + flux_se.sylius_stripe.provider.refund.create.amount: + class: FluxSE\SyliusStripePlugin\Provider\Refund\Create\AmountProvider + tags: + - name: flux_se.sylius_stripe.provider.refund.create.inner_params + priority: -100 + + flux_se.sylius_stripe.provider.refund.create.payment_intent: + class: FluxSE\SyliusStripePlugin\Provider\Refund\Create\PaymentIntentProvider + tags: + - name: flux_se.sylius_stripe.provider.refund.create.inner_params + priority: -200 + + flux_se.sylius_stripe.provider.refund.create.metadata: + class: FluxSE\SyliusStripePlugin\Provider\CompositeMetadataParamsProvider + arguments: + - !tagged_iterator flux_se.sylius_stripe.provider.refund.create.metadata + tags: + - name: flux_se.sylius_stripe.provider.refund.create.inner_params + priority: -300 + + flux_se.sylius_stripe.provider.refund.create.metadata.refund_token_hash: + class: FluxSE\SyliusStripePlugin\Provider\Refund\Create\Metadata\RefundTokenHashProvider + tags: + - name: flux_se.sylius_stripe.provider.refund.create.metadata + priority: -100 diff --git a/config/services/providers/web_elements/create_params_providers.yaml b/config/services/providers/web_elements/create_params_providers.yaml new file mode 100644 index 0000000..8ce8dea --- /dev/null +++ b/config/services/providers/web_elements/create_params_providers.yaml @@ -0,0 +1,44 @@ +services: + + flux_se.sylius_stripe.provider.web_elements.create.params: + class: FluxSE\SyliusStripePlugin\Provider\CompositeParamsProvider + arguments: + - !tagged_iterator flux_se.sylius_stripe.provider.web_elements.create.inner_params + + flux_se.sylius_stripe.provider.web_elements.create.amount: + class: FluxSE\SyliusStripePlugin\Provider\WebElements\Create\AmountProvider + tags: + - name: flux_se.sylius_stripe.provider.web_elements.create.inner_params + priority: -100 + + flux_se.sylius_stripe.provider.web_elements.create.currency: + class: FluxSE\SyliusStripePlugin\Provider\WebElements\Create\CurrencyProvider + tags: + - name: flux_se.sylius_stripe.provider.web_elements.create.inner_params + priority: -200 + + flux_se.sylius_stripe.provider.web_elements.create.payment_method_types: + class: FluxSE\SyliusStripePlugin\Provider\PaymentMethodTypesProvider + tags: + - name: flux_se.sylius_stripe.provider.web_elements.create.inner_params + priority: -300 + + flux_se.sylius_stripe.provider.web_elements.create.capture_method.manual: + class: FluxSE\SyliusStripePlugin\Provider\PaymentIntentCaptureMethodManualProvider + tags: + - name: flux_se.sylius_stripe.provider.web_elements.create.inner_params + priority: -400 + + flux_se.sylius_stripe.provider.web_elements.create.metadata: + class: FluxSE\SyliusStripePlugin\Provider\CompositeMetadataParamsProvider + arguments: + - !tagged_iterator flux_se.sylius_stripe.provider.web_elements.create.metadata + tags: + - name: flux_se.sylius_stripe.provider.web_elements.create.inner_params + priority: -500 + + flux_se.sylius_stripe.provider.web_elements.create.metadata.token_hash: + class: FluxSE\SyliusStripePlugin\Provider\TokenHashMetadataProvider + tags: + - name: flux_se.sylius_stripe.provider.web_elements.create.metadata + priority: -100 diff --git a/src/Provider/Checkout/Create/AfterUrlProvider.php b/src/Provider/Checkout/Create/AfterUrlProvider.php index a42504e..29013fc 100644 --- a/src/Provider/Checkout/Create/AfterUrlProvider.php +++ b/src/Provider/Checkout/Create/AfterUrlProvider.php @@ -5,21 +5,21 @@ namespace FluxSE\SyliusStripePlugin\Provider\Checkout\Create; use FluxSE\SyliusStripePlugin\Provider\AfterUrlProviderInterface; -use FluxSE\SyliusStripePlugin\Provider\DetailsProviderInterface; +use FluxSE\SyliusStripePlugin\Provider\InnerParamsProviderInterface; use Stripe\Checkout\Session; use Sylius\Component\Payment\Model\PaymentRequestInterface; /** - * @implements DetailsProviderInterface + * @implements InnerParamsProviderInterface */ -final readonly class AfterUrlProvider implements DetailsProviderInterface +final readonly class AfterUrlProvider implements InnerParamsProviderInterface { public function __construct( private AfterUrlProviderInterface $defaultAfterPayUrlProvider, ) { } - public function getDetails(PaymentRequestInterface $paymentRequest, array &$details): void + public function provide(PaymentRequestInterface $paymentRequest, array &$params): void { /** @var string[] $payload */ $payload = $paymentRequest->getPayload(); @@ -28,7 +28,7 @@ public function getDetails(PaymentRequestInterface $paymentRequest, array &$deta AfterUrlProviderInterface::SUCCESS_URL, AfterUrlProviderInterface::CANCEL_URL, ] as $type) { - $details[$type] = $payload[$type] ?? $this->defaultAfterPayUrlProvider->getUrl($paymentRequest, $type); + $params[$type] = $payload[$type] ?? $this->defaultAfterPayUrlProvider->getUrl($paymentRequest, $type); } } } diff --git a/src/Provider/Checkout/Create/CustomerEmailProvider.php b/src/Provider/Checkout/Create/CustomerEmailProvider.php index 2b5c4d0..57de3fc 100644 --- a/src/Provider/Checkout/Create/CustomerEmailProvider.php +++ b/src/Provider/Checkout/Create/CustomerEmailProvider.php @@ -4,17 +4,17 @@ namespace FluxSE\SyliusStripePlugin\Provider\Checkout\Create; -use FluxSE\SyliusStripePlugin\Provider\DetailsProviderInterface; +use FluxSE\SyliusStripePlugin\Provider\InnerParamsProviderInterface; use Stripe\Checkout\Session; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; /** - * @implements DetailsProviderInterface + * @implements InnerParamsProviderInterface */ -final readonly class CustomerEmailProvider implements DetailsProviderInterface +final readonly class CustomerEmailProvider implements InnerParamsProviderInterface { - public function getDetails(PaymentRequestInterface $paymentRequest, array &$details): void + public function provide(PaymentRequestInterface $paymentRequest, array &$params): void { /** @var PaymentInterface $payment */ $payment = $paymentRequest->getPayment(); @@ -26,6 +26,6 @@ public function getDetails(PaymentRequestInterface $paymentRequest, array &$deta return; } - $details['customer_email'] = $email; + $params['customer_email'] = $email; } } diff --git a/src/Provider/Checkout/Create/LineItem/OrderItemLineItemProvider.php b/src/Provider/Checkout/Create/LineItem/OrderItemLineItemProvider.php index 4beba68..89fc89a 100644 --- a/src/Provider/Checkout/Create/LineItem/OrderItemLineItemProvider.php +++ b/src/Provider/Checkout/Create/LineItem/OrderItemLineItemProvider.php @@ -5,46 +5,39 @@ namespace FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem; use FluxSE\SyliusStripePlugin\Provider\Checkout\Create\OrderItemLineItemProviderInterface; -use Sylius\Component\Core\Model\OrderInterface; +use Stripe\LineItem; use Sylius\Component\Core\Model\OrderItemInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; +/** + * @implements OrderItemLineItemProviderInterface + */ final class OrderItemLineItemProvider implements OrderItemLineItemProviderInterface { /** - * @param OrderItemLineItemProviderInterface[] $orderItemLineItemProviders + * @param OrderItemLineItemProviderInterface[] $orderItemLineItemProviders */ public function __construct( private iterable $orderItemLineItemProviders, ) { } - public function getDetails( - PaymentRequestInterface $paymentRequest, + public function provideFromOrderItem( OrderItemInterface $orderItem, - array &$details + PaymentRequestInterface $paymentRequest, + array &$params ): void { - /** @var OrderInterface|null $order */ - $order = $orderItem->getOrder(); + /** @var array, mixed> $lineItem */ + $lineItem = []; - if (null === $order) { - return; + foreach ($this->orderItemLineItemProviders as $orderItemLineItemProvider) { + $orderItemLineItemProvider->provideFromOrderItem($orderItem, $paymentRequest, $lineItem); } - $priceData = [ - 'unit_amount' => $orderItem->getTotal(), - 'currency' => $order->getCurrencyCode(), - ]; - - $lineItem = [ - 'price_data' => $priceData, - 'quantity' => 1, - ]; - - foreach ($this->orderItemLineItemProviders as $orderItemLineItemProvider) { - $orderItemLineItemProvider->getDetails($paymentRequest, $orderItem, $lineItem); + if ([] === $lineItem) { + return; } - $details[] = $lineItem; + $params[] = $lineItem; } } diff --git a/src/Provider/Checkout/Create/LineItem/OrderItemPriceDataProvider.php b/src/Provider/Checkout/Create/LineItem/OrderItemPriceDataProvider.php new file mode 100644 index 0000000..5756803 --- /dev/null +++ b/src/Provider/Checkout/Create/LineItem/OrderItemPriceDataProvider.php @@ -0,0 +1,49 @@ + + */ +final readonly class OrderItemPriceDataProvider implements OrderItemLineItemProviderInterface +{ + /** + * @param OrderItemLineItemProviderInterface[] $orderItemPriceDataProviders + */ + public function __construct( + private iterable $orderItemPriceDataProviders, + ) { + } + + public function provideFromOrderItem( + OrderItemInterface $orderItem, + PaymentRequestInterface $paymentRequest, + array &$params + ): void { + + /** @var array, mixed> $priceData */ + $priceData = []; + + foreach ($this->orderItemPriceDataProviders as $orderItemPriceDataProvider) { + $orderItemPriceDataProvider->provideFromOrderItem($orderItem, $paymentRequest, $priceData); + } + + if ([] === $priceData) { + return; + } + + if (false === isset($params['price_data'])) { + $params['price_data'] = []; + } + + $params['price_data'] += $priceData; + } +} diff --git a/src/Provider/Checkout/Create/LineItem/PriceData/CurrencyProvider.php b/src/Provider/Checkout/Create/LineItem/PriceData/CurrencyProvider.php new file mode 100644 index 0000000..18fa6ff --- /dev/null +++ b/src/Provider/Checkout/Create/LineItem/PriceData/CurrencyProvider.php @@ -0,0 +1,49 @@ + + * @implements ShipmentLineItemProviderInterface + */ +final class CurrencyProvider implements OrderItemLineItemProviderInterface, ShipmentLineItemProviderInterface +{ + public function provideFromOrderItem( + OrderItemInterface $orderItem, + PaymentRequestInterface $paymentRequest, + array &$params, + ): void { + $this->provide($paymentRequest, $params); + } + + public function provideFromShipment( + ShipmentInterface $shipment, + PaymentRequestInterface $paymentRequest, + array &$params, + ): void { + $this->provide($paymentRequest, $params); + } + + /** + * @param array, mixed> $params + */ + private function provide(PaymentRequestInterface $paymentRequest, array &$params): void + { + $currencyCode = $paymentRequest->getPayment()->getCurrencyCode(); + if (null === $currencyCode) { + return; + } + + $params['currency'] = $currencyCode; + } +} diff --git a/src/Provider/Checkout/Create/LineItem/PriceData/OrderItemProductDataProvider.php b/src/Provider/Checkout/Create/LineItem/PriceData/OrderItemProductDataProvider.php new file mode 100644 index 0000000..99aec2e --- /dev/null +++ b/src/Provider/Checkout/Create/LineItem/PriceData/OrderItemProductDataProvider.php @@ -0,0 +1,48 @@ + + */ +final class OrderItemProductDataProvider implements OrderItemLineItemProviderInterface +{ + /** + * @param OrderItemLineItemProviderInterface[] $orderItemProductDataProviders + */ + public function __construct( + private iterable $orderItemProductDataProviders, + ) { + } + + public function provideFromOrderItem( + OrderItemInterface $orderItem, + PaymentRequestInterface $paymentRequest, + array &$params + ): void { + + /** @var array, mixed> $productData */ + $productData = []; + + foreach ($this->orderItemProductDataProviders as $orderItemProductDataProvider) { + $orderItemProductDataProvider->provideFromOrderItem($orderItem, $paymentRequest, $productData); + } + + if ([] === $productData) { + return; + } + + if (false === isset($params['product_data'])) { + $params['product_data'] = []; + } + + $params['product_data'] += $productData; + } +} diff --git a/src/Provider/Checkout/Create/LineItem/OrderItemProductDataImagesProvider.php b/src/Provider/Checkout/Create/LineItem/PriceData/ProductData/ProductImagesProvider.php similarity index 83% rename from src/Provider/Checkout/Create/LineItem/OrderItemProductDataImagesProvider.php rename to src/Provider/Checkout/Create/LineItem/PriceData/ProductData/ProductImagesProvider.php index f5c9964..b31a3c7 100644 --- a/src/Provider/Checkout/Create/LineItem/OrderItemProductDataImagesProvider.php +++ b/src/Provider/Checkout/Create/LineItem/PriceData/ProductData/ProductImagesProvider.php @@ -2,16 +2,20 @@ declare(strict_types=1); -namespace FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem; +namespace FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\PriceData\ProductData; use FluxSE\SyliusStripePlugin\Provider\Checkout\Create\OrderItemLineItemProviderInterface; use Liip\ImagineBundle\Imagine\Cache\CacheManager; +use Stripe\StripeObject; use Sylius\Component\Core\Model\OrderItemInterface; use Sylius\Component\Core\Model\ProductImageInterface; use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; -final class OrderItemProductDataImagesProvider implements OrderItemLineItemProviderInterface +/** + * @implements OrderItemLineItemProviderInterface + */ +final class ProductImagesProvider implements OrderItemLineItemProviderInterface { public function __construct( private CacheManager $imagineCacheManager, @@ -21,22 +25,17 @@ public function __construct( ) { } - public function getDetails( - PaymentRequestInterface $paymentRequest, + public function provideFromOrderItem( OrderItemInterface $orderItem, - array &$details, + PaymentRequestInterface $paymentRequest, + array &$params, ): void { - if (false === isset($details['price_data'])) { - $details['price_data'] = []; - } - - if (false === isset($details['price_data']['product_data'])) { - $details['price_data']['product_data'] = []; - } - - $details['price_data']['product_data']['images'] = $this->getImageUrls($orderItem); + $params['images'] = $this->getImageUrls($orderItem); } + /** + * @return string[] + */ private function getImageUrls(OrderItemInterface $orderItem): array { $product = $orderItem->getProduct(); diff --git a/src/Provider/Checkout/Create/LineItem/OrderItemProductDataNameProvider.php b/src/Provider/Checkout/Create/LineItem/PriceData/ProductData/ProductNameProvider.php similarity index 71% rename from src/Provider/Checkout/Create/LineItem/OrderItemProductDataNameProvider.php rename to src/Provider/Checkout/Create/LineItem/PriceData/ProductData/ProductNameProvider.php index d838cce..096e7fe 100644 --- a/src/Provider/Checkout/Create/LineItem/OrderItemProductDataNameProvider.php +++ b/src/Provider/Checkout/Create/LineItem/PriceData/ProductData/ProductNameProvider.php @@ -2,31 +2,27 @@ declare(strict_types=1); -namespace FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem; +namespace FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\PriceData\ProductData; use FluxSE\SyliusStripePlugin\Provider\Checkout\Create\OrderItemLineItemProviderInterface; +use Stripe\StripeObject; use Sylius\Component\Core\Model\OrderItemInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; -final class OrderItemProductDataNameProvider implements OrderItemLineItemProviderInterface +/** + * @implements OrderItemLineItemProviderInterface + */ +final class ProductNameProvider implements OrderItemLineItemProviderInterface { - public function getDetails( - PaymentRequestInterface $paymentRequest, + public function provideFromOrderItem( OrderItemInterface $orderItem, - array &$details + PaymentRequestInterface $paymentRequest, + array &$params ): void { - if (false === isset($details['price_data'])) { - $details['price_data'] = []; - } - - if (false === isset($details['price_data']['product_data'])) { - $details['price_data']['product_data'] = []; - } - - $details['price_data']['product_data']['name'] = $this->getItemName($orderItem); + $params['name'] = $this->getItemName($orderItem); } - private function getItemName(OrderItemInterface $orderItem): ?string + private function getItemName(OrderItemInterface $orderItem): string { $itemName = $this->buildItemName($orderItem); @@ -52,6 +48,10 @@ private function buildItemName(OrderItemInterface $orderItem): string return $variantName; } + if ($productName === $variantName) { + return $productName; + } + return sprintf('%s %s', $productName, $variantName); } } diff --git a/src/Provider/Checkout/Create/LineItem/ShipmentProductDataNameProvider.php b/src/Provider/Checkout/Create/LineItem/PriceData/ProductData/ShipmentNameProvider.php similarity index 52% rename from src/Provider/Checkout/Create/LineItem/ShipmentProductDataNameProvider.php rename to src/Provider/Checkout/Create/LineItem/PriceData/ProductData/ShipmentNameProvider.php index 35c93d5..da1edfb 100644 --- a/src/Provider/Checkout/Create/LineItem/ShipmentProductDataNameProvider.php +++ b/src/Provider/Checkout/Create/LineItem/PriceData/ProductData/ShipmentNameProvider.php @@ -2,32 +2,28 @@ declare(strict_types=1); -namespace FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem; +namespace FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\PriceData\ProductData; use FluxSE\SyliusStripePlugin\Provider\Checkout\Create\ShipmentLineItemProviderInterface; +use Stripe\StripeObject; use Sylius\Component\Core\Model\ShipmentInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; -final class ShipmentProductDataNameProvider implements ShipmentLineItemProviderInterface +/** + * @implements ShipmentLineItemProviderInterface + */ +final class ShipmentNameProvider implements ShipmentLineItemProviderInterface { - public function getDetails( - PaymentRequestInterface $paymentRequest, + public function provideFromShipment( ShipmentInterface $shipment, - array &$details + PaymentRequestInterface $paymentRequest, + array &$params ): void { $shipmentMethod = $shipment->getMethod(); if (null === $shipmentMethod) { return; } - if (false === isset($details['price_data'])) { - $details['price_data'] = []; - } - - if (false === isset($details['price_data']['product_data'])) { - $details['price_data']['product_data'] = []; - } - - $details['price_data']['product_data']['name'] = $shipmentMethod->getName(); + $params['name'] = $shipmentMethod->getName(); } } diff --git a/src/Provider/Checkout/Create/LineItem/PriceData/ShipmentProductDataProvider.php b/src/Provider/Checkout/Create/LineItem/PriceData/ShipmentProductDataProvider.php new file mode 100644 index 0000000..64e7c0a --- /dev/null +++ b/src/Provider/Checkout/Create/LineItem/PriceData/ShipmentProductDataProvider.php @@ -0,0 +1,47 @@ + + */ +final class ShipmentProductDataProvider implements ShipmentLineItemProviderInterface +{ + /** + * @param ShipmentLineItemProviderInterface[] $shipmentProductDataProviders + */ + public function __construct( + private iterable $shipmentProductDataProviders, + ) { + } + + public function provideFromShipment( + ShipmentInterface $shipment, + PaymentRequestInterface $paymentRequest, + array &$params + ): void { + /** @var array, mixed> $productData */ + $productData = []; + + foreach ($this->shipmentProductDataProviders as $shipmentProductDataProvider) { + $shipmentProductDataProvider->provideFromShipment($shipment, $paymentRequest, $productData); + } + + if ([] === $productData) { + return; + } + + if (false === isset($params['product_data'])) { + $params['product_data'] = []; + } + + $params['product_data'] += $productData; + } +} diff --git a/src/Provider/Checkout/Create/LineItem/PriceData/UnitAmountProvider.php b/src/Provider/Checkout/Create/LineItem/PriceData/UnitAmountProvider.php new file mode 100644 index 0000000..29558d4 --- /dev/null +++ b/src/Provider/Checkout/Create/LineItem/PriceData/UnitAmountProvider.php @@ -0,0 +1,49 @@ + + * @implements ShipmentLineItemProviderInterface + */ +final class UnitAmountProvider implements OrderItemLineItemProviderInterface, ShipmentLineItemProviderInterface +{ + public function provideFromOrderItem( + OrderItemInterface $orderItem, + PaymentRequestInterface $paymentRequest, + array &$params + ): void { + $this->provide($orderItem->getTotal(), $params); + } + + public function provideFromShipment( + ShipmentInterface $shipment, + PaymentRequestInterface $paymentRequest, + array &$params + ): void { + $this->provide($shipment->getAdjustmentsTotal(), $params); + } + + /** + * @param array, mixed> $params + */ + private function provide(int $unitAmount, array &$params): void + { + if (0 === $unitAmount) { + return; + } + + $params['unit_amount'] = $unitAmount; + } +} diff --git a/src/Provider/Checkout/Create/LineItem/QuantityProvider.php b/src/Provider/Checkout/Create/LineItem/QuantityProvider.php new file mode 100644 index 0000000..f21585e --- /dev/null +++ b/src/Provider/Checkout/Create/LineItem/QuantityProvider.php @@ -0,0 +1,36 @@ + + * @implements ShipmentLineItemProviderInterface + */ +final class QuantityProvider implements OrderItemLineItemProviderInterface, ShipmentLineItemProviderInterface +{ + public function provideFromOrderItem( + OrderItemInterface $orderItem, + PaymentRequestInterface $paymentRequest, + array &$params + ): void { + $params['quantity'] = 1; + } + + public function provideFromShipment( + ShipmentInterface $shipment, + PaymentRequestInterface $paymentRequest, + array &$params + ): void { + $params['quantity'] = 1; + } +} diff --git a/src/Provider/Checkout/Create/LineItem/ShipmentLineItemProvider.php b/src/Provider/Checkout/Create/LineItem/ShipmentLineItemProvider.php index 4ee0fb4..f20ddc6 100644 --- a/src/Provider/Checkout/Create/LineItem/ShipmentLineItemProvider.php +++ b/src/Provider/Checkout/Create/LineItem/ShipmentLineItemProvider.php @@ -5,53 +5,40 @@ namespace FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem; use FluxSE\SyliusStripePlugin\Provider\Checkout\Create\ShipmentLineItemProviderInterface; +use Stripe\LineItem; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Core\Model\ShipmentInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; +/** + * @implements ShipmentLineItemProviderInterface + */ final class ShipmentLineItemProvider implements ShipmentLineItemProviderInterface { /** - * @param ShipmentLineItemProviderInterface[] $shipmentLineItemProviders + * @param ShipmentLineItemProviderInterface[] $shipmentLineItemProviders */ public function __construct( private iterable $shipmentLineItemProviders, ) { } - public function getDetails( - PaymentRequestInterface $paymentRequest, + public function provideFromShipment( ShipmentInterface $shipment, - array &$details + PaymentRequestInterface $paymentRequest, + array &$params ): void { - /** @var PaymentInterface $payment */ - $payment = $paymentRequest->getPayment(); + /** @var array, mixed> $lineItem */ + $lineItem = []; - $order = $payment->getOrder(); - if (null === $order) { - return; + foreach ($this->shipmentLineItemProviders as $shipmentLineItemProvider) { + $shipmentLineItemProvider->provideFromShipment($shipment, $paymentRequest, $lineItem); } - $shippingTotal = $shipment->getAdjustmentsTotal(); - if (0 === $shippingTotal) { + if ([] === $lineItem) { return; } - $priceData = [ - 'unit_amount' => $shippingTotal, - 'currency' => $order->getCurrencyCode(), - ]; - - $lineItem = [ - 'price_data' => $priceData, - 'quantity' => 1, - ]; - - - foreach ($this->shipmentLineItemProviders as $shipmentLineItemProvider) { - $shipmentLineItemProvider->getDetails($paymentRequest, $shipment, $lineItem); - } - - $details[] = $lineItem; + $params[] = $lineItem; } } diff --git a/src/Provider/Checkout/Create/LineItem/ShipmentPriceDataProvider.php b/src/Provider/Checkout/Create/LineItem/ShipmentPriceDataProvider.php new file mode 100644 index 0000000..f95ba99 --- /dev/null +++ b/src/Provider/Checkout/Create/LineItem/ShipmentPriceDataProvider.php @@ -0,0 +1,48 @@ + + */ +final class ShipmentPriceDataProvider implements ShipmentLineItemProviderInterface +{ + /** + * @param ShipmentLineItemProviderInterface[] $shipmentPriceDataProviders + */ + public function __construct( + private iterable $shipmentPriceDataProviders, + ) { + } + + public function provideFromShipment( + ShipmentInterface $shipment, + PaymentRequestInterface $paymentRequest, + array &$params + ): void { + /** @var array, mixed> $priceData */ + $priceData = []; + + foreach ($this->shipmentPriceDataProviders as $shipmentPriceDataProvider) { + $shipmentPriceDataProvider->provideFromShipment($shipment, $paymentRequest, $priceData); + } + + if ([] === $priceData) { + return; + } + + if (false === isset($params['price_data'])) { + $params['price_data'] = []; + } + + $params['price_data'] += $priceData; + } +} diff --git a/src/Provider/Checkout/Create/LineItemsProvider.php b/src/Provider/Checkout/Create/LineItemsProvider.php index e8eaec1..7c2dc7e 100644 --- a/src/Provider/Checkout/Create/LineItemsProvider.php +++ b/src/Provider/Checkout/Create/LineItemsProvider.php @@ -4,19 +4,20 @@ namespace FluxSE\SyliusStripePlugin\Provider\Checkout\Create; -use FluxSE\SyliusStripePlugin\Provider\DetailsProviderInterface; +use FluxSE\SyliusStripePlugin\Provider\InnerParamsProviderInterface; use Stripe\Checkout\Session; +use Stripe\LineItem; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; /** - * @implements DetailsProviderInterface + * @implements InnerParamsProviderInterface */ -final readonly class LineItemsProvider implements DetailsProviderInterface +final readonly class LineItemsProvider implements InnerParamsProviderInterface { /** - * @param OrderItemLineItemProviderInterface[] $orderItemLineItemProviders - * @param ShipmentLineItemProviderInterface[] $shippingDetailsProviders + * @param OrderItemLineItemProviderInterface[] $orderItemLineItemProviders + * @param ShipmentLineItemProviderInterface[] $shippingDetailsProviders */ public function __construct( private iterable $orderItemLineItemProviders, @@ -24,7 +25,7 @@ public function __construct( ) { } - public function getDetails(PaymentRequestInterface $paymentRequest, array &$details): void + public function provide(PaymentRequestInterface $paymentRequest, array &$params): void { /** @var PaymentInterface $payment */ $payment = $paymentRequest->getPayment(); @@ -33,16 +34,17 @@ public function getDetails(PaymentRequestInterface $paymentRequest, array &$deta return; } + /** @var array, mixed>> $lineItems */ $lineItems = []; foreach ($order->getItems() as $orderItem) { foreach ($this->orderItemLineItemProviders as $orderItemLineItemProvider) { - $orderItemLineItemProvider->getDetails($paymentRequest, $orderItem, $lineItems); + $orderItemLineItemProvider->provideFromOrderItem($orderItem, $paymentRequest, $lineItems); } } foreach ($order->getShipments() as $shipment) { foreach ($this->shippingDetailsProviders as $shippingDetailsProvider) { - $shippingDetailsProvider->getDetails($paymentRequest, $shipment, $lineItems); + $shippingDetailsProvider->provideFromShipment($shipment, $paymentRequest, $lineItems); } } @@ -50,10 +52,10 @@ public function getDetails(PaymentRequestInterface $paymentRequest, array &$deta return; } - if (false === isset($details['line_items'])) { - $details['line_items'] = []; + if (false === isset($params['line_items'])) { + $params['line_items'] = []; } - $details['line_items'] += $lineItems; + $params['line_items'] += $lineItems; } } diff --git a/src/Provider/Checkout/Create/ModePaymentProvider.php b/src/Provider/Checkout/Create/ModePaymentProvider.php index b2246c2..acc0120 100644 --- a/src/Provider/Checkout/Create/ModePaymentProvider.php +++ b/src/Provider/Checkout/Create/ModePaymentProvider.php @@ -4,17 +4,17 @@ namespace FluxSE\SyliusStripePlugin\Provider\Checkout\Create; -use FluxSE\SyliusStripePlugin\Provider\DetailsProviderInterface; +use FluxSE\SyliusStripePlugin\Provider\InnerParamsProviderInterface; use Stripe\Checkout\Session; use Sylius\Component\Payment\Model\PaymentRequestInterface; /** - * @implements DetailsProviderInterface + * @implements InnerParamsProviderInterface */ -final class ModePaymentProvider implements DetailsProviderInterface +final class ModePaymentProvider implements InnerParamsProviderInterface { - public function getDetails(PaymentRequestInterface $paymentRequest, array &$details): void + public function provide(PaymentRequestInterface $paymentRequest, array &$params): void { - $details['mode'] = Session::MODE_PAYMENT; + $params['mode'] = Session::MODE_PAYMENT; } } diff --git a/src/Provider/Checkout/Create/OrderItemLineItemProviderInterface.php b/src/Provider/Checkout/Create/OrderItemLineItemProviderInterface.php index 0b51ad2..08413ee 100644 --- a/src/Provider/Checkout/Create/OrderItemLineItemProviderInterface.php +++ b/src/Provider/Checkout/Create/OrderItemLineItemProviderInterface.php @@ -6,17 +6,21 @@ use Stripe\ApiResource; use Stripe\LineItem; +use Stripe\StripeObject; use Sylius\Component\Core\Model\OrderItemInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; +/** + * @template T as StripeObject + */ interface OrderItemLineItemProviderInterface { /** - * @param array, mixed> $details + * @param array, mixed> $params */ - public function getDetails( - PaymentRequestInterface $paymentRequest, + public function provideFromOrderItem( OrderItemInterface $orderItem, - array &$details + PaymentRequestInterface $paymentRequest, + array &$params ): void; } diff --git a/src/Provider/Checkout/Create/PaymentIntentDataProvider.php b/src/Provider/Checkout/Create/PaymentIntentDataProvider.php index 0034bf3..9f78380 100644 --- a/src/Provider/Checkout/Create/PaymentIntentDataProvider.php +++ b/src/Provider/Checkout/Create/PaymentIntentDataProvider.php @@ -4,40 +4,40 @@ namespace FluxSE\SyliusStripePlugin\Provider\Checkout\Create; -use FluxSE\SyliusStripePlugin\Provider\DetailsProviderInterface; +use FluxSE\SyliusStripePlugin\Provider\InnerParamsProviderInterface; use Stripe\Checkout\Session; use Stripe\PaymentIntent; use Sylius\Component\Payment\Model\PaymentRequestInterface; /** - * @implements DetailsProviderInterface + * @implements InnerParamsProviderInterface */ -final class PaymentIntentDataProvider implements DetailsProviderInterface +final class PaymentIntentDataProvider implements InnerParamsProviderInterface { /** - * @param DetailsProviderInterface[] $detailsProviders + * @param InnerParamsProviderInterface[] $detailsProviders */ public function __construct( private iterable $detailsProviders, ) { } - public function getDetails(PaymentRequestInterface $paymentRequest, array &$details): void + public function provide(PaymentRequestInterface $paymentRequest, array &$params): void { /** @var array, mixed> $paymentIntentData */ $paymentIntentData = []; foreach ($this->detailsProviders as $detailsProvider) { - $detailsProvider->getDetails($paymentRequest, $paymentIntentData); + $detailsProvider->provide($paymentRequest, $paymentIntentData); } if ([] === $paymentIntentData) { return; } - if (false === isset($details['payment_intent_data'])) { - $details['payment_intent_data'] = []; + if (false === isset($params['payment_intent_data'])) { + $params['payment_intent_data'] = []; } - $details['payment_intent_data'] += $paymentIntentData; + $params['payment_intent_data'] += $paymentIntentData; } } diff --git a/src/Provider/Checkout/Create/ShipmentLineItemProviderInterface.php b/src/Provider/Checkout/Create/ShipmentLineItemProviderInterface.php index e6e22e4..1911a1e 100644 --- a/src/Provider/Checkout/Create/ShipmentLineItemProviderInterface.php +++ b/src/Provider/Checkout/Create/ShipmentLineItemProviderInterface.php @@ -6,18 +6,22 @@ use Stripe\ApiResource; use Stripe\LineItem; +use Stripe\StripeObject; use Sylius\Component\Core\Model\OrderItemInterface; use Sylius\Component\Core\Model\ShipmentInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; +/** + * @template T as StripeObject + */ interface ShipmentLineItemProviderInterface { /** - * @param array, mixed> $details + * @param array, mixed> $params */ - public function getDetails( - PaymentRequestInterface $paymentRequest, + public function provideFromShipment( ShipmentInterface $shipment, - array &$details + PaymentRequestInterface $paymentRequest, + array &$params ): void; } diff --git a/src/Provider/CompositeMetadataParamsProvider.php b/src/Provider/CompositeMetadataParamsProvider.php new file mode 100644 index 0000000..7a89f96 --- /dev/null +++ b/src/Provider/CompositeMetadataParamsProvider.php @@ -0,0 +1,34 @@ + + */ +final readonly class CompositeMetadataParamsProvider implements InnerParamsProviderInterface +{ + /** + * @param InnerParamsProviderInterface[] $innerParamsProviders + */ + public function __construct( + private iterable $innerParamsProviders, + ) { + } + + public function provide(PaymentRequestInterface $paymentRequest, array &$params): void + { + if (false === isset($params['metadata'])) { + $params['metadata'] = []; + } + + foreach ($this->innerParamsProviders as $innerParamsProvider) { + $innerParamsProvider->provide($paymentRequest, $params['metadata']); + } + } +} diff --git a/src/Provider/CompositeParamsProvider.php b/src/Provider/CompositeParamsProvider.php index 0cb12d2..349e65d 100644 --- a/src/Provider/CompositeParamsProvider.php +++ b/src/Provider/CompositeParamsProvider.php @@ -15,10 +15,10 @@ final readonly class CompositeParamsProvider implements ParamsProviderInterface { /** - * @param DetailsProviderInterface[] $detailsProviders + * @param InnerParamsProviderInterface[] $innerParamsProviders */ public function __construct( - private iterable $detailsProviders, + private iterable $innerParamsProviders, ) { } @@ -27,13 +27,13 @@ public function __construct( */ public function getParams(PaymentRequestInterface $paymentRequest): ?array { - /** @var array, mixed> $details */ - $details = []; + /** @var array, mixed> $params */ + $params = []; - foreach ($this->detailsProviders as $checkoutSessionProvider) { - $checkoutSessionProvider->getDetails($paymentRequest, $details); + foreach ($this->innerParamsProviders as $innerParamsProvider) { + $innerParamsProvider->provide($paymentRequest, $params); } - return $details; + return $params; } } diff --git a/src/Provider/DetailsProviderInterface.php b/src/Provider/DetailsProviderInterface.php deleted file mode 100644 index 3c0558c..0000000 --- a/src/Provider/DetailsProviderInterface.php +++ /dev/null @@ -1,19 +0,0 @@ -, mixed> $details - */ - public function getDetails(PaymentRequestInterface $paymentRequest, array &$details): void; -} diff --git a/src/Provider/ExpandProvider.php b/src/Provider/ExpandProvider.php new file mode 100644 index 0000000..f25f0b3 --- /dev/null +++ b/src/Provider/ExpandProvider.php @@ -0,0 +1,37 @@ + + */ +final readonly class ExpandProvider implements InnerParamsProviderInterface +{ + /** + * @param string[] $expandFields + */ + public function __construct( + private array $expandFields, + ) { + } + + public function provide(PaymentRequestInterface $paymentRequest, array &$params): void + { + if (false === isset($params['expand'])) { + $params['expand'] = []; + } + + if (false === is_array($params['expand'])) { + return; + } + + foreach ($this->expandFields as $field) { + $params['expand'][] = $field; + } + } +} diff --git a/src/Provider/InnerParamsProviderInterface.php b/src/Provider/InnerParamsProviderInterface.php new file mode 100644 index 0000000..8a4081d --- /dev/null +++ b/src/Provider/InnerParamsProviderInterface.php @@ -0,0 +1,19 @@ +, mixed> $params + */ + public function provide(PaymentRequestInterface $paymentRequest, array &$params): void; +} diff --git a/src/Provider/ParamsProviderInterface.php b/src/Provider/ParamsProviderInterface.php index 17c0658..d3cda43 100644 --- a/src/Provider/ParamsProviderInterface.php +++ b/src/Provider/ParamsProviderInterface.php @@ -4,11 +4,11 @@ namespace FluxSE\SyliusStripePlugin\Provider; -use Stripe\ApiResource; +use Stripe\StripeObject; use Sylius\Component\Payment\Model\PaymentRequestInterface; /** - * @template T of ApiResource + * @template T of StripeObject */ interface ParamsProviderInterface { diff --git a/src/Provider/PaymentIntentCaptureMethodManualProvider.php b/src/Provider/PaymentIntentCaptureMethodManualProvider.php index 4f70026..8fb1ec6 100644 --- a/src/Provider/PaymentIntentCaptureMethodManualProvider.php +++ b/src/Provider/PaymentIntentCaptureMethodManualProvider.php @@ -8,16 +8,16 @@ use Sylius\Component\Payment\Model\PaymentRequestInterface; /** - * @implements DetailsProviderInterface + * @implements InnerParamsProviderInterface */ -final class PaymentIntentCaptureMethodManualProvider implements DetailsProviderInterface +final class PaymentIntentCaptureMethodManualProvider implements InnerParamsProviderInterface { - public function getDetails(PaymentRequestInterface $paymentRequest, array &$details): void + public function provide(PaymentRequestInterface $paymentRequest, array &$params): void { if (false === ($paymentRequest->getMethod()->getGatewayConfig()?->getConfig()['use_authorize'] ?? false)) { return; } - $details['capture_method'] = PaymentIntent::CAPTURE_METHOD_MANUAL; + $params['capture_method'] = PaymentIntent::CAPTURE_METHOD_MANUAL; } } diff --git a/src/Provider/PaymentMethodTypesProvider.php b/src/Provider/PaymentMethodTypesProvider.php index a447cf8..d9f8d9c 100644 --- a/src/Provider/PaymentMethodTypesProvider.php +++ b/src/Provider/PaymentMethodTypesProvider.php @@ -9,18 +9,18 @@ /** * @template T as ApiResource - * @implements DetailsProviderInterface + * @implements InnerParamsProviderInterface */ -final readonly class PaymentMethodTypesProvider implements DetailsProviderInterface +final readonly class PaymentMethodTypesProvider implements InnerParamsProviderInterface { - public function getDetails(PaymentRequestInterface $paymentRequest, array &$details): void + public function provide(PaymentRequestInterface $paymentRequest, array &$params): void { - /** @var string[] $types */ + /** @var string[] $paymentMethodTypes */ $paymentMethodTypes = $paymentRequest->getMethod()->getGatewayConfig()?->getConfig()['payment_method_types'] ?? []; if ([] === $paymentMethodTypes) { return; } - $details['payment_method_types'] = $paymentMethodTypes; + $params['payment_method_types'] = $paymentMethodTypes; } } diff --git a/src/Provider/Refund/Create/AmountProvider.php b/src/Provider/Refund/Create/AmountProvider.php index 17775b7..59fc109 100644 --- a/src/Provider/Refund/Create/AmountProvider.php +++ b/src/Provider/Refund/Create/AmountProvider.php @@ -4,16 +4,16 @@ namespace FluxSE\SyliusStripePlugin\Provider\Refund\Create; -use FluxSE\SyliusStripePlugin\Provider\DetailsProviderInterface; +use FluxSE\SyliusStripePlugin\Provider\InnerParamsProviderInterface; use Stripe\Refund; use Sylius\Component\Payment\Model\PaymentRequestInterface; /** - * @implements DetailsProviderInterface + * @implements InnerParamsProviderInterface */ -final readonly class AmountProvider implements DetailsProviderInterface +final readonly class AmountProvider implements InnerParamsProviderInterface { - public function getDetails(PaymentRequestInterface $paymentRequest, array &$details): void + public function provide(PaymentRequestInterface $paymentRequest, array &$params): void { $payload = $paymentRequest->getPayload(); if (false === is_array($payload)) { @@ -25,6 +25,6 @@ public function getDetails(PaymentRequestInterface $paymentRequest, array &$deta return; } - $details['amount'] = $amount; + $params['amount'] = $amount; } } diff --git a/src/Provider/Refund/Create/Metadata/RefundTokenHashProvider.php b/src/Provider/Refund/Create/Metadata/RefundTokenHashProvider.php new file mode 100644 index 0000000..6e10829 --- /dev/null +++ b/src/Provider/Refund/Create/Metadata/RefundTokenHashProvider.php @@ -0,0 +1,21 @@ + + */ +final readonly class RefundTokenHashProvider implements InnerParamsProviderInterface +{ + public function provide(PaymentRequestInterface $paymentRequest, array &$params): void + { + $params[MetadataProviderInterface::REFUND_TOKEN_HASH_KEY_NAME] = $paymentRequest->getId(); + } +} diff --git a/src/Provider/Refund/Create/PaymentIntentProvider.php b/src/Provider/Refund/Create/PaymentIntentProvider.php index 2521398..62e543d 100644 --- a/src/Provider/Refund/Create/PaymentIntentProvider.php +++ b/src/Provider/Refund/Create/PaymentIntentProvider.php @@ -4,16 +4,16 @@ namespace FluxSE\SyliusStripePlugin\Provider\Refund\Create; -use FluxSE\SyliusStripePlugin\Provider\DetailsProviderInterface; +use FluxSE\SyliusStripePlugin\Provider\InnerParamsProviderInterface; use Stripe\Refund; use Sylius\Component\Payment\Model\PaymentRequestInterface; /** - * @implements DetailsProviderInterface + * @implements InnerParamsProviderInterface */ -final readonly class PaymentIntentProvider implements DetailsProviderInterface +final readonly class PaymentIntentProvider implements InnerParamsProviderInterface { - public function getDetails(PaymentRequestInterface $paymentRequest, array &$details): void + public function provide(PaymentRequestInterface $paymentRequest, array &$params): void { $payload = $paymentRequest->getPayload(); if (false === is_array($payload)) { @@ -25,6 +25,6 @@ public function getDetails(PaymentRequestInterface $paymentRequest, array &$deta return; } - $details['payment_intent'] = $paymentIntent; + $params['payment_intent'] = $paymentIntent; } } diff --git a/src/Provider/Refund/Create/RefundTokenHashMetadataProvider.php b/src/Provider/Refund/Create/RefundTokenHashMetadataProvider.php deleted file mode 100644 index b5280c0..0000000 --- a/src/Provider/Refund/Create/RefundTokenHashMetadataProvider.php +++ /dev/null @@ -1,25 +0,0 @@ - - */ -final readonly class RefundTokenHashMetadataProvider implements DetailsProviderInterface -{ - public function getDetails(PaymentRequestInterface $paymentRequest, array &$details): void - { - if(false === isset($details['metadata'])) { - $details['metadata'] = []; - } - - $details['metadata'][MetadataProviderInterface::REFUND_TOKEN_HASH_KEY_NAME] = $paymentRequest->getId(); - } -} diff --git a/src/Provider/TokenHashMetadataProvider.php b/src/Provider/TokenHashMetadataProvider.php index e65bf9e..10b58f9 100644 --- a/src/Provider/TokenHashMetadataProvider.php +++ b/src/Provider/TokenHashMetadataProvider.php @@ -9,16 +9,12 @@ /** * @template T as ApiResource - * @implements DetailsProviderInterface + * @implements InnerParamsProviderInterface */ -final readonly class TokenHashMetadataProvider implements DetailsProviderInterface +final readonly class TokenHashMetadataProvider implements InnerParamsProviderInterface { - public function getDetails(PaymentRequestInterface $paymentRequest, array &$details): void + public function provide(PaymentRequestInterface $paymentRequest, array &$params): void { - if (false === isset($details['metadata'])) { - $details['metadata'] = []; - } - - $details['metadata'][MetadataProviderInterface::DEFAULT_TOKEN_HASH_KEY_NAME] = $paymentRequest->getId(); + $params[MetadataProviderInterface::DEFAULT_TOKEN_HASH_KEY_NAME] = $paymentRequest->getId(); } } diff --git a/src/Provider/WebElements/Create/AmountProvider.php b/src/Provider/WebElements/Create/AmountProvider.php index 0df00f8..15f7eec 100644 --- a/src/Provider/WebElements/Create/AmountProvider.php +++ b/src/Provider/WebElements/Create/AmountProvider.php @@ -4,23 +4,23 @@ namespace FluxSE\SyliusStripePlugin\Provider\WebElements\Create; -use FluxSE\SyliusStripePlugin\Provider\DetailsProviderInterface; +use FluxSE\SyliusStripePlugin\Provider\InnerParamsProviderInterface; use Stripe\PaymentIntent; use Sylius\Component\Payment\Model\PaymentRequestInterface; /** - * @implements DetailsProviderInterface + * @implements InnerParamsProviderInterface */ -final readonly class AmountProvider implements DetailsProviderInterface +final readonly class AmountProvider implements InnerParamsProviderInterface { - public function getDetails(PaymentRequestInterface $paymentRequest, array &$details): void + public function provide(PaymentRequestInterface $paymentRequest, array &$params): void { $amount = $paymentRequest->getPayment()->getAmount(); if (null === $amount) { return; } - $details['amount'] = $amount; + $params['amount'] = $amount; } } diff --git a/src/Provider/WebElements/Create/CurrencyProvider.php b/src/Provider/WebElements/Create/CurrencyProvider.php index 1bfce8e..3a0e3fa 100644 --- a/src/Provider/WebElements/Create/CurrencyProvider.php +++ b/src/Provider/WebElements/Create/CurrencyProvider.php @@ -4,23 +4,23 @@ namespace FluxSE\SyliusStripePlugin\Provider\WebElements\Create; -use FluxSE\SyliusStripePlugin\Provider\DetailsProviderInterface; +use FluxSE\SyliusStripePlugin\Provider\InnerParamsProviderInterface; use Stripe\PaymentIntent; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Webmozart\Assert\Assert; /** - * @implements DetailsProviderInterface + * @implements InnerParamsProviderInterface */ -final readonly class CurrencyProvider implements DetailsProviderInterface +final readonly class CurrencyProvider implements InnerParamsProviderInterface { - public function getDetails(PaymentRequestInterface $paymentRequest, array &$details): void + public function provide(PaymentRequestInterface $paymentRequest, array &$params): void { $currencyCode = $paymentRequest->getPayment()->getCurrencyCode(); if (null === $currencyCode) { return; } - $details['currency'] = $currencyCode; + $params['currency'] = $currencyCode; } }