> ## Documentation Index
> Fetch the complete documentation index at: https://wpay-feat-edp-guide.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a redirect transaction

> Create a payment with an alternative payment method like PayPal or GoCardless.

A transaction can be created for non-card services by calling the
[`POST /transactions`][api] API. The call requires an `amount`, `currency`, and
a `payment_method` with a `redirect_url`, `country` and `currency`.

At the moment, our API allows you to create transactions for the services below:

* Banked
* GoCardless
* PayPal

<Tip>
  There is little need to use these APIs directly if you are using \[Embed]
  instead. \[Embed] automatically creates transactions against these APIs and can
  even bind them to a previously created buyer.
</Tip>

<Warning>
  Transacting with a non-card account is a 2-step process that requires a
  buyer to be redirected to get explicit authorization.
</Warning>

## Step 1. Initialize a new transaction

The first step is to initialize a new transaction. A `redirect_url` needs to be
provided to redirect the user back to your application after they have approved
the transaction in the external service. The `country` and `currency` are optional
but sometimes are required depending on the service used.

<CodeGroup>
  ```bash cURL
  curl -i -X POST "https://api.example.gr4vy.app/transactions" \
      -H "Authorization: Bearer [JWT_TOKEN]" \
      -H "Content-Type: application/json" \
      -d '{
            "amount": 1299,
            "currency": "AUD",
            "payment_method": {
              "method": "paypal",
              "redirect_url": "https://example.com/complete",
              "country": "AU",
              "currency": "AUD"
            }
          }'
  ```

  ```js Node
  var fetch = require("node-fetch");

  fetch("https://api.example.gr4vy.app/transactions", {
    method: "POST",
    headers: {
      Authorization: "Bearer [JWT_TOKEN]",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      amount: 1299,
      currency: "AUD",
      intent: "capture",
      payment_method: {
        method: "paypal",
        redirect_url: "https://example.com/complete",
        country: "AU",
        currency: "AUD",
      },
    }),
  });
  ```
</CodeGroup>

The API returns a new `transaction` resource for which the `status` is set to
`buyer_approval_pending`.

```json POST /transactions
{
  "type": "transaction",
  "id": "f2164272-9eee-48ec-86d6-74aa2437b25a",
  "created_at": "2021-11-04T09:27:15.642524+00:00",
  "updated_at": "2021-11-04T09:27:21.277277+00:00",
  "amount": 1299,
  "captured_amount": 0,
  "refunded_amount": 0,
  "currency": "AUD",
  "external_identifier": null,
  "status": "buyer_approval_pending",
  "payment_method": {
    "approval_url": "https://www.sandbox.paypal.com/checkoutnow?token=65G62408D47889217",
    "expiration_date": null,
    "external_identifier": null,
    "id": null,
    "label": null,
    "method": "paypal",
    "scheme": null,
    "type": "payment-method"
  },
  "payment_service": {
    "id": "e9bd6ec4-03eb-410c-b655-45b458f185f2",
    "type": "payment-service",
    "payment_service_definition_id": "paypal-paypal",
    "method": "paypal"
  },
  "buyer": null
}
```

<Info>
  **Statuses**

  See our guide on [transaction statuses](/guides/api/resources/transactions/statuses) for more
  details.
</Info>

## Step 2. Redirect the user

For the next step, you will need to redirect the buyer to the URL specified in
the `payment_method.approval_url` field of the response.

The buyer then has to approve the transaction. After this, the buyer is
redirected back to the `redirect_url` you specified earlier. For example:

```
https://example.com/complete?transaction_id=f2164272-9eee-48ec-86d6-74aa2437b25a&transaction_status=authorization_succeeded
```

The `transaction_id` query parameter represents the ID of the transaction and
the `transaction_status` represents the new status of the transaction.

## (Optional) Step 3. Confirm the transaction

Finally, you could make an optional API call to confirm the transaction has been
successfully authorized or captured.

<CodeGroup>
  ```bash cURL
  curl -i -X GET "https://api.example.gr4vy.app/transactions/f2164272-9eee-48ec-86d6-74aa2437b25a" \
      -H "Authorization: Bearer [JWT_TOKEN]"
  ```

  ```js Node
  const fetch = require("node-fetch");

  fetch(
    "https://api.example.gr4vy.app/transactions/f2164272-9eee-48ec-86d6-74aa2437b25a",
    {
      method: "GET",
      headers: {
        Authorization: "Bearer [JWT_TOKEN]",
      },
    }
  );
  ```
</CodeGroup>

The API will return the same `transaction` resource with its updated status.

```json GET /transactions/f2164272-9eee-48ec-86d6-74aa2437b25a {3,12}
{
  "type": "transaction",
  "id": "f2164272-9eee-48ec-86d6-74aa2437b25a",
  "created_at": "2021-11-04T09:27:15.642524+00:00",
  "updated_at": "2021-11-04T09:31:55.414336+00:00",
  "amount": 1299,
  "captured_amount": 0,
  "refunded_amount": 0,
  "currency": "AUD",
  "external_identifier": null,
  "status": "authorization_succeeded",
  "payment_method": {
    "approval_url": "https://www.sandbox.paypal.com/checkoutnow?token=65G62408D47889217",
    "expiration_date": null,
    "external_identifier": null,
    "id": null,
    "label": "sb-fauuj6390384@personal.example.com",
    "method": "paypal",
    "scheme": null,
    "type": "payment-method"
  },
  "payment_service": {
    "id": "e9bd6ec4-03eb-410c-b655-45b458f185f2",
    "type": "payment-service",
    "payment_service_definition_id": "paypal-paypal",
    "method": "paypal"
  },
  "buyer": null
}
```

[api]: /reference/transactions/new-transaction

[guides]: /guides/api/resources/payment-methods/overview
