Skip to content

Commit

Permalink
Add cartId handling and clarify payment process.
Browse files Browse the repository at this point in the history
Introduced `cartId` as part of the payment flow to ensure complete payment context, updating associated DTOs, services, and return URLs. Additionally, enhanced documentation with Apple Pay and Google Pay setup details, and clarified webhook and return URL behaviors.
  • Loading branch information
aaronmezarguez committed Jan 30, 2025
1 parent 282b076 commit c974de5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ Regarding the development of processor module, please refer to the following doc
The following webhooks are currently supported and the payment transactions in commercetools are:
- **payment_intent.canceled**: Modified the payment transaction Authorization to Failure and create a payment transaction CancelAuthorization: Success
- **payment_intent.succeeded**: Creates a payment transaction Charge: Success.
- **payment_intent.requires_action**: Modify the payment transaction Authorization to Pending.
- **payment_intent.payment_failed**: Modify the payment transaction Authorization to Failure.
- **payment_intent.requires_action**: Logs the information in the connector app inside the Processor logs.
- **charge.refunded**: Create a payment transaction Refund to Success, and a Chargeback to Success.
- **charge.succeeded**: Logs the information in the connector app inside the Processor logs.
- **charge.succeeded**: If the charge is not captured, create the payment transaction to Authorization:Success.
- **charge.captured**: Logs the information in the connector app inside the Processor logs.


Expand Down
30 changes: 30 additions & 0 deletions enabler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,36 @@ This module provides an application based on [commercetools Connect](https://doc

PSPs provide libraries that can be used on client side to load on browser or other user agent which securely load DOM elements for payment methods and/or payment fields inputs. These libraries take control on saving PAN data of customer and reduce PCI scopes of the seller implementation. Now, with the usage of `enabler`, it allows the control to checkout product on when and how to load the `enabler` as connector UI based on business configuration. In cases connector is used directly and not through Checkout product, this connector UI can be loaded directly on frontend than the libraries provided by PSPs.

## Considerations for Apple Pay and Google Pay

### Apple Pay Requirements
To enable Apple Pay, you must ensure the following conditions are satisfied:

1. The website must include a `https://www.website.com/.well-known/apple-developer-merchantid-domain-association` call that redirects to:
```text
{COMMERCETOOLS_PROCESSOR_URL}/applePayConfig
```
This endpoint retrieves the required merchant ID domain association file. For more details, refer to Stripe’s official [Apple Pay domain association documentation](https://support.stripe.com/questions/enable-apple-pay-on-your-stripe-account).

2. The environment and devices must meet Apple Pay testing requirements:
- You need an **iOS device** running iOS 11.3 or later, or a **Mac** running macOS 11.3 or later with Safari.
- The browser must be configured with an active card in the Apple Wallet in sandbox mode.
- A valid Stripe account must be linked with Apple Pay and properly configured.
- All webpages hosting an Apple Pay button are HTTPS.

3. Make sure your Stripe account has Apple Pay enabled (this is configured via your Stripe dashboard).

### Google Pay Requirements
To enable Google Pay, you must ensure the following conditions are satisfied:

1. The device and browser requirements for testing Google Pay are met:
- Use a **Chrome browser** on any device (mobile or desktop) supporting Google Pay.
- Add a payment method (card) to your Google Pay account and ensure your testing environment is set up for sandbox mode.

2. Additional configuration for your Stripe account:
- Ensure **Google Pay** is enabled via your Stripe dashboard.
- Stripe automatically manages domain validation for Google Pay—manual setup is not required.


## Getting Started
Please run following npm commands under `enabler` folder for development work in local environment.
Expand Down
5 changes: 3 additions & 2 deletions enabler/src/dropin/dropin-embedded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export class DropinComponents implements DropinComponent {
errors : processorError,
sClientSecret : client_secret,
paymentReference: paymentReference,
merchantReturnUrl: merchantReturnUrl } = await fetch(`${this.baseOptions.processorUrl}/payments`,{
merchantReturnUrl: merchantReturnUrl,
cartId: cartId} = await fetch(`${this.baseOptions.processorUrl}/payments`,{
method : "GET",
headers : {
"Content-Type": "application/json",
Expand All @@ -86,7 +87,7 @@ export class DropinComponents implements DropinComponent {
elements: this.baseOptions.elements,
clientSecret: client_secret,
confirmParams : {
return_url : merchantReturnUrl
return_url : merchantReturnUrl+`?cartId=${cartId}&paymentReference=${paymentReference}`
},
redirect : "if_required"
});
Expand Down
3 changes: 2 additions & 1 deletion processor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ N/A
#### Response Parameters
- **sClientSecret**: The client secret is used to complete the payment from your frontend.
- **paymentReference**: The payment reference of the current process.
- **merchantReturnUrl**: The return url used in the parameter return_url of the Stripe [confirmPayment](https://docs.stripe.com/js/payment_intents/confirm_payment).
- **merchantReturnUrl**: The URL used as the `return_url` parameter in Stripe's [confirmPayment](https://docs.stripe.com/js/payment_intents/confirm_payment) process. This URL will have the `paymentReference` and `cartId` appended to it after payment confirmation.
- **cartId**: The cartId of the current proccess.

### Confirm the Payment Intent to commercetools
This endpoint update the initial payment transaction in commercetools. It is called after the Stripe confirm the payment submit was successful.
Expand Down
1 change: 1 addition & 0 deletions processor/src/dtos/stripe-payment.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const PaymentResponseSchema = Type.Object({
sClientSecret: Type.String(),
paymentReference: Type.String(),
merchantReturnUrl: Type.String(),
cartId: Type.String(),
});

export const ConfigElementResponseSchema = Type.Object({
Expand Down
1 change: 1 addition & 0 deletions processor/src/services/stripe-payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export class StripePaymentService extends AbstractPaymentService {
sClientSecret: paymentIntent.client_secret ?? '',
paymentReference: ctPayment.id,
merchantReturnUrl: merchantReturnUrl,
cartId: ctCart.id,
};
}

Expand Down
1 change: 1 addition & 0 deletions processor/test/utils/mock-routes-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ export const mockRoute__payments_succeed: PaymentResponseSchemaDTO = {
sClientSecret: 'mock_paymentReference',
paymentReference: 'mock_paymentReference',
merchantReturnUrl: 'mock_merchantReturnUrl',
cartId: 'mockCartId',
};

export const mockRoute__paymentsComponents_succeed: SupportedPaymentComponentsSchemaDTO = {
Expand Down

0 comments on commit c974de5

Please sign in to comment.