# Setting Up a DD Mandate

Source: https://docs.gocardless.com/docs/gc-embed/setting-up-mandates-collecting-payments/actions-dd-mandate

# Setting Up a DD Mandate

## What is the aim of this tutorial?

This tutorial aims to familiarise Embed PSP integrators with the `Billing Request with Actions / Billing Request` and will explain setting up either a Pay By Bank, or a Direct Debit mandate and subsequent Direct Debit payment or a Pay By Bank as well as Direct Debit mandate in a dual flow.

## Getting started

For this tutorial, you will need:

- An [API token](/docs/getting-started/set-up#step-by-step-guide)
- The GoCardless client library of your choice configured in your language of choice
- A [Creditor](/docs/api-reference/creditor) to collect payments against

## Billing Request with Actions: Setting up a Direct Debit mandate

We can start by creating a `Billing Request with Actions`. This will allow us to set up a mandate, which is linked to a creditor.

In order to create a mandate, we'll initiate a `mandate_request` and specify the `scheme` (for Pay By Bank it would be a `payment_request`).

In this instance, we are going to use `bacs` for a GBP mandate.

You will need to pass the full payer's billing address to create a `bacs` Direct Debit mandate.

If you want to collect in EUR, use `sepa_core`. We link the `Billing Request with Actions` to the creditor we wish to pay out to, `CR123`.

With this endpoint you'll be able to complete all required `actions` to fulfil the mandate request in one single API call.

The required `actions` of the `Billing Request` can change depending on the type of payment being taken or set up (e.g a Direct Debit mandate or a Pay By Bank). We don't need to worry about them too much in this tutorial - but it's good to be aware of them! You can read more about them in [billing request actions](/docs/collect-payments/setting-up-mandates) if you're interested.

> **Warning:**
> The customer's email is a mandatory field for Payment Providers using our Embed product.

```http
POST https://api.gocardless.com/billing_requests/create_with_actions HTTP/1.1
Content-Type: application/json
\,
        "actions": \,
                "customer_billing_detail": \
            \},
            "collect_bank_account": \
        \},
        "links": \
    \}
\}

HTTP/1.1 200 OK
Content-Type: application/json
\,
...
\}
```

```php
\$client->billingRequestsWithActions()->create([
"params" => [
"mandate_request" => [
"currency" => "GBP",
"scheme" => "bacs"
],
"actions" => [
"collect_customer_details" => [
"customer" => [
"email" => "alice@example.com",
"given_name" => "Alice",
"family_name" => "Smith"
],
"customer_billing_detail" => [
"address_line1" => "1 Example Street",
"city" => "London",
"postal_code" => "W1 1AA",
"country_code" => "GB"
]
],
"collect_bank_account" => [
"account_number" => "55779911",
"branch_code" => "200000",
"account_holder_name" => "Alice Smith",
"country_code" => "GB"
],
"confirm_payer_details" => []
]
]
]);
```

```python
client.billing_requests_with_actions.create(params=\,
"actions": \,
"customer_billing_detail": \
\},
"collect_bank_account": \,
"confirm_payer_details": \
\}
\})
```

```ruby
@client.billing_requests_with_actions.create(
params: \,
actions: \,
customer_billing_detail: \
\},
collect_bank_account: \,
confirm_payer_details: \
\}
\}
)
```

```java
BillingRequestWithActions response = client.billingRequestsWithActions().create()
.withMandateRequestCurrency("GBP")
.withMandateRequestScheme("bacs")
.withActionsCollectCustomerDetailsCustomerEmail("alice@example.com")
.withActionsCollectCustomerDetailsCustomerGivenName("Alice")
.withActionsCollectCustomerDetailsCustomerFamilyName("Smith")
.withActionsCollectCustomerDetailsCustomerBillingDetailAddressLine1("1 Example Street")
.withActionsCollectCustomerDetailsCustomerBillingDetailCity("London")
.withActionsCollectCustomerDetailsCustomerBillingDetailPostalCode("W1 1AA")
.withActionsCollectCustomerDetailsCustomerBillingDetailCountryCode("GB")
.withActionsCollectBankAccountAccountNumber("55779911")
.withActionsCollectBankAccountBranchCode("200000")
.withActionsCollectBankAccountAccountHolderName("Alice Smith")
.withActionsCollectBankAccountCountryCode("GB")
.withActionsConfirmPayerDetails(true)
.execute();
```

```javascript
const response = await client.billingRequestsWithActions.create(\,
actions: \,
customer_billing_detail: \,
\},
collect_bank_account: \,
confirm_payer_details: \,
\},
\});
```

```net
var mandateRequest = new GoCardless.Services.BillingRequestWithActionsCreateRequest.BillingRequestWithActionsMandateRequest
\;

var collectCustomerDetails = new GoCardless.Services.BillingRequestWithActionsCreateRequest.BillingRequestWithActionsActionsCollectCustomerDetails
\,
CustomerBillingDetail = new GoCardless.Services.BillingRequestWithActionsCreateRequest.BillingRequestWithActionsActionsCollectCustomerDetailsCustomerBillingDetail
\
\};

var collectBankAccount = new GoCardless.Services.BillingRequestWithActionsCreateRequest.BillingRequestWithActionsActionsCollectBankAccount
\;

var resp = await gocardless.BillingRequestsWithActions.CreateAsync(
new GoCardless.Services.BillingRequestWithActionsCreateRequest
\
\}
);
```

```go
billingRequestWithActionsCreateParams := gocardless.BillingRequestWithActionsCreateParams\,
Actions: &gocardless.BillingRequestWithActionsCreateParamsActions\,
CustomerBillingDetail: &gocardless.BillingRequestWithActionsCreateParamsActionsCollectCustomerDetailsCustomerBillingDetail\,
\},
CollectBankAccount: &gocardless.BillingRequestWithActionsCreateParamsActionsCollectBankAccount\,
ConfirmPayerDetails: &gocardless.BillingRequestWithActionsCreateParamsActionsConfirmPayerDetails\,
\},
\}

response, err := client.BillingRequestsWithActions.Create(context, billingRequestWithActionsCreateParams)
```

```bash
curl -X POST "https://api.gocardless.com/billing_requests/create_with_actions" \\
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \\
-H "GoCardless-Version: 2015-07-06" \\
-H "Content-Type: application/json" \\
-d '\,
"actions": \,
"customer_billing_detail": \
\},
"collect_bank_account": \,
"confirm_payer_details": \
\}
\}
\}'
```

For the purpose of this tutorial, we will only need to keep track of the mandate ID (`MD123`) from the API response in order to create a Direct Debit payment.

## What's next?

  
#### [Collecting a DD Payment](/docs/gc-embed/setting-up-mandates-collecting-payments/collecting-dd-payment)

Use the mandate ID from the previous step to collect a Direct Debit payment.

  
#### [Pay By Bank](/docs/gc-embed/setting-up-mandates-collecting-payments/actions-instant-payment)

Request a Pay By Bank using a Billing Request with Actions.