# Dual Flow

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

# Dual Flow

Similarly to the previous three guides above, we will also be able to use the `Billing Request with Actions` in order to request a Pay By Bank and create a Direct Debit mandate. We'll be able to create both requests at the same time within one flow.

By combining both a `payment_request` as well as a `mandate_request` in the API request, we'll be able to omit having to pass the customer's bank account details, as those would be retrieved automatically from the Pay By Bank.

In order to complete all the actions on the `mandate_request` we'll need to pass all required `customer_billing_details` including the payer's billing address.

> **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
\
        \},
        "mandate_request": \
        \},
        "actions": \,
                "customer_billing_detail": \
            \},
            "select_institution": \,
            "bank_authorisation_redirect_uri": "https://pay.gocardless.com/billing/static/thankyou",
            "create_bank_authorisation": true
        \},
        "links": \
    \}
\}

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

```php
\$client->billingRequestsWithActions()->create([
"params" => [
"payment_request" => [
"description" => "Pay By Bank",
"amount" => 123,
"currency" => "GBP",
"metadata" => [
"internal_payment_id" => "ID123"
]
],
"mandate_request" => [
"currency" => "GBP",
"scheme" => "bacs",
"verify" => "recommended",
"metadata" => [
"mandate_metadata" => "ID456"
]
],
"actions" => [
"collect_customer_details" => [
"customer" => [
"given_name" => "Alice",
"family_name" => "Smith",
"email" => "alice.smith@example.com"
],
"customer_billing_detail" => [
"address_line1" => "Street 123",
"city" => "London"
]
],
"select_institution" => [
"institution" => "INSTITUTION_ID123",
"country_code" => "GB"
],
"bank_authorisation_redirect_uri" => "https://pay.gocardless.com/billing/static/thankyou",
"create_bank_authorisation" => true
],
"links" => [
"creditor" => "CR123"
]
]
]);
```

```python
client.billing_requests_with_actions.create(params=\
\},
"mandate_request": \
\},
"actions": \,
"customer_billing_detail": \
\},
"select_institution": \,
"bank_authorisation_redirect_uri": "https://pay.gocardless.com/billing/static/thankyou",
"create_bank_authorisation": True
\},
"links": \
\})
```

```ruby
@client.billing_requests_with_actions.create(
params: \
\},
mandate_request: \
\},
actions: \,
customer_billing_detail: \
\},
select_institution: \,
bank_authorisation_redirect_uri: "https://pay.gocardless.com/billing/static/thankyou",
create_bank_authorisation: true
\},
links: \
\}
)
```

```java
BillingRequestWithActions response = client.billingRequestsWithActions().create()
.withPaymentRequestDescription("Pay By Bank")
.withPaymentRequestAmount(123)
.withPaymentRequestCurrency("GBP")
.withPaymentRequestMetadata("internal_payment_id", "ID123")
.withMandateRequestCurrency("GBP")
.withMandateRequestScheme("bacs")
.withMandateRequestVerify("recommended")
.withMandateRequestMetadata("mandate_metadata", "ID456")
.withActionsCollectCustomerDetailsCustomerGivenName("Alice")
.withActionsCollectCustomerDetailsCustomerFamilyName("Smith")
.withActionsCollectCustomerDetailsCustomerEmail("alice.smith@example.com")
.withActionsCollectCustomerDetailsCustomerBillingDetailAddressLine1("Street 123")
.withActionsCollectCustomerDetailsCustomerBillingDetailCity("London")
.withActionsSelectInstitutionInstitution("INSTITUTION_ID123")
.withActionsSelectInstitutionCountryCode("GB")
.withActionsBankAuthorisationRedirectUri("https://pay.gocardless.com/billing/static/thankyou")
.withActionsCreateBankAuthorisation(true)
.withLinksCreditor("CR123")
.execute();
```

```javascript
const response = await client.billingRequestsWithActions.create(\,
\},
mandate_request: \,
\},
actions: \,
customer_billing_detail: \,
\},
select_institution: \,
bank_authorisation_redirect_uri:
"https://pay.gocardless.com/billing/static/thankyou",
create_bank_authorisation: true,
\},
links: \,
\});
```

```net
var paymentRequest = new GoCardless.Services.BillingRequestWithActionsCreateRequest.BillingRequestWithActionsPaymentRequest
\
\}
\};

var mandateRequest = new GoCardless.Services.BillingRequestWithActionsCreateRequest.BillingRequestWithActionsMandateRequest
\
\}
\};

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

var selectInstitution = new GoCardless.Services.BillingRequestWithActionsCreateRequest.BillingRequestWithActionsActionsSelectInstitution
\;

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

```go
billingRequestWithActionsCreateParams := gocardless.BillingRequestWithActionsCreateParams\\,
\},
MandateRequest: &gocardless.BillingRequestWithActionsCreateParamsMandateRequest\\,
\},
Actions: &gocardless.BillingRequestWithActionsCreateParamsActions\,
CustomerBillingDetail: &gocardless.BillingRequestWithActionsCreateParamsActionsCollectCustomerDetailsCustomerBillingDetail\,
\},
SelectInstitution: &gocardless.BillingRequestWithActionsCreateParamsActionsSelectInstitution\,
BankAuthorisationRedirectUri: "https://pay.gocardless.com/billing/static/thankyou",
CreateBankAuthorisation: true,
\},
Links: &gocardless.BillingRequestWithActionsCreateParamsLinks\,
\}

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 '\
\},
"mandate_request": \
\},
"actions": \,
"customer_billing_detail": \
\},
"select_institution": \,
"bank_authorisation_redirect_uri": "https://pay.gocardless.com/billing/static/thankyou",
"create_bank_authorisation": true
\},
"links": \
\}
\}'
```

We can see that the Billing Request is still in a `pending` status. This means that the Direct Debit mandate has not yet been created.

Only if the customer approved the Pay By Bank request by authorising the bank authorisation either via their mobile banking app or via desktop, we'll then see that the mandate was created.

The customer will be able to approve this request by being redirected to the `url` parameter.

- In a mobile-to-mobile flow we'd ideally use a call-to-action so that the customer is immediately redirected to this link after they clicked on a button.
- In a desktop-to-mobile flow, we could use the `qr_code_url` instead. This will allow the customer to scan the qr code on your website using their mobile device in order to then authorise the Pay By Bank request via their banking app.

Listening to the `bank_authorisation_authorised` [webhook](/docs/api-reference/bank-authorisation#get-a-bank-authorisation) allows us to make sure that the customer has approved the payment request.

Listening to the `payment_confirmed` [webhook](/docs/api-reference/events/payments#confirmed) notifies us that the payment has been successfully collected.

Once the customer had approved the bank authorisation, the status of the Billing Request would then move from `pending` to `fulfilled`.

The Direct Debit mandate will be created.

## What's next?

  
#### [Handling Webhooks](/docs/gc-embed/handling-webhooks)

Listen to webhooks to track authorisation, payment confirmation, and mandate creation.

  
#### [Reconciling Payouts](/docs/gc-embed/reconciling-payouts)

Use the Payout Items API to reconcile your merchants' payouts.