From ec17193122805b30679a31770f78e63700d64a8c Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Mon, 24 Jun 2024 21:29:25 +0200 Subject: [PATCH] Create new APIP for the Payment Configuration endpoint --- .gitignore | 4 ++ README.md | 38 ++++++++++++++++++- src/README.md | 32 ---------------- .../stripe_checkout_session/api_platform.yaml | 21 ++++++++++ .../services/stripe_js/api_platform.yaml | 18 ++++++++- 5 files changed, 78 insertions(+), 35 deletions(-) delete mode 100644 src/README.md create mode 100644 src/Resources/config/services/stripe_checkout_session/api_platform.yaml diff --git a/.gitignore b/.gitignore index 03f167a..5a5f971 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,7 @@ /phpstan.neon /phpspec.yml /behat.yml + +# Symfony CLI https://symfony.com/doc/current/setup/symfony_server.html#different-php-settings-per-project +/.php-version +/php.ini diff --git a/README.md b/README.md index 9bd2569..ecc56e8 100644 --- a/README.md +++ b/README.md @@ -158,10 +158,46 @@ in the Sylius admin. > ⚠️ Using `stripe trigger checkout.session.completed` will always result in a `500 error`, > because the test object will not embed any usable metadata. -## Advanced usages +### More? See documentation here : https://github.com/FLUX-SE/PayumStripe/blob/master/README.md +## API (Sylius Api Platform) + +### Stripe JS gateway + +The endpoint : `GET /api/v2/shop/orders/{tokenValue}/payments/{paymentId}/configuration` +will make a Payum `Capture` and respond with the Stripe Payment Intent client secret, like this : + +```json +{ + 'publishable_key': 'pk_test_1234567890', + 'use_authorize': false, + 'stripe_payment_intent_client_secret': 'a_secret' +} +``` + +After calling this endpoint your will be able to use Stripe Elements to display a Stripe Payment form, the same as this template is doing it: +https://github.com/FLUX-SE/PayumStripe/blob/master/src/Resources/views/Action/stripeJsPaymentIntent.html.twig. +More information here : https://docs.stripe.com/payments/payment-element + +### Stripe Checkout Session gateway + +The endpoint : `GET /api/v2/shop/orders/{tokenValue}/payments/{paymentId}/configuration` +will make a Payum `Capture` and respond with the Stripe Checkout Session url, like this : + +```json +{ + 'publishable_key': 'pk_test_1234567890', + 'use_authorize': false, + 'stripe_checkout_session_url': 'https://checkout.stripe.com/c/pay/cs_test...' +} +``` + +Since this endpoint is not able to get any data from you, a service can be decorated to specify the Stripe Checkout Session `success_url` you need. +Decorate this service : `flux_se.sylius_payum_stripe.api.payum.after_url.stripe_checkout_session` to generate your own dedicated url. +You will have access to the Sylius `Payment` to decide what is the url/route and the parameters of it. + [docs-assets-create-payment-method]: docs/assets/create-payment-method.png [docs-assets-gateway-configuration]: docs/assets/gateway-configuration.png [docs-assets-gateway-configuration-authorize]: docs/assets/gateway-configuration-authorize.png diff --git a/src/README.md b/src/README.md deleted file mode 100644 index 95e5009..0000000 --- a/src/README.md +++ /dev/null @@ -1,32 +0,0 @@ - - -Checkout Session details ---- - -Provide all necessary config to create the Checkout Session -Ex: - -```php - 'mail@domain.tld', - 'line_items' => [ - [ - 'amount' => 1000, // 10$ - 'currency' => 'USD', - 'name' => 'My product', - 'quantity' => 1, - 'description' => 'My description', - 'images' => [ - 'https://myshop.tld/my_image_path.png' - ], - ] - ], - 'payment_method_types' => ['card'] -]; - -``` - -Decorates the [details provider service](./src/Provider/DetailsProvider.php) to add/remove/edit this array. -It will allow you to handle subscription or card setup mode for example. diff --git a/src/Resources/config/services/stripe_checkout_session/api_platform.yaml b/src/Resources/config/services/stripe_checkout_session/api_platform.yaml new file mode 100644 index 0000000..8b605be --- /dev/null +++ b/src/Resources/config/services/stripe_checkout_session/api_platform.yaml @@ -0,0 +1,21 @@ +services: + + flux_se.sylius_payum_stripe.api.payment_provider.stripe_checkout_session: + class: FluxSE\SyliusPayumStripePlugin\Api\PaymentConfiguration\StripeCheckoutSessionPaymentConfigProvider + arguments: + $captureProcessor: '@flux_se.sylius_payum_stripe.api.payum.capture_processor.stripe_js' + $factoryName: 'stripe_checkout_session' + tags: + - name: sylius.api.payment_method_handler + + flux_se.sylius_payum_stripe.api.payum.capture_processor.stripe_checkout_session: + class: FluxSE\SyliusPayumStripePlugin\Api\Payum\CaptureProcessor + arguments: + $payum: '@payum' + $captureRequestFactory: '@flux_se.sylius_payum_stripe.factory.capture_request' + $afterUrlProvider: '@flux_se.sylius_payum_stripe.api.payum.after_url.stripe_checkout_session' + + flux_se.sylius_payum_stripe.api.payum.after_url.stripe_checkout_session: + class: FluxSE\SyliusPayumStripePlugin\Api\Payum\AfterUrlProvider + arguments: + $afterPath: 'sylius_shop_homepage' diff --git a/src/Resources/config/services/stripe_js/api_platform.yaml b/src/Resources/config/services/stripe_js/api_platform.yaml index de2467b..3a69ba7 100644 --- a/src/Resources/config/services/stripe_js/api_platform.yaml +++ b/src/Resources/config/services/stripe_js/api_platform.yaml @@ -1,7 +1,21 @@ services: - FluxSE\SyliusPayumStripePlugin\ApiPlatform\Sylius\StripeJsPayment: + flux_se.sylius_payum_stripe.api.payment_provider.stripe_js: + class: FluxSE\SyliusPayumStripePlugin\Api\PaymentConfiguration\StripeJsPaymentConfigProvider arguments: - $payum: '@payum' + $captureProcessor: '@flux_se.sylius_payum_stripe.api.payum.capture_processor.stripe_js' + $factoryName: 'stripe_js' tags: - name: sylius.api.payment_method_handler + + flux_se.sylius_payum_stripe.api.payum.capture_processor.stripe_js: + class: FluxSE\SyliusPayumStripePlugin\Api\Payum\CaptureProcessor + arguments: + $payum: '@payum' + $captureRequestFactory: '@flux_se.sylius_payum_stripe.factory.capture_request' + $afterUrlProvider: '@flux_se.sylius_payum_stripe.api.payum.after_url.stripe_js' + + flux_se.sylius_payum_stripe.api.payum.after_url.stripe_js: + class: FluxSE\SyliusPayumStripePlugin\Api\Payum\AfterUrlProvider + arguments: + $afterPath: 'sylius_shop_homepage'