Skip to content

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

1 watching

Forks

Repository files navigation

build test audit

commercetools logo
PayPal logo

This is a connect application to integrate PayPal payment methods and package tracking into Commercetools. It follows the folder structure to ensure certification & deployment from commercetools connect team as stated here.

PayPal commercetools connector is available in the commercetools marketplace.

The payments demo can be seen at https://poc-mediaopt2.frontend.site/.

Latest release notes

Refer to the GitHub repository release notes for the comprehensive list of connector releases and changelogs. The latest release tag is the same as the version of the connector available in the Commercetools Merchant Center.

Release notification

If you would like to be notified whenever a new certified version is released, please subscribe to the release event in this repository by clicking Watch -> Custom -> Releases -> Apply.

Integration

The connector consists of five applications.

Composable Commerce mode (backend-intended):

  • paypal-commercetools-extension: backend link between commercetools and PayPal
  • paypal-commercetools-events: syncs commercetools entities with PayPal events
  • paypal-commercetools-custom-application: allows to control some payment settings and frontend components design from merchant center

commercetools Checkout mode:

  • enabler: frontend payment components
  • processor: backend-for-frontend for enabler

The modes are compatible with each other and intended to be shipped together. Checkout payments can be fine-tuned via the extension module beyond what Checkout itself permits, are updated by the events module when a relevant action happens on the PayPal side, and the Checkout components' design can be adjusted in the custom application.

See docs/README.md for a detailed description of each application.

An integration example is available on the demo website.

enabler replaces the discontinued npm client. Merchants not using commercetools Checkout can still host its components themselves (called legacy mode in this documentation), or use the PayPal JS SDK directly. Due to commercetools Checkout limitations, the following features are currently supported in legacy mode only:

  • vaulting a payment method without a payment ("pure vault")
  • storing PayPal and Venmo payment methods for future use (storing credit cards is fully supported in Checkout mode as well)
  • multiple shipping mode, which has limited support in general

If you want to use these features in commercetools Checkout, please open an issue.

See enabler/README.md for how legacy mode differs from Checkout mode.

Prerequisites

To use the connector you need to have the following:

  • commercetools Composable Commerce account and API client credentials, namely:
credential environmental variable description
region CTP_REGION region, in which your commercetools project is hosted
project key CTP_PROJECT_KEY the key of your commercetools project
client ID CTP_CLIENT_ID the ID of your commercetools API client
client secret CTP_CLIENT_SECRET the secret of your commercetools API client
scope CTP_SCOPE the scope of your commercetools API client
credential environmental variable description
client ID PAYPAL_CLIENT_ID the ID of your PayPal API client
client secret PAYPAL_CLIENT_SECRET the secret of your PayPal API client
environment PAYPAL_ENVIRONMENT the environment of your PayPal API client (production or sandbox)

Optionally for sending PayPal Pay Upon Invoice custom emails please provide SMTP credentials:

  • SMTP_HOST
  • SMTP_PORT
  • SMTP_USERNAME
  • SMTP_SENDER
  • SMTP_PASSWORD

Additionally for checkout mode (processor), see connect.yaml for the full list:

environmental variable required description
CTP_AUTH_URL yes commercetools Auth URL, e.g. https://auth.europe-west1.gcp.commercetools.com
CTP_API_URL yes commercetools API URL, e.g. https://api.europe-west1.gcp.commercetools.com
CTP_SESSION_URL yes commercetools Session API URL, e.g. https://session.europe-west1.gcp.commercetools.com
CTP_CHECKOUT_URL yes commercetools Checkout API URL, e.g. https://checkout.europe-west1.gcp.commercetools.com
CTP_JWKS_URL yes JWKs URL for JWT validation, e.g. https://mc-api.europe-west1.gcp.commercetools.com/.well-known/jwks.json
CTP_JWT_ISSUER yes JWT issuer for JWT validation, e.g. https://mc-api.europe-west1.gcp.commercetools.com

See processor/.env.template for the format and defaults of the JSON variables and for the optional variables.

The commercetools API client used by processor needs at least the following scopes (the processor health check fails otherwise): manage_payments, view_sessions, view_api_clients, manage_orders, introspect_oauth_tokens, manage_checkout_payment_intents, manage_types, plus manage_payment_methods if stored payment methods are enabled.

