Skip to content

[Payment request] Order pay via the UI#16790

Merged
GSadee merged 59 commits intoSylius:payment-requestfrom
Prometee:payment-request-ui
Sep 23, 2024
Merged

[Payment request] Order pay via the UI#16790
GSadee merged 59 commits intoSylius:payment-requestfrom
Prometee:payment-request-ui

Conversation

@Prometee
Copy link
Copy Markdown
Contributor

@Prometee Prometee commented Aug 27, 2024

Q A
Branch? 2.0
Bug fix? no
New feature? yes
BC breaks? yes
Deprecations? yes
Related tickets none
License MIT

This PR will allow PaymentRequest to be used through the UI (not the API), the goal is to allow developper to create HTTP response they need to handle any Payment Method. SyliusPayumBundle controller actions will be preserved to avoid any changes for existing Payum gateways.

Basic payment flow

---
title: Customer paying an order
---
flowchart TD
    A[sylius_shop_checkout_complete]
    B[sylius_shop_order_pay]
    subgraph Payment Provider
    C[External portal
    or
    custom page]
    end
    D[sylius_shop_order_after_pay]
    E[sylius_shop_order_thank_you]
    F[sylius_shop_order_show]
    A --> B
    B --> C
    C --> D
    D -- OK --> E
    D -- KO --> F
    F -- Choose another 
    payment method or retry --> B
Loading

What is the current (Sylius 1.*) URLs flow

---
title: Sylius 1.* - Customer paying an order
---
flowchart TD
    A[sylius_shop_checkout_complete] --> B[sylius_shop_order_pay]
    subgraph Payum
    C[payum_capture_do]
    D{External URL
    or
    custom page}
    end
    E[sylius_shop_order_after_pay]
    subgraph Payum after capture
    F[Payum Status
    &
    ResolveNextRoute
    ]
    end
    G[sylius_shop_order_thank_you]
    H[sylius_shop_order_show]
    B -- No payment --> G
    B --> C
    C <--> D
    D --> E
    C --> E
    E --> F
    F -- KO --> H
    F -- OK --> G
    H -- Choose another 
    payment method or retry --> B
Loading

What this PR is aiming to do

---
title: Sylius 2.* - Customer paying an order
---
flowchart TD
    A[sylius_shop_checkout_complete]
    B[sylius_shop_order_pay]
    subgraph No payment
    C[No payment processing]
    end
    subgraph Payum
    D[Keep existing Payum
    beforeCapture processing]
    end
    subgraph Payment Request
    E[Payment Request processing]
    F[Http Response processing]
    end
    G[sylius_shop_order_after_pay]
    subgraph Payum after pay
    H[Keep existing
    afterCapture processing]
    end
    subgraph Payment request after pay
    I[Payment request processing]
    J[Http response processing]
    end
    A --> B
    B --> C & D & E
    G --> H & I
    C --> K
    D --> G
    E --> F
    F --> G
    I --> J
    H -- OK --> K
    H -- KO --> L
    J -- OK --> K
    J -- KO --> L
    L -- Choose another 
    payment method or retry --> B
    K[sylius_shop_order_thank_you]
    L[sylius_shop_order_show]
Loading

Order pay phase

  • sylius.controller.payum::prepareCaptureAction dispatch action content into several services.
  • Create a more generic sylius.controller.shop.order_pay::payAction to replace the previous SyliusPayumBundle controller action.
  • Introduce PaymentRequest orderPay HTTP Response.

After pay phase

  • sylius.controller.payum::afterCaptureAction dispatch action content into several services.
  • Create a more generic sylius.controller.shop.order_pay::afterPayAction to replace the previous SyliusPayumBundle controller action.
  • Introduce PaymentRequest afterPay HTTP Response.

Global

  • Create or update tests.

@Prometee Prometee requested review from a team as code owners August 27, 2024 14:24
@probot-autolabeler probot-autolabeler bot added API APIs related issues and PRs. Maintenance CI configurations, READMEs, releases, etc. Shop ShopBundle related issues and PRs. labels Aug 27, 2024
@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 27, 2024

Bunnyshell Preview Environment deleted

Available commands:

  • /bns:deploy to redeploy the environment

@Prometee Prometee force-pushed the payment-request-ui branch 3 times, most recently from 085d460 to c799166 Compare September 9, 2024 15:26
@Prometee Prometee changed the title [WIP] Payment request UI Payment request UI Sep 17, 2024
Prometee and others added 14 commits September 20, 2024 13:22
… ShopBundle controller action

