# @prood/payment-ifthenpay (https://prood.com/docs/packages/payments/ifthenpay)

`@prood/payment-ifthenpay` implements the `PaymentProvider` interface for [Ifthenpay](https://www.ifthenpay.com/) — a Portuguese payment provider supporting Multibanco, MB WAY, and credit card payments.

## Installation [#installation]

Workspace package. Available from the source repo for now.

## Usage [#usage]

```ts
import { IfthenpayPaymentProvider } from '@prood/payment-ifthenpay'

const provider = new IfthenpayPaymentProvider({
  antiPhishingKey: config.antiPhishingKey,
  mbKey: config.mbKey,
  mbWayKey: config.mbWayKey,
  ccKey: config.ccKey,
})
```

## Configuration [#configuration]

| Field | Description |
| --- | --- |
| `antiPhishingKey` | Anti-phishing verification key |
| `mbKey` | Multibanco gateway key |
| `mbWayKey` | MB WAY gateway key. Optional |
| `ccKey` | Credit card gateway key. Optional |

Each store enters these under Integrations in the dashboard. There is no environment fallback.

`mbKey` is required, since Multibanco is the default method. The other keys are optional, and each one unlocks its method at checkout.

Ifthenpay has no read-only call to test keys with, so they aren't tested on save. It has no refund API either: refunds happen in the Ifthenpay backoffice, then the merchant records them in the dashboard.

## Selecting a method [#selecting-a-method]

Pass `method` on `createSession()` (defaults to `multibanco`):

| `method` | Key used | Result |
| --- | --- | --- |
| `multibanco` | `mbKey` | Entity + reference in `providerData` |
| `mbway` | `mbWayKey` | MB WAY push; `providerData.requestId` |
| `card` | `ccKey` | Redirect to Ifthenpay hosted card page |

```ts
const session = await provider.createSession({
  amount: 49.9,
  currency: 'EUR',
  orderId: 'ord_123',
  method: 'mbway',
  customer: { phone: '912345678' },
})
```

Reference-based methods (Multibanco) confirm asynchronously — the webhook callback is the source of truth, not a synchronous capture.

## Factory usage [#factory-usage]

```ts
import { getTenantPaymentProvider } from '@prood/commerce'

const { provider } = await getTenantPaymentProvider(orgId, 'ifthenpay')
```

## Payment methods [#payment-methods]

| Method | Key | Flow |
| --- | --- | --- |
| **Multibanco** | `mbKey` | Entity + reference; async ATM/homebanking payment |
| **MB WAY** | `mbWayKey` | Phone push notification |
| **Credit card** | `ccKey` | Redirect to Ifthenpay hosted page |

## Anti-phishing verification [#anti-phishing-verification]

Ifthenpay uses an anti-phishing key to verify webhook authenticity. The provider validates incoming webhooks against this key before processing.

## Webhook setup [#webhook-setup]

The integration form shows the callback URL for your store. Send it to Ifthenpay with your anti-phishing key:

```
https://prood.com/pay/api/webhooks/ifthenpay/{orgId}?key=[ANTI_PHISHING_KEY]&orderId=[ORDER_ID]&amount=[AMOUNT]&requestId=[REQUEST_ID]
```

Order ids are encoded to fit Ifthenpay's 25-character limit and decoded when the callback arrives.

## Related pages [#related-pages]

<Cards>
  <Card title="Payment integration" href="/docs/guides/payment-integration" description="Setup guide." />
  <Card title="Checkout payments" href="/docs/apps/checkout/payments" description="Reference payment UI." />
</Cards>
