<!-- canonical: https://docs.costplus.io/docs/plugins/drupal-commerce -->

> Integrate Cost+ with your Drupal Commerce store using the official payment gateway module
<div style={{background: 'white', borderRadius: '8px', padding: '1rem', display: 'inline-block', marginBottom: '1rem'}}>
  <img src="/images/logos/drupal-commerce.png" alt="Drupal Commerce" style={{height: '48px', width: 'auto'}} />
</div>

Integrate Cost+ as a payment method in your Drupal Commerce store. The official **NoPayn Payment Gateway** module uses the Hosted Payment Page flow, so no card data touches your server — fully PCI DSS compliant.

## Prerequisites

- Active Cost+ merchant account
- Drupal 10 or 11
- Drupal Commerce 3.x
- PHP 8.1 or later
- Admin access to your Drupal site

## Supported Payment Methods

- **Credit / Debit Card** — Visa, Mastercard, and more
- **Apple Pay**
- **Google Pay**
- **Vipps / MobilePay**

## 1. Install the Module

Copy the `commerce_nopayn` module into your Drupal installation and enable it:

```bash
cp -r commerce_nopayn /path/to/drupal/web/modules/custom/
drush en commerce_nopayn -y
drush cr
```

> [!NOTE]
> You can also download the module directly from the [GitHub repository](https://github.com/NoPayn/nopayn-drupal-commerce).

## 2. Add a Payment Gateway

1. Navigate to **Commerce → Configuration → Payment gateways** (`/admin/commerce/config/payment-gateways`)
2. Click **Add payment gateway**
3. Select **NoPayn Payment Gateway** as the plugin

## 3. Configure the Gateway

Enter the following settings:

- **NoPayn API Key** — Your merchant API key from the [Merchant Portal](https://dashboard.costplus.io/)
- **Payment Methods** — Enable or disable Credit Card, Apple Pay, Google Pay, Vipps MobilePay
- **Mode** — Set to **Test** when using an API key from a sandbox website, or **Live** when using a production website key

> [!WARNING]
> Only activate the payment methods you have been approved for and received confirmation for.

### Optional Settings

- **Manual Capture** — Authorize credit card payments without immediate capture (funds are reserved, then captured when the order is fulfilled)
- **Debug Logging** — Enable to log all API requests and responses to the Drupal log for troubleshooting

Click **Save** when done.

## 4. Payment Flow

Once configured, the payment flow works as follows:

1. Customer adds products to cart and proceeds to checkout
2. At the payment step, enabled Cost+ methods are shown as radio buttons
3. Customer selects a method and confirms the order
4. The module creates an order via the Cost+ API and redirects to the hosted payment page
5. Customer completes payment on the Cost+ page
6. Customer returns to the store — payment is verified via API
7. A webhook from Cost+ asynchronously confirms the payment result

> [!TIP]
> Payment sessions expire after 5 minutes per Cost+ standards. The module also sends itemized order lines (products and shipping) to Cost+ for detailed transaction records.

## 5. Webhook Configuration

The webhook URL is automatically generated by Drupal Commerce:

```
https://your-store.com/payment/notify/{gateway_machine_name}
```

For example: `https://your-store.com/payment/notify/nopayn`

This URL must be accessible from the internet without authentication. The module always verifies payment status via the API — it never trusts the webhook payload alone.

## Manual Capture

When manual capture is enabled for credit cards:

1. Customer's card is **authorized** (funds reserved) during checkout
2. Capture occurs automatically when the order transitions to **Fulfilled**
3. If the order is cancelled, the authorization is **voided** via webhook

> [!TIP]
> Use manual capture if you want to only charge customers when their order ships. This is useful for merchants with longer fulfillment times.

## Refunds

Refunds can be processed directly from the Commerce admin panel. Both full and partial refunds are supported.

## Database Tables

The module creates two tables for tracking:

| Table | Purpose |
|---|---|
| `nopayn_transactions` | Tracks payment orders created with the Cost+ API |
| `nopayn_refunds` | Records refund operations for audit purposes |

## Uninstallation

```bash
drush pmu commerce_nopayn -y
drush cr
```

> [!CAUTION]
> Uninstalling the module will drop the `nopayn_transactions` and `nopayn_refunds` tables. Make sure to export any data you need before uninstalling.

## Test and Launch

Place a few test transactions to ensure everything works smoothly. Set the gateway **Mode** to **Test** and verify both successful and failed payments before switching to **Live**.

## Support

Need help? Reach out to our support team at **support@costplus.io**.