If you already use custom types for commercetools payment, customer or payment_interaction please consider using the corresponding types keys for PAYMENT_TYPE_KEY, CUSTOMER_TYPE_KEY and PAYMENT_INTERACTION_TYPE_KEY. Please see the corresponding commercetools tutorial for details.

Instructions

Merchant center application

This step is required if the connector is deployed through the commercetools Merchant Center or through the commercetools Connect API.

  • create a custom application draft. The connector app later will be hosted by commercetools, so no valid application url is actually needed.
  • use the entry point URI path that you selected and custom application id (available after registering the app) to deploy the connector.
  • after the connector is deployed, the application can be accessed in the custom applications installations.

Deployment through commercetools

The connector can be installed directly from the commercetools marketplace or deployed from github repository via commercetools Connect API.

Local running

Composable Commerce mode

To run the connector locally for test purposes:

  • cd paypal-commercetools-extension or cd paypal-commercetools-events
  • run npm install to install the dependencies
  • insert commercetools and PayPal credentials to .env file
  • for paypal-commercetools-extension run ./bin/ngrok.sh to start ngrok and insert the dynamic url in the .env file as specified in post-deploy script
  • for paypal-commercetools-extension run npm run connector:post-deploy to register the extension with the public ngrok url
  • run npm run start:dev to build the application

