# Run a bank check

Run 3-D Secure through your own payment provider on Provenance's approval page, while the person who approved the cart is still there.

*Available on Pro, Growth and Enterprise.*

An agent's checkout has no cardholder browser at your store, so your payment provider's 3-D Secure has nowhere to ask the person. The person is on Provenance's approval page, approving the cart with a passkey. A bank check runs your provider's 3-D Secure there: your server calls your provider with the card you hold, and when the card's bank asks for a challenge, the approval page shows the bank's own screen in a frame.

**Before you begin:** the bank check is off until this deployment confirms your provider's adapter in that provider's sandbox; until then, asking for one answers 503 `threeds_bank_step_not_configured` or `threeds_provider_not_configured`. It needs a webhook endpoint subscribed to `authorize.checkout_approval.threeds_requested`, and the Pro plan or higher. Card numbers never reach Provenance.

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_ent_E7nT2vQ9bW4mK8sYd3cFjLh6gAe1pR5x
```

## 1. Ask for a bank check

Add `bank_check` with your provider when you create the approval with [`POST /v1/authorize/checkout_approvals`](https://provenanceauth.com/docs/api/checkout-approvals.md#post-v1-authorize-checkout-approvals), or when you send the cart to [`POST /v1/authorize/checkout_assessments`](https://provenanceauth.com/docs/api/assessments.md#post-v1-authorize-checkout-assessments) (it rides on a challenge's approval). The providers are Checkout.com, Adyen, Cybersource and Stripe.

**curl**

```bash norun
curl -s -X POST $PROVENANCE_API/v1/authorize/checkout_approvals \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "cart": { "order_id": "ord_8812", "total": 4250, "currency": "USD", "merchant_id": "harborbean", "origin": "https://harborbean.example" },
        "display": { "merchant_name": "Harbor Bean" }, "retry_url": "https://harborbean.example/checkout",
        "bank_check": { "provider": "adyen" } }'
```

**Node**

```ts
const approval = await (
  await fetch(`${process.env.PROVENANCE_API}/v1/authorize/checkout_approvals`, {
    method: "POST",
    headers: { Authorization: `Bearer ${process.env.PROVENANCE_KEY}`, "Content-Type": "application/json" },
    body: JSON.stringify({ cart, display: { merchant_name: "Harbor Bean" }, retry_url: "https://harborbean.example/checkout", bank_check: { provider: "adyen" } }),
  })
).json();
```

**Python**

```python
approval = httpx.post(
    f"{api}/v1/authorize/checkout_approvals",
    headers={"Authorization": f"Bearer {key}"},
    json={"cart": cart, "display": {"merchant_name": "Harbor Bean"}, "retry_url": "https://harborbean.example/checkout", "bank_check": {"provider": "adyen"}},
).json()
```

The approval's `bank_check.state` reads `awaiting_approval` until the person decides. A decline never starts it (`not_started`).

## 2. Start 3-D Secure when the person approves

When the person approves, the approval is final, and you get `authorize.checkout_approval.threeds_requested` with:

| Field | What it is |
| --- | --- |
| `requestor_data` | The 3DS Requestor fields: the FIDO data of the passkey that approved (`threeDSRequestorAuthenticationInfo`, in the FIDO Alliance's EMV 3DS format) and the person's browser fields (`browser`) |
| `provider_fields` | The same, under your provider's own field names, to merge into your authentication request beside the card and your merchant details |
| `provider_carries_fido_data` | `false` for Stripe, whose API has no field for the FIDO data |
| `result_path` | Where to report what your provider says |

Call your provider's standalone 3-D Secure from your server with those fields and the card you hold: Checkout.com Sessions, Adyen with `authenticationOnly`, Cybersource Payer Authentication or Stripe. The passkey's public key in the FIDO data is for the card's bank only: pass it to your provider unchanged.

A Stripe store whose provider allows it can run the authentication at another provider and bring the result to its Stripe charge with `stripeThreeDSImport(outcome, cryptogram)` from `@provenanceauth/rails/threeds`, on your own server.

## 3. Report your provider's answer

Send what your provider said to [`POST /v1/authorize/checkout_approvals/{id}/threeds_results`](https://provenanceauth.com/docs/api/checkout-approvals.md#post-v1-authorize-checkout-approvals-id-threeds-results), as its own response or normalised:

**curl**

```bash norun
curl -s -X POST $PROVENANCE_API/v1/authorize/checkout_approvals/$CHECKOUT_APPROVAL_ID/threeds_results \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "provider_response": { "resultCode": "AuthenticationFinished", "threeDS2Result": { "transStatus": "Y", "eci": "05" } } }'
```

**Node**

```ts
await fetch(`${process.env.PROVENANCE_API}/v1/authorize/checkout_approvals/${approvalId}/threeds_results`, {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.PROVENANCE_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({ provider_response: adyenResponse }),
});
```

**Python**

```python
httpx.post(
    f"{api}/v1/authorize/checkout_approvals/{approval_id}/threeds_results",
    headers={"Authorization": f"Bearer {key}"},
    json={"provider_response": adyen_response},
)
```

- **No challenge:** the outcome is recorded at once (`state: completed`), and the approval page says the bank confirmed the payment.
- **A challenge** (`trans_status: "C"` with an https `challenge`, or your provider's challenge response): the approval page frames the bank's page. When your provider tells you the result, report it the same way.
- **Declined or unavailable:** the page says the bank didn't confirm. The approval still stands; you decide what happens next.

Authorize your payment with the cryptogram and ECI your provider gave you. Provenance keeps the transaction status, the ECI, the authentication id and the message version, never the cryptogram or a card number, and sends `authorize.checkout_approval.threeds_completed`. A check with no result after the window (10 minutes by default) reads `timed_out`, and a late result answers 409 `threeds_bank_check_closed`.

## 4. Read the outcome

[`GET /v1/authorize/checkout_approvals/{id}`](https://provenanceauth.com/docs/api/checkout-approvals.md#get-v1-authorize-checkout-approvals-id) carries `bank_check`: the provider, the state and the `outcome`. The 3DS Requestor data alone, with `?auth_method=07` for the signed FIDO data, is [`GET /v1/authorize/checkout_approvals/{id}/threeds_requestor_data`](https://provenanceauth.com/docs/api/evidence-packs.md#get-v1-authorize-checkout-approvals-id-threeds-requestor-data).

The card networks set the rules for what an issuer's authentication means for a disputed payment; your provider can tell you how they apply to your account.

## Errors you might see

| Code | When |
| --- | --- |
| `threeds_bank_step_not_configured` (503) | The bank check isn't on for this deployment yet |
| `threeds_provider_not_configured` (503) | Your provider's adapter isn't confirmed here yet |
| `plan_required` (402) | Your plan is below Pro |
| `threeds_bank_check_closed` (409) | No bank check is waiting for a result: it already has one, it timed out, or the person declined |

## See also

- [Chargeback evidence](https://provenanceauth.com/docs/authorize/guides/chargeback-evidence.md)
- [Approval context](https://provenanceauth.com/docs/concepts/approval-context.md)
- [Assess checkouts](https://provenanceauth.com/docs/authorize/guides/assess-checkouts.md)