# Conflicts:
#	UPGRADE-2.0.md

# Conflicts:
#	src/Sylius/Bundle/PayumBundle/Controller/PayumController.php
#	src/Sylius/Bundle/PayumBundle/Resources/config/services/controller.xml
Co-authored-by: Jan Góralski <jan.wojciech.goralski@gmail.com>
Co-authored-by: Dmitri Perunov <diimpp@gmail.com>
Co-authored-by: Dmitri Perunov <diimpp@gmail.com>
Co-authored-by: Dmitri Perunov <diimpp@gmail.com>
Co-authored-by: Jan Góralski <jan.wojciech.goralski@gmail.com>
$paymentRequest = $this->paymentRequestFactory->create($payment, $paymentMethod);
$paymentRequest->setAction($addPaymentRequest->action);
$paymentRequest->setPayload($addPaymentRequest->payload);
$paymentRequest->setAction($addPaymentRequest->action ?? $this->defaultActionProvider->getAction($paymentRequest));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should create a SerializerContextBuilder to set the default value in the AddPaymentRequest command.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with this idea for the API part, but what about the UI :

$paymentRequest->setAction($this->defaultActionProvider->getAction($paymentRequest));
$paymentRequest->setPayload($this->defaultPayloadProvider->getPayload($paymentRequest));
?

Co-authored-by: Karol <33687392+Wojdylak@users.noreply.github.com>
$this->client->executeCustomRequest($request);
}

public function putPaymentRequest(string $paymentRequestUri, array $payload = []): void
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function putPaymentRequest(string $paymentRequestUri, array $payload = []): void
private function putPaymentRequest(string $paymentRequestUri, array $payload = []): void

Comment on lines +79 to +81
$request->setContent([
'payload' => $payload,
]);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$request->setContent([
'payload' => $payload,
]);
$request->setContent(['payload' => $payload]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be for splitting this controller into two files, per action

Comment on lines +34 to +36
$url = $this->orderPayFinalUrlProvider->getUrl(null);

return new RedirectResponse($url);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$url = $this->orderPayFinalUrlProvider->getUrl(null);
return new RedirectResponse($url);
return new RedirectResponse($$this->orderPayFinalUrlProvider->getUrl(null));

Comment on lines +43 to +44
$payment = $this->paymentToPayResolver->getLastPayment($order);
return null === $payment;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$payment = $this->paymentToPayResolver->getLastPayment($order);
return null === $payment;
$payment = $this->paymentToPayResolver->getLastPayment($order);
return null === $payment;

RequestConfiguration $requestConfiguration,
OrderInterface $order
): bool {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change


$gatewayName = $gatewayConfig->getGatewayName() ?? '';

return isset($this->payum->getGateways()[$gatewayName]);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return isset($this->payum->getGateways()[$gatewayName]);
return isset($this->payum->getGateways()[$gatewayName]);

) {
}

protected function getHttpResponseProviderIndex(PaymentRequestInterface $paymentRequest): string {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected function getHttpResponseProviderIndex(PaymentRequestInterface $paymentRequest): string {
protected function getHttpResponseProviderIndex(PaymentRequestInterface $paymentRequest): string
{

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>

<service abstract="true" id="Sylius\Bundle\CoreBundle\OrderPay\Provider\AfterPayUrlProvider" class="Sylius\Bundle\CoreBundle\OrderPay\Provider\AfterPayUrlProvider">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be for not using an FQCN as services' ids

Suggested change
<service abstract="true" id="Sylius\Bundle\CoreBundle\OrderPay\Provider\AfterPayUrlProvider" class="Sylius\Bundle\CoreBundle\OrderPay\Provider\AfterPayUrlProvider">
<service abstract="true" id="sylius.order_pay.provider.after_pay_url" class="Sylius\Bundle\CoreBundle\OrderPay\Provider\AfterPayUrlProvider">

@GSadee GSadee merged commit dd5c188 into Sylius:payment-request Sep 23, 2024
@Prometee Prometee deleted the payment-request-ui branch September 23, 2024 12:17
@Prometee Prometee changed the title Payment request UI [Payment request] Order pay via the UI Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API APIs related issues and PRs. Maintenance CI configurations, READMEs, releases, etc. Shop ShopBundle related issues and PRs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants