Skip to content

Commit

Permalink
36803 - added sequence diagram and slightly modified readme text
Browse files Browse the repository at this point in the history
  • Loading branch information
LiudmylaMasliuk committed Jul 19, 2024
1 parent e17ad18 commit a394642
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 5 deletions.
18 changes: 13 additions & 5 deletions docs/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
</a><br>
</p>

In this folder you can find the example workflows for the PayPal commercetools connector. Here we summarize the actual workflows for both using only the connector for the backend side implementation and using the [PayPal client](https://www.npmjs.com/package/paypal-commercetools-client) in commercetools Frontend (CoFe) [integration](https://github.com/mediaopt/paypal-commercetools-cofe-integration/tree/main) and the expected results. The workflow that only includes backend calls through Postman is also provided as a [workflow Postman Collection](PayPal-commercetools-workflow.postman_collection.json).
In this folder you can find simplified example workflows for the PayPal commercetools connector, which should be sufficient to reproduce demonstrated payments. For all details please refer to [Architecture.pdf](../Architecture.pdf).

Here we summarize the actual workflows for:
1. using only the connector for the backend side implementation
2. using the [PayPal client](https://www.npmjs.com/package/paypal-commercetools-client) in commercetools Frontend (CoFe) [integration](https://github.com/mediaopt/paypal-commercetools-cofe-integration/tree/main).

The workflow that only includes backend calls through Postman is also provided as a [workflow Postman Collection](PayPal-commercetools-workflow.postman_collection.json).

The sequence diagram that show a bit more details about the backend side of a payment process with PayPal buy now payment is also provided at [sequence_diagram_paypal_payment.md](sequence_diagram_paypal_payment.md).

# Table of Contents

Expand All @@ -25,13 +33,13 @@ In this folder you can find the example workflows for the PayPal commercetools c
- [Rendering payment buttons](#rendering-payment-buttons)
- [Payment methods parameters](#payment-methods-parameters)
- [Payment method dependent flow](#payment-method-dependent-flow)
- [PayPal PayPal buy now](#paypal-buy-now)
- [PayPal buy now](#paypal-buy-now)
- [Card](#card)
- [Pay Upon Invoice](#pay-upon-invoice-1)

# Installation

For installation of CoFe please refer to [commercetools official documentation](https://commercetools.com/products/frontend). If you prefer to use the PayPal JS SDK instead of the PayPal client app, please refer to [PayPal official documentation](https://developer.paypal.com/sdk/js/)
For installation of CoFe please refer to [commercetools official documentation](https://commercetools.com/products/frontend). If you prefer to use the PayPal JS SDK instead of the PayPal client app, please refer to [PayPal official documentation](https://developer.paypal.com/sdk/js/).

## Connector installation

Expand Down Expand Up @@ -112,7 +120,7 @@ Pay Upon invoice is the simplest as the payment is not processed immediately.

## Standard flow

In this section we describe the flow that is used at our [demo website](https://poc-mediaopt2.frontend.site/) where the PayPal client is integrated into CoFe and the connector is installed at the merchant center. It is important to note that the CoFe project structure involves two separate parts - frontend and backend and [our integration](https://github.com/mediaopt/paypal-commercetools-cofe-integration/tree/main/packages/poc) involves both of them.
In this section we describe the flow that is used at our [demo website](https://poc-mediaopt2.frontend.site/) where the PayPal client is integrated into CoFe and the connector is installed at the merchant center. It is important to note that the CoFe project structure involves two separate parts - frontend and backend and [our integration](https://github.com/mediaopt/paypal-commercetools-cofe-integration/tree/main/packages/poc) involves both of them. Frontend is responsible for a client side and backend for the server (see also [Architecture.pdf](../Architecture.pdf)).

In our integration the PayPal client components are imported at [CoFe frontend](https://github.com/mediaopt/paypal-commercetools-cofe-integration/tree/main/packages/poc/frontend) and the API required for proper communication between the components and commercetools HTTP API ((and therefore the PayPal commercetools connector) is developed at the [CoFe backend](https://github.com/mediaopt/paypal-commercetools-cofe-integration/tree/main/packages/poc/backend).

Expand All @@ -123,7 +131,7 @@ Here we will describe the [checkout payment](https://github.com/mediaopt/paypal-
### Rendering payment buttons

| Step | performed at | description |
| ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 | CoFe frontend [formPayment](https://github.com/mediaopt/paypal-commercetools-cofe-integration/blob/main/packages/poc/frontend/components/commercetools-ui/checkout/checkout-form/fields/formPayment.tsx) | all necessary payment methods are imported from the package:<br>`import { PayPal, PayUponInvoice, CardFields, ApplePay, GooglePay } from 'paypal-commercetools-client/dist/esm';` |
| 2 | CoFe frontend [actions](https://github.com/mediaopt/paypal-commercetools-cofe-integration/blob/main/packages/poc/frontend/frontastic/actions/paypal/index.ts) | the getSettings is called. It actually uses [commercetools frontend api action](https://docs.commercetools.com/frontend-api/action) and addresses CoFe backend |
| 3 | CoFe backend [SettingsController](https://github.com/mediaopt/paypal-commercetools-cofe-integration/blob/main/packages/poc/backend/payment-paypal/actionControllers/SettingController.ts) | commercetools HTTP API is used to obtain PayPal settings (see also the [PayPal Postman collection](https://github.com/mediaopt/paypal-commercetools-connector/blob/main/docs/paypal.postman_collection.json) getSettings call). |
Expand Down
53 changes: 53 additions & 0 deletions docs/workflows/sequence_diagram_paypal_payment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Here we present a simplified sequence diagram for payment process with PayPal buy now payment. For full detailed process please refer to [Architecture.pdf](../Architecture.pdf).

In this diagram we focus on the interaction with the PayPal commercetools connector and PayPal client app required to complete the payment.

The communication between commercetools frontend (CoFe) and commercetools HTTP API (CoCo) that is not related directly to the payment with PayPal is not shown in this diagram. In brief CoFe has built in routines to update the cart and the payment whenever they might have being changed.

The official documentation for the API mentioned it the diagram can be found at [commercetools Frontend API's](https://docs.commercetools.com/frontend-api/action), [commercetools HTTP API](https://docs.commercetools.com/http-api), and [PayPal orders v2 API](https://developer.paypal.com/docs/api/orders/v2/).

```mermaid
sequenceDiagram
title PayPal payment flow
box CoFe
participant frontend as frontend/client app
participant backend
end
participant CoCo as CoCo/connector (extension)
Note over frontend,backend: commercetools Frontend API
Note over backend, CoCo: commercetools HTTP API,<br/> connector: endpoint custom-objects <br/>or action custom fields
Note over CoCo, PayPal: PayPal orders v2 API
frontend-->>backend: getSettings action
backend-->>CoCo: getSetting request
Note over backend, CoCo: endpoint >custom-objects/<br/>paypal-commercetools-connector
CoCo-->>backend: GetSettingsResponse
backend-->>frontend: GetSettingsResponse, Session data
frontend-->>backend: createPayment action
backend-->>CoCo: createPayment request
note over backend, CoCo: paymentInterface: 'PayPal'
CoCo-->>backend: createPayment response
backend-->>CoCo: updateCart request
note over backend, CoCo: action addPayment
CoCo-->>backend: updateCart response
backend-->>frontend: cart data, payment data, session data
frontend-->>frontend: render payment component(s)
frontend-->>frontend: user clicks on buy now button
frontend-->>backend: createOrder action.
backend-->>CoCo: createPayPalOrder request
Note over backend, CoCo: endpoint payments/{{payment-id}}<br/>action setCustomField
CoCo-->>PayPal: PayPal createOrder request
PayPal-->>CoCo: PayPal createOrder response
CoCo-->>CoCo: update payment request
CoCo-->>backend: createPayPal order response
backend-->>frontend: createPayPal order response, payment data
create participant window as PayPal floating window
frontend-->>window: PayPal order data
window-->>window: user approves the payment
destroy window
window-->>frontend: order approve
frontend-->>backend: captureOrder action
backend-->>CoCo: capturePayPal order request
Note over backend, CoCo: endpoint payments/{{payment-id}}<br/>action setCustomField
CoCo-->>backend: capturePayPal order response
backend-->>frontend: capturePayPal order response, payment data
```

0 comments on commit a394642

Please sign in to comment.