Skip to content

Commit

Permalink
Create new APIP for the Payment Configuration endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometee committed Jun 24, 2024
1 parent 4dd1b28 commit ec17193
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 35 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 0 additions & 32 deletions src/README.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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'
18 changes: 16 additions & 2 deletions src/Resources/config/services/stripe_js/api_platform.yaml
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit ec17193

Please sign in to comment.