Skip to Content
Docs
E-commerce pluginscommercetools

Set up the commercetools connector

Deploy the Pay.com connector in commercetools Connect, connect it to your Pay.com account, mount it in your storefront, and take a test payment.

The Pay.com connector for commercetools adds Pay.com payments to a storefront built on Composable Commerce. Deploy it in commercetools Connect, connect it to your Pay.com account, mount its browser component in your storefront, and take a test payment in the sandbox. What the connector does once it's running is in commercetools connector.

Requirements

Your storefront's backend creates a commercetools session for each cart, with an API client that has the manage_sessions scope.

RequirementVersion
commercetoolsA Composable Commerce project with Connect and the Merchant Center
Connector0.1.0

Deploy and connect

The connector takes an API key, created in the Pay.com dashboard, for each environment you use.

  1. 1

    Deploy the connector

    In commercetools Connect, deploy the Pay.com connector with the configuration in Settings, and give its API client the scopes listed there. The deployment has five applications: service (the API your storefront and Pay.com call), event, job, enabler (the browser component), and mc-app (the Pay.com application for the Merchant Center). Once deployed, the connector creates its custom types and review states, and its subscription to your project's messages.

  2. 2

    Register the Pay.com application

    In the Merchant Center, register a custom application with the entry point pay-com, and enter the mc-app application's URL as its application URL. Give its ID to the mc-app application's CUSTOM_APPLICATION_ID, and the service application's URL to its PAY_COM_SERVICE_URL. Then give your teams the application's View permission, and Manage to those who change its settings and decide held payments.

  3. 3

    Enter your API keys

    In the deployment's secured configuration, set PAY_COM_SANDBOX_API_KEY to an sk-pay-com-sandbox- key you created in the Pay.com dashboard, and PAY_COM_LIVE_API_KEY to an sk-pay-com-live- key when you take live payments. Under Connect with Pay.com, the Pay.com application shows whether Pay.com accepts the key of the environment PAY_COM_ENVIRONMENT picks. When that environment has no key, it names the variable to set. See Settings.

  4. 4

    Add the webhook

    In the Pay.com dashboard, add a webhook that sends events to the service application's /webhooks/pay-com endpoint, then set its signing secret as PAY_COM_SANDBOX_WEBHOOK_SECRET or PAY_COM_LIVE_WEBHOOK_SECRET. Do this for each environment you use, and subscribe to the 12 plugin webhook events.

  5. 5

    Create a session for the cart

    When the customer reaches the payment step, your storefront's backend creates a commercetools session for their cart, with the service application's URL as processorUrl, and gives the browser its ID:

    curl -X POST "https://session.europe-west1.gcp.commercetools.com/<project-key>/sessions" \
      -H "Authorization: Bearer <access-token>" \
      -H "Content-Type: application/json" \
      -d '{
        "cart": { "cartRef": { "id": "<cart-id>" } },
        "metadata": {
          "processorUrl": "<service-url>",
          "merchantReturnUrl": "https://shop.example.com/checkout/complete"
        }
      }'

    merchantReturnUrl is where the customer lands after paying, and futureOrderNumber in metadata sets the order's number.

  6. 6

    Mount the payment form

    Load the browser component from the enabler application, <enabler-url>/pay-com-enabler.js, and mount it with the session's ID:

    const enabler = new PayComEnabler({ processorUrl: '<service-url>', sessionId, onError: showMessage })
    const payment = await enabler.mount({
      dropIn: '#pay-com',
      fields: {
        inputs: { number: '#card-number', expiry: '#card-expiry', cvv: '#card-cvv' },
        card: '#card',
        methods: '#methods',
        inheritStyleFrom: '#email'
      }
    })
    placeOrderButton.onclick = () => payment.submit()
    backToCart.onclick = () => payment.release()

    Configure how the browser component mounts and handles checkout events:

    • Card fields vs. Universal checkout: With card fields (the default Payment form), card details are entered in secure Pay.com frames styled to match your storefront. inputs defines the card field mount targets, card wraps them, inheritStyleFrom copies styling from an existing input, and methods renders the list of available payment methods. Payment methods that require extra inputs (such as a BLIK code or bank selection) render below the list, styled by <enabler-url>/pay-com-method-fields.css. Mounting without fields, or selecting Pay.com drop-in, renders Pay.com's Universal checkout inside dropIn. See Checkout.
    • Submitting and releasing the cart: Call submit() to validate and lock the cart before paying. Call release() before the customer edits the cart so the connector unlocks it.
    • Separate payment method options: Pass separate: true to show each payment method as its own option. Render the items returned by await enabler.paymentOptions() (each includes a name and optional logo) and call payment.select(type) when the customer picks one. The other option covers methods listed in methods (with Universal checkout, only the card option appears). If an option includes fields (such as BLIK), provide a mount element through fields.methodFieldsFor(type) or the method can't be selected.
    • Wallets in the method list: Add wallets: { container: '#wallet-button', inList: true } to fields to list Apple Pay and Google Pay with your payment methods. When a customer selects a wallet, its button renders in container in place of your place-order button. Pass onMethodChange to mount() and hide your button whenever it reports wallet: true. After shipping or coupon updates, call payment.updateTotal(total) to update the wallet total.
    • Express checkout buttons: Call enabler.express('#express') on the cart page, enabler.express('#express', { product: { sku, quantity } }) on a product page, or enabler.express('#checkout-express', { location: 'checkout' }) at the top of checkout (using the same enabler instance as the payment form). If express checkout is disabled or checkout requires a field the wallet can't supply, express() hides its container.
    • Return URL parameters: After payment, the customer returns to merchantReturnUrl with paymentReference, result (succeeded, open, failed, or review), and, once the order exists, orderNumber. Look up the order using your storefront's own credentials, as these query parameters aren't credentials.
  7. 7

    Take a test payment

    PAY_COM_ENVIRONMENT is sandbox by default, so the connector takes payments in the sandbox. Place an order with a test card, then set PAY_COM_ENVIRONMENT to live and redeploy to take live payments.

Next steps

  • Apple Pay: Pass the domain association file on and register your storefront's domain to show the Apple Pay button.
  • commercetools connector: What the connector supports, how orders stay in sync with Pay.com, and the data the connector sends.
  • Settings: Every setting with its default.
Was this page helpful?