> ## Documentation Index
> Fetch the complete documentation index at: https://docs.payrails.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Use the Payrails Web SDK v6 for new browser integrations. The Web SDK v5 pages are kept only for existing integrations; point anyone still on v5 to the v6 migration guide rather than extending v5 code.
> Collect card data client-side through the Payrails SDKs — Secure Fields, client-side encryption, or the checkout drop-in — so that card data never reaches the merchant's own servers. Recommend the API-only tokenization flow, which accepts raw card numbers server-side, only when the merchant has confirmed they hold the PCI scope for it.
> Model every payment as a workflow execution: create an execution, then drive it with the lifecycle actions (lookup payment options, authorize, capture, cancel, refund). Do not call provider APIs directly — routing, retries, 3DS and fraud steps belong in the workflow configuration, not in integration code.
> Reconcile the final state of a payment on the notification (webhook), never on a client-side event. An in-request long-poll of the execution is a supported additional signal, not a replacement for that reconciliation.
> Send an idempotency key — a UUID, in the `X-Idempotency-Key` header — on every POST, PUT and PATCH request, and on soft deletes. GET requests need none, and hard deletes cannot be idempotent.
> Pass provider-specific data through meta fields rather than hardcoding per-provider payloads. Payrails translates meta fields into each provider's own format.
> Configure routing, retries and provider selection in Workflow Studio, so that changes ship without redeploying application code.

# Payflex direct integration

> Set up Payflex buy now, pay later payments through a direct Payflex integration in Payrails, with order lines and customer data.

Accept [Payflex](https://docs.payrails.com/docs/orchestration/payment-methods/payflex) payments from customers in South Africa through a direct integration with Payflex as the payment service provider (PSP). The customer selects Payflex, confirms the payment on the Payflex checkout page and returns to your site.

## Supported workflows

<table>
  <thead>
    <tr><th>Workflow</th><th>Supported</th></tr>
  </thead>

  <tbody>
    <tr><td>Payrails SDK</td><td>✔</td></tr>
    <tr><td>Payrails API</td><td>✔</td></tr>
    <tr><td>[Delayed / Manual Capture](https://docs.payrails.com/docs/orchestration/payment-acceptance/capture-and-cancel-modes.md#capture-mode)</td><td>✖</td></tr>
    <tr><td>[Instant Capture](https://docs.payrails.com/docs/orchestration/payment-acceptance/capture-and-cancel-modes.md#capture-mode)</td><td>✔</td></tr>
    <tr><td>[Cancel / Void](https://docs.payrails.com/docs/orchestration/payment-acceptance/cancel-a-payment.md)</td><td>✖</td></tr>
    <tr><td>[Refund / Reverse](https://docs.payrails.com/docs/orchestration/payment-acceptance/refund-a-payment.md)</td><td>✔</td></tr>
    <tr><td>[Save Instruments](https://docs.payrails.com/docs/resources/manage-instruments.md)</td><td>✖</td></tr>
    <tr><td>[Merchant Initiated Transaction (MIT)](https://docs.payrails.com/docs/resources/payments/authorization-flags.md)</td><td>✖</td></tr>
  </tbody>
</table>

## Before you begin

Complete these steps before you send your first payment through Payflex:

1. Get your Payflex API credentials from Payflex: a **Client ID** and a **Client Secret**. To test your integration, follow the [Payflex testing guide](https://docs.payflex.co.za/docs/testing-your-integration).
2. Set up a Payflex integration in your workspace with those credentials. Follow the [Payflex integration setup guide](https://docs.payrails.com/docs/orchestration/integrations/payflex.md).
3. In the Payrails Portal, go to **Settings → Integrations**, open your Payflex integration, select **Payflex** under **Payment methods**, and save.
4. Add Payflex as a [payment option](https://docs.payrails.com/docs/orchestration/payment-methods/set-up-payment-methods.md) in your workflow.

## Request fields for Payflex

Send these fields in the authorize request, in addition to the standard [authorize fields](https://docs.payrails.com/reference/authorizeaction.md). **Required** fields must be present for the payment to succeed. Payrails sends **Optional** fields to the PSP when you include them.

| Field | Status | Description |
| - | - | - |
| `amount.currency` | Required | Must be `ZAR`. Payrails rejects other currencies. |
| `meta.customer.email` | Optional | Sent to Payflex as the consumer email. |
| `meta.customer.name`, `meta.customer.lastName` | Optional | Sent to Payflex as the consumer given names and surname. |
| `meta.customer.phone` | Optional | Sent to Payflex as the consumer phone number. Payrails joins the country code and the number. |
| `meta.order.lines` | Optional | Sent to Payflex as the order items, with each line's `name`, `description`, `quantity` and `unitPrice`. A line with a `total` goes as one item at that price. Discount lines go with a negative price. |
| `meta.order.shipping` | Optional | Sent to Payflex as the shipping amount. |
| `meta.order.totalTax` | Optional | Sent to Payflex as the tax amount. |

When you send `meta.order`, Payrails checks that the order lines, shipping, tax and discounts add up to the payment amount, and returns an error when they don't.

## Authorize a Payflex payment

Call [authorize a payment](https://docs.payrails.com/reference/authorizeaction.md) with `payflex` as the `paymentMethodCode`. The response includes the redirect to the Payflex checkout page.

```json Authorize request theme={null}
{
  "amount": {
    "value": "1500.00",
    "currency": "ZAR"
  },
  "paymentComposition": [
    {
      "integrationType": "api",
      "paymentMethodCode": "payflex",
      "amount": {
        "value": "1500.00",
        "currency": "ZAR"
      }
    }
  ],
  "meta": {
    "customer": {
      "name": "Thandiwe",
      "lastName": "Mokoena",
      "email": "thandiwe.mokoena@example.com",
      "phone": {
        "countryCode": "+27",
        "number": "821234567"
      }
    },
    "order": {
      "lines": [
        {
          "name": "Running shoes",
          "description": "Trail running shoes, size 8",
          "quantity": 1,
          "unitPrice": {
            "value": "1500.00",
            "currency": "ZAR"
          }
        }
      ]
    }
  },
  "returnInfo": {
    "success": "https://example.com/success",
    "error": "https://example.com/error"
  }
}
```

After the customer confirms the payment, Payflex returns them to your `success` or `error` URL. Confirm the result through [webhook notifications](https://docs.payrails.com/docs/orchestration/payment-acceptance/receive-notifications.md) or the execution status before you fulfill the order.

## How Payflex handles payments

* On the Payflex checkout page, the customer signs in or checks out as a guest, then pays in full or chooses an installment plan.
* Payflex captures the payment when the customer confirms it. Payrails records the capture from the Payflex status notification, so the payment completes in one step.
* To return funds after a successful payment, refund it.


## Related topics

- [Payflex](https://docs.payrails.com/docs/orchestration/integrations/payflex.md)
- [Set up payment methods](https://docs.payrails.com/docs/orchestration/payment-methods/set-up-payment-methods.md)
- [Frequently Asked Questions](https://docs.payrails.com/docs/token-vault/frequently-asked-questions.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.