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.
| Requirement | Version |
|---|---|
| commercetools | A Composable Commerce project with Connect and the Merchant Center |
| Connector | 0.1.0 |
Deploy and connect
The connector takes an API key, created in the Pay.com dashboard, for each environment you use.
- 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), andmc-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
Register the Pay.com application
In the Merchant Center, register a custom application with the entry point
pay-com, and enter themc-appapplication's URL as its application URL. Give its ID to themc-appapplication'sCUSTOM_APPLICATION_ID, and theserviceapplication's URL to itsPAY_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
Enter your API keys
In the deployment's secured configuration, set
PAY_COM_SANDBOX_API_KEYto ansk-pay-com-sandbox-key you created in the Pay.com dashboard, andPAY_COM_LIVE_API_KEYto ansk-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 environmentPAY_COM_ENVIRONMENTpicks. When that environment has no key, it names the variable to set. See Settings. - 4
Add the webhook
In the Pay.com dashboard, add a webhook that sends events to the
serviceapplication's/webhooks/pay-comendpoint, then set its signing secret asPAY_COM_SANDBOX_WEBHOOK_SECRETorPAY_COM_LIVE_WEBHOOK_SECRET. Do this for each environment you use, and subscribe to the 12 plugin webhook events. - 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
serviceapplication's URL asprocessorUrl, 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" } }'merchantReturnUrlis where the customer lands after paying, andfutureOrderNumberinmetadatasets the order's number. - 6
Mount the payment form
Load the browser component from the
enablerapplication,<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.
inputsdefines the card field mount targets,cardwraps them,inheritStyleFromcopies styling from an existing input, andmethodsrenders 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 withoutfields, or selecting Pay.com drop-in, renders Pay.com's Universal checkout insidedropIn. See Checkout. - Submitting and releasing the cart: Call
submit()to validate and lock the cart before paying. Callrelease()before the customer edits the cart so the connector unlocks it. - Separate payment method options: Pass
separate: trueto show each payment method as its own option. Render the items returned byawait enabler.paymentOptions()(each includes anameand optionallogo) and callpayment.select(type)when the customer picks one. Theotheroption covers methods listed inmethods(with Universal checkout, only the card option appears). If an option includesfields(such as BLIK), provide a mount element throughfields.methodFieldsFor(type)or the method can't be selected. - Wallets in the method list: Add
wallets: { container: '#wallet-button', inList: true }tofieldsto list Apple Pay and Google Pay with your payment methods. When a customer selects a wallet, its button renders incontainerin place of your place-order button. PassonMethodChangetomount()and hide your button whenever it reportswallet: true. After shipping or coupon updates, callpayment.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, orenabler.express('#checkout-express', { location: 'checkout' })at the top of checkout (using the sameenablerinstance 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
merchantReturnUrlwithpaymentReference,result(succeeded,open,failed, orreview), and, once the order exists,orderNumber. Look up the order using your storefront's own credentials, as these query parameters aren't credentials.
- 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.
- 7
Take a test payment
PAY_COM_ENVIRONMENTissandboxby default, so the connector takes payments in the sandbox. Place an order with a test card, then setPAY_COM_ENVIRONMENTtoliveand 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.