Checkout mode

  • in both processor and enabler run cp .env.template .env and fill in the values
  • build the shared module: cd common-connect, npm install, npm run build
  • from the repository root run docker compose up to start:
    • the local JWT mock server (http://localhost:9002)
    • the processor (http://localhost:8080)
    • the enabler development page (http://localhost:3000)
  • open http://localhost:3000, enter a cart id and the page creates a commercetools session and mounts the payment components

docker-compose.yaml overrides CTP_JWKS_URL, CTP_JWT_ISSUER (https://issuer.com) and VITE_PROCESSOR_URL, so their .env values are not used locally. See processor/README.md for authentication details, including how to get a local JWT.

In production the Payment Intents API is called on commercetools' own Checkout host, which forwards to the processor's POST /operations/payment-intents/:id route. Locally there's no Checkout host in front of the processor, so that route can be called directly for testing. Note, that on stage/production commercetools order is required to reach the intents API.

Hosting externally

Please set your application url (see the example in ngrok.sh) in the .env file and run post-deploy script. The url should be accessible externally.

Using the connector without Checkout mode

If you deploy the connector yourself (via the commercetools Connect API or other services), you can remove processor and enabler from connect.yaml and the repository to speed up the installation. common-connect must remain, as the extension module depends on it. If you use a package manager other than npm (e.g. yarn), replace the "common-connect": "file:../common-connect" dependency in paypal-commercetools-extension (and processor, if kept) with your package manager's equivalent (for yarn: "common-connect": "link:../common-connect").

Checkout mode installation and configuration

The processor is designed to be driven by the enabler only. The one part of its API meant to be triggered by the merchant is the Payment Intents API (capturePayment, cancelPayment, refundPayment), called on commercetools' own Checkout host (checkout.<region>.commercetools.com/{projectKey}/payment-intents/{paymentId}) — never on the processor directly. See enabler/README.md for how capture works after a PayPal Express review redirect.

To use the commercetools Checkout compatible track (processor/enabler), create a checkout application in the merchant center. In the application payment integrations you can select this connector and configure the payment methods available. Apart from Pay Upon Invoice and Venmo, the connector does not restrict which payment methods are offered to a buyer by country or currency — this is your responsibility to configure, via a payment integration predicate, in the merchant center → checkout application → payment integration screen.

Payment methods and their restrictions

Category Method checkout reference Recommended predicate
Standard PayPal paypal None needed
Standard Credit Card (CardFields) card None needed
Standard SEPA (Sepa) Sepa¹ must be determined based on PayPal merchant settings
Standard Pay Later (PayLater) PayLater¹ billingAddress.country = "AU" or billingAddress.country = "US" or billingAddress.country = "FR" or billingAddress.country = "DE" or billingAddress.country = "IT" or billingAddress.country = "ES" or billingAddress.country = "GB"
Standard Credit Card button (PayPalCreditCard)² PayPalCreditCard¹ None needed
Standard All funding sources (AllButtons) AllButtons¹ None needed
Standard Venmo Venmo¹ billingAddress.country = "US" and totalPrice.currencyCode = "USD"
Express PayPal Buy Now (via the express builder) paypal None needed
Standard Pay Upon Invoice PayUponInvoice³ billingAddress.country = "DE" and totalPrice.currencyCode = "EUR"

¹ Sepa, PayLater, PayPalCreditCard, AllButtons, and Venmo don't have a commercetools Checkout key yet, so no UI defaults are provided at the moment in merchant center. Some of these methods are supposed to be included in future commercetools releases and when the proper key will be available the merchant center reference will be set to match.

² Only one of Credit Card (CardFields) and Credit Card button (PayPalCreditCard) can work at the same time, and PayPal officially recommends Credit Card (CardFields). If you require Credit Card button (PayPalCreditCard), please consult your PayPal manager.

³ Pay Upon Invoice requires PayPal intent "Capture" and forces it even if the intent for connector is set to "Authorize" for all other methods. Also it has limitation for minimal and maximal cart price, which will be forced automatically.

Configure these via payment integration predicates. The "Recommended predicate" column above shows a starting point for each method — real-world eligibility (e.g. Pay Later's exact country/currency pairing) can vary by merchant account and change over time, so verify against your own PayPal account before relying on it in production.

PayPal Express asks the buyer for a delivery address only when the cart has a shipping address (at least its country). Without one, the cart is treated as digital goods only. See enabler/README.md for how to configure it.

Venmo's browser/device support (Safari on iOS or Chrome on Android; any browser on desktop) is the one exception the connector does enforce itself, not something you need a predicate for — see enabler/README.md's "Venmo eligibility is not enforced by the payment-method list" section for details.

A practical way to check which of PayPal buttons based methods are actually enabled for your PayPal account is to temporarily add the AllButtons method to your payment integration with no predicate — PayPal's own SDK only ever renders funding sources it currently considers eligible for that account/currency, so whichever of Sepa/PayLater/PayPalCreditCard/Venmo/etc. actually show up there are the ones genuinely available; anything missing was already ineligible before any predicate could help. Keeping the payment integration accurate is your responsibility: leave out entirely any method you don't intend to accept, and use the recommended predicate above for any conditional method you do want to offer.

Stored payment methods

Only credit cards can be stored and reused in Checkout mode. To enable it:

  1. set STORED_PAYMENT_METHODS_ENABLED=true and optionally STORED_PAYMENT_METHODS_PAYMENT_INTERFACE (default PayPal) and STORED_PAYMENT_METHODS_INTERFACE_ACCOUNT;
  2. give the processor's API client the additional manage_payment_methods scope;
  3. make sure cart.customerId is set before Checkout is instantiated.

Changing the payment interface or interface account later means previously stored cards are no longer found and would need to be migrated manually. See enabler/README.md for the Checkout behavior of stored cards.

Technology Stack

The connector is written in TypeScript and npm is used as the package manager.

Contributing

Feel free to contribute to the project by opening an issue.

Additional information

In the docs folder you can find:

  • description of each application included (README.md)
  • architecture of the connector (Architecture.pdf)
  • documented PayPal Commercetools API Postman collection (PayPal.md, paypal.postman_collection.json)
  • workflows folder with examples how to use the connector individually or together with PayPal client and commercetools frontend

Limited Support: Multiple Shipping Mode

The connector provides limited support for the Multiple shipping mode in commercetools in legacy mode only. This feature is supported only for project level setting "totalPriceDiscountDoesNotReduceExternalTax": false, prices "type": "centPrecision" (lineItem variant prices can be any type) and a specific set of Cart level settings listed below.

Name Value
taxMode Platform
taxRoundingMode HalfEven
taxCalculationMode LineItemLevel
discountTypeCombination Stacking
shippingMode Multiple

If your use case requires a different set of parameters, please request it by opening an issue or contacting us directly.

Using this feature outside the supported parameter set is entirely at your own risk — any issues arising from unsupported configurations are your responsibility to resolve.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages